Bug 1597499 - Move nsIDocShell::ChildOffset to BrowsingContext, r=nika

Differential Revision: https://phabricator.services.mozilla.com/D89969
This commit is contained in:
Kashav Madan
2021-03-17 16:43:04 +00:00
parent 5b0a4601c4
commit ff7ceddbcb
7 changed files with 24 additions and 46 deletions

View File

@@ -489,6 +489,7 @@ void BrowsingContext::CreateFromIPC(BrowsingContext::IPCInitializer&& aInit,
context->mWindowless = aInit.mWindowless; context->mWindowless = aInit.mWindowless;
context->mCreatedDynamically = aInit.mCreatedDynamically; context->mCreatedDynamically = aInit.mCreatedDynamically;
context->mChildOffset = aInit.mChildOffset;
if (context->GetHasSessionHistory()) { if (context->GetHasSessionHistory()) {
context->CreateChildSHistory(); context->CreateChildSHistory();
if (mozilla::SessionHistoryInParent()) { if (mozilla::SessionHistoryInParent()) {
@@ -528,7 +529,8 @@ BrowsingContext::BrowsingContext(WindowContext* aParentWindow,
mEmbeddedByThisProcess(false), mEmbeddedByThisProcess(false),
mUseRemoteTabs(false), mUseRemoteTabs(false),
mUseRemoteSubframes(false), mUseRemoteSubframes(false),
mCreatedDynamically(false) { mCreatedDynamically(false),
mChildOffset(0) {
MOZ_RELEASE_ASSERT(!mParentWindow || mParentWindow->Group() == mGroup); MOZ_RELEASE_ASSERT(!mParentWindow || mParentWindow->Group() == mGroup);
MOZ_RELEASE_ASSERT(mBrowsingContextId != 0); MOZ_RELEASE_ASSERT(mBrowsingContextId != 0);
MOZ_RELEASE_ASSERT(mGroup); MOZ_RELEASE_ASSERT(mGroup);
@@ -717,7 +719,8 @@ void BrowsingContext::Attach(bool aFromIPC, ContentParent* aOriginProcess) {
MOZ_DIAGNOSTIC_ASSERT(!GetParent()->IsDiscarded(), MOZ_DIAGNOSTIC_ASSERT(!GetParent()->IsDiscarded(),
"local attach call in discarded bc"); "local attach call in discarded bc");
} }
mChildOffset =
mCreatedDynamically ? -1 : mParentWindow->Children().Length();
mParentWindow->AppendChildBrowsingContext(this); mParentWindow->AppendChildBrowsingContext(this);
} else { } else {
mGroup->Toplevels().AppendElement(this); mGroup->Toplevels().AppendElement(this);
@@ -2369,6 +2372,7 @@ BrowsingContext::IPCInitializer BrowsingContext::GetIPCInitializer() {
init.mUseRemoteTabs = mUseRemoteTabs; init.mUseRemoteTabs = mUseRemoteTabs;
init.mUseRemoteSubframes = mUseRemoteSubframes; init.mUseRemoteSubframes = mUseRemoteSubframes;
init.mCreatedDynamically = mCreatedDynamically; init.mCreatedDynamically = mCreatedDynamically;
init.mChildOffset = mChildOffset;
init.mOriginAttributes = mOriginAttributes; init.mOriginAttributes = mOriginAttributes;
if (mChildSessionHistory && mozilla::SessionHistoryInParent()) { if (mChildSessionHistory && mozilla::SessionHistoryInParent()) {
init.mSessionHistoryIndex = mChildSessionHistory->Index(); init.mSessionHistoryIndex = mChildSessionHistory->Index();
@@ -3387,6 +3391,7 @@ void IPDLParamTraits<dom::BrowsingContext::IPCInitializer>::Write(
WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteTabs); WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteTabs);
WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteSubframes); WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteSubframes);
WriteIPDLParam(aMessage, aActor, aInit.mCreatedDynamically); WriteIPDLParam(aMessage, aActor, aInit.mCreatedDynamically);
WriteIPDLParam(aMessage, aActor, aInit.mChildOffset);
WriteIPDLParam(aMessage, aActor, aInit.mOriginAttributes); WriteIPDLParam(aMessage, aActor, aInit.mOriginAttributes);
WriteIPDLParam(aMessage, aActor, aInit.mRequestContextId); WriteIPDLParam(aMessage, aActor, aInit.mRequestContextId);
WriteIPDLParam(aMessage, aActor, aInit.mSessionHistoryIndex); WriteIPDLParam(aMessage, aActor, aInit.mSessionHistoryIndex);
@@ -3406,6 +3411,7 @@ bool IPDLParamTraits<dom::BrowsingContext::IPCInitializer>::Read(
&aInit->mUseRemoteSubframes) || &aInit->mUseRemoteSubframes) ||
!ReadIPDLParam(aMessage, aIterator, aActor, !ReadIPDLParam(aMessage, aIterator, aActor,
&aInit->mCreatedDynamically) || &aInit->mCreatedDynamically) ||
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mChildOffset) ||
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mOriginAttributes) || !ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mOriginAttributes) ||
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mRequestContextId) || !ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mRequestContextId) ||
!ReadIPDLParam(aMessage, aIterator, aActor, !ReadIPDLParam(aMessage, aIterator, aActor,

View File

@@ -678,6 +678,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool mUseRemoteTabs = false; bool mUseRemoteTabs = false;
bool mUseRemoteSubframes = false; bool mUseRemoteSubframes = false;
bool mCreatedDynamically = false; bool mCreatedDynamically = false;
int32_t mChildOffset = 0;
int32_t mSessionHistoryIndex = -1; int32_t mSessionHistoryIndex = -1;
int32_t mSessionHistoryCount = 0; int32_t mSessionHistoryCount = 0;
OriginAttributes mOriginAttributes; OriginAttributes mOriginAttributes;
@@ -716,6 +717,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool CreatedDynamically() const { return mCreatedDynamically; } bool CreatedDynamically() const { return mCreatedDynamically; }
int32_t ChildOffset() const { return mChildOffset; }
const OriginAttributes& OriginAttributesRef() { return mOriginAttributes; } const OriginAttributes& OriginAttributesRef() { return mOriginAttributes; }
nsresult SetOriginAttributes(const OriginAttributes& aAttrs); nsresult SetOriginAttributes(const OriginAttributes& aAttrs);
@@ -1134,6 +1137,10 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
// True if this BrowsingContext is for a frame that was added dynamically. // True if this BrowsingContext is for a frame that was added dynamically.
bool mCreatedDynamically : 1; bool mCreatedDynamically : 1;
// The original offset of this context in its container. This property is -1
// if this BrowsingContext is for a frame that was added dynamically.
int32_t mChildOffset;
// The start time of user gesture, this is only available if the browsing // The start time of user gesture, this is only available if the browsing
// context is in process. // context is in process.
TimeStamp mUserGestureStart; TimeStamp mUserGestureStart;

View File

@@ -376,7 +376,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mItemType(aBrowsingContext->IsContent() ? typeContent : typeChrome), mItemType(aBrowsingContext->IsContent() ? typeContent : typeChrome),
mPreviousEntryIndex(-1), mPreviousEntryIndex(-1),
mLoadedEntryIndex(-1), mLoadedEntryIndex(-1),
mChildOffset(0),
mBusyFlags(BUSY_FLAGS_NONE), mBusyFlags(BUSY_FLAGS_NONE),
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
mLoadType(0), mLoadType(0),
@@ -1023,7 +1022,7 @@ bool nsDocShell::MaybeHandleSubframeHistory(
// it wasn't originally for some other frame. // it wasn't originally for some other frame.
nsCOMPtr<nsISHEntry> shEntry; nsCOMPtr<nsISHEntry> shEntry;
currentSH->GetChildSHEntryIfHasNoDynamicallyAddedChild( currentSH->GetChildSHEntryIfHasNoDynamicallyAddedChild(
mChildOffset, getter_AddRefs(shEntry)); mBrowsingContext->ChildOffset(), getter_AddRefs(shEntry));
if (shEntry) { if (shEntry) {
aLoadState->SetSHEntry(shEntry); aLoadState->SetSHEntry(shEntry);
} }
@@ -2990,12 +2989,6 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) {
return NS_OK; return NS_OK;
} }
void nsDocShell::SetChildOffset(int32_t aChildOffset) {
mChildOffset = aChildOffset;
}
int32_t nsDocShell::GetChildOffset() { return mChildOffset; }
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::GetHistoryID(nsID& aID) { nsDocShell::GetHistoryID(nsID& aID) {
aID = mBrowsingContext->GetHistoryID(); aID = mBrowsingContext->GetHistoryID();
@@ -3049,24 +3042,11 @@ nsDocShell::AddChild(nsIDocShellTreeItem* aChild) {
NS_ASSERTION(!mChildList.IsEmpty(), NS_ASSERTION(!mChildList.IsEmpty(),
"child list must not be empty after a successful add"); "child list must not be empty after a successful add");
nsCOMPtr<nsIDocShell> childDocShell = do_QueryInterface(aChild);
bool dynamic = nsDocShell::Cast(childDocShell)->GetCreatedDynamically();
if (!dynamic) {
nsCOMPtr<nsISHEntry> currentSH;
bool oshe = false;
GetCurrentSHEntry(getter_AddRefs(currentSH), &oshe);
if (currentSH) {
currentSH->HasDynamicallyAddedChild(&dynamic);
}
}
childDocShell->SetChildOffset(dynamic ? -1 : mChildList.Length() - 1);
/* Set the child's global history if the parent has one */ /* Set the child's global history if the parent has one */
if (mBrowsingContext->GetUseGlobalHistory()) { if (mBrowsingContext->GetUseGlobalHistory()) {
// childDocShell->SetUseGlobalHistory(true); // childDocShell->SetUseGlobalHistory(true);
// this should be set through BC inherit // this should be set through BC inherit
MOZ_ASSERT(nsDocShell::Cast(childDocShell) MOZ_ASSERT(aChild->GetBrowsingContext()->GetUseGlobalHistory());
->mBrowsingContext->GetUseGlobalHistory());
} }
if (aChild->ItemType() != mItemType) { if (aChild->ItemType() != mItemType) {
@@ -11832,7 +11812,8 @@ nsresult nsDocShell::AddToSessionHistory(
MOZ_ALWAYS_SUCCEEDS(topWc->SetSHEntryHasUserInteraction(false)); MOZ_ALWAYS_SUCCEEDS(topWc->SetSHEntryHasUserInteraction(false));
} }
if (!mOSHE || !LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) { if (!mOSHE || !LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {
rv = AddChildSHEntryToParent(entry, mChildOffset, aCloneChildren); rv = AddChildSHEntryToParent(entry, mBrowsingContext->ChildOffset(),
aCloneChildren);
} }
} }

View File

@@ -1193,10 +1193,6 @@ class nsDocShell final : public nsDocLoader,
int32_t mPreviousEntryIndex; int32_t mPreviousEntryIndex;
int32_t mLoadedEntryIndex; int32_t mLoadedEntryIndex;
// Offset in the parent's child list.
// -1 if the docshell is added dynamically to the parent shell.
int32_t mChildOffset;
BusyFlags mBusyFlags; BusyFlags mBusyFlags;
AppType mAppType; AppType mAppType;
uint32_t mLoadType; uint32_t mLoadType;

View File

@@ -450,12 +450,6 @@ interface nsIDocShell : nsIDocShellTreeItem
*/ */
readonly attribute nsIChannel currentDocumentChannel; readonly attribute nsIChannel currentDocumentChannel;
/**
* The original offset of this child in its container. This property is -1 for
* dynamically added docShells.
*/
[notxpcom,nostdcall] attribute long childOffset;
/** /**
* Find out whether the docshell is currently in the middle of a page * Find out whether the docshell is currently in the middle of a page
* transition. This is set just before the pagehide/unload events fire. * transition. This is set just before the pagehide/unload events fire.

View File

@@ -201,6 +201,8 @@ interface BrowsingContext {
// Resets the location change rate limit. Used for testing. // Resets the location change rate limit. Used for testing.
void resetLocationChangeRateLimit(); void resetLocationChangeRateLimit();
readonly attribute long childOffset;
}; };
BrowsingContext includes LoadContextMixin; BrowsingContext includes LoadContextMixin;

View File

@@ -121,20 +121,12 @@ void SessionStoreUtils::ForEachNonDynamicChildFrame(
return; return;
} }
if (context->CreatedDynamically()) { if (!context->CreatedDynamically()) {
continue; int32_t childOffset = context->ChildOffset();
}
nsCOMPtr<nsIDocShell> childDocShell(do_QueryInterface(item));
if (!childDocShell) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
int32_t childOffset = childDocShell->GetChildOffset();
aCallback.Call(WindowProxyHolder(context.forget()), childOffset); aCallback.Call(WindowProxyHolder(context.forget()), childOffset);
} }
} }
}
/* static */ /* static */
already_AddRefed<nsISupports> already_AddRefed<nsISupports>