toolkit/mozapps/extensions/content/newaddon.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial