Skip to content

Commit

Permalink
Remove E4X dependency from KeySnail plugin system
Browse files Browse the repository at this point in the history
Since Mozilla plan to remove E4X from their systems completely (WTF?),
we remove E4X dependency from KeySnail plugin system with this commit.

For plugin developers:

Don't too worry about compatibility issues. Based on a dirty
hack (script-rewriting), *KeySnail still allows you to use XML literal
to express PLUGIN_INFO*. Note that you cannot use most of wonderful
E4X features include expression-expansion, various query expressions,
and so forth.

R.I.P E4X.
  • Loading branch information
mooz committed Sep 1, 2012
1 parent 8e3f4c0 commit dd6ca1f
Show file tree
Hide file tree
Showing 9 changed files with 482 additions and 324 deletions.
60 changes: 23 additions & 37 deletions content/installplugindialog.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
var ksInstallPluginDialog = function () {
var modules;

var dom;
var elementContainer;
var pluginPath;

var defaultIconURL = "chrome://keysnail/skin/script.png";

function setInfo() {
var xml = window.arguments[0].xml;
var pluginInfo = window.arguments[0].pluginInfo;

if (!xml)
if (!pluginInfo)
return;

function setAttributeFromXml(destination, attribute, xml) {
destination.setAttribute(attribute, modules.util.xmlGetLocaleString(xml));
}

setAttributeFromXml(dom["plugin-info-name"] , "value", xml.name);
setAttributeFromXml(dom["plugin-info-description"] , "value", xml.description);
setAttributeFromXml(dom["plugin-info-version"] , "value", xml.version);

dom["plugin-info-icon"].setAttribute("src",
modules.util.xmlGetLocaleString(xml.iconURL) ||
defaultIconURL);
elementContainer["plugin-info-name"].setAttribute("value", pluginInfo.name);
elementContainer["plugin-info-description"].setAttribute("value", pluginInfo.description);
elementContainer["plugin-info-version"].setAttribute("value", pluginInfo.version);
elementContainer["plugin-info-icon"].setAttribute("src", pluginInfo.iconURL);
}

function createScriptItem(aURL) {
Expand All @@ -49,22 +40,19 @@ var ksInstallPluginDialog = function () {
}

function setScriptList() {
var xml = window.arguments[0].xml;
var pluginURL = window.arguments[0].pluginURL;
var pluginInfo = window.arguments[0].pluginInfo;
var pluginURL = window.arguments[0].pluginURL;

if (!xml)
if (!pluginInfo)
return;

var item;

dom["plugin-script-list"].appendChild(
createScriptItem(pluginURL));
elementContainer["plugin-script-list"].appendChild(createScriptItem(pluginURL));

for (let [, script] in Iterator(xml.require.script))
{
dom["plugin-script-list"].appendChild(
createScriptItem(script.text()));
}
pluginInfo.requiredScripts.forEach(function (scriptURL) {
elementContainer["plugin-script-list"].appendChild(createScriptItem(scriptURL));
});
}

var self = {
Expand All @@ -78,13 +66,11 @@ var ksInstallPluginDialog = function () {
"plugin-info-description",
"plugin-script-list",
"plugin-info-version"];
dom = new Object();
elementContainer = new Object();

ids.forEach(
function (id) {
dom[id] = document.getElementById(id);
}
);
ids.forEach(function (id) {
elementContainer[id] = document.getElementById(id);
});

pluginPath = window.arguments[0].pluginPath;
setInfo();
Expand Down Expand Up @@ -114,8 +100,8 @@ var ksInstallPluginDialog = function () {
}();

(function () {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
ksInstallPluginDialog.modules = browserWindow.KeySnail.modules;
})();
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
ksInstallPluginDialog.modules = browserWindow.KeySnail.modules;
})();
2 changes: 1 addition & 1 deletion content/keysnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@
userscript.installPluginAndRequiredFiles({
name : util.getLeafNameFromURL(util.pathToURL(script.path)),
code : script.code,
info : script.info,
pluginInfo : script.pluginInfo,
forceOverWrite : true,
next : function (succeeded) {
if (typeof next === "function")
Expand Down
Loading

0 comments on commit dd6ca1f

Please sign in to comment.