gecko-dev/browser/actors/BlockedSiteChild.jsm

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

199 строки
5.6 KiB
JavaScript
Исходник Обычный вид История

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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/. */
Bug 1514594: Part 3 - Change ChromeUtils.import API. *** Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8 This changes the behavior of ChromeUtils.import() to return an exports object, rather than a module global, in all cases except when `null` is passed as a second argument, and changes the default behavior not to pollute the global scope with the module's exports. Thus, the following code written for the old model: ChromeUtils.import("resource://gre/modules/Services.jsm"); is approximately the same as the following, in the new model: var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); Since the two behaviors are mutually incompatible, this patch will land with a scripted rewrite to update all existing callers to use the new model rather than the old. *** Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs This was done using the followng script: https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm *** Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D16747 *** Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16748 *** Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16749 *** Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs *** Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16750 --HG-- extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895 extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
2019-01-17 21:18:31 +03:00
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ["BlockedSiteChild"];
ChromeUtils.defineModuleGetter(
this,
"SafeBrowsing",
"resource://gre/modules/SafeBrowsing.jsm"
);
function getSiteBlockedErrorDetails(docShell) {
let blockedInfo = {};
if (docShell.failedChannel) {
let classifiedChannel = docShell.failedChannel.QueryInterface(
Ci.nsIClassifiedChannel
);
if (classifiedChannel) {
let httpChannel = docShell.failedChannel.QueryInterface(
Ci.nsIHttpChannel
);
let reportUri = httpChannel.URI;
// Remove the query to avoid leaking sensitive data
if (reportUri instanceof Ci.nsIURL) {
reportUri = reportUri
.mutate()
.setQuery("")
.finalize();
}
let triggeringPrincipal = docShell.failedChannel.loadInfo
? docShell.failedChannel.loadInfo.triggeringPrincipal
: null;
blockedInfo = {
list: classifiedChannel.matchedList,
triggeringPrincipal,
provider: classifiedChannel.matchedProvider,
uri: reportUri.asciiSpec,
};
}
}
return blockedInfo;
}
class BlockedSiteChild extends JSWindowActorChild {
receiveMessage(msg) {
if (msg.name == "DeceptiveBlockedDetails") {
return getSiteBlockedErrorDetails(this.docShell);
}
return null;
}
handleEvent(event) {
if (event.type == "AboutBlockedLoaded") {
this.onAboutBlockedLoaded(event);
} else if (event.type == "click" && event.button == 0) {
this.onClick(event);
}
}
onAboutBlockedLoaded(aEvent) {
let content = aEvent.target.ownerGlobal;
let blockedInfo = getSiteBlockedErrorDetails(this.docShell);
let provider = blockedInfo.provider || "";
let doc = content.document;
/**
* Set error description link in error details.
* For example, the "reported as a deceptive site" link for
* blocked phishing pages.
*/
let desc = Services.prefs.getCharPref(
"browser.safebrowsing.provider." + provider + ".reportURL",
""
);
if (desc) {
doc
.getElementById("error_desc_link")
.setAttribute("href", desc + encodeURIComponent(aEvent.detail.url));
}
// Set other links in error details.
switch (aEvent.detail.err) {
case "malware":
doc
.getElementById("report_detection")
.setAttribute(
"href",
SafeBrowsing.getReportURL("MalwareMistake", blockedInfo) ||
"https://www.stopbadware.org/firefox"
);
doc
.getElementById("learn_more_link")
.setAttribute("href", "https://www.stopbadware.org/firefox");
break;
case "unwanted":
doc
.getElementById("learn_more_link")
.setAttribute(
"href",
"https://www.google.com/about/unwanted-software-policy.html"
);
break;
case "phishing":
doc
.getElementById("report_detection")
.setAttribute(
"href",
SafeBrowsing.getReportURL("PhishMistake", blockedInfo) ||
"https://safebrowsing.google.com/safebrowsing/report_error/?tpl=mozilla"
);
doc
.getElementById("learn_more_link")
.setAttribute("href", "https://www.antiphishing.org//");
break;
}
// Set the firefox support url.
doc
.getElementById("firefox_support")
.setAttribute(
"href",
Services.urlFormatter.formatURLPref("app.support.baseURL") +
"phishing-malware"
);
// Show safe browsing details on load if the pref is set to true.
let showDetails = Services.prefs.getBoolPref(
"browser.xul.error_pages.show_safe_browsing_details_on_load"
);
if (showDetails) {
let details = content.document.getElementById(
"errorDescriptionContainer"
);
details.removeAttribute("hidden");
}
// Set safe browsing advisory link.
let advisoryUrl = Services.prefs.getCharPref(
"browser.safebrowsing.provider." + provider + ".advisoryURL",
""
);
let advisoryDesc = content.document.getElementById("advisoryDescText");
if (!advisoryUrl) {
advisoryDesc.remove();
return;
}
let advisoryLinkText = Services.prefs.getCharPref(
"browser.safebrowsing.provider." + provider + ".advisoryName",
""
);
if (!advisoryLinkText) {
advisoryDesc.remove();
return;
}
content.document.l10n.setAttributes(
advisoryDesc,
"safeb-palm-advisory-desc",
{ advisoryname: advisoryLinkText }
);
content.document
.getElementById("advisory_provider")
.setAttribute("href", advisoryUrl);
}
onClick(event) {
let ownerDoc = event.target.ownerDocument;
if (!ownerDoc) {
return;
}
var reason = "phishing";
if (/e=malwareBlocked/.test(ownerDoc.documentURI)) {
reason = "malware";
} else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {
reason = "unwanted";
} else if (/e=harmfulBlocked/.test(ownerDoc.documentURI)) {
reason = "harmful";
}
this.sendAsyncMessage("Browser:SiteBlockedError", {
location: ownerDoc.location.href,
reason,
elementId: event.target.getAttribute("id"),
blockedInfo: getSiteBlockedErrorDetails(this.docShell),
});
}
}