Bug 1533951, base NetError handler on JSWindowActor, move message listeners out of browser.js and into JSWindowActorParent, r=johannh

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Neil Deakin 2019-11-12 20:00:32 +00:00
Родитель 9ae23f45d4
Коммит 39a97c89d5
5 изменённых файлов: 109 добавлений и 73 удалений

Просмотреть файл

@ -5,30 +5,28 @@
var EXPORTED_SYMBOLS = ["NetErrorChild"];
const { ActorChild } = ChromeUtils.import(
"resource://gre/modules/ActorChild.jsm"
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
function getSerializedSecurityInfo(docShell) {
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"].getService(
Ci.nsISerializationHelper
);
XPCOMUtils.defineLazyServiceGetter(
this,
"gSerializationHelper",
"@mozilla.org/network/serialization-helper;1",
"nsISerializationHelper"
);
let securityInfo =
docShell.failedChannel && docShell.failedChannel.securityInfo;
if (!securityInfo) {
return "";
}
securityInfo
.QueryInterface(Ci.nsITransportSecurityInfo)
.QueryInterface(Ci.nsISerializable);
class NetErrorChild extends JSWindowActorChild {
getSerializedSecurityInfo(docShell) {
let securityInfo =
docShell.failedChannel && docShell.failedChannel.securityInfo;
if (!securityInfo) {
return "";
}
securityInfo.QueryInterface(Ci.nsITransportSecurityInfo)
.QueryInterface(Ci.nsISerializable);
return serhelper.serializeToString(securityInfo);
}
class NetErrorChild extends ActorChild {
isAboutNetError(doc) {
return doc.documentURI.startsWith("about:neterror");
return gSerializationHelper.serializeToString(securityInfo);
}
handleEvent(aEvent) {
@ -39,10 +37,10 @@ class NetErrorChild extends ActorChild {
case "click":
let elem = aEvent.originalTarget;
if (elem.id == "viewCertificate") {
this.mm.sendAsyncMessage("Browser:CertExceptionError", {
this.sendAsyncMessage("Browser:CertExceptionError", {
location: doc.location.href,
elementId: elem.id,
securityInfoAsString: getSerializedSecurityInfo(
securityInfoAsString: this.getSerializedSecurityInfo(
doc.defaultView.docShell
),
});

Просмотреть файл

@ -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 = ["NetErrorParent"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"gSerializationHelper",
"@mozilla.org/network/serialization-helper;1",
"nsISerializationHelper"
);
class NetErrorParent extends JSWindowActorParent {
getSecurityInfo(securityInfoAsString) {
if (!securityInfoAsString) {
return null;
}
let securityInfo = gSerializationHelper.deserializeObject(
securityInfoAsString
);
securityInfo.QueryInterface(Ci.nsITransportSecurityInfo);
return securityInfo;
}
receiveMessage(message) {
switch (message.name) {
case "Browser:CertExceptionError":
switch (message.data.elementId) {
case "viewCertificate": {
let browser = this.browsingContext.top.embedderElement;
if (!browser) {
break;
}
let window = browser.ownerGlobal;
let securityInfo = this.getSecurityInfo(message.data.securityInfoAsString);
let cert = securityInfo.serverCert;
if (Services.prefs.getBoolPref("security.aboutcertificate.enabled")) {
let certChain = securityInfo.failedCertChain;
let certs = certChain.map(elem =>
encodeURIComponent(elem.getBase64DERString())
);
let certsStringURL = certs.map(elem => `cert=${elem}`);
certsStringURL = certsStringURL.join("&");
let url = `about:certificate?${certsStringURL}`;
if (window.openTrustedLinkIn) {
window.openTrustedLinkIn(url, "tab");
}
} else {
Services.ww.openWindow(
window,
"chrome://pippki/content/certViewer.xul",
"_blank",
"centerscreen,chrome",
cert
);
}
break;
}
}
}
}
}

Просмотреть файл

@ -41,6 +41,7 @@ FINAL_TARGET_FILES.actors += [
'LinkHandlerChild.jsm',
'LinkHandlerParent.jsm',
'NetErrorChild.jsm',
'NetErrorParent.jsm',
'OfflineAppsChild.jsm',
'PageInfoChild.jsm',
'PageStyleChild.jsm',

Просмотреть файл

@ -3503,26 +3503,16 @@ const PREF_SSL_IMPACT_ROOTS = ["security.tls.version.", "security.ssl3."];
var BrowserOnClick = {
init() {
let mm = window.messageManager;
mm.addMessageListener("Browser:CertExceptionError", this);
mm.addMessageListener("Browser:SiteBlockedError", this);
},
uninit() {
let mm = window.messageManager;
mm.removeMessageListener("Browser:CertExceptionError", this);
mm.removeMessageListener("Browser:SiteBlockedError", this);
},
receiveMessage(msg) {
switch (msg.name) {
case "Browser:CertExceptionError":
this.onCertError(
msg.target,
msg.data.elementId,
msg.data.location,
msg.data.securityInfoAsString
);
break;
case "Browser:SiteBlockedError":
this.onAboutBlocked(
msg.data.elementId,
@ -3535,36 +3525,6 @@ var BrowserOnClick = {
}
},
onCertError(browser, elementId, location, securityInfoAsString) {
let securityInfo;
let cert;
switch (elementId) {
case "viewCertificate":
securityInfo = getSecurityInfo(securityInfoAsString);
cert = securityInfo.serverCert;
if (Services.prefs.getBoolPref("security.aboutcertificate.enabled")) {
let certChain = securityInfo.failedCertChain;
let certs = certChain.map(elem =>
encodeURIComponent(elem.getBase64DERString())
);
let certsStringURL = certs.map(elem => `cert=${elem}`);
certsStringURL = certsStringURL.join("&");
let url = `about:certificate?${certsStringURL}`;
openTrustedLinkIn(url, "tab");
} else {
Services.ww.openWindow(
window,
"chrome://pippki/content/certViewer.xul",
"_blank",
"centerscreen,chrome",
cert
);
}
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.

Просмотреть файл

@ -137,6 +137,21 @@ let ACTORS = {
},
},
NetError: {
parent: {
moduleURI: "resource:///actors/NetErrorParent.jsm",
},
child: {
moduleURI: "resource:///actors/NetErrorChild.jsm",
events: {
click: {},
},
},
matches: ["about:certerror?*", "about:neterror?*"],
allFrames: true,
},
PageInfo: {
child: {
moduleURI: "resource:///actors/PageInfoChild.jsm",
@ -335,17 +350,6 @@ let LEGACY_ACTORS = {
},
},
NetError: {
child: {
module: "resource:///actors/NetErrorChild.jsm",
events: {
click: {},
},
matches: ["about:certerror?*", "about:neterror?*"],
allFrames: true,
},
},
OfflineApps: {
child: {
module: "resource:///actors/OfflineAppsChild.jsm",