|
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/. */ |
|
4 |
|
5 const Cc = Components.classes; |
|
6 const Ci = Components.interfaces; |
|
7 const Cu = Components.utils; |
|
8 |
|
9 Cu.import("resource://gre/modules/Services.jsm"); |
|
10 Cu.import("resource://gre/modules/AddonManager.jsm"); |
|
11 |
|
12 var gAddon = null; |
|
13 |
|
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); |
|
22 |
|
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); |
|
31 |
|
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 } |
|
38 |
|
39 let bundle = Services.strings.createBundle("chrome://mozapps/locale/extensions/newaddon.properties"); |
|
40 |
|
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 } |
|
50 |
|
51 gAddon = aAddon; |
|
52 |
|
53 document.getElementById("addon-info").setAttribute("type", aAddon.type); |
|
54 |
|
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; |
|
60 |
|
61 let name = bundle.formatStringFromName("name", [aAddon.name, aAddon.version], |
|
62 2); |
|
63 document.getElementById("name").value = name; |
|
64 |
|
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 } |
|
71 |
|
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 } |
|
81 |
|
82 var event = document.createEvent("Events"); |
|
83 event.initEvent("AddonDisplayed", true, true); |
|
84 document.dispatchEvent(event); |
|
85 }); |
|
86 } |
|
87 |
|
88 function unload() { |
|
89 AddonManager.removeAddonListener(EnableListener); |
|
90 } |
|
91 |
|
92 function continueClicked() { |
|
93 AddonManager.removeAddonListener(EnableListener); |
|
94 |
|
95 if (document.getElementById("allow").checked) { |
|
96 gAddon.userDisabled = false; |
|
97 |
|
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 } |
|
104 |
|
105 window.close(); |
|
106 } |
|
107 |
|
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 |
|
115 |
|
116 window.close(); |
|
117 |
|
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 } |
|
122 |
|
123 function cancelClicked() { |
|
124 gAddon.userDisabled = true; |
|
125 AddonManager.addAddonListener(EnableListener); |
|
126 |
|
127 document.getElementById("allow").disabled = false; |
|
128 document.getElementById("buttonDeck").selectedPanel = document.getElementById("continuePanel"); |
|
129 } |