2018-08-02 07:36:12 +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/. */
|
|
|
|
|
2022-06-06 21:59:44 +03:00
|
|
|
const lazy = {};
|
|
|
|
|
Bug 1834831 - update imports of browser/modules JSMs r=webdriver-reviewers,perftest-reviewers,zeid,extension-reviewers,settings-reviewers,pip-reviewers,credential-management-reviewers,devtools-reviewers,fxview-reviewers,sessionstore-reviewers,tabbrowser-reviewers,whimboo,mhowell,sgalich,robwu,sparky,Standard8,mconley,dao,sclements
Differential Revision: https://phabricator.services.mozilla.com/D179169
2023-06-19 21:44:48 +03:00
|
|
|
ChromeUtils.defineESModuleGetters(lazy, {
|
|
|
|
FaviconLoader: "resource:///modules/FaviconLoader.sys.mjs",
|
|
|
|
});
|
2018-08-02 07:36:12 +03:00
|
|
|
|
2023-03-17 10:46:57 +03:00
|
|
|
export class LinkHandlerChild extends JSWindowActorChild {
|
2020-03-03 17:52:20 +03:00
|
|
|
constructor() {
|
|
|
|
super();
|
2018-08-02 07:36:12 +03:00
|
|
|
|
|
|
|
this.seenTabIcon = false;
|
|
|
|
this._iconLoader = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get iconLoader() {
|
|
|
|
if (!this._iconLoader) {
|
2022-06-06 21:59:44 +03:00
|
|
|
this._iconLoader = new lazy.FaviconLoader(this);
|
2018-08-02 07:36:12 +03:00
|
|
|
}
|
|
|
|
return this._iconLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
addRootIcon() {
|
|
|
|
if (
|
|
|
|
!this.seenTabIcon &&
|
|
|
|
Services.prefs.getBoolPref("browser.chrome.guess_favicon", true) &&
|
|
|
|
Services.prefs.getBoolPref("browser.chrome.site_icons", true)
|
|
|
|
) {
|
|
|
|
// Inject the default icon. Use documentURIObject so that we do the right
|
|
|
|
// thing with about:-style error pages. See bug 453442
|
2019-11-04 17:48:04 +03:00
|
|
|
let pageURI = this.document.documentURIObject;
|
2018-09-13 16:24:41 +03:00
|
|
|
if (["http", "https"].includes(pageURI.scheme)) {
|
2018-08-02 07:36:12 +03:00
|
|
|
this.seenTabIcon = true;
|
2018-09-13 16:24:41 +03:00
|
|
|
this.iconLoader.addDefaultIcon(pageURI);
|
2018-08-02 07:36:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onHeadParsed(event) {
|
2019-11-04 17:48:04 +03:00
|
|
|
if (event.target.ownerDocument != this.document) {
|
2018-08-02 07:36:12 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Per spec icons are meant to be in the <head> tag so we should have seen
|
|
|
|
// all the icons now so add the root icon if no other tab icons have been
|
|
|
|
// seen.
|
|
|
|
this.addRootIcon();
|
|
|
|
|
|
|
|
// We're likely done with icon parsing so load the pending icons now.
|
|
|
|
if (this._iconLoader) {
|
|
|
|
this._iconLoader.onPageShow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPageShow(event) {
|
2019-11-04 17:48:04 +03:00
|
|
|
if (event.target != this.document) {
|
2018-08-02 07:36:12 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addRootIcon();
|
|
|
|
|
|
|
|
if (this._iconLoader) {
|
|
|
|
this._iconLoader.onPageShow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPageHide(event) {
|
2019-11-04 17:48:04 +03:00
|
|
|
if (event.target != this.document) {
|
2018-08-02 07:36:12 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._iconLoader) {
|
|
|
|
this._iconLoader.onPageHide();
|
|
|
|
}
|
2018-08-16 20:29:57 +03:00
|
|
|
|
|
|
|
this.seenTabIcon = false;
|
2018-08-02 07:36:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onLinkEvent(event) {
|
|
|
|
let link = event.target;
|
|
|
|
// Ignore sub-frames (bugs 305472, 479408).
|
2019-11-04 17:48:04 +03:00
|
|
|
if (link.ownerGlobal != this.contentWindow) {
|
2018-08-02 07:36:12 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let rel = link.rel && link.rel.toLowerCase();
|
2018-08-30 11:35:51 +03:00
|
|
|
// We also check .getAttribute, since an empty href attribute will give us
|
|
|
|
// a link.href that is the same as the document.
|
|
|
|
if (!rel || !link.href || !link.getAttribute("href")) {
|
2018-08-02 07:36:12 +03:00
|
|
|
return;
|
2019-07-05 10:46:28 +03:00
|
|
|
}
|
2018-08-02 07:36:12 +03:00
|
|
|
|
|
|
|
// Note: following booleans only work for the current link, not for the
|
|
|
|
// whole content
|
|
|
|
let iconAdded = false;
|
|
|
|
let searchAdded = false;
|
|
|
|
let rels = {};
|
|
|
|
for (let relString of rel.split(/\s+/)) {
|
|
|
|
rels[relString] = true;
|
2019-07-05 10:46:28 +03:00
|
|
|
}
|
2018-08-02 07:36:12 +03:00
|
|
|
|
|
|
|
for (let relVal in rels) {
|
|
|
|
let isRichIcon = false;
|
|
|
|
|
|
|
|
switch (relVal) {
|
|
|
|
case "apple-touch-icon":
|
|
|
|
case "apple-touch-icon-precomposed":
|
|
|
|
case "fluid-icon":
|
|
|
|
isRichIcon = true;
|
2019-08-08 18:18:49 +03:00
|
|
|
// fall through
|
2018-08-02 07:36:12 +03:00
|
|
|
case "icon":
|
|
|
|
if (iconAdded || link.hasAttribute("mask")) {
|
|
|
|
// Masked icons are not supported yet.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Services.prefs.getBoolPref("browser.chrome.site_icons", true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:24:41 +03:00
|
|
|
if (this.iconLoader.addIconFromLink(link, isRichIcon)) {
|
2018-08-02 07:36:12 +03:00
|
|
|
iconAdded = true;
|
|
|
|
if (!isRichIcon) {
|
|
|
|
this.seenTabIcon = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "search":
|
|
|
|
if (
|
|
|
|
Services.policies &&
|
|
|
|
!Services.policies.isAllowed("installSearchEngine")
|
|
|
|
) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!searchAdded && event.type == "DOMLinkAdded") {
|
|
|
|
let type = link.type && link.type.toLowerCase();
|
|
|
|
type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
|
|
|
|
|
2021-02-10 21:12:08 +03:00
|
|
|
// Note: This protocol list should be kept in sync with
|
|
|
|
// the one in OpenSearchEngine's install function.
|
2021-04-07 14:10:36 +03:00
|
|
|
let re = /^https?:/i;
|
2018-08-02 07:36:12 +03:00
|
|
|
if (
|
|
|
|
type == "application/opensearchdescription+xml" &&
|
|
|
|
link.title &&
|
|
|
|
re.test(link.href)
|
|
|
|
) {
|
|
|
|
let engine = { title: link.title, href: link.href };
|
2019-11-04 17:48:04 +03:00
|
|
|
this.sendAsyncMessage("Link:AddSearch", {
|
2018-08-02 07:36:12 +03:00
|
|
|
engine,
|
|
|
|
});
|
|
|
|
searchAdded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEvent(event) {
|
|
|
|
switch (event.type) {
|
|
|
|
case "pageshow":
|
|
|
|
return this.onPageShow(event);
|
|
|
|
case "pagehide":
|
|
|
|
return this.onPageHide(event);
|
|
|
|
case "DOMHeadElementParsed":
|
|
|
|
return this.onHeadParsed(event);
|
|
|
|
default:
|
|
|
|
return this.onLinkEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|