Bug 1591474 - Port BlockedSite to JSWindowActors r=Gijs

These actors appear in about:blocked sites.

Differential Revision: https://phabricator.services.mozilla.com/D51176

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Jahns 2019-11-18 12:06:23 +00:00
parent 06d06cbec7
commit 8d5dd26b39
5 changed files with 135 additions and 129 deletions

View File

@ -7,9 +7,6 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ["BlockedSiteChild"];
const { ActorChild } = ChromeUtils.import(
"resource://gre/modules/ActorChild.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"E10SUtils",
@ -59,13 +56,12 @@ function getSiteBlockedErrorDetails(docShell) {
return blockedInfo;
}
class BlockedSiteChild extends ActorChild {
class BlockedSiteChild extends JSWindowActorChild {
receiveMessage(msg) {
if (msg.name == "DeceptiveBlockedDetails") {
this.mm.sendAsyncMessage("DeceptiveBlockedDetails:Result", {
blockedInfo: getSiteBlockedErrorDetails(this.mm.docShell),
});
return getSiteBlockedErrorDetails(this.docShell);
}
return null;
}
handleEvent(event) {
@ -77,10 +73,9 @@ class BlockedSiteChild extends ActorChild {
}
onAboutBlockedLoaded(aEvent) {
let global = this.mm;
let content = aEvent.target.ownerGlobal;
let blockedInfo = getSiteBlockedErrorDetails(global.docShell);
let blockedInfo = getSiteBlockedErrorDetails(this.docShell);
let provider = blockedInfo.provider || "";
let doc = content.document;
@ -201,12 +196,11 @@ class BlockedSiteChild extends ActorChild {
reason = "harmful";
}
this.mm.sendAsyncMessage("Browser:SiteBlockedError", {
this.sendAsyncMessage("Browser:SiteBlockedError", {
location: ownerDoc.location.href,
reason,
elementId: event.target.getAttribute("id"),
isTopFrame: ownerDoc.defaultView.parent === ownerDoc.defaultView,
blockedInfo: getSiteBlockedErrorDetails(ownerDoc.defaultView.docShell),
blockedInfo: getSiteBlockedErrorDetails(this.docShell),
});
}
}

View File

@ -0,0 +1,73 @@
/* -*- 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/. */
var EXPORTED_SYMBOLS = ["BlockedSiteParent"];
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
class BlockedSiteParent extends JSWindowActorParent {
receiveMessage(msg) {
switch (msg.name) {
case "Browser:SiteBlockedError":
this._onAboutBlocked(
msg.data.elementId,
msg.data.reason,
this.browsingContext === this.browsingContext.top,
msg.data.blockedInfo
);
break;
}
}
_onAboutBlocked(elementId, reason, isTopFrame, blockedInfo) {
let browser = this.browsingContext.top.embedderElement;
if (!browser) {
return;
}
let { BrowserOnClick } = browser.ownerGlobal;
// Depending on what page we are displaying here (malware/phishing/unwanted)
// use the right strings and links for each.
let bucketName = "";
let sendTelemetry = false;
if (reason === "malware") {
sendTelemetry = true;
bucketName = "WARNING_MALWARE_PAGE_";
} else if (reason === "phishing") {
sendTelemetry = true;
bucketName = "WARNING_PHISHING_PAGE_";
} else if (reason === "unwanted") {
sendTelemetry = true;
bucketName = "WARNING_UNWANTED_PAGE_";
} else if (reason === "harmful") {
sendTelemetry = true;
bucketName = "WARNING_HARMFUL_PAGE_";
}
let secHistogram = Services.telemetry.getHistogramById(
"URLCLASSIFIER_UI_EVENTS"
);
let nsISecTel = Ci.IUrlClassifierUITelemetry;
bucketName += isTopFrame ? "TOP_" : "FRAME_";
switch (elementId) {
case "goBackButton":
if (sendTelemetry) {
secHistogram.add(nsISecTel[bucketName + "GET_ME_OUT_OF_HERE"]);
}
browser.ownerGlobal.getMeOutOfHere(this.browsingContext);
break;
case "ignore_warning_link":
if (Services.prefs.getBoolPref("browser.safebrowsing.allowOverride")) {
if (sendTelemetry) {
secHistogram.add(nsISecTel[bucketName + "IGNORE_WARNING"]);
}
BrowserOnClick.ignoreWarningLink(
reason,
blockedInfo,
this.browsingContext
);
}
break;
}
}
}

View File

@ -25,6 +25,7 @@ with Files("WebRTCChild.jsm"):
FINAL_TARGET_FILES.actors += [
'AboutReaderChild.jsm',
'BlockedSiteChild.jsm',
'BlockedSiteParent.jsm',
'BrowserTabChild.jsm',
'BrowserTabParent.jsm',
'ClickHandlerChild.jsm',

View File

@ -1808,7 +1808,6 @@ var gBrowserInit = {
// message sent between when the frame script is loaded and when
// the listener is registered.
LanguageDetectionListener.init();
BrowserOnClick.init();
CaptivePortalWatcher.init();
ZoomUI.init(window);
@ -2447,8 +2446,6 @@ var gBrowserInit = {
gTabletModePageCounter.finish();
BrowserOnClick.uninit();
CaptivePortalWatcher.uninit();
SidebarUI.uninit();
@ -3498,73 +3495,7 @@ const PREF_SSL_IMPACT_ROOTS = ["security.tls.version.", "security.ssl3."];
* us via async messaging.
*/
var BrowserOnClick = {
init() {
let mm = window.messageManager;
mm.addMessageListener("Browser:SiteBlockedError", this);
},
uninit() {
let mm = window.messageManager;
mm.removeMessageListener("Browser:SiteBlockedError", this);
},
receiveMessage(msg) {
switch (msg.name) {
case "Browser:SiteBlockedError":
this.onAboutBlocked(
msg.data.elementId,
msg.data.reason,
msg.data.isTopFrame,
msg.data.location,
msg.data.blockedInfo
);
break;
}
},
onAboutBlocked(elementId, reason, isTopFrame, location, blockedInfo) {
// Depending on what page we are displaying here (malware/phishing/unwanted)
// use the right strings and links for each.
let bucketName = "";
let sendTelemetry = false;
if (reason === "malware") {
sendTelemetry = true;
bucketName = "WARNING_MALWARE_PAGE_";
} else if (reason === "phishing") {
sendTelemetry = true;
bucketName = "WARNING_PHISHING_PAGE_";
} else if (reason === "unwanted") {
sendTelemetry = true;
bucketName = "WARNING_UNWANTED_PAGE_";
} else if (reason === "harmful") {
sendTelemetry = true;
bucketName = "WARNING_HARMFUL_PAGE_";
}
let secHistogram = Services.telemetry.getHistogramById(
"URLCLASSIFIER_UI_EVENTS"
);
let nsISecTel = Ci.IUrlClassifierUITelemetry;
bucketName += isTopFrame ? "TOP_" : "FRAME_";
switch (elementId) {
case "goBackButton":
if (sendTelemetry) {
secHistogram.add(nsISecTel[bucketName + "GET_ME_OUT_OF_HERE"]);
}
getMeOutOfHere();
break;
case "ignore_warning_link":
if (Services.prefs.getBoolPref("browser.safebrowsing.allowOverride")) {
if (sendTelemetry) {
secHistogram.add(nsISecTel[bucketName + "IGNORE_WARNING"]);
}
this.ignoreWarningLink(reason, blockedInfo);
}
break;
}
},
ignoreWarningLink(reason, blockedInfo) {
ignoreWarningLink(reason, blockedInfo, browsingContext) {
let triggeringPrincipal = E10SUtils.deserializePrincipal(
blockedInfo.triggeringPrincipal,
_createNullPrincipalFromTabUserContextId()
@ -3572,16 +3503,16 @@ var BrowserOnClick = {
// Allow users to override and continue through to the site,
// but add a notify bar as a reminder, so that they don't lose
// track after, e.g., tab switching.
gBrowser.loadURI(gBrowser.currentURI.spec, {
browsingContext.loadURI(blockedInfo.uri, {
triggeringPrincipal,
flags: Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CLASSIFIER,
});
// We can't use gBrowser.contentPrincipal which is principal of about:blocked
// We can't use browser.contentPrincipal which is principal of about:blocked
// Create one from uri with current principal origin attributes
let principal = Services.scriptSecurityManager.createContentPrincipal(
gBrowser.currentURI,
gBrowser.contentPrincipal.originAttributes
Services.io.newURI(blockedInfo.uri),
browsingContext.currentWindowGlobal.documentPrincipal.originAttributes
);
Services.perms.addFromPrincipal(
principal,
@ -3599,7 +3530,7 @@ var BrowserOnClick = {
"safebrowsing.getMeOutOfHereButton.accessKey"
),
callback() {
getMeOutOfHere();
getMeOutOfHere(browsingContext);
},
},
];
@ -3662,8 +3593,8 @@ var BrowserOnClick = {
* button should take the user to the default start page so that even
* when their own homepage is infected, we can get them somewhere safe.
*/
function getMeOutOfHere() {
gBrowser.loadURI(getDefaultHomePage(), {
function getMeOutOfHere(browsingContext) {
browsingContext.top.loadURI(getDefaultHomePage(), {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), // Also needs to load homepage
});
}
@ -8423,36 +8354,41 @@ function checkEmptyPageOrigin(
}
function ReportFalseDeceptiveSite() {
let docURI = gBrowser.selectedBrowser.documentURI;
let isPhishingPage =
docURI && docURI.spec.startsWith("about:blocked?e=deceptiveBlocked");
let contextsToVisit = [gBrowser.selectedBrowser.browsingContext];
while (contextsToVisit.length) {
let currentContext = contextsToVisit.pop();
let global = currentContext.currentWindowGlobal;
if (isPhishingPage) {
let mm = gBrowser.selectedBrowser.messageManager;
let onMessage = message => {
mm.removeMessageListener("DeceptiveBlockedDetails:Result", onMessage);
let reportUrl = gSafeBrowsing.getReportURL(
"PhishMistake",
message.data.blockedInfo
);
if (reportUrl) {
openTrustedLinkIn(reportUrl, "tab");
} else {
let bundle = Services.strings.createBundle(
"chrome://browser/locale/safebrowsing/safebrowsing.properties"
if (!global) {
continue;
}
let docURI = global.documentURI;
// Ensure the page is an about:blocked pagae before handling.
if (docURI && docURI.spec.startsWith("about:blocked?e=deceptiveBlocked")) {
let actor = global.getActor("BlockedSite");
actor.sendQuery("DeceptiveBlockedDetails").then(data => {
let reportUrl = gSafeBrowsing.getReportURL(
"PhishMistake",
data.blockedInfo
);
Services.prompt.alert(
window,
bundle.GetStringFromName("errorReportFalseDeceptiveTitle"),
bundle.formatStringFromName("errorReportFalseDeceptiveMessage", [
message.data.blockedInfo.provider,
])
);
}
};
mm.addMessageListener("DeceptiveBlockedDetails:Result", onMessage);
if (reportUrl) {
openTrustedLinkIn(reportUrl, "tab");
} else {
let bundle = Services.strings.createBundle(
"chrome://browser/locale/safebrowsing/safebrowsing.properties"
);
Services.prompt.alert(
window,
bundle.GetStringFromName("errorReportFalseDeceptiveTitle"),
bundle.formatStringFromName("errorReportFalseDeceptiveMessage", [
data.blockedInfo.provider,
])
);
}
});
}
mm.sendAsyncMessage("DeceptiveBlockedDetails");
contextsToVisit.push(...currentContext.getChildren());
}
}

View File

@ -41,6 +41,21 @@ const PREF_PDFJS_ENABLED_CACHE_STATE = "pdfjs.enabledCache.state";
* available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jswindowactor
*/
let ACTORS = {
BlockedSite: {
parent: {
moduleURI: "resource:///actors/BlockedSiteParent.jsm",
},
child: {
moduleURI: "resource:///actors/BlockedSiteChild.jsm",
events: {
AboutBlockedLoaded: { wantUntrusted: true },
click: {},
},
},
matches: ["about:blocked?*"],
allFrames: true,
},
BrowserTab: {
parent: {
moduleURI: "resource:///actors/BrowserTabParent.jsm",
@ -300,19 +315,6 @@ let LEGACY_ACTORS = {
},
},
BlockedSite: {
child: {
module: "resource:///actors/BlockedSiteChild.jsm",
events: {
AboutBlockedLoaded: { wantUntrusted: true },
click: {},
},
matches: ["about:blocked?*"],
allFrames: true,
messages: ["DeceptiveBlockedDetails"],
},
},
ClickHandler: {
child: {
module: "resource:///actors/ClickHandlerChild.jsm",