mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1689601, pass various states of remoteness change / browsing context swap using a helper struct, r=peterv
The name RemotenessChangeState uses same the convention as the related methods, even though there might not be a remoteness change happening, only a browsing context switch. But the naming inconsistency exists there even without any bfcache work. RemotenessChangeState will be renamed to RemotenessChangeOptions in a followup. Differential Revision: https://phabricator.services.mozilla.com/D105229
This commit is contained in:
parent
aead729570
commit
3df3621351
@ -156,8 +156,8 @@ void CanonicalBrowsingContext::MaybeAddAsProgressListener(
|
||||
aWebProgress->AddProgressListener(mStatusFilter, nsIWebProgress::NOTIFY_ALL);
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::ReplacedBy(
|
||||
CanonicalBrowsingContext* aNewContext) {
|
||||
void CanonicalBrowsingContext::ReplacedBy(CanonicalBrowsingContext* aNewContext,
|
||||
const RemotenessChangeState& aState) {
|
||||
MOZ_ASSERT(!aNewContext->EverAttached());
|
||||
MOZ_ASSERT(IsTop() && aNewContext->IsTop());
|
||||
if (mStatusFilter) {
|
||||
@ -1123,8 +1123,8 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Finish() {
|
||||
// The process has been created, hand off to nsFrameLoaderOwner to finish
|
||||
// the process switch.
|
||||
ErrorResult error;
|
||||
frameLoaderOwner->ChangeRemotenessToProcess(
|
||||
mContentParent, mReplaceBrowsingContext, mSpecificGroup, error);
|
||||
frameLoaderOwner->ChangeRemotenessToProcess(mContentParent, mState,
|
||||
mSpecificGroup, error);
|
||||
if (error.Failed()) {
|
||||
Cancel(error.StealNSResult());
|
||||
return;
|
||||
@ -1228,7 +1228,7 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Finish() {
|
||||
oldBrowser->Destroy();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!mReplaceBrowsingContext, "Cannot replace BC for subframe");
|
||||
MOZ_ASSERT(!mState.mReplaceBrowsingContext, "Cannot replace BC for subframe");
|
||||
nsCOMPtr<nsIPrincipal> initialPrincipal =
|
||||
NullPrincipal::CreateWithInheritedAttributes(
|
||||
target->OriginAttributesRef(),
|
||||
@ -1314,11 +1314,11 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Clear() {
|
||||
|
||||
CanonicalBrowsingContext::PendingRemotenessChange::PendingRemotenessChange(
|
||||
CanonicalBrowsingContext* aTarget, RemotenessPromise::Private* aPromise,
|
||||
uint64_t aPendingSwitchId, bool aReplaceBrowsingContext)
|
||||
uint64_t aPendingSwitchId, const RemotenessChangeState& aState)
|
||||
: mTarget(aTarget),
|
||||
mPromise(aPromise),
|
||||
mPendingSwitchId(aPendingSwitchId),
|
||||
mReplaceBrowsingContext(aReplaceBrowsingContext) {}
|
||||
mState(aState) {}
|
||||
|
||||
CanonicalBrowsingContext::PendingRemotenessChange::~PendingRemotenessChange() {
|
||||
MOZ_ASSERT(!mPromise && !mTarget && !mContentParent && !mSpecificGroup &&
|
||||
@ -1334,19 +1334,18 @@ BrowserParent* CanonicalBrowsingContext::GetBrowserParent() const {
|
||||
}
|
||||
|
||||
RefPtr<CanonicalBrowsingContext::RemotenessPromise>
|
||||
CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
uint64_t aPendingSwitchId,
|
||||
bool aReplaceBrowsingContext,
|
||||
uint64_t aSpecificGroupId) {
|
||||
CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
|
||||
uint64_t aPendingSwitchId) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsContent(),
|
||||
"cannot change the process of chrome contexts");
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
IsTop() == IsEmbeddedInProcess(0),
|
||||
"toplevel content must be embedded in the parent process");
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aReplaceBrowsingContext || IsTop(),
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aState.mReplaceBrowsingContext || IsTop(),
|
||||
"Cannot replace BrowsingContext for subframes");
|
||||
MOZ_DIAGNOSTIC_ASSERT(aSpecificGroupId == 0 || aReplaceBrowsingContext,
|
||||
"Cannot specify group ID unless replacing BC");
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
aState.mSpecificGroupId == 0 || aState.mReplaceBrowsingContext,
|
||||
"Cannot specify group ID unless replacing BC");
|
||||
MOZ_DIAGNOSTIC_ASSERT(aPendingSwitchId || !IsTop(),
|
||||
"Should always have aPendingSwitchId for top-level "
|
||||
"frames");
|
||||
@ -1368,7 +1367,7 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
return RemotenessPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__);
|
||||
}
|
||||
|
||||
if (aRemoteType.IsEmpty() && (!IsTop() || !GetEmbedderElement())) {
|
||||
if (aState.mRemoteType.IsEmpty() && (!IsTop() || !GetEmbedderElement())) {
|
||||
NS_WARNING("Cannot load non-remote subframes");
|
||||
return RemotenessPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
|
||||
}
|
||||
@ -1383,7 +1382,7 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
embedderWindowGlobal->GetBrowserParent();
|
||||
// Switching to local. No new process, so perform switch sync.
|
||||
if (embedderBrowser &&
|
||||
aRemoteType == embedderBrowser->Manager()->GetRemoteType()) {
|
||||
aState.mRemoteType == embedderBrowser->Manager()->GetRemoteType()) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
aPendingSwitchId,
|
||||
"We always have a PendingSwitchId, except for print-preview loads, "
|
||||
@ -1405,8 +1404,8 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
|
||||
// If the embedder process is remote, tell that remote process to become
|
||||
// the owner.
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aReplaceBrowsingContext);
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aRemoteType.IsEmpty());
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aState.mReplaceBrowsingContext);
|
||||
MOZ_DIAGNOSTIC_ASSERT(!aState.mRemoteType.IsEmpty());
|
||||
SetOwnerProcessId(embedderBrowser->Manager()->ChildID());
|
||||
Unused << embedderWindowGlobal->SendMakeFrameLocal(this, aPendingSwitchId);
|
||||
return RemotenessPromise::CreateAndResolve(embedderBrowser, __func__);
|
||||
@ -1414,15 +1413,15 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
|
||||
// Switching to remote. Wait for new process to launch before switch.
|
||||
auto promise = MakeRefPtr<RemotenessPromise::Private>(__func__);
|
||||
RefPtr<PendingRemotenessChange> change = new PendingRemotenessChange(
|
||||
this, promise, aPendingSwitchId, aReplaceBrowsingContext);
|
||||
RefPtr<PendingRemotenessChange> change =
|
||||
new PendingRemotenessChange(this, promise, aPendingSwitchId, aState);
|
||||
mPendingRemotenessChange = change;
|
||||
|
||||
// If a specific BrowsingContextGroup ID was specified for this load, make
|
||||
// sure to keep it alive until the process switch is completed.
|
||||
if (aSpecificGroupId) {
|
||||
if (aState.mSpecificGroupId) {
|
||||
change->mSpecificGroup =
|
||||
BrowsingContextGroup::GetOrCreate(aSpecificGroupId);
|
||||
BrowsingContextGroup::GetOrCreate(aState.mSpecificGroupId);
|
||||
change->mSpecificGroup->AddKeepAlive();
|
||||
}
|
||||
|
||||
@ -1444,7 +1443,7 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
change->mPrepareToChangePromise = GenericPromise::FromDomPromise(blocker);
|
||||
}
|
||||
|
||||
if (aRemoteType.IsEmpty()) {
|
||||
if (aState.mRemoteType.IsEmpty()) {
|
||||
change->ProcessReady();
|
||||
} else {
|
||||
// Try to predict which BrowsingContextGroup will be used for the final load
|
||||
@ -1456,10 +1455,10 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsACString& aRemoteType,
|
||||
// switch into a brand new group, though it's sub-optimal, as it can
|
||||
// restrict the set of processes we're using.
|
||||
BrowsingContextGroup* finalGroup =
|
||||
aReplaceBrowsingContext ? change->mSpecificGroup.get() : Group();
|
||||
aState.mReplaceBrowsingContext ? change->mSpecificGroup.get() : Group();
|
||||
|
||||
change->mContentParent = ContentParent::GetNewOrUsedLaunchingBrowserProcess(
|
||||
/* aRemoteType = */ aRemoteType,
|
||||
/* aRemoteType = */ aState.mRemoteType,
|
||||
/* aGroup = */ finalGroup,
|
||||
/* aPriority = */ hal::PROCESS_PRIORITY_FOREGROUND,
|
||||
/* aPreferUsed = */ false);
|
||||
|
@ -44,6 +44,15 @@ struct LoadingSessionHistoryInfo;
|
||||
class SessionHistoryEntry;
|
||||
class WindowGlobalParent;
|
||||
|
||||
// RemotenessChangeState is passed through the methods to store the state
|
||||
// of the possible remoteness change.
|
||||
struct RemotenessChangeState {
|
||||
nsCString mRemoteType;
|
||||
bool mReplaceBrowsingContext = false;
|
||||
uint64_t mSpecificGroupId = 0;
|
||||
bool mTryUseBFCache = false;
|
||||
};
|
||||
|
||||
// CanonicalBrowsingContext is a BrowsingContext living in the parent
|
||||
// process, with whatever extra data that a BrowsingContext in the
|
||||
// parent needs.
|
||||
@ -206,10 +215,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
// A NOT_REMOTE_TYPE aRemoteType argument will perform a process switch into
|
||||
// the parent process, and the method will resolve with a null BrowserParent.
|
||||
using RemotenessPromise = MozPromise<RefPtr<BrowserParent>, nsresult, false>;
|
||||
RefPtr<RemotenessPromise> ChangeRemoteness(const nsACString& aRemoteType,
|
||||
uint64_t aPendingSwitchId,
|
||||
bool aReplaceBrowsingContext,
|
||||
uint64_t aSpecificGroupId);
|
||||
RefPtr<RemotenessPromise> ChangeRemoteness(
|
||||
const RemotenessChangeState& aState, uint64_t aPendingSwitchId);
|
||||
|
||||
// Return a media controller from the top-level browsing context that can
|
||||
// control all media belonging to this browsing context tree. Return nullptr
|
||||
@ -247,7 +254,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
// process).
|
||||
// aNewContext is the newly created BrowsingContext that is replacing
|
||||
// us.
|
||||
void ReplacedBy(CanonicalBrowsingContext* aNewContext);
|
||||
void ReplacedBy(CanonicalBrowsingContext* aNewContext,
|
||||
const RemotenessChangeState& aState);
|
||||
|
||||
bool HasHistoryEntry(nsISHEntry* aEntry);
|
||||
|
||||
@ -293,7 +301,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
PendingRemotenessChange(CanonicalBrowsingContext* aTarget,
|
||||
RemotenessPromise::Private* aPromise,
|
||||
uint64_t aPendingSwitchId,
|
||||
bool aReplaceBrowsingContext);
|
||||
const RemotenessChangeState& aState);
|
||||
|
||||
void Cancel(nsresult aRv);
|
||||
|
||||
@ -312,7 +320,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
RefPtr<BrowsingContextGroup> mSpecificGroup;
|
||||
|
||||
uint64_t mPendingSwitchId;
|
||||
bool mReplaceBrowsingContext;
|
||||
RemotenessChangeState mState;
|
||||
};
|
||||
|
||||
friend class net::DocumentLoadListener;
|
||||
|
@ -452,8 +452,8 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Create(
|
||||
/* static */
|
||||
already_AddRefed<nsFrameLoader> nsFrameLoader::Recreate(
|
||||
mozilla::dom::Element* aOwner, BrowsingContext* aContext,
|
||||
BrowsingContextGroup* aSpecificGroup, bool aIsRemote, bool aNetworkCreated,
|
||||
bool aPreserveContext) {
|
||||
BrowsingContextGroup* aSpecificGroup, const RemotenessChangeState& aState,
|
||||
bool aIsRemote, bool aNetworkCreated, bool aPreserveContext) {
|
||||
NS_ENSURE_TRUE(aOwner, nullptr);
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -473,7 +473,7 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Recreate(
|
||||
MOZ_ASSERT(
|
||||
XRE_IsParentProcess(),
|
||||
"Recreating browing contexts only supported in the parent process");
|
||||
aContext->Canonical()->ReplacedBy(context->Canonical());
|
||||
aContext->Canonical()->ReplacedBy(context->Canonical(), aState);
|
||||
}
|
||||
}
|
||||
NS_ENSURE_TRUE(context, nullptr);
|
||||
|
@ -71,6 +71,7 @@ class MutableTabContext;
|
||||
class BrowserBridgeChild;
|
||||
class RemoteBrowser;
|
||||
struct RemotenessOptions;
|
||||
struct RemotenessChangeState;
|
||||
|
||||
namespace ipc {
|
||||
class StructuredCloneData;
|
||||
@ -119,7 +120,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
|
||||
// FrameLoaders.
|
||||
static already_AddRefed<nsFrameLoader> Recreate(
|
||||
Element* aOwner, BrowsingContext* aContext, BrowsingContextGroup* aGroup,
|
||||
bool aIsRemote, bool aNetworkCreated, bool aPreserveContext);
|
||||
const mozilla::dom::RemotenessChangeState& aState, bool aIsRemote,
|
||||
bool aNetworkCreated, bool aPreserveContext);
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_FRAMELOADER_IID)
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "nsSubDocumentFrame.h"
|
||||
#include "nsQueryObject.h"
|
||||
#include "mozilla/AsyncEventDispatcher.h"
|
||||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/FrameLoaderBinding.h"
|
||||
#include "mozilla/dom/HTMLIFrameElement.h"
|
||||
@ -87,7 +88,8 @@ nsFrameLoaderOwner::ShouldPreserveBrowsingContext(
|
||||
|
||||
void nsFrameLoaderOwner::ChangeRemotenessCommon(
|
||||
const ChangeRemotenessContextType& aContextType,
|
||||
bool aSwitchingInProgressLoad, bool aIsRemote, BrowsingContextGroup* aGroup,
|
||||
const RemotenessChangeState& aState, bool aSwitchingInProgressLoad,
|
||||
bool aIsRemote, BrowsingContextGroup* aGroup,
|
||||
std::function<void()>& aFrameLoaderInit, mozilla::ErrorResult& aRv) {
|
||||
MOZ_ASSERT_IF(aGroup, aContextType != ChangeRemotenessContextType::PRESERVE);
|
||||
|
||||
@ -136,7 +138,7 @@ void nsFrameLoaderOwner::ChangeRemotenessCommon(
|
||||
}
|
||||
|
||||
mFrameLoader = nsFrameLoader::Recreate(
|
||||
owner, bc, aGroup, aIsRemote, networkCreated,
|
||||
owner, bc, aGroup, aState, aIsRemote, networkCreated,
|
||||
aContextType == ChangeRemotenessContextType::PRESERVE);
|
||||
if (NS_WARN_IF(!mFrameLoader)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
@ -204,8 +206,10 @@ void nsFrameLoaderOwner::ChangeRemoteness(
|
||||
|
||||
auto shouldPreserve = ShouldPreserveBrowsingContext(
|
||||
isRemote, /* replaceBrowsingContext */ false);
|
||||
ChangeRemotenessCommon(shouldPreserve, aOptions.mSwitchingInProgressLoad,
|
||||
isRemote, /* group */ nullptr, frameLoaderInit, rv);
|
||||
RemotenessChangeState state;
|
||||
ChangeRemotenessCommon(shouldPreserve, state,
|
||||
aOptions.mSwitchingInProgressLoad, isRemote,
|
||||
/* group */ nullptr, frameLoaderInit, rv);
|
||||
}
|
||||
|
||||
void nsFrameLoaderOwner::ChangeRemotenessWithBridge(BrowserBridgeChild* aBridge,
|
||||
@ -223,17 +227,18 @@ void nsFrameLoaderOwner::ChangeRemotenessWithBridge(BrowserBridgeChild* aBridge,
|
||||
mFrameLoader->mRemoteBrowser = host;
|
||||
};
|
||||
|
||||
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE,
|
||||
RemotenessChangeState state;
|
||||
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE, state,
|
||||
/* inProgress */ true,
|
||||
/* isRemote */ true, /* group */ nullptr,
|
||||
frameLoaderInit, rv);
|
||||
}
|
||||
|
||||
void nsFrameLoaderOwner::ChangeRemotenessToProcess(
|
||||
ContentParent* aContentParent, bool aReplaceBrowsingContext,
|
||||
ContentParent* aContentParent, const RemotenessChangeState& aState,
|
||||
BrowsingContextGroup* aGroup, mozilla::ErrorResult& rv) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT_IF(aGroup, aReplaceBrowsingContext);
|
||||
MOZ_ASSERT_IF(aGroup, aState.mReplaceBrowsingContext);
|
||||
bool isRemote = aContentParent != nullptr;
|
||||
|
||||
std::function<void()> frameLoaderInit = [&] {
|
||||
@ -244,9 +249,9 @@ void nsFrameLoaderOwner::ChangeRemotenessToProcess(
|
||||
};
|
||||
|
||||
auto shouldPreserve =
|
||||
ShouldPreserveBrowsingContext(isRemote, aReplaceBrowsingContext);
|
||||
ChangeRemotenessCommon(shouldPreserve, /* inProgress */ true, isRemote,
|
||||
aGroup, frameLoaderInit, rv);
|
||||
ShouldPreserveBrowsingContext(isRemote, aState.mReplaceBrowsingContext);
|
||||
ChangeRemotenessCommon(shouldPreserve, aState, /* inProgress */ true,
|
||||
isRemote, aGroup, frameLoaderInit, rv);
|
||||
}
|
||||
|
||||
void nsFrameLoaderOwner::SubframeCrashed() {
|
||||
@ -273,7 +278,8 @@ void nsFrameLoaderOwner::SubframeCrashed() {
|
||||
}));
|
||||
};
|
||||
|
||||
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE,
|
||||
RemotenessChangeState state;
|
||||
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE, state,
|
||||
/* inProgress */ false, /* isRemote */ false,
|
||||
/* group */ nullptr, frameLoaderInit, IgnoreErrors());
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ class BrowsingContextGroup;
|
||||
class BrowserBridgeChild;
|
||||
class ContentParent;
|
||||
struct RemotenessOptions;
|
||||
struct RemotenessChangeState;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
@ -71,10 +72,10 @@ class nsFrameLoaderOwner : public nsISupports {
|
||||
//
|
||||
// If `aReplaceBrowsingContext` is set, BrowsingContext preservation will be
|
||||
// disabled for this process switch.
|
||||
void ChangeRemotenessToProcess(mozilla::dom::ContentParent* aContentParent,
|
||||
bool aReplaceBrowsingContext,
|
||||
mozilla::dom::BrowsingContextGroup* aGroup,
|
||||
mozilla::ErrorResult& rv);
|
||||
void ChangeRemotenessToProcess(
|
||||
mozilla::dom::ContentParent* aContentParent,
|
||||
const mozilla::dom::RemotenessChangeState& aState,
|
||||
mozilla::dom::BrowsingContextGroup* aGroup, mozilla::ErrorResult& rv);
|
||||
|
||||
void SubframeCrashed();
|
||||
|
||||
@ -95,6 +96,7 @@ class nsFrameLoaderOwner : public nsISupports {
|
||||
bool aIsRemote, bool aReplaceBrowsingContext);
|
||||
|
||||
void ChangeRemotenessCommon(const ChangeRemotenessContextType& aContextType,
|
||||
const mozilla::dom::RemotenessChangeState& aState,
|
||||
bool aSwitchingInProgressLoad, bool aIsRemote,
|
||||
mozilla::dom::BrowsingContextGroup* aGroup,
|
||||
std::function<void()>& aFrameLoaderInit,
|
||||
|
@ -3880,9 +3880,9 @@ mozilla::ipc::IPCResult ContentParent::RecvCloneDocumentTreeInto(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
target
|
||||
->ChangeRemoteness(cp->GetRemoteType(), /* aLoadID = */ 0,
|
||||
/* aReplaceBC = */ false, /* aSpecificGroupId = */ 0)
|
||||
RemotenessChangeState state;
|
||||
state.mRemoteType = cp->GetRemoteType();
|
||||
target->ChangeRemoteness(state, /* aPendingSwitchId = */ 0)
|
||||
->Then(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[source = RefPtr{source}](BrowserParent* aBp) {
|
||||
|
@ -1490,8 +1490,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
|
||||
// Determine what type of content process this load should finish in.
|
||||
nsAutoCString preferredRemoteType(currentRemoteType);
|
||||
bool replaceBrowsingContext = false;
|
||||
uint64_t specificGroupId = 0;
|
||||
RemotenessChangeState changeState;
|
||||
|
||||
// If we're in a preloaded browser, force browsing context replacement to
|
||||
// ensure the current process is re-selected.
|
||||
@ -1506,7 +1505,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
if (NS_SUCCEEDED(mChannel->GetOriginalURI(getter_AddRefs(originalURI))) &&
|
||||
!originalURI->GetSpecOrDefault().EqualsLiteral("about:newtab")) {
|
||||
LOG(("Process Switch: leaving preloaded browser"));
|
||||
replaceBrowsingContext = true;
|
||||
changeState.mReplaceBrowsingContext = true;
|
||||
browserElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::preloadedState,
|
||||
true);
|
||||
}
|
||||
@ -1517,7 +1516,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
// Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers.
|
||||
{
|
||||
bool isCOOPSwitch = HasCrossOriginOpenerPolicyMismatch();
|
||||
replaceBrowsingContext |= isCOOPSwitch;
|
||||
changeState.mReplaceBrowsingContext |= isCOOPSwitch;
|
||||
|
||||
// Determine our COOP status, which will be used to determine our preferred
|
||||
// remote type.
|
||||
@ -1553,10 +1552,10 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
if (!parentWindow && browsingContext->Group()->Toplevels().Length() == 1) {
|
||||
if (IsLargeAllocationLoad(browsingContext, mChannel)) {
|
||||
preferredRemoteType = LARGE_ALLOCATION_REMOTE_TYPE;
|
||||
replaceBrowsingContext = true;
|
||||
changeState.mReplaceBrowsingContext = true;
|
||||
} else if (preferredRemoteType == LARGE_ALLOCATION_REMOTE_TYPE) {
|
||||
preferredRemoteType = DEFAULT_REMOTE_TYPE;
|
||||
replaceBrowsingContext = true;
|
||||
changeState.mReplaceBrowsingContext = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1574,8 +1573,8 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
|
||||
if (browsingContext->Group()->Id() !=
|
||||
addonPolicy->GetBrowsingContextGroupId()) {
|
||||
replaceBrowsingContext = true;
|
||||
specificGroupId = addonPolicy->GetBrowsingContextGroupId();
|
||||
changeState.mReplaceBrowsingContext = true;
|
||||
changeState.mSpecificGroupId = addonPolicy->GetBrowsingContextGroupId();
|
||||
}
|
||||
} else {
|
||||
// As a temporary measure, extension iframes must be loaded within the
|
||||
@ -1603,11 +1602,10 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
currentPrincipal = wgp->DocumentPrincipal();
|
||||
}
|
||||
|
||||
nsAutoCString remoteType;
|
||||
rv = e10sUtils->GetRemoteTypeForPrincipal(
|
||||
resultPrincipal, mChannelCreationURI, browsingContext->UseRemoteTabs(),
|
||||
browsingContext->UseRemoteSubframes(), preferredRemoteType,
|
||||
currentPrincipal, parentWindow, remoteType);
|
||||
currentPrincipal, parentWindow, changeState.mRemoteType);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
LOG(("Process Switch Abort: getRemoteTypeForPrincipal threw an exception"));
|
||||
return false;
|
||||
@ -1616,32 +1614,33 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
// If the final decision is to switch from an 'extension' remote type to any
|
||||
// other remote type, ensure the browsing context is replaced so that we leave
|
||||
// the extension-specific BrowsingContextGroup.
|
||||
if (!parentWindow && currentRemoteType != remoteType &&
|
||||
if (!parentWindow && currentRemoteType != changeState.mRemoteType &&
|
||||
currentRemoteType == EXTENSION_REMOTE_TYPE) {
|
||||
replaceBrowsingContext = true;
|
||||
changeState.mReplaceBrowsingContext = true;
|
||||
}
|
||||
|
||||
LOG(("GetRemoteTypeForPrincipal -> current:%s remoteType:%s",
|
||||
currentRemoteType.get(), remoteType.get()));
|
||||
currentRemoteType.get(), changeState.mRemoteType.get()));
|
||||
|
||||
// Check if a process switch is needed.
|
||||
if (currentRemoteType == remoteType && !replaceBrowsingContext) {
|
||||
LOG(("Process Switch Abort: type (%s) is compatible", remoteType.get()));
|
||||
if (currentRemoteType == changeState.mRemoteType &&
|
||||
!changeState.mReplaceBrowsingContext) {
|
||||
LOG(("Process Switch Abort: type (%s) is compatible",
|
||||
changeState.mRemoteType.get()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(parentWindow && remoteType.IsEmpty())) {
|
||||
if (NS_WARN_IF(parentWindow && changeState.mRemoteType.IsEmpty())) {
|
||||
LOG(("Process Switch Abort: non-remote target process for subframe"));
|
||||
return false;
|
||||
}
|
||||
|
||||
*aWillSwitchToRemote = !remoteType.IsEmpty();
|
||||
*aWillSwitchToRemote = !changeState.mRemoteType.IsEmpty();
|
||||
|
||||
// If we're doing a document load, we can immediately perform a process
|
||||
// switch.
|
||||
if (mIsDocumentLoad) {
|
||||
TriggerProcessSwitch(browsingContext, remoteType, replaceBrowsingContext,
|
||||
specificGroupId);
|
||||
TriggerProcessSwitch(browsingContext, changeState);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1660,8 +1659,8 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
|
||||
mObjectUpgradeHandler->UpgradeObjectLoad()->Then(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr{this}, remoteType, replaceBrowsingContext, specificGroupId,
|
||||
wgp](const RefPtr<CanonicalBrowsingContext>& aBrowsingContext) {
|
||||
[self = RefPtr{this}, changeState,
|
||||
wgp](const RefPtr<CanonicalBrowsingContext>& aBrowsingContext) mutable {
|
||||
if (aBrowsingContext->IsDiscarded() ||
|
||||
wgp != aBrowsingContext->GetParentWindowContext()) {
|
||||
LOG(
|
||||
@ -1672,8 +1671,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
}
|
||||
|
||||
LOG(("Process Switch: Upgraded Object to Document Load"));
|
||||
self->TriggerProcessSwitch(aBrowsingContext, remoteType,
|
||||
replaceBrowsingContext, specificGroupId);
|
||||
self->TriggerProcessSwitch(aBrowsingContext, changeState);
|
||||
},
|
||||
[self = RefPtr{this}](nsresult aStatusCode) {
|
||||
MOZ_ASSERT(NS_FAILED(aStatusCode), "Status should be error");
|
||||
@ -1683,8 +1681,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
|
||||
}
|
||||
|
||||
void DocumentLoadListener::TriggerProcessSwitch(
|
||||
CanonicalBrowsingContext* aContext, const nsCString& aRemoteType,
|
||||
bool aReplaceBrowsingContext, uint64_t aSpecificGroupId) {
|
||||
CanonicalBrowsingContext* aContext, const RemotenessChangeState& aState) {
|
||||
nsAutoCString currentRemoteType(NOT_REMOTE_TYPE);
|
||||
if (RefPtr<ContentParent> contentParent = aContext->GetContentParent()) {
|
||||
currentRemoteType = contentParent->GetRemoteType();
|
||||
@ -1692,7 +1689,7 @@ void DocumentLoadListener::TriggerProcessSwitch(
|
||||
MOZ_ASSERT_IF(currentRemoteType.IsEmpty(), !OtherPid());
|
||||
|
||||
LOG(("Process Switch: Changing Remoteness from '%s' to '%s'",
|
||||
currentRemoteType.get(), aRemoteType.get()));
|
||||
currentRemoteType.get(), aState.mRemoteType.get()));
|
||||
|
||||
// We're now committing to a process switch, so we can disconnect from
|
||||
// the listeners in the old process.
|
||||
@ -1710,9 +1707,7 @@ void DocumentLoadListener::TriggerProcessSwitch(
|
||||
DisconnectListeners(NS_BINDING_ABORTED, NS_BINDING_ABORTED, true);
|
||||
|
||||
LOG(("Process Switch: Calling ChangeRemoteness"));
|
||||
aContext
|
||||
->ChangeRemoteness(aRemoteType, mLoadIdentifier, aReplaceBrowsingContext,
|
||||
aSpecificGroupId)
|
||||
aContext->ChangeRemoteness(aState, mLoadIdentifier)
|
||||
->Then(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr{this}](BrowserParent* aBrowserParent) {
|
||||
|
@ -36,7 +36,8 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class CanonicalBrowsingContext;
|
||||
}
|
||||
struct RemotenessChangeState;
|
||||
} // namespace dom
|
||||
namespace net {
|
||||
using ChildEndpointPromise =
|
||||
MozPromise<ipc::Endpoint<extensions::PStreamFilterChild>, bool, true>;
|
||||
@ -320,9 +321,7 @@ class DocumentLoadListener : public nsIInterfaceRequestor,
|
||||
// and that the new remote type will be something other than NOT_REMOTE
|
||||
bool MaybeTriggerProcessSwitch(bool* aWillSwitchToRemote);
|
||||
void TriggerProcessSwitch(dom::CanonicalBrowsingContext* aContext,
|
||||
const nsCString& aRemoteType,
|
||||
bool aReplaceBrowsingContext,
|
||||
uint64_t aSpecificGroupId);
|
||||
const dom::RemotenessChangeState& aState);
|
||||
|
||||
// A helper for TriggerRedirectToRealChannel that abstracts over
|
||||
// the same-process and cross-process switch cases and returns
|
||||
|
Loading…
Reference in New Issue
Block a user