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);
|
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);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// 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";
|
2016-11-24 18:08:30 +03:00
|
|
|
const DEFAULT_REMOTE_TYPE = WEB_REMOTE_TYPE;
|
|
|
|
|
2016-11-24 18:08:32 +03:00
|
|
|
function validatedWebRemoteType(aPreferredRemoteType) {
|
|
|
|
return aPreferredRemoteType && aPreferredRemoteType.startsWith(WEB_REMOTE_TYPE)
|
|
|
|
? aPreferredRemoteType : WEB_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
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,
|
2016-11-24 18:08:30 +03:00
|
|
|
|
2016-12-30 01:05:44 +03:00
|
|
|
canLoadURIInProcess: function(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 01:05:44 +03:00
|
|
|
getRemoteTypeForURI: function(aURL, aMultiProcess,
|
2016-11-24 18:08:30 +03:00
|
|
|
aPreferredRemoteType = DEFAULT_REMOTE_TYPE) {
|
|
|
|
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
|
|
|
|
2015-02-18 21:59:10 +03:00
|
|
|
// Javascript urls can load in any process, they apply to the current document
|
2016-11-24 18:08:30 +03:00
|
|
|
if (aURL.startsWith("javascript:")) {
|
|
|
|
return aPreferredRemoteType;
|
|
|
|
}
|
2016-11-17 18:48:52 +03:00
|
|
|
|
2016-11-24 18:08:30 +03:00
|
|
|
// We need data: URIs to load in any remote process, because some of our
|
|
|
|
// tests rely on this.
|
|
|
|
if (aURL.startsWith("data:")) {
|
|
|
|
return aPreferredRemoteType == NOT_REMOTE ? DEFAULT_REMOTE_TYPE
|
|
|
|
: aPreferredRemoteType;
|
|
|
|
}
|
2016-11-23 16:36:57 +03:00
|
|
|
|
2016-11-24 18:08:32 +03:00
|
|
|
if (aURL.startsWith("file:")) {
|
|
|
|
return Services.prefs.getBoolPref("browser.tabs.remote.separateFileUriProcess")
|
|
|
|
? FILE_REMOTE_TYPE : DEFAULT_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
2016-11-23 20:33:10 +03:00
|
|
|
if (aURL.startsWith("about:")) {
|
2016-11-24 18:08:30 +03:00
|
|
|
// We need to special case about:blank because it needs to load in any.
|
|
|
|
if (aURL == "about:blank") {
|
|
|
|
return aPreferredRemoteType;
|
|
|
|
}
|
|
|
|
|
2015-02-05 19:09:15 +03:00
|
|
|
let url = Services.io.newURI(aURL, null, null);
|
|
|
|
let module = getAboutModule(url);
|
|
|
|
// If the module doesn't exist then an error page will be loading, that
|
2016-11-24 18:08:30 +03:00
|
|
|
// should be ok to load in any process
|
|
|
|
if (!module) {
|
|
|
|
return aPreferredRemoteType;
|
|
|
|
}
|
|
|
|
|
|
|
|
let flags = module.getURIFlags(url);
|
|
|
|
if (flags & Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
2015-02-05 19:09:15 +03:00
|
|
|
}
|
2016-11-24 18:08:30 +03:00
|
|
|
|
|
|
|
if (flags & Ci.nsIAboutModule.URI_CAN_LOAD_IN_CHILD &&
|
|
|
|
aPreferredRemoteType != NOT_REMOTE) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOT_REMOTE;
|
2015-02-04 02:51:24 +03:00
|
|
|
}
|
2015-01-08 02:56:18 +03:00
|
|
|
|
2015-02-05 19:09:15 +03:00
|
|
|
if (aURL.startsWith("chrome:")) {
|
2016-05-11 12:42:21 +03:00
|
|
|
let url;
|
|
|
|
try {
|
|
|
|
// This can fail for invalid Chrome URIs, in which case we will end up
|
|
|
|
// not loading anything anyway.
|
|
|
|
url = Services.io.newURI(aURL, null, null);
|
|
|
|
} catch (ex) {
|
2016-11-24 18:08:30 +03:00
|
|
|
return aPreferredRemoteType;
|
2016-05-11 12:42:21 +03:00
|
|
|
}
|
2016-11-17 18:48:52 +03:00
|
|
|
|
2016-11-24 18:08:30 +03:00
|
|
|
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIXULChromeRegistry);
|
|
|
|
if (chromeReg.mustLoadURLRemotely(url)) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
2016-05-11 12:42:21 +03:00
|
|
|
}
|
2016-11-24 18:08:30 +03:00
|
|
|
|
|
|
|
if (chromeReg.canLoadURLRemotely(url) &&
|
|
|
|
aPreferredRemoteType != NOT_REMOTE) {
|
|
|
|
return DEFAULT_REMOTE_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOT_REMOTE;
|
2016-11-18 03:10:00 +03:00
|
|
|
}
|
2016-11-17 18:48:52 +03:00
|
|
|
|
2015-06-04 01:34:44 +03:00
|
|
|
if (aURL.startsWith("moz-extension:")) {
|
2016-11-24 18:08:30 +03:00
|
|
|
return useRemoteWebExtensions ? WEB_REMOTE_TYPE : NOT_REMOTE;
|
2015-06-04 01:34:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aURL.startsWith("view-source:")) {
|
2016-11-24 18:08:30 +03:00
|
|
|
return this.getRemoteTypeForURI(aURL.substr("view-source:".length),
|
|
|
|
aMultiProcess, aPreferredRemoteType);
|
2015-06-04 01:34:44 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:08:32 +03:00
|
|
|
return validatedWebRemoteType(aPreferredRemoteType);
|
2014-09-25 22:35:45 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 01:05:44 +03:00
|
|
|
shouldLoadURIInThisProcess: function(aURI) {
|
2016-11-24 18:08:31 +03:00
|
|
|
let remoteType = Services.appinfo.remoteType;
|
|
|
|
return remoteType == this.getRemoteTypeForURI(aURI.spec, true, remoteType);
|
|
|
|
},
|
|
|
|
|
2016-12-30 01:05:44 +03:00
|
|
|
shouldLoadURI: function(aDocShell, aURI, aReferrer) {
|
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;
|
|
|
|
|
|
|
|
// 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
|
|
|
},
|
|
|
|
|
2016-12-30 01:05:44 +03:00
|
|
|
redirectLoad: function(aDocShell, aURI, aReferrer, aFreshProcess) {
|
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,
|
|
|
|
flags: Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
|
|
|
referrer: aReferrer ? aReferrer.spec : 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 01:05:44 +03:00
|
|
|
wrapHandlingUserInput: function(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
|
|
|
};
|