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");
108 { pageURL, originalURL, canUseForTab, expiration, iconURL, canStoreIcon }
110 let tab = gBrowser.getTabForBrowser(browser);
116 this.clearPendingIcon(gBrowser, browser);
121 iconURI = Services.io.newURI(iconURL);
126 if (iconURI.scheme != "data") {
128 Services.scriptSecurityManager.checkLoadURIWithPrincipal(
129 browser.contentPrincipal,
131 Services.scriptSecurityManager.ALLOW_CHROME
139 lazy.PlacesUIUtils.loadFavicon(
141 Services.scriptSecurityManager.getSystemPrincipal(),
142 Services.io.newURI(pageURL),
143 Services.io.newURI(originalURL),
153 gBrowser.setIcon(tab, iconURL, originalURL);