Bug 1656753 - Track CrossGroupOpener on CanonicalBrowsingContext, r=farre

Differential Revision: https://phabricator.services.mozilla.com/D90890
This commit is contained in:
Nika Layzell 2020-09-22 16:28:37 +00:00
Родитель f73e3431ed
Коммит c0868a6edb
5 изменённых файлов: 33 добавлений и 13 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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.
@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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();

Просмотреть файл

@ -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);