Skip to content

Commit

Permalink
Bug 1656753 - Track CrossGroupOpener on CanonicalBrowsingContext, r=f…
Browse files Browse the repository at this point in the history
  • Loading branch information
mystor committed Sep 22, 2020
1 parent 4d4ac26 commit ac1e373
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
7 changes: 7 additions & 0 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,13 @@ void CanonicalBrowsingContext::HistoryCommitIndexAndLength(
});
}

void CanonicalBrowsingContext::SetCrossGroupOpenerId(uint64_t aOpenerId) {
MOZ_DIAGNOSTIC_ASSERT(IsTopContent());
MOZ_DIAGNOSTIC_ASSERT(mCrossGroupOpenerId == 0,
"Can only set CrossGroupOpenerId once");
mCrossGroupOpenerId = aOpenerId;
}

NS_IMPL_CYCLE_COLLECTION_INHERITED(CanonicalBrowsingContext, BrowsingContext,
mSessionHistory)

Expand Down
9 changes: 9 additions & 0 deletions docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class CanonicalBrowsingContext final : public BrowsingContext {
void ClearInFlightProcessId(uint64_t aProcessId);
uint64_t GetInFlightProcessId() const { return mInFlightProcessId; }

// The ID of the BrowsingContext which caused this BrowsingContext to be
// opened, or `0` if this is unknown.
// Only set for toplevel content BrowsingContexts, and may be from a different
// BrowsingContextGroup.
uint64_t GetCrossGroupOpenerId() const { return mCrossGroupOpenerId; }
void SetCrossGroupOpenerId(uint64_t aOpenerId);

void GetWindowGlobals(nsTArray<RefPtr<WindowGlobalParent>>& aWindows);

// The current active WindowGlobal.
Expand Down Expand Up @@ -301,6 +308,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {
// have in-flight messages that assume it is still the owner.
uint64_t mInFlightProcessId = 0;

uint64_t mCrossGroupOpenerId = 0;

// The current remoteness change which is in a pending state.
RefPtr<PendingRemotenessChange> mPendingRemotenessChange;

Expand Down
16 changes: 6 additions & 10 deletions docshell/base/nsDSURIContentListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,20 @@ BrowsingContext* MaybeCloseWindowHelper::MaybeCloseWindow() {

already_AddRefed<BrowsingContext>
MaybeCloseWindowHelper::ChooseNewBrowsingContext(BrowsingContext* aBC) {
RefPtr<BrowsingContext> bc = aBC;

RefPtr<BrowsingContext> opener = bc->GetOpener();
RefPtr<BrowsingContext> opener = aBC->GetOpener();
if (opener && !opener->IsDiscarded()) {
return opener.forget();
}

if (!XRE_IsParentProcess()) {
return bc.forget();
return nullptr;
}

CanonicalBrowsingContext* cbc = CanonicalBrowsingContext::Cast(aBC);
RefPtr<WindowGlobalParent> wgp = cbc->GetEmbedderWindowGlobal();
if (!wgp) {
return bc.forget();
opener = BrowsingContext::Get(aBC->Canonical()->GetCrossGroupOpenerId());
if (!opener || opener->IsDiscarded()) {
return nullptr;
}

return do_AddRef(wgp->BrowsingContext());
return opener.forget();
}

NS_IMETHODIMP
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/nsDSURIContentListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class MaybeCloseWindowHelper final : public nsITimerCallback {
* Closes the provided window async (if mShouldCloseWindow is true) and
* returns a valid browsingContext to be used instead as parent for dialogs or
* similar things.
* In case mShouldCloseWindow is true, the final browsing context will be the
* a valid new chrome window to use. It can be the opener, or the opener's
* top, or the top chrome window.
* In case mShouldCloseWindow is true, the returned BrowsingContext will be
* the window's opener (or original cross-group opener in the case of a
* `noopener` popup).
*/
mozilla::dom::BrowsingContext* MaybeCloseWindow();

Expand Down
8 changes: 8 additions & 0 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Create(
CreateBrowsingContext(aOwner, aOpenWindowInfo, group, aNetworkCreated);
NS_ENSURE_TRUE(context, nullptr);

if (XRE_IsParentProcess() && aOpenWindowInfo) {
MOZ_ASSERT(context->IsTopContent());
if (RefPtr<BrowsingContext> crossGroupOpener =
aOpenWindowInfo->GetParent()) {
context->Canonical()->SetCrossGroupOpenerId(crossGroupOpener->Id());
}
}

bool isRemoteFrame = InitialLoadIsRemote(aOwner);
RefPtr<nsFrameLoader> fl =
new nsFrameLoader(aOwner, context, isRemoteFrame, aNetworkCreated);
Expand Down

0 comments on commit ac1e373

Please sign in to comment.