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 file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // Error url MUST be formatted like this:
6 // about:blocked?e=error_code&u=url(&o=1)?
7 // (o=1 when user overrides are allowed)
9 // Note that this file uses document.documentURI to get
10 // the URL (with the format from above). This is because
11 // document.location.href gets the current URI off the docshell,
12 // which is the URL displayed in the location bar, i.e.
13 // the URI that the user attempted to load.
15 function getErrorCode() {
16 var url = document.documentURI;
17 var error = url.search(/e\=/);
18 var duffUrl = url.search(/\&u\=/);
19 return decodeURIComponent(url.slice(error + 2, duffUrl));
23 var url = document.documentURI;
24 var match = url.match(/&u=([^&]+)&/);
26 // match == null if not found; if so, return an empty string
27 // instead of what would turn out to be portions of the URI
32 url = decodeURIComponent(match[1]);
34 // If this is a view-source page, then get then real URI of the page
35 if (url.startsWith("view-source:")) {
42 * Check whether this warning page is overridable or not, in which case
43 * the "ignore the risk" suggestion in the error description
44 * should not be shown.
46 function getOverride() {
47 var url = document.documentURI;
48 var match = url.match(/&o=1&/);
53 * Attempt to get the hostname via document.location. Fail back
54 * to getURL so that we always return something meaningful.
56 function getHostString() {
58 return document.location.hostname;
64 function onClickSeeDetails() {
65 let details = document.getElementById("errorDescriptionContainer");
66 details.hidden = !details.hidden;
71 switch (getErrorCode()) {
72 case "malwareBlocked":
75 case "deceptiveBlocked":
78 case "unwantedBlocked":
81 case "harmfulBlocked":
88 // Set page contents depending on type of blocked page
89 // Prepare the title and short description text
90 let titleText = document.getElementById("errorTitleText");
91 document.l10n.setAttributes(
93 "safeb-blocked-" + error + "-page-title"
95 let shortDesc = document.getElementById("errorShortDescText");
96 document.l10n.setAttributes(
98 "safeb-blocked-" + error + "-page-short-desc"
101 // Prepare the inner description, ensuring any redundant inner elements are removed.
102 let innerDesc = document.getElementById("errorInnerDescription");
103 let innerDescL10nID = "safeb-blocked-" + error + "-page-error-desc-";
104 if (!getOverride()) {
105 innerDescL10nID += "no-override";
106 document.getElementById("ignore_warning_link").remove();
108 innerDescL10nID += "override";
110 if (error == "unwanted" || error == "harmful") {
111 document.getElementById("report_detection").remove();
114 // Add the inner description:
115 // Map specific elements to a different message ID, to allow updates to
117 let descriptionMapping = {
118 malware: innerDescL10nID + "-sumo",
120 document.l10n.setAttributes(
122 descriptionMapping[error] || innerDescL10nID,
124 sitename: getHostString(),
128 // Add the learn more content:
129 // Map specific elements to a different message ID, to allow updates to
131 let stringMapping = {
132 malware: "safeb-blocked-malware-page-learn-more-sumo",
135 let learnMore = document.getElementById("learn_more");
136 document.l10n.setAttributes(
138 stringMapping[error] || `safeb-blocked-${error}-page-learn-more`
141 // Set sitename to bold by adding class
142 let errorSitename = document.getElementById("error_desc_sitename");
143 errorSitename.setAttribute("class", "sitename");
145 let titleEl = document.createElement("title");
146 document.l10n.setAttributes(
148 "safeb-blocked-" + error + "-page-title"
150 document.head.appendChild(titleEl);
152 // Inform the test harness that we're done loading the page.
153 var event = new CustomEvent("AboutBlockedLoaded", {
160 document.dispatchEvent(event);
163 let seeDetailsButton = document.getElementById("seeDetailsButton");
164 seeDetailsButton.addEventListener("click", onClickSeeDetails);
165 // Note: It is important to run the script this way, instead of using
166 // an onload handler. This is because error pages are loaded as
167 // LOAD_BACKGROUND, which means that onload handlers will not be executed.