]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/addons.jsm
Import r6923 from upstream hg supporting Firefox up to 22.0a1
[dactyl.git] / common / modules / addons.jsm
index 8ea7f8a4a6414a0016ffd0c77f13a9dd9c398d17..2e52a9aaee7f888675b430c852032b193e5f2df5 100644 (file)
@@ -1,17 +1,19 @@
-// Copyright (c) 2009-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2009-2012 Kris Maglione <maglione.k@gmail.com>
 // Copyright (c) 2009-2010 by Doug Kearns <dougkearns@gmail.com>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
 
 try {
 
-Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("addons", {
     exports: ["AddonManager", "Addons", "Addon", "addons"],
-    require: ["services"]
-}, this);
+    require: ["services", "util"]
+});
+
+this.lazyRequire("completion", ["completion"]);
+lazyRequire("template", ["template"]);
 
 var callResult = function callResult(method) {
     let args = Array.slice(arguments, 1);
@@ -144,21 +146,18 @@ var Addon = Class("Addon", {
         this.nodes = {
             commandTarget: this
         };
-        XML.ignoreWhitespace = true;
-        util.xmlToDom(
-            <tr highlight="Addon" key="row" xmlns:dactyl={NS} xmlns={XHTML}>
-                <td highlight="AddonName" key="name"/>
-                <td highlight="AddonVersion" key="version"/>
-                <td highlight="AddonButtons Buttons">
-                    <a highlight="Button" href="javascript:0" key="enable">{_("addon.action.On")}</a>
-                    <a highlight="Button" href="javascript:0" key="disable">{_("addon.action.Off")}</a>
-                    <a highlight="Button" href="javascript:0" key="delete">{_("addon.action.Delete")}</a>
-                    <a highlight="Button" href="javascript:0" key="update">{_("addon.action.Update")}</a>
-                    <a highlight="Button" href="javascript:0" key="options">{_("addon.action.Options")}</a>
-                </td>
-                <td highlight="AddonStatus" key="status"/>
-                <td highlight="AddonDescription" key="description"/>
-            </tr>,
+        DOM.fromJSON(
+            ["tr", { highlight: "Addon", key: "row" },
+                ["td", { highlight: "AddonName", key: "name" }],
+                ["td", { highlight: "AddonVersion", key: "version" }],
+                ["td", { highlight: "AddonButtons Buttons" },
+                    ["a", { highlight: "Button", href: "javascript:0", key: "enable" }, _("addon.action.On")],
+                    ["a", { highlight: "Button", href: "javascript:0", key: "disable" }, _("addon.action.Off")],
+                    ["a", { highlight: "Button", href: "javascript:0", key: "delete" }, _("addon.action.Delete")],
+                    ["a", { highlight: "Button", href: "javascript:0", key: "update" }, _("addon.action.Update")],
+                    ["a", { highlight: "Button", href: "javascript:0", key: "options" }, _("addon.action.Options")]],
+                ["td", { highlight: "AddonStatus", key: "status" }],
+                ["td", { highlight: "AddonDescription", key: "description" }]],
             this.list.document, this.nodes);
 
         this.update();
@@ -188,11 +187,8 @@ var Addon = Class("Addon", {
     compare: function compare(other) String.localeCompare(this.name, other.name),
 
     get statusInfo() {
-        XML.ignoreWhitespace = XML.prettyPrinting = false;
-        default xml namespace = XHTML;
-
-        let info = this.isActive ? <span highlight="Enabled">enabled</span>
-                                 : <span highlight="Disabled">disabled</span>;
+        let info = this.isActive ? ["span", { highlight: "Enabled" }, "enabled"]
+                                 : ["span", { highlight: "Disabled" }, "disabled"];
 
         let pending;
         if (this.pendingOperations & AddonManager.PENDING_UNINSTALL)
@@ -206,8 +202,11 @@ var Addon = Class("Addon", {
         else if (this.pendingOperations & AddonManager.PENDING_UPGRADE)
             pending = ["Enabled", "upgraded"];
         if (pending)
-            return <>{info}&#xa0;(<span highlight={pending[0]}>{pending[1]}</span>
-                                  &#xa0;on <a href="#" dactyl:command="dactyl.restart" xmlns:dactyl={NS}>restart</a>)</>;
+            return [info, " (",
+                    ["span", { highlight: pending[0] }, pending[1]],
+                    " on ",
+                    ["a", { href: "#", "dactyl:command": "dactyl.restart" }, "restart"],
+                    ")"]
         return info;
     },
 
@@ -217,7 +216,8 @@ var Addon = Class("Addon", {
             let node = self.nodes[key];
             while (node.firstChild)
                 node.removeChild(node.firstChild);
-            node.appendChild(util.xmlToDom(<>{xml}</>, self.list.document));
+
+            DOM(node).append(isArray(xml) ? xml : DOM.DOMString(xml));
         }
 
         update("name", template.icon({ icon: this.iconURL }, this.name));
@@ -279,17 +279,14 @@ var AddonList = Class("AddonList", {
     },
 
     message: Class.Memoize(function () {
-
-        XML.ignoreWhitespace = true;
-        util.xmlToDom(<table highlight="Addons" key="list" xmlns={XHTML}>
-                        <tr highlight="AddonHead">
-                            <td>{_("title.Name")}</td>
-                            <td>{_("title.Version")}</td>
-                            <td/>
-                            <td>{_("title.Status")}</td>
-                            <td>{_("title.Description")}</td>
-                        </tr>
-                      </table>, this.document, this.nodes);
+        DOM.fromJSON(["table", { highlight: "Addons", key: "list" },
+                        ["tr", { highlight: "AddonHead" },
+                            ["td", {}, _("title.Name")],
+                            ["td", {}, _("title.Version")],
+                            ["td"],
+                            ["td", {}, _("title.Status")],
+                            ["td", {}, _("title.Description")]]],
+                      this.document, this.nodes);
 
         if (this._addons)
             this._init();
@@ -355,7 +352,7 @@ var Addons = Module("addons", {
                 .toObject())
 }, {
 }, {
-    commands: function (dactyl, modules, window) {
+    commands: function initCommands(dactyl, modules, window) {
         const { CommandOption, commands, completion, io } = modules;
 
         commands.add(["addo[ns]", "ao"],
@@ -456,7 +453,7 @@ var Addons = Module("addons", {
                 });
         });
     },
-    completion: function (dactyl, modules, window) {
+    completion: function initCompletion(dactyl, modules, window) {
         completion.addonType = function addonType(context) {
             let base = ["extension", "theme"];
             function update(types) {
@@ -495,127 +492,7 @@ var Addons = Module("addons", {
     }
 });
 
-if (!services.has("extensionManager"))
-    Components.utils.import("resource://gre/modules/AddonManager.jsm");
-else
-    var AddonManager = {
-        PERM_CAN_UNINSTALL: 1,
-        PERM_CAN_ENABLE: 2,
-        PERM_CAN_DISABLE: 4,
-        PERM_CAN_UPGRADE: 8,
-
-        getAddonByID: function (id, callback) {
-            callback = callback || util.identity;
-            addon = services.extensionManager.getItemForID(id);
-            if (addon)
-                addon = this.wrapAddon(addon);
-            return callback(addon);
-        },
-
-        wrapAddon: function wrapAddon(addon) {
-            addon = Object.create(addon.QueryInterface(Ci.nsIUpdateItem));
-
-            ["aboutURL", "creator", "description", "developers",
-             "homepageURL", "installDate", "optionsURL",
-             "releaseNotesURI", "updateDate"].forEach(function (item) {
-                memoize(addon, item, function (item) this.getProperty(item));
-            });
-
-            update(addon, {
-
-                get permissions() 1 | (this.userDisabled ? 2 : 4),
-
-                appDisabled: false,
-
-                getProperty: function getProperty(property) {
-                    let resource = services.rdf.GetResource("urn:mozilla:item:" + this.id);
-
-                    if (resource) {
-                        let target = services.extensionManager.datasource.GetTarget(resource,
-                            services.rdf.GetResource("http://www.mozilla.org/2004/em-rdf#" + property), true);
-
-                        if (target && target instanceof Ci.nsIRDFLiteral)
-                            return target.Value;
-                    }
-
-                    return "";
-                },
-
-                installLocation: Class.Memoize(function () services.extensionManager.getInstallLocation(this.id)),
-                getResourceURI: function getResourceURI(path) {
-                    let file = this.installLocation.getItemFile(this.id, path);
-                    return services.io.newFileURI(file);
-                },
-
-                get isActive() this.getProperty("isDisabled") != "true",
-
-                uninstall: function uninstall() {
-                    services.extensionManager.uninstallItem(this.id);
-                },
-
-                get userDisabled() this.getProperty("userDisabled") === "true",
-                set userDisabled(val) {
-                    services.extensionManager[val ? "disableItem" : "enableItem"](this.id);
-                }
-            });
-
-            return addon;
-        },
-
-        getAddonsByTypes: function (types, callback) {
-            let res = [];
-            for (let [, type] in Iterator(types))
-                for (let [, item] in Iterator(services.extensionManager
-                            .getItemList(Ci.nsIUpdateItem["TYPE_" + type.toUpperCase()], {})))
-                    res.push(this.wrapAddon(item));
-
-            if (callback)
-                util.timeout(function () { callback(res); });
-            return res;
-        },
-
-        getInstallForFile: function (file, callback, mimetype) {
-            callback({
-                addListener: function () {},
-                install: function () {
-                    services.extensionManager.installItemFromFile(file, "app-profile");
-                }
-            });
-        },
-
-        getInstallForURL: function (url, callback, mimetype) {
-            util.assert(false, _("error.unavailable", config.host, services.runtime.version));
-        },
-
-        observers: [],
-        addAddonListener: function (listener) {
-            observer.listener = listener;
-            function observer(subject, topic, data) {
-                if (subject instanceof Ci.nsIUpdateItem)
-                    subject = AddonManager.wrapAddon(subject);
-
-                if (data === "item-installed")
-                    listener.onInstalling(subject, true);
-                else if (data === "item-uninstalled")
-                    listener.onUnistalling(subject, true);
-                else if (data === "item-upgraded")
-                    listener.onInstalling(subject, true);
-                else if (data === "item-enabled")
-                    listener.onEnabling(subject, true);
-                else if (data === "item-disabled")
-                    listener.onDisabling(subject, true);
-            }
-            services.observer.addObserver(observer, "em-action-requested", false);
-            this.observers.push(observer);
-        },
-        removeAddonListener: function (listener) {
-            this.observers = this.observers.filter(function (observer) {
-                if (observer.listener !== listener)
-                    return true;
-                services.observer.removeObserver(observer, "em-action-requested");
-            });
-        }
-    };
+Components.utils.import("resource://gre/modules/AddonManager.jsm", this);
 
 endModule();