Skip to content

Commit

Permalink
Bug 666809 - Support SecurityUI in e10s mode. r=felipe f=gavin [missi…
Browse files Browse the repository at this point in the history
…ng bits]
  • Loading branch information
rmottola committed Aug 28, 2019
1 parent d0758c5 commit 0e7aa13
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 44 deletions.
77 changes: 33 additions & 44 deletions browser/base/content/browser.js
Expand Up @@ -3458,10 +3458,6 @@ var XULBrowserWindow = {
init: function () {
this.throbberElement = document.getElementById("navigator-throbber");

// Bug 666809 - SecurityUI support for e10s
if (gMultiProcessBrowser)
return;

// Initialize the security button's state and tooltip text. Remember to reset
// _hostChanged, otherwise onSecurityChange will short circuit.
var securityUI = gBrowser.securityUI;
Expand Down Expand Up @@ -3880,26 +3876,11 @@ var XULBrowserWindow = {
gURLBar.removeAttribute("level");
}

if (gMultiProcessBrowser)
return;

// Don't pass in the actual location object, since it can cause us to
// hold on to the window object too long. Just pass in the fields we
// care about. (bug 424829)
var location = gBrowser.contentWindow.location;
var locationObj = {};
let uri = gBrowser.currentURI;
try {
// about:blank can be used by webpages so pretend it is http
locationObj.protocol = location == "about:blank" ? "http:" : location.protocol;
locationObj.host = location.host;
locationObj.hostname = location.hostname;
locationObj.port = location.port;
} catch (ex) {
// Can sometimes throw if the URL being visited has no host/hostname,
// e.g. about:blank. The _state for these pages means we won't need these
// properties anyways, though.
}
gIdentityHandler.checkIdentity(this._state, locationObj);
uri = Services.uriFixup.createExposableURI(uri);
} catch (e) {}
gIdentityHandler.checkIdentity(this._state, uri);
},

// simulate all change notifications after switching tabs
Expand Down Expand Up @@ -6148,7 +6129,7 @@ var gIdentityHandler = {

// Cache the most recent SSLStatus and Location seen in checkIdentity
_lastStatus : null,
_lastLocation : null,
_lastUri : null,
_mode : "unknownIdentity",

// smart getters
Expand Down Expand Up @@ -6286,19 +6267,29 @@ var gIdentityHandler = {
* be called by onSecurityChange
*
* @param PRUint32 state
* @param JS Object location that mirrors an nsLocation (i.e. has .host and
* .hostname and .port)
* @param nsIURI uri The address for which the UI should be updated.
*/
checkIdentity : function(state, location) {
checkIdentity : function(state, uri) {
var currentStatus = gBrowser.securityUI
.QueryInterface(Components.interfaces.nsISSLStatusProvider)
.SSLStatus;
this._lastStatus = currentStatus;
this._lastLocation = location;
this._lastUri = uri;

let nsIWebProgressListener = Ci.nsIWebProgressListener;
if (location.protocol == "chrome:" || location.protocol == "about:") {

// For some URIs like data: we can't get a host and so can't do
// anything useful here. Chrome URIs however get special treatment.
let unknown = false;
try {
uri.host;
} catch (e) { unknown = true; }

if ((uri.scheme == "chrome" || uri.scheme == "about") &&
uri.spec !== "about:blank") {
this.setMode(this.IDENTITY_MODE_CHROMEUI);
} else if (unknown) {
this.setMode(this.IDENTITY_MODE_UNKNOWN);
} else if (state & nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL) {
this.setMode(this.IDENTITY_MODE_IDENTIFIED);
} else if (state & nsIWebProgressListener.STATE_IS_SECURE) {
Expand Down Expand Up @@ -6361,12 +6352,12 @@ var gIdentityHandler = {
getEffectiveHost : function() {
try {
let baseDomain =
Services.eTLD.getBaseDomainFromHost(this._lastLocation.hostname);
Services.eTLD.getBaseDomainFromHost(this._lastUri.host);
return this._IDNService.convertToDisplayIDN(baseDomain, {});
} catch (e) {
// If something goes wrong (e.g. hostname is an IP address) just fail back
// If something goes wrong (e.g. host is an IP address) just fail back
// to the full domain.
return this._lastLocation.hostname;
return this._lastUri.host;
}
},

Expand Down Expand Up @@ -6435,19 +6426,17 @@ var gIdentityHandler = {
tooltip = gNavigatorBundle.getFormattedString("identity.identified.verifier",
[iData.caOrg]);

// Check whether this site is a security exception. XPConnect does the right
// thing here in terms of converting _lastLocation.port from string to int, but
// the overrideService doesn't like undefined ports, so make sure we have
// something in the default case (bug 432241).
// .hostname can return an empty string in some exceptional cases -
// hasMatchingOverride does not handle that, so avoid calling it.
// Updating the tooltip value in those cases isn't critical.
// FIXME: Fixing bug 646690 would probably makes this check unnecessary
if (this._lastLocation.hostname &&
this._overrideService.hasMatchingOverride(this._lastLocation.hostname,
(this._lastLocation.port || 443),
iData.cert, {}, {}))
// This can't throw, because URI's with a host that throw don't end up in this case.
let host = this._lastUri.host;
let port = 443;
try {
if (this._lastUri.port > 0)
port = this._lastUri.port;
} catch (e) {}

if (this._overrideService.hasMatchingOverride(host, port, iData.cert, {}, {}))
tooltip = gNavigatorBundle.getString("identity.identified.verified_by_you");

break; }
case this.IDENTITY_MODE_IDENTIFIED: {
// If it's identified, then we can populate the dialog with credentials
Expand Down
48 changes: 48 additions & 0 deletions toolkit/modules/RemoteSecurityUI.jsm
@@ -1,3 +1,51 @@
// -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 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/.

this.EXPORTED_SYMBOLS = ["RemoteSecurityUI"];

const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

function RemoteSecurityUI()
{
this._state = 0;
this._SSLStatus = null;
}

RemoteSecurityUI.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISSLStatusProvider, Ci.nsISecureBrowserUI]),

// nsISecureBrowserUI
get state() { return this._state; },
get tooltipText() { return ""; },

// nsISSLStatusProvider
get SSLStatus() { return this._SSLStatus; },

_update: function (state, status) {
let deserialized = null;
if (status) {
let helper = Cc["@mozilla.org/network/serialization-helper;1"]
.getService(Components.interfaces.nsISerializationHelper);

deserialized = helper.deserializeObject(status)
deserialized.QueryInterface(Ci.nsISSLStatus);
}

// We must check the Extended Validation (EV) state here, on the chrome
// process, because NSS is needed for that determination.
if (deserialized && deserialized.isExtendedValidation)
state |= Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL;

this._state = state;
this._SSLStatus = deserialized;
}
};
// -*- 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
Expand Down

0 comments on commit 0e7aa13

Please sign in to comment.