Bug 1627533 - Create LoadGroups for docshells using the BrowsingContext's request context id. r=dragana,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D75885
This commit is contained in:
Matt Woodrow 2020-05-20 23:41:36 +00:00
Родитель d958cab047
Коммит f8b14e22ba
6 изменённых файлов: 48 добавлений и 2 удалений

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

@ -464,7 +464,7 @@ already_AddRefed<nsDocShell> nsDocShell::Create(
RefPtr<nsDocShell> ds = new nsDocShell(aBrowsingContext, aContentWindowID);
// Initialize the underlying nsDocLoader.
rv = ds->nsDocLoader::Init();
rv = ds->nsDocLoader::InitWithBrowsingContext(aBrowsingContext);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}

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

@ -94,6 +94,7 @@ nsLoadGroup::nsLoadGroup()
mIsCanceling(false),
mDefaultLoadIsTimed(false),
mBrowsingContextDiscarded(false),
mExternalRequestContext(false),
mTimedRequests(0),
mCachedRequests(0) {
LOG(("LOADGROUP [%p]: Created.\n", this));
@ -105,7 +106,7 @@ nsLoadGroup::~nsLoadGroup() {
mDefaultLoadRequest = nullptr;
if (mRequestContext) {
if (mRequestContext && !mExternalRequestContext) {
mRequestContextService->RemoveRequestContext(mRequestContext->GetID());
if (IsNeckoChild() && gNeckoChild) {
gNeckoChild->SendRemoveRequestContext(mRequestContext->GetID());
@ -978,6 +979,23 @@ nsresult nsLoadGroup::Init() {
return NS_OK;
}
nsresult nsLoadGroup::InitWithRequestContextId(
const uint64_t& aRequestContextId) {
mRequestContextService = RequestContextService::GetOrCreate();
if (mRequestContextService) {
Unused << mRequestContextService->GetRequestContext(
aRequestContextId, getter_AddRefs(mRequestContext));
}
mExternalRequestContext = true;
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
NS_ENSURE_STATE(os);
Unused << os->AddObserver(this, "last-pb-context-exited", true);
return NS_OK;
}
NS_IMETHODIMP
nsLoadGroup::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {

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

@ -56,6 +56,7 @@ class nsLoadGroup : public nsILoadGroup,
nsLoadGroup();
nsresult Init();
nsresult InitWithRequestContextId(const uint64_t& aRequestContextId);
protected:
virtual ~nsLoadGroup();
@ -92,6 +93,7 @@ class nsLoadGroup : public nsILoadGroup,
bool mIsCanceling;
bool mDefaultLoadIsTimed;
bool mBrowsingContextDiscarded;
bool mExternalRequestContext;
/* Telemetry */
mozilla::TimeStamp mDefaultRequestCreationTime;

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

@ -30,4 +30,8 @@ UNIFIED_SOURCES += [
'nsURILoader.cpp',
]
LOCAL_INCLUDES += [
'/netwerk/base',
]
FINAL_LIBRARY = 'xul'

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

@ -15,6 +15,7 @@
#include "nsDocLoader.h"
#include "nsDocShell.h"
#include "nsLoadGroup.h"
#include "nsNetUtil.h"
#include "nsIHttpChannel.h"
#include "nsIWebNavigation.h"
@ -139,6 +140,24 @@ nsresult nsDocLoader::Init() {
return NS_OK;
}
nsresult nsDocLoader::InitWithBrowsingContext(
BrowsingContext* aBrowsingContext) {
RefPtr<net::nsLoadGroup> loadGroup = new net::nsLoadGroup();
nsresult rv = loadGroup->InitWithRequestContextId(
aBrowsingContext->GetRequestContextId());
if (NS_FAILED(rv)) return rv;
rv = loadGroup->SetGroupObserver(this);
if (NS_FAILED(rv)) return rv;
mLoadGroup = loadGroup;
MOZ_LOG(gDocLoaderLog, LogLevel::Debug,
("DocLoader:%p: load group %p.\n", this, mLoadGroup.get()));
return NS_OK;
}
nsDocLoader::~nsDocLoader() {
/*
|ClearWeakReferences()| here is intended to prevent people holding

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

@ -31,6 +31,7 @@
namespace mozilla {
namespace dom {
class BrowserBridgeChild;
class BrowsingContext;
} // namespace dom
} // namespace mozilla
@ -61,6 +62,8 @@ class nsDocLoader : public nsIDocumentLoader,
nsDocLoader();
[[nodiscard]] virtual nsresult Init();
[[nodiscard]] nsresult InitWithBrowsingContext(
mozilla::dom::BrowsingContext* aBrowsingContext);
static already_AddRefed<nsDocLoader> GetAsDocLoader(nsISupports* aSupports);
// Needed to deal with ambiguous inheritance from nsISupports...