diff options
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/browser-addons.js | 110 |
1 files changed, 87 insertions, 23 deletions
diff --git a/browser/base/content/browser-addons.js b/browser/base/content/browser-addons.js index 1e97428e24..e00952b2dc 100644 --- a/browser/base/content/browser-addons.js +++ b/browser/base/content/browser-addons.js @@ -618,7 +618,6 @@ var gXPInstallObserver = { break; } case "addon-install-blocked": { - await window.ensureCustomElements("moz-support-link"); // Dismiss the progress notification. Note that this is bad if // there are multiple simultaneous installs happening, see // bug 1329884 for a longer explanation. @@ -1089,27 +1088,18 @@ var BrowserAddonUI = { return { remove: result === 0, report: checkboxState.value }; }, - async reportAddon(addonId, reportEntryPoint) { + async reportAddon(addonId, _reportEntryPoint) { let addon = addonId && (await AddonManager.getAddonByID(addonId)); if (!addon) { return; } - // Do not open an additional about:addons tab if the abuse report should be - // opened in its own tab. - if (lazy.AbuseReporter.amoFormEnabled) { - const amoUrl = lazy.AbuseReporter.getAMOFormURL({ addonId }); - window.openTrustedLinkIn(amoUrl, "tab", { - // Make sure the newly open tab is going to be focused, independently - // from general user prefs. - forceForeground: true, - }); - return; - } - - const win = await BrowserOpenAddonsMgr("addons://list/extension"); - - win.openAbuseReport({ addonId, reportEntryPoint }); + const amoUrl = lazy.AbuseReporter.getAMOFormURL({ addonId }); + window.openTrustedLinkIn(amoUrl, "tab", { + // Make sure the newly open tab is going to be focused, independently + // from general user prefs. + forceForeground: true, + }); }, async removeAddon(addonId) { @@ -1137,7 +1127,85 @@ var BrowserAddonUI = { return; } - BrowserOpenAddonsMgr("addons://detail/" + encodeURIComponent(addon.id)); + this.openAddonsMgr("addons://detail/" + encodeURIComponent(addon.id)); + }, + + /** + * Open about:addons page by given view id. + * @param {String} aView + * View id of page that will open. + * e.g. "addons://discover/" + * @param {Object} options + * { + * selectTabByViewId: If true, if there is the tab opening page having + * same view id, select the tab. Else if the current + * page is blank, load on it. Otherwise, open a new + * tab, then load on it. + * If false, if there is the tab opening + * about:addoons page, select the tab and load page + * for view id on it. Otherwise, leave the loading + * behavior to switchToTabHavingURI(). + * If no options, handles as false. + * } + * @returns {Promise} When the Promise resolves, returns window object loaded the + * view id. + */ + openAddonsMgr(aView, { selectTabByViewId = false } = {}) { + return new Promise(resolve => { + let emWindow; + let browserWindow; + + const receivePong = function (aSubject) { + const browserWin = aSubject.browsingContext.topChromeWindow; + if (!emWindow || browserWin == window /* favor the current window */) { + if ( + selectTabByViewId && + aSubject.gViewController.currentViewId !== aView + ) { + return; + } + + emWindow = aSubject; + browserWindow = browserWin; + } + }; + Services.obs.addObserver(receivePong, "EM-pong"); + Services.obs.notifyObservers(null, "EM-ping"); + Services.obs.removeObserver(receivePong, "EM-pong"); + + if (emWindow) { + if (aView && !selectTabByViewId) { + emWindow.loadView(aView); + } + let tab = browserWindow.gBrowser.getTabForBrowser( + emWindow.docShell.chromeEventHandler + ); + browserWindow.gBrowser.selectedTab = tab; + emWindow.focus(); + resolve(emWindow); + return; + } + + if (selectTabByViewId) { + const target = isBlankPageURL(gBrowser.currentURI.spec) + ? "current" + : "tab"; + openTrustedLinkIn("about:addons", target); + } else { + // This must be a new load, else the ping/pong would have + // found the window above. + switchToTabHavingURI("about:addons", true); + } + + Services.obs.addObserver(function observer(aSubject, aTopic) { + Services.obs.removeObserver(observer, aTopic); + if (aView) { + aSubject.loadView(aView); + } + aSubject.focus(); + resolve(aSubject); + }, "EM-loaded"); + }); }, }; @@ -1551,7 +1619,7 @@ var gUnifiedExtensions = { } else { viewID = "addons://list/extension"; } - await BrowserOpenAddonsMgr(viewID); + await BrowserAddonUI.openAddonsMgr(viewID); return; } } @@ -1877,8 +1945,6 @@ var gUnifiedExtensions = { supportPage = null, type = "warning", }) { - window.ensureCustomElements("moz-message-bar"); - const messageBar = document.createElement("moz-message-bar"); messageBar.setAttribute("type", type); messageBar.classList.add("unified-extensions-message-bar"); @@ -1886,8 +1952,6 @@ var gUnifiedExtensions = { messageBar.setAttribute("data-l10n-attrs", "heading, message"); if (supportPage) { - window.ensureCustomElements("moz-support-link"); - const supportUrl = document.createElement("a", { is: "moz-support-link", }); |