toolkit/mozapps/extensions/content/newaddon.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 const Cc = Components.classes;
     6 const Ci = Components.interfaces;
     7 const Cu = Components.utils;
     9 Cu.import("resource://gre/modules/Services.jsm");
    10 Cu.import("resource://gre/modules/AddonManager.jsm");
    12 var gAddon = null;
    14 // If the user enables the add-on through some other UI close this window
    15 var EnableListener = {
    16   onEnabling: function EnableListener_onEnabling(aAddon) {
    17     if (aAddon.id == gAddon.id)
    18       window.close();
    19   }
    20 }
    21 AddonManager.addAddonListener(EnableListener);
    23 function initialize() {
    24   // About URIs don't implement nsIURL so we have to find the query string
    25   // manually
    26   let spec = document.location.href;
    27   let pos = spec.indexOf("?");
    28   let query = "";
    29   if (pos >= 0)
    30     query = spec.substring(pos + 1);
    32   // Just assume the query is "id=<id>"
    33   let id = query.substring(3);
    34   if (!id) {
    35     window.location = "about:blank";
    36     return;
    37   }
    39   let bundle = Services.strings.createBundle("chrome://mozapps/locale/extensions/newaddon.properties");
    41   AddonManager.getAddonByID(id, function initialize_getAddonByID(aAddon) {
    42     // If the add-on doesn't exist or it is already enabled or it cannot be
    43     // enabled then this UI is useless, just close it. This shouldn't normally
    44     // happen unless session restore restores the tab
    45     if (!aAddon || !aAddon.userDisabled ||
    46         !(aAddon.permissions & AddonManager.PERM_CAN_ENABLE)) {
    47       window.close();
    48       return;
    49     }
    51     gAddon = aAddon;
    53     document.getElementById("addon-info").setAttribute("type", aAddon.type);
    55     let icon = document.getElementById("icon");
    56     if (aAddon.icon64URL)
    57       icon.src = aAddon.icon64URL;
    58     else if (aAddon.iconURL)
    59       icon.src = aAddon.iconURL;
    61     let name = bundle.formatStringFromName("name", [aAddon.name, aAddon.version],
    62                                            2);
    63     document.getElementById("name").value = name;
    65     if (aAddon.creator) {
    66       let creator = bundle.formatStringFromName("author", [aAddon.creator], 1);
    67       document.getElementById("author").value = creator;
    68     } else {
    69       document.getElementById("author").hidden = true;
    70     }
    72     let uri = "getResourceURI" in aAddon ? aAddon.getResourceURI() : null;
    73     let locationLabel = document.getElementById("location");
    74     if (uri instanceof Ci.nsIFileURL) {
    75       let location = bundle.formatStringFromName("location", [uri.file.path], 1);
    76       locationLabel.value = location;
    77       locationLabel.setAttribute("tooltiptext", location);
    78     } else {
    79       document.getElementById("location").hidden = true;
    80     }
    82     var event = document.createEvent("Events");
    83     event.initEvent("AddonDisplayed", true, true);
    84     document.dispatchEvent(event);
    85   });
    86 }
    88 function unload() {
    89   AddonManager.removeAddonListener(EnableListener);
    90 }
    92 function continueClicked() {
    93   AddonManager.removeAddonListener(EnableListener);
    95   if (document.getElementById("allow").checked) {
    96     gAddon.userDisabled = false;
    98     if (gAddon.pendingOperations & AddonManager.PENDING_ENABLE) {
    99       document.getElementById("allow").disabled = true;
   100       document.getElementById("buttonDeck").selectedPanel = document.getElementById("restartPanel");
   101       return;
   102     }
   103   }
   105   window.close();
   106 }
   108 function restartClicked() {
   109   let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].
   110                    createInstance(Ci.nsISupportsPRBool);
   111   Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
   112                                "restart");
   113   if (cancelQuit.data)
   114     return; // somebody canceled our quit request
   116   window.close();
   118   let appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
   119                    getService(Components.interfaces.nsIAppStartup);
   120   appStartup.quit(Ci.nsIAppStartup.eAttemptQuit |  Ci.nsIAppStartup.eRestart);
   121 }
   123 function cancelClicked() {
   124   gAddon.userDisabled = true;
   125   AddonManager.addAddonListener(EnableListener);
   127   document.getElementById("allow").disabled = false;
   128   document.getElementById("buttonDeck").selectedPanel = document.getElementById("continuePanel");
   129 }

mercurial