Bug 1689601, Rename RemotenessChangeState to RemotenessChangeOptions, r=peterv

This addresses part of the review comment from https://phabricator.services.mozilla.com/D105229

Differential Revision: https://phabricator.services.mozilla.com/D106561
This commit is contained in:
Olli Pettay 2021-03-02 09:44:13 +00:00
parent 9a08f751a4
commit 42a29f41de
10 changed files with 102 additions and 96 deletions

View File

@ -157,8 +157,9 @@ void CanonicalBrowsingContext::MaybeAddAsProgressListener(
aWebProgress->AddProgressListener(mStatusFilter, nsIWebProgress::NOTIFY_ALL);
}
void CanonicalBrowsingContext::ReplacedBy(CanonicalBrowsingContext* aNewContext,
const RemotenessChangeState& aState) {
void CanonicalBrowsingContext::ReplacedBy(
CanonicalBrowsingContext* aNewContext,
const RemotenessChangeOptions& aRemotenessOptions) {
MOZ_ASSERT(!aNewContext->mWebProgress);
MOZ_ASSERT(!aNewContext->mSessionHistory);
MOZ_ASSERT(IsTop() && aNewContext->IsTop());
@ -174,7 +175,7 @@ void CanonicalBrowsingContext::ReplacedBy(CanonicalBrowsingContext* aNewContext,
// XXXBFCache name handling is still a bit broken in Fission in general,
// at least in case name should be cleared.
if (aState.mTryUseBFCache) {
if (aRemotenessOptions.mTryUseBFCache) {
aNewContext->mFields.SetWithoutSyncing<IDX_Name>(GetName());
aNewContext->mFields.SetWithoutSyncing<IDX_HasLoadedNonInitialDocument>(
GetHasLoadedNonInitialDocument());
@ -1142,7 +1143,7 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Finish() {
// The process has been created, hand off to nsFrameLoaderOwner to finish
// the process switch.
ErrorResult error;
frameLoaderOwner->ChangeRemotenessToProcess(mContentParent, mState,
frameLoaderOwner->ChangeRemotenessToProcess(mContentParent, mOptions,
mSpecificGroup, error);
if (error.Failed()) {
Cancel(error.StealNSResult());
@ -1247,7 +1248,8 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Finish() {
oldBrowser->Destroy();
}
MOZ_ASSERT(!mState.mReplaceBrowsingContext, "Cannot replace BC for subframe");
MOZ_ASSERT(!mOptions.mReplaceBrowsingContext,
"Cannot replace BC for subframe");
nsCOMPtr<nsIPrincipal> initialPrincipal =
NullPrincipal::CreateWithInheritedAttributes(
target->OriginAttributesRef(),
@ -1333,11 +1335,11 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Clear() {
CanonicalBrowsingContext::PendingRemotenessChange::PendingRemotenessChange(
CanonicalBrowsingContext* aTarget, RemotenessPromise::Private* aPromise,
uint64_t aPendingSwitchId, const RemotenessChangeState& aState)
uint64_t aPendingSwitchId, const RemotenessChangeOptions& aOptions)
: mTarget(aTarget),
mPromise(aPromise),
mPendingSwitchId(aPendingSwitchId),
mState(aState) {}
mOptions(aOptions) {}
CanonicalBrowsingContext::PendingRemotenessChange::~PendingRemotenessChange() {
MOZ_ASSERT(!mPromise && !mTarget && !mContentParent && !mSpecificGroup &&
@ -1353,17 +1355,17 @@ BrowserParent* CanonicalBrowsingContext::GetBrowserParent() const {
}
RefPtr<CanonicalBrowsingContext::RemotenessPromise>
CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
uint64_t aPendingSwitchId) {
CanonicalBrowsingContext::ChangeRemoteness(
const RemotenessChangeOptions& aOptions, 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(!aState.mReplaceBrowsingContext || IsTop(),
MOZ_DIAGNOSTIC_ASSERT(!aOptions.mReplaceBrowsingContext || IsTop(),
"Cannot replace BrowsingContext for subframes");
MOZ_DIAGNOSTIC_ASSERT(
aState.mSpecificGroupId == 0 || aState.mReplaceBrowsingContext,
aOptions.mSpecificGroupId == 0 || aOptions.mReplaceBrowsingContext,
"Cannot specify group ID unless replacing BC");
MOZ_DIAGNOSTIC_ASSERT(aPendingSwitchId || !IsTop(),
"Should always have aPendingSwitchId for top-level "
@ -1386,7 +1388,7 @@ CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
return RemotenessPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__);
}
if (aState.mRemoteType.IsEmpty() && (!IsTop() || !GetEmbedderElement())) {
if (aOptions.mRemoteType.IsEmpty() && (!IsTop() || !GetEmbedderElement())) {
NS_WARNING("Cannot load non-remote subframes");
return RemotenessPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
}
@ -1401,7 +1403,7 @@ CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
embedderWindowGlobal->GetBrowserParent();
// Switching to local. No new process, so perform switch sync.
if (embedderBrowser &&
aState.mRemoteType == embedderBrowser->Manager()->GetRemoteType()) {
aOptions.mRemoteType == embedderBrowser->Manager()->GetRemoteType()) {
MOZ_DIAGNOSTIC_ASSERT(
aPendingSwitchId,
"We always have a PendingSwitchId, except for print-preview loads, "
@ -1423,8 +1425,8 @@ CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
// If the embedder process is remote, tell that remote process to become
// the owner.
MOZ_DIAGNOSTIC_ASSERT(!aState.mReplaceBrowsingContext);
MOZ_DIAGNOSTIC_ASSERT(!aState.mRemoteType.IsEmpty());
MOZ_DIAGNOSTIC_ASSERT(!aOptions.mReplaceBrowsingContext);
MOZ_DIAGNOSTIC_ASSERT(!aOptions.mRemoteType.IsEmpty());
SetOwnerProcessId(embedderBrowser->Manager()->ChildID());
Unused << embedderWindowGlobal->SendMakeFrameLocal(this, aPendingSwitchId);
return RemotenessPromise::CreateAndResolve(embedderBrowser, __func__);
@ -1433,14 +1435,14 @@ CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
// 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, aState);
new PendingRemotenessChange(this, promise, aPendingSwitchId, aOptions);
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 (aState.mSpecificGroupId) {
if (aOptions.mSpecificGroupId) {
change->mSpecificGroup =
BrowsingContextGroup::GetOrCreate(aState.mSpecificGroupId);
BrowsingContextGroup::GetOrCreate(aOptions.mSpecificGroupId);
change->mSpecificGroup->AddKeepAlive();
}
@ -1462,7 +1464,7 @@ CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
change->mPrepareToChangePromise = GenericPromise::FromDomPromise(blocker);
}
if (aState.mRemoteType.IsEmpty()) {
if (aOptions.mRemoteType.IsEmpty()) {
change->ProcessReady();
} else {
// Try to predict which BrowsingContextGroup will be used for the final load
@ -1473,11 +1475,12 @@ CanonicalBrowsingContext::ChangeRemoteness(const RemotenessChangeState& aState,
// It's _technically_ OK to provide a group here if we're actually going to
// switch into a brand new group, though it's sub-optimal, as it can
// restrict the set of processes we're using.
BrowsingContextGroup* finalGroup =
aState.mReplaceBrowsingContext ? change->mSpecificGroup.get() : Group();
BrowsingContextGroup* finalGroup = aOptions.mReplaceBrowsingContext
? change->mSpecificGroup.get()
: Group();
change->mContentParent = ContentParent::GetNewOrUsedLaunchingBrowserProcess(
/* aRemoteType = */ aState.mRemoteType,
/* aRemoteType = */ aOptions.mRemoteType,
/* aGroup = */ finalGroup,
/* aPriority = */ hal::PROCESS_PRIORITY_FOREGROUND,
/* aPreferUsed = */ false);

View File

@ -44,9 +44,9 @@ struct LoadingSessionHistoryInfo;
class SessionHistoryEntry;
class WindowGlobalParent;
// RemotenessChangeState is passed through the methods to store the state
// RemotenessChangeOptions is passed through the methods to store the state
// of the possible remoteness change.
struct RemotenessChangeState {
struct RemotenessChangeOptions {
nsCString mRemoteType;
bool mReplaceBrowsingContext = false;
uint64_t mSpecificGroupId = 0;
@ -217,7 +217,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// the parent process, and the method will resolve with a null BrowserParent.
using RemotenessPromise = MozPromise<RefPtr<BrowserParent>, nsresult, false>;
RefPtr<RemotenessPromise> ChangeRemoteness(
const RemotenessChangeState& aState, uint64_t aPendingSwitchId);
const RemotenessChangeOptions& aOptions, 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
@ -256,7 +256,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// aNewContext is the newly created BrowsingContext that is replacing
// us.
void ReplacedBy(CanonicalBrowsingContext* aNewContext,
const RemotenessChangeState& aState);
const RemotenessChangeOptions& aRemotenessOptions);
bool HasHistoryEntry(nsISHEntry* aEntry);
@ -302,7 +302,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
PendingRemotenessChange(CanonicalBrowsingContext* aTarget,
RemotenessPromise::Private* aPromise,
uint64_t aPendingSwitchId,
const RemotenessChangeState& aState);
const RemotenessChangeOptions& aOptions);
void Cancel(nsresult aRv);
@ -321,7 +321,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
RefPtr<BrowsingContextGroup> mSpecificGroup;
uint64_t mPendingSwitchId;
RemotenessChangeState mState;
RemotenessChangeOptions mOptions;
};
friend class net::DocumentLoadListener;

View File

@ -1247,8 +1247,8 @@ void nsSHistory::LoadURIOrBFCache(LoadEntryResult& aLoadEntry) {
canonicalBC->SetActiveSessionHistoryEntry(she);
loadingBC->Canonical()->SetActiveSessionHistoryEntry(
nullptr);
RemotenessChangeState state;
canonicalBC->ReplacedBy(loadingBC->Canonical(), state);
RemotenessChangeOptions options;
canonicalBC->ReplacedBy(loadingBC->Canonical(), options);
frameLoaderOwner->ReplaceFrameLoader(fl);
// The old page can't be stored in the bfcache,

View File

@ -457,8 +457,9 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Create(
/* static */
already_AddRefed<nsFrameLoader> nsFrameLoader::Recreate(
mozilla::dom::Element* aOwner, BrowsingContext* aContext,
BrowsingContextGroup* aSpecificGroup, const RemotenessChangeState& aState,
bool aIsRemote, bool aNetworkCreated, bool aPreserveContext) {
BrowsingContextGroup* aSpecificGroup,
const RemotenessChangeOptions& aRemotenessOptions, bool aIsRemote,
bool aNetworkCreated, bool aPreserveContext) {
NS_ENSURE_TRUE(aOwner, nullptr);
#ifdef DEBUG
@ -478,7 +479,8 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Recreate(
MOZ_ASSERT(
XRE_IsParentProcess(),
"Recreating browing contexts only supported in the parent process");
aContext->Canonical()->ReplacedBy(context->Canonical(), aState);
aContext->Canonical()->ReplacedBy(context->Canonical(),
aRemotenessOptions);
}
}
NS_ENSURE_TRUE(context, nullptr);

View File

@ -72,7 +72,7 @@ class MutableTabContext;
class BrowserBridgeChild;
class RemoteBrowser;
struct RemotenessOptions;
struct RemotenessChangeState;
struct RemotenessChangeOptions;
namespace ipc {
class StructuredCloneData;
@ -122,8 +122,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
// FrameLoaders.
static already_AddRefed<nsFrameLoader> Recreate(
Element* aOwner, BrowsingContext* aContext, BrowsingContextGroup* aGroup,
const mozilla::dom::RemotenessChangeState& aState, bool aIsRemote,
bool aNetworkCreated, bool aPreserveContext);
const mozilla::dom::RemotenessChangeOptions& aRemotenessOptions,
bool aIsRemote, bool aNetworkCreated, bool aPreserveContext);
NS_DECLARE_STATIC_IID_ACCESSOR(NS_FRAMELOADER_IID)

View File

@ -91,7 +91,7 @@ nsFrameLoaderOwner::ShouldPreserveBrowsingContext(
void nsFrameLoaderOwner::ChangeRemotenessCommon(
const ChangeRemotenessContextType& aContextType,
const RemotenessChangeState& aState, bool aSwitchingInProgressLoad,
const RemotenessChangeOptions& aOptions, bool aSwitchingInProgressLoad,
bool aIsRemote, BrowsingContextGroup* aGroup,
std::function<void()>& aFrameLoaderInit, mozilla::ErrorResult& aRv) {
MOZ_ASSERT_IF(aGroup, aContextType != ChangeRemotenessContextType::PRESERVE);
@ -131,8 +131,8 @@ void nsFrameLoaderOwner::ChangeRemotenessCommon(
bc = mFrameLoader->GetMaybePendingBrowsingContext();
networkCreated = mFrameLoader->IsNetworkCreated();
MOZ_ASSERT_IF(aState.mTryUseBFCache, aState.mReplaceBrowsingContext);
if (aState.mTryUseBFCache) {
MOZ_ASSERT_IF(aOptions.mTryUseBFCache, aOptions.mReplaceBrowsingContext);
if (aOptions.mTryUseBFCache) {
if (bc) {
SessionHistoryEntry* she =
bc->Canonical()->GetActiveSessionHistoryEntry();
@ -162,7 +162,7 @@ void nsFrameLoaderOwner::ChangeRemotenessCommon(
}
mFrameLoader = nsFrameLoader::Recreate(
owner, bc, aGroup, aState, aIsRemote, networkCreated,
owner, bc, aGroup, aOptions, aIsRemote, networkCreated,
aContextType == ChangeRemotenessContextType::PRESERVE);
if (NS_WARN_IF(!mFrameLoader)) {
aRv.Throw(NS_ERROR_FAILURE);
@ -234,8 +234,8 @@ void nsFrameLoaderOwner::ChangeRemoteness(
auto shouldPreserve = ShouldPreserveBrowsingContext(
isRemote, /* replaceBrowsingContext */ false);
RemotenessChangeState state;
ChangeRemotenessCommon(shouldPreserve, state,
RemotenessChangeOptions options;
ChangeRemotenessCommon(shouldPreserve, options,
aOptions.mSwitchingInProgressLoad, isRemote,
/* group */ nullptr, frameLoaderInit, rv);
}
@ -255,18 +255,18 @@ void nsFrameLoaderOwner::ChangeRemotenessWithBridge(BrowserBridgeChild* aBridge,
mFrameLoader->mRemoteBrowser = host;
};
RemotenessChangeState state;
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE, state,
RemotenessChangeOptions options;
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE, options,
/* inProgress */ true,
/* isRemote */ true, /* group */ nullptr,
frameLoaderInit, rv);
}
void nsFrameLoaderOwner::ChangeRemotenessToProcess(
ContentParent* aContentParent, const RemotenessChangeState& aState,
ContentParent* aContentParent, const RemotenessChangeOptions& aOptions,
BrowsingContextGroup* aGroup, mozilla::ErrorResult& rv) {
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT_IF(aGroup, aState.mReplaceBrowsingContext);
MOZ_ASSERT_IF(aGroup, aOptions.mReplaceBrowsingContext);
bool isRemote = aContentParent != nullptr;
std::function<void()> frameLoaderInit = [&] {
@ -277,8 +277,8 @@ void nsFrameLoaderOwner::ChangeRemotenessToProcess(
};
auto shouldPreserve =
ShouldPreserveBrowsingContext(isRemote, aState.mReplaceBrowsingContext);
ChangeRemotenessCommon(shouldPreserve, aState, /* inProgress */ true,
ShouldPreserveBrowsingContext(isRemote, aOptions.mReplaceBrowsingContext);
ChangeRemotenessCommon(shouldPreserve, aOptions, /* inProgress */ true,
isRemote, aGroup, frameLoaderInit, rv);
}
@ -306,8 +306,8 @@ void nsFrameLoaderOwner::SubframeCrashed() {
}));
};
RemotenessChangeState state;
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE, state,
RemotenessChangeOptions options;
ChangeRemotenessCommon(ChangeRemotenessContextType::PRESERVE, options,
/* inProgress */ false, /* isRemote */ false,
/* group */ nullptr, frameLoaderInit, IgnoreErrors());
}

View File

@ -20,7 +20,7 @@ class BrowserBridgeChild;
class ContentParent;
class Element;
struct RemotenessOptions;
struct RemotenessChangeState;
struct RemotenessChangeOptions;
} // namespace dom
} // namespace mozilla
@ -75,7 +75,7 @@ class nsFrameLoaderOwner : public nsISupports {
// disabled for this process switch.
void ChangeRemotenessToProcess(
mozilla::dom::ContentParent* aContentParent,
const mozilla::dom::RemotenessChangeState& aState,
const mozilla::dom::RemotenessChangeOptions& aOptions,
mozilla::dom::BrowsingContextGroup* aGroup, mozilla::ErrorResult& rv);
void SubframeCrashed();
@ -102,12 +102,12 @@ class nsFrameLoaderOwner : public nsISupports {
ChangeRemotenessContextType ShouldPreserveBrowsingContext(
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,
mozilla::ErrorResult& aRv);
void ChangeRemotenessCommon(
const ChangeRemotenessContextType& aContextType,
const mozilla::dom::RemotenessChangeOptions& aOptions,
bool aSwitchingInProgressLoad, bool aIsRemote,
mozilla::dom::BrowsingContextGroup* aGroup,
std::function<void()>& aFrameLoaderInit, mozilla::ErrorResult& aRv);
void ChangeFrameLoaderCommon(mozilla::dom::Element* aOwner);

View File

@ -3880,9 +3880,9 @@ mozilla::ipc::IPCResult ContentParent::RecvCloneDocumentTreeInto(
return IPC_OK();
}
RemotenessChangeState state;
state.mRemoteType = cp->GetRemoteType();
target->ChangeRemoteness(state, /* aPendingSwitchId = */ 0)
RemotenessChangeOptions options;
options.mRemoteType = cp->GetRemoteType();
target->ChangeRemoteness(options, /* aPendingSwitchId = */ 0)
->Then(
GetMainThreadSerialEventTarget(), __func__,
[source = RefPtr{source}](BrowserParent* aBp) {

View File

@ -1497,7 +1497,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
// Determine what type of content process this load should finish in.
nsAutoCString preferredRemoteType(currentRemoteType);
RemotenessChangeState changeState;
RemotenessChangeOptions options;
// If we're in a preloaded browser, force browsing context replacement to
// ensure the current process is re-selected.
@ -1512,7 +1512,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
if (NS_SUCCEEDED(mChannel->GetOriginalURI(getter_AddRefs(originalURI))) &&
!originalURI->GetSpecOrDefault().EqualsLiteral("about:newtab")) {
LOG(("Process Switch: leaving preloaded browser"));
changeState.mReplaceBrowsingContext = true;
options.mReplaceBrowsingContext = true;
browserElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::preloadedState,
true);
}
@ -1523,7 +1523,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
// Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers.
{
bool isCOOPSwitch = HasCrossOriginOpenerPolicyMismatch();
changeState.mReplaceBrowsingContext |= isCOOPSwitch;
options.mReplaceBrowsingContext |= isCOOPSwitch;
// Determine our COOP status, which will be used to determine our preferred
// remote type.
@ -1559,10 +1559,10 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
if (!parentWindow && browsingContext->Group()->Toplevels().Length() == 1) {
if (IsLargeAllocationLoad(browsingContext, mChannel)) {
preferredRemoteType = LARGE_ALLOCATION_REMOTE_TYPE;
changeState.mReplaceBrowsingContext = true;
options.mReplaceBrowsingContext = true;
} else if (preferredRemoteType == LARGE_ALLOCATION_REMOTE_TYPE) {
preferredRemoteType = DEFAULT_REMOTE_TYPE;
changeState.mReplaceBrowsingContext = true;
options.mReplaceBrowsingContext = true;
}
}
@ -1580,8 +1580,8 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
if (browsingContext->Group()->Id() !=
addonPolicy->GetBrowsingContextGroupId()) {
changeState.mReplaceBrowsingContext = true;
changeState.mSpecificGroupId = addonPolicy->GetBrowsingContextGroupId();
options.mReplaceBrowsingContext = true;
options.mSpecificGroupId = addonPolicy->GetBrowsingContextGroupId();
}
} else {
// As a temporary measure, extension iframes must be loaded within the
@ -1612,7 +1612,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
rv = e10sUtils->GetRemoteTypeForPrincipal(
resultPrincipal, mChannelCreationURI, browsingContext->UseRemoteTabs(),
browsingContext->UseRemoteSubframes(), preferredRemoteType,
currentPrincipal, parentWindow, changeState.mRemoteType);
currentPrincipal, parentWindow, options.mRemoteType);
if (NS_WARN_IF(NS_FAILED(rv))) {
LOG(("Process Switch Abort: getRemoteTypeForPrincipal threw an exception"));
return false;
@ -1621,9 +1621,9 @@ 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 != changeState.mRemoteType &&
if (!parentWindow && currentRemoteType != options.mRemoteType &&
currentRemoteType == EXTENSION_REMOTE_TYPE) {
changeState.mReplaceBrowsingContext = true;
options.mReplaceBrowsingContext = true;
}
if (mozilla::SessionHistoryInParent() &&
@ -1631,35 +1631,35 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
nsSHistory::GetMaxTotalViewers() > 0 && !parentWindow &&
!browsingContext->HadOriginalOpener() &&
browsingContext->Group()->Toplevels().Length() == 1 &&
!changeState.mRemoteType.IsEmpty() &&
!options.mRemoteType.IsEmpty() &&
browsingContext->GetHasLoadedNonInitialDocument() &&
mLoadStateLoadType != LOAD_ERROR_PAGE) {
changeState.mReplaceBrowsingContext = true;
changeState.mTryUseBFCache = true;
options.mReplaceBrowsingContext = true;
options.mTryUseBFCache = true;
}
LOG(("GetRemoteTypeForPrincipal -> current:%s remoteType:%s",
currentRemoteType.get(), changeState.mRemoteType.get()));
currentRemoteType.get(), options.mRemoteType.get()));
// Check if a process switch is needed.
if (currentRemoteType == changeState.mRemoteType &&
!changeState.mReplaceBrowsingContext) {
if (currentRemoteType == options.mRemoteType &&
!options.mReplaceBrowsingContext) {
LOG(("Process Switch Abort: type (%s) is compatible",
changeState.mRemoteType.get()));
options.mRemoteType.get()));
return false;
}
if (NS_WARN_IF(parentWindow && changeState.mRemoteType.IsEmpty())) {
if (NS_WARN_IF(parentWindow && options.mRemoteType.IsEmpty())) {
LOG(("Process Switch Abort: non-remote target process for subframe"));
return false;
}
*aWillSwitchToRemote = !changeState.mRemoteType.IsEmpty();
*aWillSwitchToRemote = !options.mRemoteType.IsEmpty();
// If we're doing a document load, we can immediately perform a process
// switch.
if (mIsDocumentLoad) {
if (changeState.mTryUseBFCache && wgp) {
if (options.mTryUseBFCache && wgp) {
if (RefPtr<BrowserParent> browserParent = wgp->GetBrowserParent()) {
nsTArray<RefPtr<PContentParent::CanSavePresentationPromise>>
canSavePromises;
@ -1675,29 +1675,29 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
->Then(
GetMainThreadSerialEventTarget(), __func__,
[self = RefPtr{this}, browsingContext,
changeState](const nsTArray<bool> aCanSaves) mutable {
options](const nsTArray<bool> aCanSaves) mutable {
bool canSave = !aCanSaves.Contains(false);
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug,
("DocumentLoadListener::MaybeTriggerProcessSwitch "
"saving presentation=%i",
canSave));
changeState.mTryUseBFCache = canSave;
self->TriggerProcessSwitch(browsingContext, changeState);
options.mTryUseBFCache = canSave;
self->TriggerProcessSwitch(browsingContext, options);
},
[self = RefPtr{this}, browsingContext,
changeState](ipc::ResponseRejectReason) mutable {
options](ipc::ResponseRejectReason) mutable {
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug,
("DocumentLoadListener::MaybeTriggerProcessSwitch "
"error in trying to save presentation"));
changeState.mTryUseBFCache = false;
self->TriggerProcessSwitch(browsingContext, changeState);
options.mTryUseBFCache = false;
self->TriggerProcessSwitch(browsingContext, options);
});
return true;
}
}
changeState.mTryUseBFCache = false;
TriggerProcessSwitch(browsingContext, changeState);
options.mTryUseBFCache = false;
TriggerProcessSwitch(browsingContext, options);
return true;
}
@ -1716,7 +1716,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
mObjectUpgradeHandler->UpgradeObjectLoad()->Then(
GetMainThreadSerialEventTarget(), __func__,
[self = RefPtr{this}, changeState,
[self = RefPtr{this}, options,
wgp](const RefPtr<CanonicalBrowsingContext>& aBrowsingContext) mutable {
if (aBrowsingContext->IsDiscarded() ||
wgp != aBrowsingContext->GetParentWindowContext()) {
@ -1728,7 +1728,7 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
}
LOG(("Process Switch: Upgraded Object to Document Load"));
self->TriggerProcessSwitch(aBrowsingContext, changeState);
self->TriggerProcessSwitch(aBrowsingContext, options);
},
[self = RefPtr{this}](nsresult aStatusCode) {
MOZ_ASSERT(NS_FAILED(aStatusCode), "Status should be error");
@ -1738,7 +1738,8 @@ bool DocumentLoadListener::MaybeTriggerProcessSwitch(
}
void DocumentLoadListener::TriggerProcessSwitch(
CanonicalBrowsingContext* aContext, const RemotenessChangeState& aState) {
CanonicalBrowsingContext* aContext,
const RemotenessChangeOptions& aOptions) {
nsAutoCString currentRemoteType(NOT_REMOTE_TYPE);
if (RefPtr<ContentParent> contentParent = aContext->GetContentParent()) {
currentRemoteType = contentParent->GetRemoteType();
@ -1746,7 +1747,7 @@ void DocumentLoadListener::TriggerProcessSwitch(
MOZ_ASSERT_IF(currentRemoteType.IsEmpty(), !OtherPid());
LOG(("Process Switch: Changing Remoteness from '%s' to '%s'",
currentRemoteType.get(), aState.mRemoteType.get()));
currentRemoteType.get(), aOptions.mRemoteType.get()));
// We're now committing to a process switch, so we can disconnect from
// the listeners in the old process.
@ -1764,7 +1765,7 @@ void DocumentLoadListener::TriggerProcessSwitch(
DisconnectListeners(NS_BINDING_ABORTED, NS_BINDING_ABORTED, true);
LOG(("Process Switch: Calling ChangeRemoteness"));
aContext->ChangeRemoteness(aState, mLoadIdentifier)
aContext->ChangeRemoteness(aOptions, mLoadIdentifier)
->Then(
GetMainThreadSerialEventTarget(), __func__,
[self = RefPtr{this}](BrowserParent* aBrowserParent) {

View File

@ -36,7 +36,7 @@
namespace mozilla {
namespace dom {
class CanonicalBrowsingContext;
struct RemotenessChangeState;
struct RemotenessChangeOptions;
} // namespace dom
namespace net {
using ChildEndpointPromise =
@ -322,7 +322,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 dom::RemotenessChangeState& aState);
const dom::RemotenessChangeOptions& aOptions);
// A helper for TriggerRedirectToRealChannel that abstracts over
// the same-process and cross-process switch cases and returns