2014-09-25 22:35:45 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["E10SUtils"];
|
|
|
|
|
|
|
|
const {interfaces: Ci, utils: Cu, classes: Cc} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2016-11-13 02:36:03 +03:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "useRemoteWebExtensions",
|
|
|
|
"extensions.webextensions.remote", false);
|
2017-02-06 15:14:21 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "useSeparateFileUriProcess",
|
|
|
|
"browser.tabs.remote.separateFileUriProcess", false);
|
2017-03-10 13:53:44 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "allowLinkedWebInFileUriProcess",
|
|
|
|
"browser.tabs.remote.allowLinkedWebInFileUriProcess", false);
|
2017-01-18 10:24:55 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Utils",
|
|
|
|
"resource://gre/modules/sessionstore/Utils.jsm");
|
2017-02-06 15:14:21 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "console",
|
|
|
|
"resource://gre/modules/Console.jsm");
|
2014-09-25 22:35:45 +04:00
|
|
|
|
2015-02-05 19:09:15 +03:00
|
|
|
function getAboutModule(aURL) {
|
|
|
|
// Needs to match NS_GetAboutModuleName
|
|
|
|
let moduleName = aURL.path.replace(/[#?].*/, "").toLowerCase();
|
|
|
|
let contract = "@mozilla.org/network/protocol/about;1?what=" + moduleName;
|
|
|
|
try {
|
|
|
|
return Cc[contract].getService(Ci.nsIAboutModule);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2015-02-05 19:09:15 +03:00
|
|
|
// Either the about module isn't defined or it is broken. In either case
|
|
|
|
// ignore it.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:08:30 +03:00
|
|
|
const NOT_REMOTE = null;
|
2016-11-24 18:08:32 +03:00
|
|
|
|
|
|
|
// These must match any similar ones in ContentParent.h.
|
2016-11-24 18:08:30 +03:00
|
|
|
const WEB_REMOTE_TYPE = "web";
|
2016-11-24 18:08:32 +03:00
|
|
|
const FILE_REMOTE_TYPE = "file";
|
2017-01-13 01:11:47 +03:00
|
|
|
const EXTENSION_REMOTE_TYPE = "extension";
|
2017-02-10 00:30:59 +03:00
|
|
|
|
|
|
|
// This must start with the WEB_REMOTE_TYPE above.
|
|
|
|
const LARGE_ALLOCATION_REMOTE_TYPE = "webLargeAllocation";
|
2016-11-24 18:08:30 +03:00
|
|
|
const DEFAULT_REMOTE_TYPE = WEB_REMOTE_TYPE;
|
|
|
|
|
2017-05-18 14:08:56 +03:00
|
|
|
function validatedWebRemoteType(aPreferredRemoteType, aTargetUri, aCurrentUri) {
|
2017-03-10 13:53:44 +03:00
|
|
|
if (!aPreferredRemoteType) {
|
|
|
|
return WEB_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPreferredRemoteType.startsWith(WEB_REMOTE_TYPE)) {
|
|
|
|
return aPreferredRemoteType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allowLinkedWebInFileUriProcess &&
|
|
|
|
aPreferredRemoteType == FILE_REMOTE_TYPE) {
|
2017-05-18 14:08:56 +03:00
|
|
|
// If aCurrentUri is passed then we should only allow FILE_REMOTE_TYPE
|
|
|
|
// when it is same origin as target.
|
|
|
|
if (aCurrentUri) {
|
|
|
|
const sm = Services.scriptSecurityManager;
|
|
|
|
try {
|
|
|
|
// checkSameOriginURI throws when not same origin.
|
|
|
|
sm.checkSameOriginURI(aCurrentUri, aTargetUri, false);
|
|
|
|
return FILE_REMOTE_TYPE;
|
|
|
|
} catch (e) {
|
|
|
|
return WEB_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FILE_REMOTE_TYPE;
|
2017-03-10 13:53:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return WEB_REMOTE_TYPE;
|
2016-11-24 18:08:32 +03:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:35:45 +04:00
|
|
|
this.E10SUtils = {
|
2016-11-24 18:08:30 +03:00
|
|
|
DEFAULT_REMOTE_TYPE,
|
|
|
|
NOT_REMOTE,
|
|
|
|
WEB_REMOTE_TYPE,
|
2016-11-24 18:08:32 +03:00
|
|
|
FILE_REMOTE_TYPE,
|
2017-01-13 01:11:47 +03:00
|
|
|
EXTENSION_REMOTE_TYPE,
|
2017-02-10 00:30:59 +03:00
|
|
|
LARGE_ALLOCATION_REMOTE_TYPE,
|
2016-11-24 18:08:30 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
canLoadURIInProcess(aURL, aProcess) {
|
2016-11-24 18:08:30 +03:00
|
|
|
let remoteType = aProcess == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
|
|
|
|
? DEFAULT_REMOTE_TYPE : NOT_REMOTE;
|
|
|
|
return remoteType == this.getRemoteTypeForURI(aURL, true, remoteType);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getRemoteTypeForURI(aURL, aMultiProcess,
|
2017-02-10 00:30:59 +03:00
|
|
|
aPreferredRemoteType = DEFAULT_REMOTE_TYPE,
|
2017-05-18 14:08:56 +03:00
|
|
|
aCurrentUri) {
|
2016-11-24 18:08:30 +03:00
|
|
|
if (!aMultiProcess) {
|
|
|
|
return NOT_REMOTE;
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:35:45 +04:00
|
|
|
// loadURI in browser.xml treats null as about:blank
|
2016-11-24 18:08:30 +03:00
|
|
|
if (!aURL) {
|
2014-09-25 22:35:45 +04:00
|
|
|
aURL = "about:blank";
|
2016-11-24 18:08:30 +03:00
|
|
|
}
|
2014-09-25 22:35:45 +04:00
|
|
|
|
2017-02-06 15:14:21 +03:00
|
|
|
let uri;
|
|
|
|
try {
|
2017-05-18 14:08:56 +03:00
|
|
|
uri = Services.uriFixup.createFixupURI(aURL, Ci.nsIURIFixup.FIXUP_FLAG_NONE);
|
2017-02-06 15:14:21 +03:00
|
|
|
} catch (e) {
|
|
|
|
// If we have an invalid URI, it's still possible that it might get
|
|
|
|
// fixed-up into a valid URI later on. However, we don't want to return
|
|
|
|
// aPreferredRemoteType here, in case the URI gets fixed-up into
|
|
|
|
// something that wouldn't normally run in that process.
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
2016-11-24 18:08:30 +03:00
|
|
|
}
|
2016-11-17 18:48:52 +03:00
|
|
|
|
2017-02-06 15:14:21 +03:00
|
|
|
return this.getRemoteTypeForURIObject(uri, aMultiProcess,
|
2017-05-18 14:08:56 +03:00
|
|
|
aPreferredRemoteType, aCurrentUri);
|
2017-02-06 15:14:21 +03:00
|
|
|
},
|
2016-11-24 18:08:30 +03:00
|
|
|
|
2017-02-06 15:14:21 +03:00
|
|
|
getRemoteTypeForURIObject(aURI, aMultiProcess,
|
2017-05-18 14:08:56 +03:00
|
|
|
aPreferredRemoteType = DEFAULT_REMOTE_TYPE,
|
|
|
|
aCurrentUri) {
|
2017-02-06 15:14:21 +03:00
|
|
|
if (!aMultiProcess) {
|
2016-11-24 18:08:30 +03:00
|
|
|
return NOT_REMOTE;
|
2015-02-04 02:51:24 +03:00
|
|
|
}
|
2015-01-08 02:56:18 +03:00
|
|
|
|
2017-02-06 15:14:21 +03:00
|
|
|
switch (aURI.scheme) {
|
|
|
|
case "javascript":
|
|
|
|
// javascript URIs can load in any, they apply to the current document.
|
2016-11-24 18:08:30 +03:00
|
|
|
return aPreferredRemoteType;
|
2016-11-17 18:48:52 +03:00
|
|
|
|
2017-02-06 15:14:21 +03:00
|
|
|
case "data":
|
|
|
|
case "blob":
|
|
|
|
// We need data: and blob: URIs to load in any remote process, because
|
|
|
|
// they need to be able to load in whatever is the current process
|
|
|
|
// unless it is non-remote. In that case we don't want to load them in
|
|
|
|
// the parent process, so we load them in the default remote process,
|
|
|
|
// which is sandboxed and limits any risk.
|
|
|
|
return aPreferredRemoteType == NOT_REMOTE ? DEFAULT_REMOTE_TYPE
|
|
|
|
: aPreferredRemoteType;
|
|
|
|
|
|
|
|
case "file":
|
|
|
|
return useSeparateFileUriProcess ? FILE_REMOTE_TYPE
|
|
|
|
: DEFAULT_REMOTE_TYPE;
|
|
|
|
|
|
|
|
case "about":
|
|
|
|
let module = getAboutModule(aURI);
|
|
|
|
// If the module doesn't exist then an error page will be loading, that
|
|
|
|
// should be ok to load in any process
|
|
|
|
if (!module) {
|
|
|
|
return aPreferredRemoteType;
|
|
|
|
}
|
|
|
|
|
|
|
|
let flags = module.getURIFlags(aURI);
|
|
|
|
if (flags & Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the about page can load in parent or child, it should be safe to
|
|
|
|
// load in any remote type.
|
|
|
|
if (flags & Ci.nsIAboutModule.URI_CAN_LOAD_IN_CHILD) {
|
|
|
|
return aPreferredRemoteType;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOT_REMOTE;
|
|
|
|
|
|
|
|
case "chrome":
|
|
|
|
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIXULChromeRegistry);
|
|
|
|
if (chromeReg.mustLoadURLRemotely(aURI)) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chromeReg.canLoadURLRemotely(aURI) &&
|
|
|
|
aPreferredRemoteType != NOT_REMOTE) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOT_REMOTE;
|
|
|
|
|
|
|
|
case "moz-extension":
|
|
|
|
return useRemoteWebExtensions ? EXTENSION_REMOTE_TYPE : NOT_REMOTE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// For any other nested URIs, we use the innerURI to determine the
|
|
|
|
// remote type. In theory we should use the innermost URI, but some URIs
|
|
|
|
// have fake inner URIs (e.g. about URIs with inner moz-safe-about) and
|
|
|
|
// if such URIs are wrapped in other nested schemes like view-source:,
|
|
|
|
// we don't want to "skip" past "about:" by going straight to the
|
|
|
|
// innermost URI. Any URIs like this will need to be handled in the
|
|
|
|
// cases above, so we don't still end up using the fake inner URI here.
|
|
|
|
if (aURI instanceof Ci.nsINestedURI) {
|
|
|
|
let innerURI = aURI.QueryInterface(Ci.nsINestedURI).innerURI;
|
|
|
|
return this.getRemoteTypeForURIObject(innerURI, aMultiProcess,
|
2017-05-18 14:08:56 +03:00
|
|
|
aPreferredRemoteType,
|
|
|
|
aCurrentUri);
|
2017-02-06 15:14:21 +03:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:08:56 +03:00
|
|
|
return validatedWebRemoteType(aPreferredRemoteType, aURI, aCurrentUri);
|
2015-06-04 01:34:44 +03:00
|
|
|
}
|
2014-09-25 22:35:45 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
shouldLoadURIInThisProcess(aURI) {
|
2016-11-24 18:08:31 +03:00
|
|
|
let remoteType = Services.appinfo.remoteType;
|
2017-02-06 15:14:21 +03:00
|
|
|
return remoteType == this.getRemoteTypeForURIObject(aURI, true, remoteType);
|
2016-11-24 18:08:31 +03:00
|
|
|
},
|
|
|
|
|
2017-03-16 21:32:26 +03:00
|
|
|
shouldLoadURI(aDocShell, aURI, aReferrer, aHasPostData) {
|
2014-09-25 22:35:45 +04:00
|
|
|
// Inner frames should always load in the current process
|
|
|
|
if (aDocShell.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeParent)
|
|
|
|
return true;
|
|
|
|
|
2017-01-26 22:20:44 +03:00
|
|
|
// If we are in a Large-Allocation process, and it wouldn't be content visible
|
|
|
|
// to change processes, we want to load into a new process so that we can throw
|
2017-03-16 21:32:26 +03:00
|
|
|
// this one out. We don't want to move into a new process if we have post data,
|
|
|
|
// because we would accidentally throw out that data.
|
|
|
|
if (!aHasPostData &&
|
|
|
|
Services.appinfo.remoteType == LARGE_ALLOCATION_REMOTE_TYPE &&
|
2017-01-26 22:20:44 +03:00
|
|
|
!aDocShell.awaitingLargeAlloc &&
|
|
|
|
aDocShell.isOnlyToplevelInTabGroup) {
|
2017-01-07 00:38:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:08:56 +03:00
|
|
|
// Allow history load if loaded in this process before.
|
|
|
|
let webNav = aDocShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
let sessionHistory = webNav.sessionHistory;
|
|
|
|
let requestedIndex = sessionHistory.requestedIndex;
|
|
|
|
if (requestedIndex >= 0) {
|
|
|
|
if (sessionHistory.getEntryAtIndex(requestedIndex, false).loadedInThisProcess) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not originally loaded in this process allow it if the URI would
|
|
|
|
// normally be allowed to load in this process by default.
|
|
|
|
let remoteType = Services.appinfo.remoteType;
|
|
|
|
return remoteType ==
|
|
|
|
this.getRemoteTypeForURIObject(aURI, true, remoteType, webNav.currentURI);
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:35:45 +04:00
|
|
|
// If the URI can be loaded in the current process then continue
|
2016-11-24 18:08:31 +03:00
|
|
|
return this.shouldLoadURIInThisProcess(aURI);
|
2014-09-25 22:35:45 +04:00
|
|
|
},
|
|
|
|
|
2017-01-27 22:14:31 +03:00
|
|
|
redirectLoad(aDocShell, aURI, aReferrer, aTriggeringPrincipal, aFreshProcess, aFlags) {
|
2014-09-25 22:35:45 +04:00
|
|
|
// Retarget the load to the correct process
|
|
|
|
let messageManager = aDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIContentFrameMessageManager);
|
|
|
|
let sessionHistory = aDocShell.getInterface(Ci.nsIWebNavigation).sessionHistory;
|
|
|
|
|
|
|
|
messageManager.sendAsyncMessage("Browser:LoadURI", {
|
2014-10-29 23:26:14 +03:00
|
|
|
loadOptions: {
|
|
|
|
uri: aURI.spec,
|
2017-01-27 22:14:31 +03:00
|
|
|
flags: aFlags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
2014-10-29 23:26:14 +03:00
|
|
|
referrer: aReferrer ? aReferrer.spec : null,
|
2017-01-18 10:24:55 +03:00
|
|
|
triggeringPrincipal: aTriggeringPrincipal
|
|
|
|
? Utils.serializePrincipal(aTriggeringPrincipal)
|
|
|
|
: null,
|
2016-10-21 23:56:51 +03:00
|
|
|
reloadInFreshProcess: !!aFreshProcess,
|
2014-10-29 23:26:14 +03:00
|
|
|
},
|
2014-09-25 22:35:45 +04:00
|
|
|
historyIndex: sessionHistory.requestedIndex,
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
2016-03-29 06:58:43 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
wrapHandlingUserInput(aWindow, aIsHandling, aCallback) {
|
2016-03-29 06:58:43 +03:00
|
|
|
var handlingUserInput;
|
|
|
|
try {
|
|
|
|
handlingUserInput = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.setHandlingUserInput(aIsHandling);
|
|
|
|
aCallback();
|
|
|
|
} finally {
|
|
|
|
handlingUserInput.destruct();
|
|
|
|
}
|
|
|
|
},
|
2014-09-25 22:35:45 +04:00
|
|
|
};
|