Bug 1147911 Part 6: Send remote type down to child. r=gijs, r=smaug

This commit is contained in:
Bob Owen 2016-11-17 15:48:52 +00:00
parent 04eeda5731
commit fb53b5987c
9 changed files with 77 additions and 12 deletions

View File

@ -26,6 +26,7 @@ function getAboutModule(aURL) {
const NOT_REMOTE = null;
const WEB_REMOTE_TYPE = "web";
// This must match the one in ContentParent.h.
const DEFAULT_REMOTE_TYPE = WEB_REMOTE_TYPE;
this.E10SUtils = {
@ -117,13 +118,18 @@ this.E10SUtils = {
return WEB_REMOTE_TYPE;
},
shouldLoadURIInThisProcess: function(aURI) {
let remoteType = Services.appinfo.remoteType;
return remoteType == this.getRemoteTypeForURI(aURI.spec, true, remoteType);
},
shouldLoadURI: function(aDocShell, aURI, aReferrer) {
// 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
return this.canLoadURIInProcess(aURI.spec, Services.appinfo.processType);
return this.shouldLoadURIInThisProcess(aURI);
},
redirectLoad: function(aDocShell, aURI, aReferrer, aFreshProcess) {

View File

@ -2214,6 +2214,7 @@ GK_ATOM(monospace, "monospace")
// IPC stuff
GK_ATOM(Remote, "remote")
GK_ATOM(RemoteId, "_remote_id")
GK_ATOM(RemoteType, "remoteType")
GK_ATOM(DisplayPort, "_displayport")
GK_ATOM(DisplayPortMargins, "_displayportmargins")
GK_ATOM(DisplayPortBase, "_displayportbase")

View File

@ -2352,6 +2352,21 @@ ContentChild::RecvAppInfo(const nsCString& version, const nsCString& buildID,
return IPC_OK();
}
mozilla::ipc::IPCResult
ContentChild::RecvRemoteType(const nsString& aRemoteType)
{
MOZ_ASSERT(DOMStringIsNull(mRemoteType));
mRemoteType.Assign(aRemoteType);
return IPC_OK();
}
const nsAString&
ContentChild::GetRemoteType() const
{
return mRemoteType;
}
mozilla::ipc::IPCResult
ContentChild::RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig)
{

View File

@ -422,6 +422,10 @@ public:
const nsCString& name, const nsCString& UAName,
const nsCString& ID, const nsCString& vendor) override;
virtual mozilla::ipc::IPCResult RecvRemoteType(const nsString& aRemoteType) override;
const nsAString& GetRemoteType() const;
virtual mozilla::ipc::IPCResult
RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig) override;
@ -680,6 +684,7 @@ private:
AppInfo mAppInfo;
bool mIsForBrowser;
nsString mRemoteType = NullString();
bool mCanOverrideProcessName;
bool mIsAlive;
nsString mProcessName;

View File

@ -642,7 +642,7 @@ ContentParent::JoinAllSubprocesses()
}
/*static*/ already_AddRefed<ContentParent>
ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
ContentParent::GetNewOrUsedBrowserProcess(const nsAString& aRemoteType,
ProcessPriority aPriority,
ContentParent* aOpener,
bool aLargeAllocationProcess)
@ -687,8 +687,7 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
} while (currIdx != startIdx);
}
RefPtr<ContentParent> p = new ContentParent(aOpener,
aForBrowserElement);
RefPtr<ContentParent> p = new ContentParent(aOpener, aRemoteType);
if (!p->LaunchSubprocess(aPriority)) {
return nullptr;
@ -772,8 +771,7 @@ ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
return IPC_FAIL_NO_REASON(this);
}
cp = GetNewOrUsedBrowserProcess(/* isBrowserElement = */ true,
aPriority, this);
cp = GetNewOrUsedBrowserProcess(DEFAULT_REMOTE_TYPE, aPriority, this);
if (!cp) {
*aCpId = 0;
@ -965,9 +963,15 @@ ContentParent::CreateBrowser(const TabContext& aContext,
if (aOpenerContentParent) {
constructorSender = aOpenerContentParent;
} else {
nsAutoString remoteType;
if (!aFrameElement->GetAttr(kNameSpaceID_None, nsGkAtoms::RemoteType,
remoteType)) {
remoteType.Assign(DEFAULT_REMOTE_TYPE);
}
constructorSender =
GetNewOrUsedBrowserProcess(aContext.IsMozBrowserElement(),
initialPriority, nullptr, aFreshProcess);
GetNewOrUsedBrowserProcess(remoteType, initialPriority, nullptr,
aFreshProcess);
if (!constructorSender) {
return nullptr;
}
@ -1141,6 +1145,9 @@ ContentParent::ForwardKnownInfo()
if (!mMetamorphosed) {
return;
}
Unused << SendRemoteType(mRemoteType);
#ifdef MOZ_WIDGET_GONK
InfallibleTArray<VolumeInfo> volumeInfo;
RefPtr<nsVolumeService> vs = nsVolumeService::GetSingleton();
@ -1787,10 +1794,11 @@ ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PR
}
ContentParent::ContentParent(ContentParent* aOpener,
bool aIsForBrowser)
const nsAString& aRemoteType)
: nsIContentParent()
, mOpener(aOpener)
, mIsForBrowser(aIsForBrowser)
, mRemoteType(aRemoteType)
, mIsForBrowser(!mRemoteType.IsEmpty())
, mLargeAllocationProcess(false)
{
InitializeMembers(); // Perform common initialization.

View File

@ -84,6 +84,10 @@ class TabContext;
class ContentBridgeParent;
class GetFilesHelper;
// This must match the one in E10SUtils.jsm.
static NS_NAMED_LITERAL_STRING(DEFAULT_REMOTE_TYPE, "web");
static NS_NAMED_LITERAL_STRING(NO_REMOTE_TYPE, "");
class ContentParent final : public PContentParent
, public nsIContentParent
, public nsIObserver
@ -129,7 +133,7 @@ public:
* 3. normal iframe
*/
static already_AddRefed<ContentParent>
GetNewOrUsedBrowserProcess(bool aForBrowserElement = false,
GetNewOrUsedBrowserProcess(const nsAString& aRemoteType = NO_REMOTE_TYPE,
hal::ProcessPriority aPriority =
hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
ContentParent* aOpener = nullptr,
@ -565,7 +569,7 @@ private:
FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
ContentParent(ContentParent* aOpener,
bool aIsForBrowser);
const nsAString& aRemoteType);
// The common initialization for the constructors.
void InitializeMembers();
@ -1044,6 +1048,8 @@ private:
GeckoChildProcessHost* mSubprocess;
ContentParent* mOpener;
nsString mRemoteType;
ContentParentId mChildID;
int32_t mGeolocationWatchID;

View File

@ -530,6 +530,11 @@ child:
async AppInfo(nsCString version, nsCString buildID, nsCString name, nsCString UAName,
nsCString ID, nsCString vendor);
/**
* Send the remote type associated with the content process.
*/
async RemoteType(nsString aRemoteType);
/**
* Send ServiceWorkerRegistrationData to child process.
*/

View File

@ -888,6 +888,19 @@ nsXULAppInfo::GetUniqueProcessID(uint64_t* aResult)
return NS_OK;
}
NS_IMETHODIMP
nsXULAppInfo::GetRemoteType(nsAString& aRemoteType)
{
if (XRE_IsContentProcess()) {
ContentChild* cc = ContentChild::GetSingleton();
aRemoteType.Assign(cc->GetRemoteType());
} else {
SetDOMStringToNull(aRemoteType);
}
return NS_OK;
}
static bool gBrowserTabsRemoteAutostart = false;
static uint64_t gBrowserTabsRemoteStatus = 0;
static bool gBrowserTabsRemoteAutostartInitialized = false;

View File

@ -91,6 +91,12 @@ interface nsIXULRuntime : nsISupports
*/
readonly attribute uint64_t uniqueProcessID;
/**
* The type of remote content process we're running in.
* null if we're in the parent/chrome process.
*/
readonly attribute DOMString remoteType;
/**
* If true, browser tabs may be opened by default in a different process
* from the main browser UI.