Skip to content

Commit

Permalink
Backed out changeset c807d0b9d872 (bug 1555287) for valgrind bustages…
Browse files Browse the repository at this point in the history
… CLOSED TREE

--HG--
extra : rebase_source : e53f888399cf5eb46d3996a107d572aabfad4b97
  • Loading branch information
nerli1 committed Jun 13, 2019
1 parent b93335c commit c8d23f6
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 109 deletions.
75 changes: 26 additions & 49 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {

MOZ_DIAGNOSTIC_ASSERT(mType == Type::Chrome, "must be chrome");
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(), "must be in parent");
MOZ_DIAGNOSTIC_ASSERT(!mGroup->IsContextCached(this),
MOZ_DIAGNOSTIC_ASSERT(!Group()->IsContextCached(this),
"cannot be in bfcache");

RefPtr<BrowsingContext> kungFuDeathGrip(this);
Expand Down Expand Up @@ -248,9 +248,7 @@ void BrowsingContext::Attach(bool aFromIPC) {
XRE_IsParentProcess() ? "Parent" : "Child", Id(),
mParent ? mParent->Id() : 0));

MOZ_DIAGNOSTIC_ASSERT(mGroup);
MOZ_DIAGNOSTIC_ASSERT(!mGroup->IsContextCached(this));
MOZ_DIAGNOSTIC_ASSERT(!mIsDiscarded);
MOZ_DIAGNOSTIC_ASSERT(!Group()->IsContextCached(this));

auto* children = mParent ? &mParent->mChildren : &mGroup->Toplevels();
MOZ_DIAGNOSTIC_ASSERT(!children->Contains(this));
Expand All @@ -264,7 +262,7 @@ void BrowsingContext::Attach(bool aFromIPC) {
GetIPCInitializer());
} else if (IsContent()) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
mGroup->EachParent([&](ContentParent* aParent) {
Group()->EachParent([&](ContentParent* aParent) {
Unused << aParent->SendAttachBrowsingContext(GetIPCInitializer());
});
}
Expand All @@ -277,56 +275,41 @@ void BrowsingContext::Detach(bool aFromIPC) {
XRE_IsParentProcess() ? "Parent" : "Child", Id(),
mParent ? mParent->Id() : 0));

// Unlinking might remove our group before Detach gets called.
if (NS_WARN_IF(!mGroup)) {
return;
}

RefPtr<BrowsingContext> kungFuDeathGrip(this);

if (!mGroup->EvictCachedContext(this)) {
if (Group() && !Group()->EvictCachedContext(this)) {
Children* children = nullptr;
if (mParent) {
children = &mParent->mChildren;
} else {
} else if (mGroup) {
children = &mGroup->Toplevels();
}

children->RemoveElement(this);
}

Unregister();
if (children) {
// TODO(farre): This assert looks extremely fishy, I know, but
// what we're actually saying is this: if we're detaching, but our
// parent doesn't have any children, it is because we're being
// detached by the cycle collector destroying docshells out of
// order.
MOZ_DIAGNOSTIC_ASSERT(children->IsEmpty() || children->Contains(this));

if (!aFromIPC && XRE_IsContentProcess()) {
auto cc = ContentChild::GetSingleton();
MOZ_DIAGNOSTIC_ASSERT(cc);
cc->SendDetachBrowsingContext(this);
children->RemoveElement(this);
}
}
}

void BrowsingContext::DetachChildren(bool aFromIPC) {
if (mChildren.IsEmpty()) {
return;
if (mGroup) {
mGroup->Unregister(this);
}

MOZ_LOG(GetLog(), LogLevel::Debug,
("%s: Detaching all children of 0x%08" PRIx64 "",
XRE_IsParentProcess() ? "Parent" : "Child", Id()));

// TODO(farre). Watch out! Notice the missing call to
// BrowsingContextGroup::Unregister here, this is intentional. If we
// unregister and set the detached flag here, tests will fail
// because not being able to look up Window.top. (Un-)Fortunately
// nsDocShell::Destroy will still call BrowsingContext::Detach,
// which will set the detached flag at that point. Bug 1558176 would
// clean this up.

mChildren.Clear();
// As our nsDocShell is going away, this should implicitly mark us as closed.
// We directly set our member, rather than using a transaction as we're going
// to send a `Detach` message to other processes either way.
mClosed = true;

if (!aFromIPC && XRE_IsContentProcess()) {
auto cc = ContentChild::GetSingleton();
MOZ_DIAGNOSTIC_ASSERT(cc);
cc->SendDetachBrowsingContextChildren(this);
cc->SendDetachBrowsingContext(this);
}
}

Expand Down Expand Up @@ -355,7 +338,7 @@ void BrowsingContext::CacheChildren(bool aFromIPC) {
("%s: Caching children of 0x%08" PRIx64 "",
XRE_IsParentProcess() ? "Parent" : "Child", Id()));

mGroup->CacheContexts(mChildren);
Group()->CacheContexts(mChildren);
mChildren.Clear();

if (!aFromIPC && XRE_IsContentProcess()) {
Expand All @@ -372,7 +355,7 @@ void BrowsingContext::RestoreChildren(Children&& aChildren, bool aFromIPC) {

for (BrowsingContext* child : aChildren) {
MOZ_DIAGNOSTIC_ASSERT(child->GetParent() == this);
Unused << mGroup->EvictCachedContext(child);
Unused << Group()->EvictCachedContext(child);
}

mChildren.AppendElements(aChildren);
Expand All @@ -384,7 +367,7 @@ void BrowsingContext::RestoreChildren(Children&& aChildren, bool aFromIPC) {
}
}

bool BrowsingContext::IsCached() { return mGroup->IsContextCached(this); }
bool BrowsingContext::IsCached() { return Group()->IsContextCached(this); }

bool BrowsingContext::HasOpener() const {
return sBrowsingContexts->Contains(mOpenerId);
Expand Down Expand Up @@ -548,12 +531,6 @@ bool BrowsingContext::IsActive() const {
return false;
}

void BrowsingContext::Unregister() {
MOZ_DIAGNOSTIC_ASSERT(mGroup);
mGroup->Unregister(this);
mIsDiscarded = true;
}

BrowsingContext::~BrowsingContext() {
MOZ_DIAGNOSTIC_ASSERT(!mParent || !mParent->mChildren.Contains(this));
MOZ_DIAGNOSTIC_ASSERT(!mGroup || !mGroup->Toplevels().Contains(this));
Expand Down Expand Up @@ -693,7 +670,7 @@ void BrowsingContext::Blur(ErrorResult& aError) {
}

Nullable<WindowProxyHolder> BrowsingContext::GetTop(ErrorResult& aError) {
if (mIsDiscarded) {
if (mClosed) {
return nullptr;
}

Expand All @@ -717,7 +694,7 @@ void BrowsingContext::GetOpener(JSContext* aCx,
}

Nullable<WindowProxyHolder> BrowsingContext::GetParent(ErrorResult& aError) {
if (mIsDiscarded) {
if (mClosed) {
return nullptr;
}

Expand Down
11 changes: 0 additions & 11 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
// Prepare this BrowsingContext to leave the current process.
void PrepareForProcessChange();

// Detach the current BrowsingContext's children, in both the child
// and the parent process.
void DetachChildren(bool aFromIPC = false);

// Remove all children from the current BrowsingContext and cache
// them to allow them to be attached again.
void CacheChildren(bool aFromIPC = false);
Expand Down Expand Up @@ -384,9 +380,6 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {

bool IsActive() const;

// Removes the context from its group and sets mIsDetached to true.
void Unregister();

friend class ::nsOuterWindowProxy;
friend class ::nsGlobalWindowOuter;
// Update the window proxy object that corresponds to this browsing context.
Expand Down Expand Up @@ -468,10 +461,6 @@ class BrowsingContext : public nsWrapperCache, public BrowsingContextBase {
// process? This may be true with a null mDocShell after the Window has been
// closed.
bool mIsInProcess : 1;

// Has this browsing context been detached? BrowsingContexts should
// only be detached once.
bool mIsDiscarded : 1;
};

/**
Expand Down
2 changes: 0 additions & 2 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,6 @@ void nsDocShell::DestroyChildren() {
}

nsDocLoader::DestroyChildren();

mBrowsingContext->DetachChildren();
}

NS_IMPL_CYCLE_COLLECTION_INHERITED(nsDocShell, nsDocLoader,
Expand Down
9 changes: 0 additions & 9 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3855,15 +3855,6 @@ mozilla::ipc::IPCResult ContentChild::RecvDetachBrowsingContext(
return IPC_OK();
}

mozilla::ipc::IPCResult ContentChild::RecvDetachBrowsingContextChildren(
BrowsingContext* aContext) {
MOZ_RELEASE_ASSERT(aContext);

aContext->DetachChildren(/* aFromIPC */ true);

return IPC_OK();
}

mozilla::ipc::IPCResult ContentChild::RecvCacheBrowsingContextChildren(
BrowsingContext* aContext) {
MOZ_RELEASE_ASSERT(aContext);
Expand Down
3 changes: 0 additions & 3 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,6 @@ class ContentChild final : public PContentChild,

mozilla::ipc::IPCResult RecvDetachBrowsingContext(BrowsingContext* aContext);

mozilla::ipc::IPCResult RecvDetachBrowsingContextChildren(
BrowsingContext* aContext);

mozilla::ipc::IPCResult RecvCacheBrowsingContextChildren(
BrowsingContext* aContext);

Expand Down
27 changes: 0 additions & 27 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5834,33 +5834,6 @@ mozilla::ipc::IPCResult ContentParent::RecvCacheBrowsingContextChildren(
return IPC_OK();
}

mozilla::ipc::IPCResult ContentParent::RecvDetachBrowsingContextChildren(
BrowsingContext* aContext) {
if (!aContext) {
MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug,
("ParentIPC: Trying to detach from already detached context"));
return IPC_OK();
}

if (!aContext->Canonical()->IsOwnedByProcess(ChildID())) {
// We're trying to detach the children of a BrowsingContext in
// another child process. This is illegal since the owner of the
// BrowsingContext is the proccess with the in-process docshell,
// which is tracked by OwnerProcessId.
MOZ_DIAGNOSTIC_ASSERT(false,
"Trying to detach from out of process context");
return IPC_OK();
}

aContext->DetachChildren(/* aFromIPC */ true);

aContext->Group()->EachOtherParent(this, [&](ContentParent* aParent) {
Unused << aParent->SendDetachBrowsingContextChildren(aContext);
});

return IPC_OK();
}

mozilla::ipc::IPCResult ContentParent::RecvRestoreBrowsingContextChildren(
BrowsingContext* aContext, BrowsingContext::Children&& aChildren) {
if (!aContext) {
Expand Down
3 changes: 0 additions & 3 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,6 @@ class ContentParent final : public PContentParent,

mozilla::ipc::IPCResult RecvDetachBrowsingContext(BrowsingContext* aContext);

mozilla::ipc::IPCResult RecvDetachBrowsingContextChildren(
BrowsingContext* aContext);

mozilla::ipc::IPCResult RecvCacheBrowsingContextChildren(
BrowsingContext* aContext);

Expand Down
5 changes: 0 additions & 5 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -1424,11 +1424,6 @@ both:
*/
async DetachBrowsingContext(BrowsingContext aContext);

/**
* Removes all children from 'aContext'.
*/
async DetachBrowsingContextChildren(BrowsingContext aContext);

/**
* Removes all of 'aContext'\'s children, and caches them in the
* BrowsingContextGroup.
Expand Down

0 comments on commit c8d23f6

Please sign in to comment.