2017-01-03 21:55:25 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["ExtensionsUI"];
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
const {EventEmitter} = ChromeUtils.import("resource://gre/modules/EventEmitter.jsm");
|
2017-01-19 05:16:19 +03:00
|
|
|
|
2018-04-11 13:05:56 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
|
|
|
AddonManager: "resource://gre/modules/AddonManager.jsm",
|
|
|
|
AddonManagerPrivate: "resource://gre/modules/AddonManager.jsm",
|
2018-09-19 19:43:11 +03:00
|
|
|
AMTelemetry: "resource://gre/modules/AddonManager.jsm",
|
2018-04-11 13:05:56 +03:00
|
|
|
AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
|
2019-02-27 23:05:38 +03:00
|
|
|
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
2018-04-11 13:05:56 +03:00
|
|
|
ExtensionData: "resource://gre/modules/Extension.jsm",
|
2019-02-27 23:05:38 +03:00
|
|
|
ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.jsm",
|
2019-01-29 04:39:37 +03:00
|
|
|
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
2018-08-31 08:59:17 +03:00
|
|
|
Services: "resource://gre/modules/Services.jsm",
|
2018-04-11 13:05:56 +03:00
|
|
|
});
|
2017-01-19 05:16:19 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "WEBEXT_PERMISSION_PROMPTS",
|
|
|
|
"extensions.webextPermissionPrompts", false);
|
2019-01-29 04:39:37 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "allowPrivateBrowsingByDefault",
|
|
|
|
"extensions.allowPrivateBrowsingByDefault", true);
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "privateNotificationShown",
|
|
|
|
"extensions.privatebrowsing.notification", false);
|
2019-02-27 23:05:38 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "SUPPORT_URL", "app.support.baseURL",
|
|
|
|
"", null, val => Services.urlFormatter.formatURL(val));
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2017-01-20 21:28:47 +03:00
|
|
|
const DEFAULT_EXTENSION_ICON = "chrome://mozapps/skin/extensions/extensionGeneric.svg";
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2017-02-08 23:09:49 +03:00
|
|
|
const BROWSER_PROPERTIES = "chrome://browser/locale/browser.properties";
|
2017-02-23 19:41:17 +03:00
|
|
|
const BRAND_PROPERTIES = "chrome://branding/locale/brand.properties";
|
2017-02-08 23:09:49 +03:00
|
|
|
|
2017-01-03 21:55:25 +03:00
|
|
|
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
function getTabBrowser(browser) {
|
2018-05-22 02:58:23 +03:00
|
|
|
while (browser.ownerGlobal.docShell.itemType !== Ci.nsIDocShell.typeChrome) {
|
|
|
|
browser = browser.ownerGlobal.docShell.chromeEventHandler;
|
2018-04-08 06:38:21 +03:00
|
|
|
}
|
|
|
|
return {browser, window: browser.ownerGlobal};
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var ExtensionsUI = {
|
2017-01-19 05:16:19 +03:00
|
|
|
sideloaded: new Set(),
|
2017-01-20 06:28:08 +03:00
|
|
|
updates: new Set(),
|
2017-02-16 02:40:56 +03:00
|
|
|
sideloadListener: null,
|
2017-02-28 20:08:49 +03:00
|
|
|
histogram: null,
|
2017-01-19 05:16:19 +03:00
|
|
|
|
2018-03-18 03:42:51 +03:00
|
|
|
pendingNotifications: new WeakMap(),
|
|
|
|
|
2017-04-16 00:09:41 +03:00
|
|
|
async init() {
|
2017-02-28 20:08:49 +03:00
|
|
|
this.histogram = Services.telemetry.getHistogramById("EXTENSION_INSTALL_PROMPT_RESULT");
|
|
|
|
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(this, "webextension-permission-prompt");
|
|
|
|
Services.obs.addObserver(this, "webextension-update-permissions");
|
|
|
|
Services.obs.addObserver(this, "webextension-install-notify");
|
|
|
|
Services.obs.addObserver(this, "webextension-optional-permission-prompt");
|
2017-09-08 03:38:55 +03:00
|
|
|
Services.obs.addObserver(this, "webextension-defaultsearch-prompt");
|
2017-01-19 05:16:19 +03:00
|
|
|
|
2017-07-12 00:30:23 +03:00
|
|
|
await Services.wm.getMostRecentWindow("navigator:browser").delayedStartupPromise;
|
2017-04-16 00:09:41 +03:00
|
|
|
|
2017-01-19 05:16:19 +03:00
|
|
|
this._checkForSideloaded();
|
|
|
|
},
|
|
|
|
|
2017-05-10 22:34:17 +03:00
|
|
|
async _checkForSideloaded() {
|
|
|
|
let sideloaded = await AddonManagerPrivate.getNewSideloads();
|
2017-05-10 22:34:17 +03:00
|
|
|
|
2017-05-10 22:34:17 +03:00
|
|
|
if (!sideloaded.length) {
|
|
|
|
// No new side-loads. We're done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ordering shouldn't matter, but tests depend on notifications
|
|
|
|
// happening in a specific order.
|
|
|
|
sideloaded.sort((a, b) => a.id.localeCompare(b.id));
|
|
|
|
|
|
|
|
if (WEBEXT_PERMISSION_PROMPTS) {
|
|
|
|
if (!this.sideloadListener) {
|
|
|
|
this.sideloadListener = {
|
|
|
|
onEnabled: addon => {
|
|
|
|
if (!this.sideloaded.has(addon)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sideloaded.delete(addon);
|
2017-05-15 20:38:33 +03:00
|
|
|
this._updateNotifications();
|
2017-05-10 22:34:17 +03:00
|
|
|
|
|
|
|
if (this.sideloaded.size == 0) {
|
|
|
|
AddonManager.removeAddonListener(this.sideloadListener);
|
|
|
|
this.sideloadListener = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
AddonManager.addAddonListener(this.sideloadListener);
|
2017-01-19 05:16:19 +03:00
|
|
|
}
|
|
|
|
|
2017-05-10 22:34:17 +03:00
|
|
|
for (let addon of sideloaded) {
|
|
|
|
this.sideloaded.add(addon);
|
2017-05-10 22:34:17 +03:00
|
|
|
}
|
2017-05-15 20:38:33 +03:00
|
|
|
this._updateNotifications();
|
2017-05-10 22:34:17 +03:00
|
|
|
}
|
2017-01-19 05:16:19 +03:00
|
|
|
},
|
|
|
|
|
2017-05-15 20:38:33 +03:00
|
|
|
_updateNotifications() {
|
|
|
|
if (this.sideloaded.size + this.updates.size == 0) {
|
|
|
|
AppMenuNotifications.removeNotification("addon-alert");
|
|
|
|
} else {
|
|
|
|
AppMenuNotifications.showBadgeOnlyNotification("addon-alert");
|
|
|
|
}
|
|
|
|
this.emit("change");
|
|
|
|
},
|
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
showAddonsManager(browser, strings, icon, histkey) {
|
2017-02-08 23:09:49 +03:00
|
|
|
let global = browser.selectedBrowser.ownerGlobal;
|
|
|
|
return global.BrowserOpenAddonsMgr("addons://list/extension").then(aomWin => {
|
2018-05-22 02:58:23 +03:00
|
|
|
let aomBrowser = aomWin.docShell.chromeEventHandler;
|
2017-02-28 20:08:49 +03:00
|
|
|
return this.showPermissionsPrompt(aomBrowser, strings, icon, histkey);
|
2017-01-20 06:28:08 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showSideloaded(browser, addon) {
|
|
|
|
addon.markAsSeen();
|
|
|
|
this.sideloaded.delete(addon);
|
2017-05-15 20:38:33 +03:00
|
|
|
this._updateNotifications();
|
2017-01-20 06:28:08 +03:00
|
|
|
|
2017-02-08 23:09:49 +03:00
|
|
|
let strings = this._buildStrings({
|
2017-01-20 06:28:08 +03:00
|
|
|
addon,
|
|
|
|
permissions: addon.userPermissions,
|
|
|
|
type: "sideload",
|
2017-02-08 23:09:49 +03:00
|
|
|
});
|
2018-09-19 19:43:11 +03:00
|
|
|
|
|
|
|
AMTelemetry.recordManageEvent(addon, "sideload_prompt", {
|
2019-01-29 20:32:51 +03:00
|
|
|
num_strings: strings.msgs.length,
|
2018-09-19 19:43:11 +03:00
|
|
|
});
|
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
this.showAddonsManager(browser, strings, addon.iconURL, "sideload")
|
2018-05-13 04:51:32 +03:00
|
|
|
.then(async answer => {
|
|
|
|
if (answer) {
|
|
|
|
await addon.enable();
|
|
|
|
}
|
|
|
|
this.emit("sideload-response");
|
2017-02-28 20:08:49 +03:00
|
|
|
});
|
2017-01-20 06:28:08 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
showUpdate(browser, info) {
|
2019-01-29 20:32:51 +03:00
|
|
|
AMTelemetry.recordInstallEvent(info.install, {
|
|
|
|
step: "permissions_prompt",
|
|
|
|
num_strings: info.strings.msgs.length,
|
|
|
|
});
|
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
this.showAddonsManager(browser, info.strings, info.addon.iconURL, "update")
|
2017-02-08 23:09:49 +03:00
|
|
|
.then(answer => {
|
|
|
|
if (answer) {
|
|
|
|
info.resolve();
|
|
|
|
} else {
|
|
|
|
info.reject();
|
|
|
|
}
|
|
|
|
// At the moment, this prompt will re-appear next time we do an update
|
|
|
|
// check. See bug 1332360 for proposal to avoid this.
|
|
|
|
this.updates.delete(info);
|
2017-05-15 20:38:33 +03:00
|
|
|
this._updateNotifications();
|
2017-02-08 23:09:49 +03:00
|
|
|
});
|
2017-01-03 21:55:25 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
observe(subject, topic, data) {
|
|
|
|
if (topic == "webextension-permission-prompt") {
|
|
|
|
let {target, info} = subject.wrappedJSObject;
|
2017-01-06 03:35:07 +03:00
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
let {browser, window} = getTabBrowser(target);
|
|
|
|
|
2017-01-06 03:35:07 +03:00
|
|
|
// Dismiss the progress notification. Note that this is bad if
|
|
|
|
// there are multiple simultaneous installs happening, see
|
|
|
|
// bug 1329884 for a longer explanation.
|
2018-04-08 06:38:21 +03:00
|
|
|
let progressNotification = window.PopupNotifications.getNotification("addon-progress", browser);
|
2017-01-06 03:35:07 +03:00
|
|
|
if (progressNotification) {
|
|
|
|
progressNotification.remove();
|
|
|
|
}
|
|
|
|
|
2017-03-02 22:30:41 +03:00
|
|
|
info.unsigned = info.addon.signedState <= AddonManager.SIGNEDSTATE_MISSING;
|
2017-05-10 22:34:17 +03:00
|
|
|
if (info.unsigned && Cu.isInAutomation &&
|
|
|
|
Services.prefs.getBoolPref("extensions.ui.ignoreUnsigned", false)) {
|
|
|
|
info.unsigned = false;
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:31:50 +03:00
|
|
|
let strings = this._buildStrings(info);
|
2017-03-02 22:30:41 +03:00
|
|
|
|
2017-03-03 22:05:35 +03:00
|
|
|
// If this is an update with no promptable permissions, just apply it
|
|
|
|
if (info.type == "update" && strings.msgs.length == 0) {
|
|
|
|
info.resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-02 22:30:41 +03:00
|
|
|
let icon = info.unsigned ? "chrome://browser/skin/warning.svg" : info.icon;
|
|
|
|
|
2017-02-28 20:08:49 +03:00
|
|
|
let histkey;
|
|
|
|
if (info.type == "sideload") {
|
|
|
|
histkey = "sideload";
|
|
|
|
} else if (info.type == "update") {
|
|
|
|
histkey = "update";
|
|
|
|
} else if (info.source == "AMO") {
|
|
|
|
histkey = "installAmo";
|
|
|
|
} else if (info.source == "local") {
|
|
|
|
histkey = "installLocal";
|
|
|
|
} else {
|
|
|
|
histkey = "installWeb";
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:51 +03:00
|
|
|
if (info.type == "sideload") {
|
|
|
|
AMTelemetry.recordManageEvent(info.addon, "sideload_prompt", {
|
|
|
|
num_strings: strings.msgs.length,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
AMTelemetry.recordInstallEvent(info.install, {
|
|
|
|
step: "permissions_prompt",
|
|
|
|
num_strings: strings.msgs.length,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
this.showPermissionsPrompt(browser, strings, icon, histkey)
|
2017-02-28 20:08:49 +03:00
|
|
|
.then(answer => {
|
|
|
|
if (answer) {
|
|
|
|
info.resolve();
|
|
|
|
} else {
|
|
|
|
info.reject();
|
|
|
|
}
|
|
|
|
});
|
2017-01-20 06:28:08 +03:00
|
|
|
} else if (topic == "webextension-update-permissions") {
|
2017-02-08 23:09:49 +03:00
|
|
|
let info = subject.wrappedJSObject;
|
2017-02-17 00:41:27 +03:00
|
|
|
info.type = "update";
|
2017-02-08 23:09:49 +03:00
|
|
|
let strings = this._buildStrings(info);
|
|
|
|
|
|
|
|
// If we don't prompt for any new permissions, just apply it
|
|
|
|
if (strings.msgs.length == 0) {
|
|
|
|
info.resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let update = {
|
|
|
|
strings,
|
2019-01-29 20:32:51 +03:00
|
|
|
permissions: info.permissions,
|
|
|
|
install: info.install,
|
2017-02-08 23:09:49 +03:00
|
|
|
addon: info.addon,
|
|
|
|
resolve: info.resolve,
|
|
|
|
reject: info.reject,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.updates.add(update);
|
2017-05-15 20:38:33 +03:00
|
|
|
this._updateNotifications();
|
2017-01-20 21:28:47 +03:00
|
|
|
} else if (topic == "webextension-install-notify") {
|
2017-01-20 08:26:23 +03:00
|
|
|
let {target, addon, callback} = subject.wrappedJSObject;
|
|
|
|
this.showInstallNotification(target, addon).then(() => {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2017-03-24 23:55:09 +03:00
|
|
|
} else if (topic == "webextension-optional-permission-prompt") {
|
|
|
|
let {browser, name, icon, permissions, resolve} = subject.wrappedJSObject;
|
|
|
|
let strings = this._buildStrings({
|
|
|
|
type: "optional",
|
|
|
|
addon: {name},
|
|
|
|
permissions,
|
|
|
|
});
|
2017-04-11 05:12:23 +03:00
|
|
|
|
|
|
|
// If we don't have any promptable permissions, just proceed
|
|
|
|
if (strings.msgs.length == 0) {
|
2017-06-02 16:14:22 +03:00
|
|
|
resolve(true);
|
2017-04-11 05:12:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-03-24 23:55:09 +03:00
|
|
|
resolve(this.showPermissionsPrompt(browser, strings, icon));
|
2017-09-08 03:38:55 +03:00
|
|
|
} else if (topic == "webextension-defaultsearch-prompt") {
|
|
|
|
let {browser, name, icon, resolve, currentEngine, newEngine} = subject.wrappedJSObject;
|
|
|
|
|
|
|
|
let bundle = Services.strings.createBundle(BROWSER_PROPERTIES);
|
|
|
|
|
|
|
|
let strings = {};
|
|
|
|
strings.acceptText = bundle.GetStringFromName("webext.defaultSearchYes.label");
|
|
|
|
strings.acceptKey = bundle.GetStringFromName("webext.defaultSearchYes.accessKey");
|
|
|
|
strings.cancelText = bundle.GetStringFromName("webext.defaultSearchNo.label");
|
|
|
|
strings.cancelKey = bundle.GetStringFromName("webext.defaultSearchNo.accessKey");
|
2018-01-19 21:04:25 +03:00
|
|
|
strings.addonName = name;
|
2017-09-08 03:38:55 +03:00
|
|
|
strings.text = bundle.formatStringFromName("webext.defaultSearch.description",
|
2018-01-19 21:04:25 +03:00
|
|
|
["<>", currentEngine, newEngine], 3);
|
2017-09-08 03:38:55 +03:00
|
|
|
resolve(this.showDefaultSearchPrompt(browser, strings, icon));
|
2017-01-03 21:55:25 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-08 23:09:49 +03:00
|
|
|
// Create a set of formatted strings for a permission prompt
|
|
|
|
_buildStrings(info) {
|
|
|
|
let bundle = Services.strings.createBundle(BROWSER_PROPERTIES);
|
2017-08-02 23:15:30 +03:00
|
|
|
let brandBundle = Services.strings.createBundle(BRAND_PROPERTIES);
|
|
|
|
let appName = brandBundle.GetStringFromName("brandShortName");
|
2018-01-19 21:04:25 +03:00
|
|
|
let info2 = Object.assign({appName}, info);
|
2017-02-24 05:27:34 +03:00
|
|
|
|
2018-01-19 21:04:25 +03:00
|
|
|
let strings = ExtensionData.formatPermissionStrings(info2, bundle);
|
|
|
|
strings.addonName = info.addon.name;
|
2019-02-21 13:36:33 +03:00
|
|
|
strings.learnMore = bundle.GetStringFromName("webextPerms.learnMore");
|
2018-01-19 21:04:25 +03:00
|
|
|
return strings;
|
2017-02-08 23:09:49 +03:00
|
|
|
},
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
async showPermissionsPrompt(target, strings, icon, histkey) {
|
|
|
|
let {browser, window} = getTabBrowser(target);
|
2018-03-18 03:42:51 +03:00
|
|
|
|
|
|
|
// Wait for any pending prompts in this window to complete before
|
|
|
|
// showing the next one.
|
|
|
|
let pending;
|
2018-04-08 06:38:21 +03:00
|
|
|
while ((pending = this.pendingNotifications.get(window))) {
|
2018-03-18 03:42:51 +03:00
|
|
|
await pending;
|
|
|
|
}
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2018-03-18 03:42:51 +03:00
|
|
|
let promise = new Promise(resolve => {
|
|
|
|
function eventCallback(topic) {
|
|
|
|
let doc = this.browser.ownerDocument;
|
|
|
|
if (topic == "showing") {
|
|
|
|
let textEl = doc.getElementById("addon-webext-perm-text");
|
|
|
|
textEl.textContent = strings.text;
|
|
|
|
textEl.hidden = !strings.text;
|
|
|
|
|
|
|
|
let listIntroEl = doc.getElementById("addon-webext-perm-intro");
|
|
|
|
listIntroEl.textContent = strings.listIntro;
|
|
|
|
listIntroEl.hidden = (strings.msgs.length == 0);
|
|
|
|
|
2019-02-21 13:36:33 +03:00
|
|
|
let listInfoEl = doc.getElementById("addon-webext-perm-info");
|
|
|
|
listInfoEl.textContent = strings.learnMore;
|
|
|
|
listInfoEl.href = Services.urlFormatter.formatURLPref("app.support.baseURL") + "extension-permissions";
|
|
|
|
listInfoEl.hidden = (strings.msgs.length == 0);
|
|
|
|
|
2018-03-18 03:42:51 +03:00
|
|
|
let list = doc.getElementById("addon-webext-perm-list");
|
|
|
|
while (list.firstChild) {
|
|
|
|
list.firstChild.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let msg of strings.msgs) {
|
|
|
|
let item = doc.createElementNS(HTML_NS, "li");
|
|
|
|
item.textContent = msg;
|
|
|
|
list.appendChild(item);
|
|
|
|
}
|
|
|
|
} else if (topic == "swapping") {
|
|
|
|
return true;
|
2017-01-03 21:55:25 +03:00
|
|
|
}
|
2018-05-17 21:46:21 +03:00
|
|
|
if (topic == "removed") {
|
2018-03-18 03:42:51 +03:00
|
|
|
Services.tm.dispatchToMainThread(() => {
|
|
|
|
resolve(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
2017-02-08 23:09:49 +03:00
|
|
|
}
|
|
|
|
|
2018-03-18 03:42:51 +03:00
|
|
|
let popupOptions = {
|
|
|
|
hideClose: true,
|
|
|
|
popupIconURL: icon || DEFAULT_EXTENSION_ICON,
|
|
|
|
persistent: true,
|
|
|
|
eventCallback,
|
|
|
|
name: strings.addonName,
|
2018-05-17 21:46:21 +03:00
|
|
|
removeOnDismissal: true,
|
2018-03-18 03:42:51 +03:00
|
|
|
};
|
2017-01-03 21:55:25 +03:00
|
|
|
|
2017-02-08 23:09:49 +03:00
|
|
|
let action = {
|
|
|
|
label: strings.acceptText,
|
|
|
|
accessKey: strings.acceptKey,
|
2017-02-28 20:08:49 +03:00
|
|
|
callback: () => {
|
2017-04-24 20:44:41 +03:00
|
|
|
if (histkey) {
|
|
|
|
this.histogram.add(histkey + "Accepted");
|
|
|
|
}
|
2017-02-28 20:08:49 +03:00
|
|
|
resolve(true);
|
|
|
|
},
|
2017-02-08 23:09:49 +03:00
|
|
|
};
|
|
|
|
let secondaryActions = [
|
|
|
|
{
|
|
|
|
label: strings.cancelText,
|
|
|
|
accessKey: strings.cancelKey,
|
2017-02-28 20:08:49 +03:00
|
|
|
callback: () => {
|
2017-04-24 20:44:41 +03:00
|
|
|
if (histkey) {
|
|
|
|
this.histogram.add(histkey + "Rejected");
|
|
|
|
}
|
2017-02-28 20:08:49 +03:00
|
|
|
resolve(false);
|
|
|
|
},
|
2017-02-08 23:09:49 +03:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
window.PopupNotifications.show(browser, "addon-webext-permissions", strings.header,
|
|
|
|
"addons-notification-icon", action,
|
|
|
|
secondaryActions, popupOptions);
|
2017-09-08 03:38:55 +03:00
|
|
|
});
|
2018-03-18 03:42:51 +03:00
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
this.pendingNotifications.set(window, promise);
|
|
|
|
promise.finally(() => this.pendingNotifications.delete(window));
|
2018-03-18 03:42:51 +03:00
|
|
|
return promise;
|
2017-09-08 03:38:55 +03:00
|
|
|
},
|
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
showDefaultSearchPrompt(target, strings, icon) {
|
2017-09-08 03:38:55 +03:00
|
|
|
return new Promise(resolve => {
|
|
|
|
let popupOptions = {
|
|
|
|
hideClose: true,
|
|
|
|
popupIconURL: icon || DEFAULT_EXTENSION_ICON,
|
2018-11-27 21:05:59 +03:00
|
|
|
persistent: true,
|
2017-09-08 03:38:55 +03:00
|
|
|
removeOnDismissal: true,
|
|
|
|
eventCallback(topic) {
|
2018-01-19 21:04:25 +03:00
|
|
|
if (topic == "removed") {
|
2017-09-08 03:38:55 +03:00
|
|
|
resolve(false);
|
|
|
|
}
|
2018-02-27 23:31:55 +03:00
|
|
|
},
|
|
|
|
name: strings.addonName,
|
2017-09-08 03:38:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let action = {
|
|
|
|
label: strings.acceptText,
|
|
|
|
accessKey: strings.acceptKey,
|
|
|
|
disableHighlight: true,
|
|
|
|
callback: () => {
|
|
|
|
resolve(true);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let secondaryActions = [
|
|
|
|
{
|
|
|
|
label: strings.cancelText,
|
|
|
|
accessKey: strings.cancelKey,
|
|
|
|
callback: () => {
|
|
|
|
resolve(false);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
let {browser, window} = getTabBrowser(target);
|
|
|
|
window.PopupNotifications.show(browser, "addon-webext-defaultsearch", strings.text,
|
|
|
|
"addons-notification-icon", action,
|
|
|
|
secondaryActions, popupOptions);
|
2017-01-03 21:55:25 +03:00
|
|
|
});
|
|
|
|
},
|
2017-01-20 21:28:47 +03:00
|
|
|
|
|
|
|
showInstallNotification(target, addon) {
|
2018-10-08 17:56:39 +03:00
|
|
|
let {window} = getTabBrowser(target);
|
2017-01-20 21:28:47 +03:00
|
|
|
|
2018-04-08 06:38:21 +03:00
|
|
|
let brandBundle = window.document.getElementById("bundle_brand");
|
2017-01-20 21:28:47 +03:00
|
|
|
let appName = brandBundle.getString("brandShortName");
|
2018-04-08 06:38:21 +03:00
|
|
|
let bundle = window.gNavigatorBundle;
|
2017-01-20 21:28:47 +03:00
|
|
|
|
2018-02-27 23:31:55 +03:00
|
|
|
let message = bundle.getFormattedString("addonPostInstall.message1",
|
|
|
|
["<>", appName]);
|
2017-01-20 08:26:23 +03:00
|
|
|
return new Promise(resolve => {
|
2019-02-27 23:05:38 +03:00
|
|
|
// Show or hide private permission ui based on the pref.
|
|
|
|
let checkbox = window.document.getElementById("addon-incognito-checkbox");
|
|
|
|
checkbox.checked = false;
|
2019-03-04 22:00:21 +03:00
|
|
|
checkbox.hidden = allowPrivateBrowsingByDefault;
|
2019-02-27 23:05:38 +03:00
|
|
|
|
|
|
|
async function actionResolve() {
|
|
|
|
if (checkbox.checked) {
|
|
|
|
let perms = {permissions: ["internal:privateBrowsingAllowed"], origins: []};
|
|
|
|
await ExtensionPermissions.add(addon.id, perms);
|
|
|
|
// Reload the extension if it is already enabled. This ensures any change
|
|
|
|
// on the private browsing permission is properly handled.
|
|
|
|
if (addon.isActive) {
|
|
|
|
await addon.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
|
2017-01-20 08:26:23 +03:00
|
|
|
let action = {
|
2019-02-27 23:05:38 +03:00
|
|
|
callback: actionResolve,
|
2017-01-20 08:26:23 +03:00
|
|
|
};
|
2017-01-20 21:28:47 +03:00
|
|
|
|
2017-02-10 02:20:02 +03:00
|
|
|
let icon = addon.isWebExtension ?
|
2018-07-13 14:51:28 +03:00
|
|
|
AddonManager.getPreferredIconURL(addon, 32, window) || DEFAULT_EXTENSION_ICON :
|
2017-02-10 02:20:02 +03:00
|
|
|
"chrome://browser/skin/addons/addon-install-installed.svg";
|
2017-01-20 08:26:23 +03:00
|
|
|
let options = {
|
2018-02-27 23:31:55 +03:00
|
|
|
name: addon.name,
|
2018-10-08 17:56:39 +03:00
|
|
|
message,
|
|
|
|
popupIconURL: icon,
|
2018-10-11 02:40:32 +03:00
|
|
|
onDismissed: () => {
|
|
|
|
AppMenuNotifications.removeNotification("addon-installed");
|
2019-02-27 23:05:38 +03:00
|
|
|
actionResolve();
|
2018-10-11 02:40:32 +03:00
|
|
|
},
|
2017-01-20 08:26:23 +03:00
|
|
|
};
|
2018-10-08 17:56:39 +03:00
|
|
|
AppMenuNotifications.showNotification("addon-installed", action, null, options);
|
2017-01-20 08:26:23 +03:00
|
|
|
});
|
2017-01-20 21:28:47 +03:00
|
|
|
},
|
2019-01-29 04:39:37 +03:00
|
|
|
|
|
|
|
promisePrivateBrowsingNotification(window) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let action = {
|
2019-02-15 17:32:31 +03:00
|
|
|
callback: () => {
|
|
|
|
resolve();
|
|
|
|
AMTelemetry.recordActionEvent({
|
|
|
|
object: "doorhanger",
|
|
|
|
action: "dismiss",
|
|
|
|
view: "privateBrowsing",
|
|
|
|
});
|
|
|
|
},
|
2019-01-29 04:39:37 +03:00
|
|
|
dismiss: false,
|
|
|
|
};
|
|
|
|
let manage = {
|
|
|
|
callback: () => {
|
2019-02-15 17:32:31 +03:00
|
|
|
AMTelemetry.recordActionEvent({
|
|
|
|
object: "doorhanger",
|
|
|
|
action: "manage",
|
|
|
|
view: "privateBrowsing",
|
|
|
|
});
|
2019-02-27 23:05:38 +03:00
|
|
|
// Callback may happen in a different window, use the top window
|
|
|
|
// for the new tab.
|
|
|
|
let win = BrowserWindowTracker.getTopWindow();
|
|
|
|
win.BrowserOpenAddonsMgr("addons://list/extension");
|
2019-01-29 04:39:37 +03:00
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
dismiss: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
popupIconURL: "chrome://browser/skin/addons/addon-private-browsing.svg",
|
|
|
|
onDismissed: () => {
|
|
|
|
AppMenuNotifications.removeNotification("addon-private-browsing");
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
};
|
2019-02-27 23:05:38 +03:00
|
|
|
window.document.getElementById("addon-private-browsing-learn-more")
|
|
|
|
.setAttribute("href", SUPPORT_URL + "extensions-pb");
|
2019-01-29 04:39:37 +03:00
|
|
|
AppMenuNotifications.showNotification("addon-private-browsing", manage, action, options);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showPrivateBrowsingNotification(window) {
|
|
|
|
// Show the addons private browsing panel the first time a private window
|
|
|
|
// is opened.
|
|
|
|
if (!allowPrivateBrowsingByDefault && !privateNotificationShown &&
|
|
|
|
PrivateBrowsingUtils.isWindowPrivate(window)) {
|
|
|
|
ExtensionsUI.promisePrivateBrowsingNotification(window).then(() => {
|
|
|
|
Services.prefs.setBoolPref("extensions.privatebrowsing.notification", true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2017-01-03 21:55:25 +03:00
|
|
|
};
|
2017-01-19 05:16:19 +03:00
|
|
|
|
|
|
|
EventEmitter.decorate(ExtensionsUI);
|