Bug 1580565 - Part 5: Remove redundant 'mParent' member, r=farre

Differential Revision: https://phabricator.services.mozilla.com/D71239
This commit is contained in:
Nika Layzell 2020-04-23 21:52:49 +00:00
parent 8f2ceafb38
commit 5e242428d9
2 changed files with 24 additions and 30 deletions

View File

@ -93,10 +93,14 @@ static void Register(BrowsingContext* aBrowsingContext) {
aBrowsingContext->Group()->Register(aBrowsingContext);
}
BrowsingContext* BrowsingContext::GetParent() const {
return mParentWindow ? mParentWindow->GetBrowsingContext() : nullptr;
}
BrowsingContext* BrowsingContext::Top() {
BrowsingContext* bc = this;
while (bc->mParent) {
bc = bc->mParent;
while (bc->mParentWindow) {
bc = bc->GetParent();
}
return bc;
}
@ -370,10 +374,7 @@ BrowsingContext::BrowsingContext(WindowContext* aParentWindow,
mEmbeddedByThisProcess(false),
mUseRemoteTabs(false),
mUseRemoteSubframes(false) {
if (mParentWindow) {
MOZ_RELEASE_ASSERT(mParentWindow->Group() == mGroup);
mParent = mParentWindow->GetBrowsingContext();
}
MOZ_RELEASE_ASSERT(!mParentWindow || mParentWindow->Group() == mGroup);
MOZ_RELEASE_ASSERT(mBrowsingContextId != 0);
MOZ_RELEASE_ASSERT(mGroup);
}
@ -475,7 +476,7 @@ void BrowsingContext::Attach(bool aFromIPC) {
("%s: Connecting 0x%08" PRIx64 " to 0x%08" PRIx64
" (private=%d, remote=%d, fission=%d, oa=%s)",
XRE_IsParentProcess() ? "Parent" : "Child", Id(),
mParent ? mParent->Id() : 0, (int)mPrivateBrowsingId,
GetParent() ? GetParent()->Id() : 0, (int)mPrivateBrowsingId,
(int)mUseRemoteTabs, (int)mUseRemoteSubframes, suffix.get()));
}
@ -513,7 +514,7 @@ void BrowsingContext::Detach(bool aFromIPC) {
MOZ_LOG(GetLog(), LogLevel::Debug,
("%s: Detaching 0x%08" PRIx64 " from 0x%08" PRIx64,
XRE_IsParentProcess() ? "Parent" : "Child", Id(),
mParent ? mParent->Id() : 0));
GetParent() ? GetParent()->Id() : 0));
// This will only ever be null if the cycle-collector has unlinked us. Don't
// try to detach ourselves in that case.
@ -716,7 +717,7 @@ BrowsingContext* BrowsingContext::FindWithName(
do {
Span<RefPtr<BrowsingContext>> siblings;
BrowsingContext* parent = current->mParent;
BrowsingContext* parent = current->GetParent();
if (!parent) {
// We've reached the root of the tree, consider browsing
@ -783,8 +784,8 @@ BrowsingContext* BrowsingContext::FindWithSpecialName(
}
if (aName.LowerCaseEqualsLiteral("_parent")) {
if (mParent) {
return aRequestingContext.CanAccess(mParent) ? mParent.get() : nullptr;
if (BrowsingContext* parent = GetParent()) {
return aRequestingContext.CanAccess(parent) ? parent : nullptr;
}
return this;
}
@ -1204,8 +1205,8 @@ NS_IMETHODIMP BrowsingContext::GetUseTrackingProtection(
return NS_OK;
}
if (mParent) {
return mParent->GetUseTrackingProtection(aUseTrackingProtection);
if (GetParent()) {
return GetParent()->GetUseTrackingProtection(aUseTrackingProtection);
}
return NS_OK;
@ -1292,7 +1293,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BrowsingContext)
tmp->mFields.SetWithoutSyncing<IDX_IsPopupSpam>(false);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocShell, mParentWindow, mParent, mGroup,
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocShell, mParentWindow, mGroup,
mEmbedderElement, mWindowContexts,
mCurrentWindowContext, mSessionStorageManager)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
@ -1300,8 +1301,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BrowsingContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(
mDocShell, mParentWindow, mParent, mGroup, mEmbedderElement,
mWindowContexts, mCurrentWindowContext, mSessionStorageManager)
mDocShell, mParentWindow, mGroup, mEmbedderElement, mWindowContexts,
mCurrentWindowContext, mSessionStorageManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
class RemoteLocationProxy
@ -1547,17 +1548,17 @@ void BrowsingContext::GetOpener(JSContext* aCx,
}
}
// We never throw an error, but the implementation in nsGlobalWindow does and
// we need to use the same signature.
Nullable<WindowProxyHolder> BrowsingContext::GetParent(ErrorResult& aError) {
if (mIsDiscarded) {
return nullptr;
}
// We never throw an error, but the implementation in nsGlobalWindow does and
// we need to use the same signature.
if (!mParent) {
return WindowProxyHolder(this);
if (GetParent()) {
return WindowProxyHolder(GetParent());
}
return WindowProxyHolder(mParent.get());
return WindowProxyHolder(this);
}
void BrowsingContext::PostMessageMoz(JSContext* aCx,
@ -1728,7 +1729,7 @@ void BrowsingContext::DidSet(FieldIndex<IDX_UserActivationState>) {
}
void BrowsingContext::DidSet(FieldIndex<IDX_Muted>) {
MOZ_ASSERT(!mParent, "Set muted flag on non top-level context!");
MOZ_ASSERT(!GetParent(), "Set muted flag on non top-level context!");
USER_ACTIVATION_LOG("Set audio muted %d for %s browsing context 0x%08" PRIx64,
GetMuted(), XRE_IsParentProcess() ? "Parent" : "Child",
Id());

View File

@ -288,10 +288,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool IsContentSubframe() const { return IsContent() && GetParent(); }
uint64_t Id() const { return mBrowsingContextId; }
BrowsingContext* GetParent() const {
MOZ_ASSERT_IF(mParent, mParent->mType == mType);
return mParent;
}
BrowsingContext* GetParent() const;
BrowsingContext* Top();
// NOTE: Unlike `GetEmbedderWindowGlobal`, `GetParentWindow` does not cross
@ -724,10 +721,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
RefPtr<BrowsingContextGroup> mGroup;
RefPtr<WindowContext> mParentWindow;
// NOTE: `mParent` must be the same as `mParentWindow->GetBrowsingContext()`
// at all times.
// FIXME: Consider removing this field?
RefPtr<BrowsingContext> mParent;
nsCOMPtr<nsIDocShell> mDocShell;
RefPtr<Element> mEmbedderElement;