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/. */
7 ChromeUtils.defineESModuleGetters(lazy, {
8 PlacesUIUtils: "resource:///modules/PlacesUIUtils.sys.mjs",
11 let gTestListeners = new Set();
13 export class LinkHandlerParent extends JSWindowActorParent {
14 static addListenerForTests(listener) {
15 gTestListeners.add(listener);
18 static removeListenerForTests(listener) {
19 gTestListeners.delete(listener);
22 receiveMessage(aMsg) {
23 let browser = this.browsingContext.top.embedderElement;
28 let win = browser.ownerGlobal;
30 let gBrowser = win.gBrowser;
33 case "Link:LoadingIcon":
38 if (aMsg.data.canUseForTab) {
39 let tab = gBrowser.getTabForBrowser(browser);
40 if (tab.hasAttribute("busy")) {
41 tab.setAttribute("pendingicon", "true");
45 this.notifyTestListeners("LoadingIcon", aMsg.data);
49 // Cache the most recent icon and rich icon locally.
50 if (aMsg.data.canUseForTab) {
51 this.icon = aMsg.data;
53 this.richIcon = aMsg.data;
60 this.setIconFromLink(gBrowser, browser, aMsg.data);
62 this.notifyTestListeners("SetIcon", aMsg.data);
65 case "Link:SetFailedIcon":
70 if (aMsg.data.canUseForTab) {
71 this.clearPendingIcon(gBrowser, browser);
74 this.notifyTestListeners("SetFailedIcon", aMsg.data);
77 case "Link:AddSearch":
82 let tab = gBrowser.getTabForBrowser(browser);
87 if (win.BrowserSearch) {
88 win.BrowserSearch.addEngine(browser, aMsg.data.engine);
94 notifyTestListeners(name, data) {
95 for (let listener of gTestListeners) {
100 clearPendingIcon(gBrowser, aBrowser) {
101 let tab = gBrowser.getTabForBrowser(aBrowser);
102 tab.removeAttribute("pendingicon");
118 let tab = gBrowser.getTabForBrowser(browser);
124 this.clearPendingIcon(gBrowser, browser);
129 iconURI = Services.io.newURI(iconURL);
134 if (iconURI.scheme != "data") {
136 Services.scriptSecurityManager.checkLoadURIWithPrincipal(
137 browser.contentPrincipal,
139 Services.scriptSecurityManager.ALLOW_CHROME
147 lazy.PlacesUIUtils.loadFavicon(
149 Services.scriptSecurityManager.getSystemPrincipal(),
150 Services.io.newURI(pageURL),
151 Services.io.newURI(originalURL),
161 gBrowser.setIcon(tab, iconURL, originalURL, null, beforePageShow);