1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 ChromeUtils.defineESModuleGetters(lazy, {
9 SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
12 function getSiteBlockedErrorDetails(docShell) {
14 if (docShell.failedChannel) {
15 let classifiedChannel = docShell.failedChannel.QueryInterface(
16 Ci.nsIClassifiedChannel
18 if (classifiedChannel) {
19 let httpChannel = docShell.failedChannel.QueryInterface(
23 let reportUri = httpChannel.URI;
25 // Remove the query to avoid leaking sensitive data
26 if (reportUri instanceof Ci.nsIURL) {
27 reportUri = reportUri.mutate().setQuery("").finalize();
30 let triggeringPrincipal = docShell.failedChannel.loadInfo
31 ? docShell.failedChannel.loadInfo.triggeringPrincipal
34 list: classifiedChannel.matchedList,
36 provider: classifiedChannel.matchedProvider,
37 uri: reportUri.asciiSpec,
44 export class BlockedSiteChild extends JSWindowActorChild {
46 if (msg.name == "DeceptiveBlockedDetails") {
47 return getSiteBlockedErrorDetails(this.docShell);
53 if (event.type == "AboutBlockedLoaded") {
54 this.onAboutBlockedLoaded(event);
55 } else if (event.type == "click" && event.button == 0) {
60 onAboutBlockedLoaded(aEvent) {
61 let content = aEvent.target.ownerGlobal;
63 let blockedInfo = getSiteBlockedErrorDetails(this.docShell);
64 let provider = blockedInfo.provider || "";
66 let doc = content.document;
69 * Set error description link in error details.
70 * For example, the "reported as a deceptive site" link for
71 * blocked phishing pages.
73 let desc = Services.prefs.getCharPref(
74 "browser.safebrowsing.provider." + provider + ".reportURL",
79 .getElementById("error_desc_link")
80 .setAttribute("href", desc + encodeURIComponent(aEvent.detail.url));
83 // Set other links in error details.
84 switch (aEvent.detail.err) {
87 .getElementById("report_detection")
90 lazy.SafeBrowsing.getReportURL("MalwareMistake", blockedInfo)
95 .getElementById("learn_more_link")
98 "https://www.google.com/about/unwanted-software-policy.html"
103 .getElementById("report_detection")
106 lazy.SafeBrowsing.getReportURL("PhishMistake", blockedInfo) ||
107 "https://safebrowsing.google.com/safebrowsing/report_error/?tpl=mozilla"
110 .getElementById("learn_more_link")
111 .setAttribute("href", "https://www.antiphishing.org//");
115 // Set the firefox support url.
117 .getElementById("firefox_support")
120 Services.urlFormatter.formatURLPref("app.support.baseURL") +
124 // Show safe browsing details on load if the pref is set to true.
125 let showDetails = Services.prefs.getBoolPref(
126 "browser.xul.error_pages.show_safe_browsing_details_on_load"
129 let details = content.document.getElementById(
130 "errorDescriptionContainer"
132 details.removeAttribute("hidden");
135 // Set safe browsing advisory link.
136 let advisoryUrl = Services.prefs.getCharPref(
137 "browser.safebrowsing.provider." + provider + ".advisoryURL",
140 let advisoryDesc = content.document.getElementById("advisoryDescText");
142 advisoryDesc.remove();
146 let advisoryLinkText = Services.prefs.getCharPref(
147 "browser.safebrowsing.provider." + provider + ".advisoryName",
150 if (!advisoryLinkText) {
151 advisoryDesc.remove();
155 content.document.l10n.setAttributes(
157 "safeb-palm-advisory-desc",
158 { advisoryname: advisoryLinkText }
161 .getElementById("advisory_provider")
162 .setAttribute("href", advisoryUrl);
166 let ownerDoc = event.target.ownerDocument;
171 var reason = "phishing";
172 if (/e=malwareBlocked/.test(ownerDoc.documentURI)) {
174 } else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {
176 } else if (/e=harmfulBlocked/.test(ownerDoc.documentURI)) {
180 this.sendAsyncMessage("Browser:SiteBlockedError", {
181 location: ownerDoc.location.href,
183 elementId: event.target.getAttribute("id"),
184 blockedInfo: getSiteBlockedErrorDetails(this.docShell),