Bug 1615480 - Part 1: Return a raw pointer from Get[Extant]BrowsingContext, r=kmag

The BrowsingContext is guaranteed to be being kept alive by
`nsFrameLoader::mBrowsingContext` and by the nsDocShell or RemoteBrowser object.
This improves the ergonomics of this helper method, which may help avoid misuse
of `mBrowsingContext`.

Differential Revision: https://phabricator.services.mozilla.com/D62957

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nika Layzell 2020-02-21 18:44:57 +00:00
Родитель 5065663562
Коммит df715e383d
4 изменённых файлов: 9 добавлений и 12 удалений

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

@ -3262,8 +3262,7 @@ already_AddRefed<nsILoadContext> nsFrameLoader::LoadContext() {
return loadContext.forget();
}
already_AddRefed<BrowsingContext> nsFrameLoader::GetBrowsingContext() {
RefPtr<BrowsingContext> browsingContext;
BrowsingContext* nsFrameLoader::GetBrowsingContext() {
if (IsRemoteFrame()) {
Unused << EnsureRemoteBrowser();
} else if (mOwnerContent) {
@ -3272,15 +3271,15 @@ already_AddRefed<BrowsingContext> nsFrameLoader::GetBrowsingContext() {
return GetExtantBrowsingContext();
}
already_AddRefed<BrowsingContext> nsFrameLoader::GetExtantBrowsingContext() {
RefPtr<BrowsingContext> browsingContext;
BrowsingContext* nsFrameLoader::GetExtantBrowsingContext() {
BrowsingContext* browsingContext = nullptr;
if (mRemoteBrowser) {
browsingContext = mRemoteBrowser->GetBrowsingContext();
} else if (mDocShell) {
browsingContext = mDocShell->GetBrowsingContext();
}
MOZ_ASSERT_IF(browsingContext, browsingContext == mBrowsingContext);
return browsingContext.forget();
return browsingContext;
}
void nsFrameLoader::InitializeBrowserAPI() {
@ -3487,8 +3486,7 @@ void nsFrameLoader::SetWillChangeProcess() {
// resilient. For the moment, though, the surrounding process switch code
// is enough in flux that we're better off with a workable interim
// solution.
MOZ_DIAGNOSTIC_ASSERT(mBrowsingContext ==
RefPtr<BrowsingContext>(GetBrowsingContext()));
MOZ_DIAGNOSTIC_ASSERT(mBrowsingContext == GetBrowsingContext());
RefPtr<CanonicalBrowsingContext> bc(mBrowsingContext->Canonical());
bc->SetInFlightProcessId(browserParent->Manager()->ChildID());
auto callback = [bc](auto) { bc->SetInFlightProcessId(0); };

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

@ -152,8 +152,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
already_AddRefed<nsILoadContext> LoadContext();
already_AddRefed<mozilla::dom::BrowsingContext> GetBrowsingContext();
already_AddRefed<mozilla::dom::BrowsingContext> GetExtantBrowsingContext();
mozilla::dom::BrowsingContext* GetBrowsingContext();
mozilla::dom::BrowsingContext* GetExtantBrowsingContext();
/**
* Start loading the frame. This method figures out what to load

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

@ -33,8 +33,7 @@ void nsFrameLoaderOwner::SetFrameLoader(nsFrameLoader* aNewFrameLoader) {
mFrameLoader = aNewFrameLoader;
}
already_AddRefed<mozilla::dom::BrowsingContext>
nsFrameLoaderOwner::GetBrowsingContext() {
mozilla::dom::BrowsingContext* nsFrameLoaderOwner::GetBrowsingContext() {
if (mFrameLoader) {
return mFrameLoader->GetBrowsingContext();
}

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

@ -42,7 +42,7 @@ class nsFrameLoaderOwner : public nsISupports {
already_AddRefed<nsFrameLoader> GetFrameLoader();
void SetFrameLoader(nsFrameLoader* aNewFrameLoader);
already_AddRefed<mozilla::dom::BrowsingContext> GetBrowsingContext();
mozilla::dom::BrowsingContext* GetBrowsingContext();
// Destroy (if it exists) and recreate our frameloader, based on new
// remoteness requirements. This should follow the same path as