Sat, 03 Jan 2015 20:18:00 +0100
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 | // This file is a test-only JSM containing utility methods for |
michael@0 | 6 | // interacting with the add-ons manager. |
michael@0 | 7 | |
michael@0 | 8 | "use strict"; |
michael@0 | 9 | |
michael@0 | 10 | this.EXPORTED_SYMBOLS = [ |
michael@0 | 11 | "AddonTestUtils", |
michael@0 | 12 | ]; |
michael@0 | 13 | |
michael@0 | 14 | const {utils: Cu} = Components; |
michael@0 | 15 | |
michael@0 | 16 | Cu.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 17 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 18 | |
michael@0 | 19 | XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", |
michael@0 | 20 | "resource://gre/modules/AddonManager.jsm"); |
michael@0 | 21 | |
michael@0 | 22 | this.AddonTestUtils = { |
michael@0 | 23 | /** |
michael@0 | 24 | * Uninstall an add-on that is specified by its ID. |
michael@0 | 25 | * |
michael@0 | 26 | * The returned promise resolves on successful uninstall and rejects |
michael@0 | 27 | * if the add-on is not unknown. |
michael@0 | 28 | * |
michael@0 | 29 | * @return Promise<restartRequired> |
michael@0 | 30 | */ |
michael@0 | 31 | uninstallAddonByID: function (id) { |
michael@0 | 32 | let deferred = Promise.defer(); |
michael@0 | 33 | |
michael@0 | 34 | AddonManager.getAddonByID(id, (addon) => { |
michael@0 | 35 | if (!addon) { |
michael@0 | 36 | deferred.reject(new Error("Add-on is not known: " + id)); |
michael@0 | 37 | return; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | let listener = { |
michael@0 | 41 | onUninstalling: function (addon, needsRestart) { |
michael@0 | 42 | if (addon.id != id) { |
michael@0 | 43 | return; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | if (needsRestart) { |
michael@0 | 47 | AddonManager.removeAddonListener(listener); |
michael@0 | 48 | deferred.resolve(true); |
michael@0 | 49 | } |
michael@0 | 50 | }, |
michael@0 | 51 | |
michael@0 | 52 | onUninstalled: function (addon) { |
michael@0 | 53 | if (addon.id != id) { |
michael@0 | 54 | return; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | AddonManager.removeAddonListener(listener); |
michael@0 | 58 | deferred.resolve(false); |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | onOperationCancelled: function (addon) { |
michael@0 | 62 | if (addon.id != id) { |
michael@0 | 63 | return; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | AddonManager.removeAddonListener(listener); |
michael@0 | 67 | deferred.reject(new Error("Uninstall cancelled.")); |
michael@0 | 68 | }, |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | AddonManager.addAddonListener(listener); |
michael@0 | 72 | addon.uninstall(); |
michael@0 | 73 | }); |
michael@0 | 74 | |
michael@0 | 75 | return deferred.promise; |
michael@0 | 76 | }, |
michael@0 | 77 | |
michael@0 | 78 | /** |
michael@0 | 79 | * Install an XPI add-on from a URL. |
michael@0 | 80 | * |
michael@0 | 81 | * @return Promise<addon> |
michael@0 | 82 | */ |
michael@0 | 83 | installXPIFromURL: function (url, hash, name, iconURL, version) { |
michael@0 | 84 | let deferred = Promise.defer(); |
michael@0 | 85 | |
michael@0 | 86 | AddonManager.getInstallForURL(url, (install) => { |
michael@0 | 87 | let fail = () => { deferred.reject(new Error("Add-on install failed.")) }; |
michael@0 | 88 | |
michael@0 | 89 | let listener = { |
michael@0 | 90 | onDownloadCancelled: fail, |
michael@0 | 91 | onDownloadFailed: fail, |
michael@0 | 92 | onInstallCancelled: fail, |
michael@0 | 93 | onInstallFailed: fail, |
michael@0 | 94 | onInstallEnded: function (install, addon) { |
michael@0 | 95 | deferred.resolve(addon); |
michael@0 | 96 | }, |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | install.addListener(listener); |
michael@0 | 100 | install.install(); |
michael@0 | 101 | }, "application/x-xpinstall", hash, name, iconURL, version); |
michael@0 | 102 | |
michael@0 | 103 | return deferred.promise; |
michael@0 | 104 | }, |
michael@0 | 105 | }; |