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

View File

@ -1808,7 +1808,6 @@ var gBrowserInit = {
// message sent between when the frame script is loaded and when // message sent between when the frame script is loaded and when
// the listener is registered. // the listener is registered.
LanguageDetectionListener.init(); LanguageDetectionListener.init();
BrowserOnClick.init();
CaptivePortalWatcher.init(); CaptivePortalWatcher.init();
ZoomUI.init(window); ZoomUI.init(window);
@ -2447,8 +2446,6 @@ var gBrowserInit = {
gTabletModePageCounter.finish(); gTabletModePageCounter.finish();
BrowserOnClick.uninit();
CaptivePortalWatcher.uninit(); CaptivePortalWatcher.uninit();
SidebarUI.uninit(); SidebarUI.uninit();
@ -3498,73 +3495,7 @@ const PREF_SSL_IMPACT_ROOTS = ["security.tls.version.", "security.ssl3."];
* us via async messaging. * us via async messaging.
*/ */
var BrowserOnClick = { var BrowserOnClick = {
init() { ignoreWarningLink(reason, blockedInfo, browsingContext) {
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) {
let triggeringPrincipal = E10SUtils.deserializePrincipal( let triggeringPrincipal = E10SUtils.deserializePrincipal(
blockedInfo.triggeringPrincipal, blockedInfo.triggeringPrincipal,
_createNullPrincipalFromTabUserContextId() _createNullPrincipalFromTabUserContextId()
@ -3572,16 +3503,16 @@ var BrowserOnClick = {
// Allow users to override and continue through to the site, // Allow users to override and continue through to the site,
// but add a notify bar as a reminder, so that they don't lose // but add a notify bar as a reminder, so that they don't lose
// track after, e.g., tab switching. // track after, e.g., tab switching.
gBrowser.loadURI(gBrowser.currentURI.spec, { browsingContext.loadURI(blockedInfo.uri, {
triggeringPrincipal, triggeringPrincipal,
flags: Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CLASSIFIER, 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 // Create one from uri with current principal origin attributes
let principal = Services.scriptSecurityManager.createContentPrincipal( let principal = Services.scriptSecurityManager.createContentPrincipal(
gBrowser.currentURI, Services.io.newURI(blockedInfo.uri),
gBrowser.contentPrincipal.originAttributes browsingContext.currentWindowGlobal.documentPrincipal.originAttributes
); );
Services.perms.addFromPrincipal( Services.perms.addFromPrincipal(
principal, principal,
@ -3599,7 +3530,7 @@ var BrowserOnClick = {
"safebrowsing.getMeOutOfHereButton.accessKey" "safebrowsing.getMeOutOfHereButton.accessKey"
), ),
callback() { callback() {
getMeOutOfHere(); getMeOutOfHere(browsingContext);
}, },
}, },
]; ];
@ -3662,8 +3593,8 @@ var BrowserOnClick = {
* button should take the user to the default start page so that even * 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. * when their own homepage is infected, we can get them somewhere safe.
*/ */
function getMeOutOfHere() { function getMeOutOfHere(browsingContext) {
gBrowser.loadURI(getDefaultHomePage(), { browsingContext.top.loadURI(getDefaultHomePage(), {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), // Also needs to load homepage triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), // Also needs to load homepage
}); });
} }
@ -8423,36 +8354,41 @@ function checkEmptyPageOrigin(
} }
function ReportFalseDeceptiveSite() { function ReportFalseDeceptiveSite() {
let docURI = gBrowser.selectedBrowser.documentURI; let contextsToVisit = [gBrowser.selectedBrowser.browsingContext];
let isPhishingPage = while (contextsToVisit.length) {
docURI && docURI.spec.startsWith("about:blocked?e=deceptiveBlocked"); let currentContext = contextsToVisit.pop();
let global = currentContext.currentWindowGlobal;
if (isPhishingPage) { if (!global) {
let mm = gBrowser.selectedBrowser.messageManager; continue;
let onMessage = message => { }
mm.removeMessageListener("DeceptiveBlockedDetails:Result", onMessage); let docURI = global.documentURI;
let reportUrl = gSafeBrowsing.getReportURL( // Ensure the page is an about:blocked pagae before handling.
"PhishMistake", if (docURI && docURI.spec.startsWith("about:blocked?e=deceptiveBlocked")) {
message.data.blockedInfo let actor = global.getActor("BlockedSite");
); actor.sendQuery("DeceptiveBlockedDetails").then(data => {
if (reportUrl) { let reportUrl = gSafeBrowsing.getReportURL(
openTrustedLinkIn(reportUrl, "tab"); "PhishMistake",
} else { data.blockedInfo
let bundle = Services.strings.createBundle(
"chrome://browser/locale/safebrowsing/safebrowsing.properties"
); );
Services.prompt.alert( if (reportUrl) {
window, openTrustedLinkIn(reportUrl, "tab");
bundle.GetStringFromName("errorReportFalseDeceptiveTitle"), } else {
bundle.formatStringFromName("errorReportFalseDeceptiveMessage", [ let bundle = Services.strings.createBundle(
message.data.blockedInfo.provider, "chrome://browser/locale/safebrowsing/safebrowsing.properties"
]) );
); Services.prompt.alert(
} window,
}; bundle.GetStringFromName("errorReportFalseDeceptiveTitle"),
mm.addMessageListener("DeceptiveBlockedDetails:Result", onMessage); 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 * available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jswindowactor
*/ */
let ACTORS = { 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: { BrowserTab: {
parent: { parent: {
moduleURI: "resource:///actors/BrowserTabParent.jsm", 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: { ClickHandler: {
child: { child: {
module: "resource:///actors/ClickHandlerChild.jsm", module: "resource:///actors/ClickHandlerChild.jsm",