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 const EXPORTED_SYMBOLS = ["LinkHandlerParent"];
9 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
11 ChromeUtils.defineModuleGetter(
14 "resource:///modules/PlacesUIUtils.jsm"
17 let gTestListeners = new Set();
19 class LinkHandlerParent extends JSWindowActorParent {
20 static addListenerForTests(listener) {
21 gTestListeners.add(listener);
24 static removeListenerForTests(listener) {
25 gTestListeners.delete(listener);
28 receiveMessage(aMsg) {
29 let browser = this.browsingContext.top.embedderElement;
34 let win = browser.ownerGlobal;
36 let gBrowser = win.gBrowser;
39 case "Link:LoadingIcon":
44 if (aMsg.data.canUseForTab) {
45 let tab = gBrowser.getTabForBrowser(browser);
46 if (tab.hasAttribute("busy")) {
47 tab.setAttribute("pendingicon", "true");
51 this.notifyTestListeners("LoadingIcon", aMsg.data);
55 // Cache the most recent icon and rich icon locally.
56 if (aMsg.data.canUseForTab) {
57 this.icon = aMsg.data;
59 this.richIcon = aMsg.data;
66 this.setIconFromLink(gBrowser, browser, aMsg.data);
68 this.notifyTestListeners("SetIcon", aMsg.data);
71 case "Link:SetFailedIcon":
76 if (aMsg.data.canUseForTab) {
77 this.clearPendingIcon(gBrowser, browser);
80 this.notifyTestListeners("SetFailedIcon", aMsg.data);
83 case "Link:AddSearch":
88 let tab = gBrowser.getTabForBrowser(browser);
93 if (win.BrowserSearch) {
94 win.BrowserSearch.addEngine(
97 Services.io.newURI(aMsg.data.url)
104 notifyTestListeners(name, data) {
105 for (let listener of gTestListeners) {
106 listener(name, data);
110 clearPendingIcon(gBrowser, aBrowser) {
111 let tab = gBrowser.getTabForBrowser(aBrowser);
112 tab.removeAttribute("pendingicon");
118 { pageURL, originalURL, canUseForTab, expiration, iconURL, canStoreIcon }
120 let tab = gBrowser.getTabForBrowser(browser);
126 this.clearPendingIcon(gBrowser, browser);
131 iconURI = Services.io.newURI(iconURL);
136 if (iconURI.scheme != "data") {
138 Services.scriptSecurityManager.checkLoadURIWithPrincipal(
139 browser.contentPrincipal,
141 Services.scriptSecurityManager.ALLOW_CHROME
149 PlacesUIUtils.loadFavicon(
151 Services.scriptSecurityManager.getSystemPrincipal(),
152 Services.io.newURI(pageURL),
153 Services.io.newURI(originalURL),
163 gBrowser.setIcon(tab, iconURL, originalURL);