зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1696158 - Move CanSavePresentation to the parent process. Make nsDocShell listen for background requests too. r=smaug,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D112201
This commit is contained in:
Родитель
cecda3f1ca
Коммит
f296f5bb9a
|
@ -367,7 +367,7 @@ static bool IsUrgentStart(BrowsingContext* aBrowsingContext,
|
|||
|
||||
nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
|
||||
uint64_t aContentWindowID)
|
||||
: nsDocLoader(),
|
||||
: nsDocLoader(true),
|
||||
mContentWindowID(aContentWindowID),
|
||||
mBrowsingContext(aBrowsingContext),
|
||||
mForcedCharset(nullptr),
|
||||
|
|
|
@ -36,6 +36,17 @@ const blockBFCacheTests = [
|
|||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Background request",
|
||||
test: () => {
|
||||
return new Promise((resolve) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "slow.sjs");
|
||||
xhr.addEventListener("readystatechange", () => { if (xhr.readyState == xhr.HEADERS_RECEIVED) resolve(xhr); });
|
||||
xhr.send();
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getUserMedia",
|
||||
prefs: getUserMediaPrefs,
|
||||
|
|
|
@ -96,6 +96,7 @@ nsLoadGroup::nsLoadGroup()
|
|||
mDefaultLoadIsTimed(false),
|
||||
mBrowsingContextDiscarded(false),
|
||||
mExternalRequestContext(false),
|
||||
mNotifyObserverAboutBackgroundRequests(false),
|
||||
mTimedRequests(0),
|
||||
mCachedRequests(0) {
|
||||
LOG(("LOADGROUP [%p]: Created.\n", this));
|
||||
|
@ -465,10 +466,13 @@ nsLoadGroup::AddRequest(nsIRequest* request, nsISupports* ctxt) {
|
|||
nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(request);
|
||||
if (timedChannel) timedChannel->SetTimingEnabled(true);
|
||||
|
||||
if (!(flags & nsIRequest::LOAD_BACKGROUND)) {
|
||||
bool foreground = !(flags & nsIRequest::LOAD_BACKGROUND);
|
||||
if (foreground) {
|
||||
// Update the count of foreground URIs..
|
||||
mForegroundCount += 1;
|
||||
}
|
||||
|
||||
if (foreground || mNotifyObserverAboutBackgroundRequests) {
|
||||
//
|
||||
// Fire the OnStartRequest notification out to the observer...
|
||||
//
|
||||
|
@ -495,12 +499,14 @@ nsLoadGroup::AddRequest(nsIRequest* request, nsISupports* ctxt) {
|
|||
|
||||
rv = NS_OK;
|
||||
|
||||
mForegroundCount -= 1;
|
||||
if (foreground) {
|
||||
mForegroundCount -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that we're part of our loadgroup while pending
|
||||
if (mForegroundCount == 1 && mLoadGroup) {
|
||||
if (foreground && mForegroundCount == 1 && mLoadGroup) {
|
||||
mLoadGroup->AddRequest(this, nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -601,10 +607,13 @@ nsresult nsLoadGroup::NotifyRemovalObservers(nsIRequest* request,
|
|||
nsresult rv = request->GetLoadFlags(&flags);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!(flags & nsIRequest::LOAD_BACKGROUND)) {
|
||||
bool foreground = !(flags & nsIRequest::LOAD_BACKGROUND);
|
||||
if (foreground) {
|
||||
NS_ASSERTION(mForegroundCount > 0, "ForegroundCount messed up");
|
||||
mForegroundCount -= 1;
|
||||
}
|
||||
|
||||
if (foreground || mNotifyObserverAboutBackgroundRequests) {
|
||||
// Fire the OnStopRequest out to the observer...
|
||||
nsCOMPtr<nsIRequestObserver> observer = do_QueryReferent(mObserver);
|
||||
if (observer) {
|
||||
|
@ -622,7 +631,7 @@ nsresult nsLoadGroup::NotifyRemovalObservers(nsIRequest* request,
|
|||
}
|
||||
|
||||
// If that was the last request -> remove ourselves from loadgroup
|
||||
if (mForegroundCount == 0 && mLoadGroup) {
|
||||
if (foreground && mForegroundCount == 0 && mLoadGroup) {
|
||||
mLoadGroup->RemoveRequest(this, nullptr, aStatus);
|
||||
}
|
||||
}
|
||||
|
@ -645,10 +654,16 @@ nsLoadGroup::GetRequests(nsISimpleEnumerator** aRequests) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::SetGroupObserver(nsIRequestObserver* aObserver) {
|
||||
mObserver = do_GetWeakReference(aObserver);
|
||||
SetGroupObserver(aObserver, false);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsLoadGroup::SetGroupObserver(nsIRequestObserver* aObserver,
|
||||
bool aIncludeBackgroundRequests) {
|
||||
mObserver = do_GetWeakReference(aObserver);
|
||||
mNotifyObserverAboutBackgroundRequests = aIncludeBackgroundRequests;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::GetGroupObserver(nsIRequestObserver** aResult) {
|
||||
nsCOMPtr<nsIRequestObserver> observer = do_QueryReferent(mObserver);
|
||||
|
|
|
@ -58,6 +58,9 @@ class nsLoadGroup : public nsILoadGroup,
|
|||
nsresult Init();
|
||||
nsresult InitWithRequestContextId(const uint64_t& aRequestContextId);
|
||||
|
||||
void SetGroupObserver(nsIRequestObserver* aObserver,
|
||||
bool aIncludeBackgroundRequests);
|
||||
|
||||
protected:
|
||||
virtual ~nsLoadGroup();
|
||||
|
||||
|
@ -94,6 +97,7 @@ class nsLoadGroup : public nsILoadGroup,
|
|||
bool mDefaultLoadIsTimed;
|
||||
bool mBrowsingContextDiscarded;
|
||||
bool mExternalRequestContext;
|
||||
bool mNotifyObserverAboutBackgroundRequests;
|
||||
|
||||
/* Telemetry */
|
||||
mozilla::TimeStamp mDefaultRequestCreationTime;
|
||||
|
|
|
@ -103,7 +103,7 @@ class nsDefaultComparator<nsDocLoader::nsListenerInfo,
|
|||
PLDHashTable::MoveEntryStub, nsDocLoader::RequestInfoHashClearEntry,
|
||||
nsDocLoader::RequestInfoHashInitEntry};
|
||||
|
||||
nsDocLoader::nsDocLoader()
|
||||
nsDocLoader::nsDocLoader(bool aNotifyAboutBackgroundRequests)
|
||||
: mParent(nullptr),
|
||||
mProgressStateFlags(0),
|
||||
mCurrentSelfProgress(0),
|
||||
|
@ -119,7 +119,8 @@ nsDocLoader::nsDocLoader()
|
|||
mTreatAsBackgroundLoad(false),
|
||||
mHasFakeOnLoadDispatched(false),
|
||||
mIsReadyToHandlePostMessage(false),
|
||||
mDocumentOpenedButNotLoaded(false) {
|
||||
mDocumentOpenedButNotLoaded(false),
|
||||
mNotifyAboutBackgroundRequests(aNotifyAboutBackgroundRequests) {
|
||||
ClearInternalProgress();
|
||||
|
||||
MOZ_LOG(gDocLoaderLog, LogLevel::Debug, ("DocLoader:%p: created.\n", this));
|
||||
|
@ -131,9 +132,14 @@ nsresult nsDocLoader::SetDocLoaderParent(nsDocLoader* aParent) {
|
|||
}
|
||||
|
||||
nsresult nsDocLoader::Init() {
|
||||
nsresult rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), this);
|
||||
RefPtr<net::nsLoadGroup> loadGroup = new net::nsLoadGroup();
|
||||
nsresult rv = loadGroup->Init();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
loadGroup->SetGroupObserver(this, mNotifyAboutBackgroundRequests);
|
||||
|
||||
mLoadGroup = loadGroup;
|
||||
|
||||
MOZ_LOG(gDocLoaderLog, LogLevel::Debug,
|
||||
("DocLoader:%p: load group %p.\n", this, mLoadGroup.get()));
|
||||
|
||||
|
@ -150,8 +156,7 @@ nsresult nsDocLoader::InitWithBrowsingContext(
|
|||
aBrowsingContext->GetRequestContextId());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = loadGroup->SetGroupObserver(this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
loadGroup->SetGroupObserver(this, mNotifyAboutBackgroundRequests);
|
||||
|
||||
mLoadGroup = loadGroup;
|
||||
|
||||
|
@ -404,6 +409,14 @@ NS_IMETHODIMP
|
|||
nsDocLoader::OnStartRequest(nsIRequest* request) {
|
||||
// called each time a request is added to the group.
|
||||
|
||||
// Some docloaders deal with background requests in their OnStartRequest
|
||||
// override, but here we don't want to do anything with them, so return early.
|
||||
nsLoadFlags loadFlags = 0;
|
||||
request->GetLoadFlags(&loadFlags);
|
||||
if (loadFlags & nsIRequest::LOAD_BACKGROUND) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (MOZ_LOG_TEST(gDocLoaderLog, LogLevel::Debug)) {
|
||||
nsAutoCString name;
|
||||
request->GetName(name);
|
||||
|
@ -420,9 +433,6 @@ nsDocLoader::OnStartRequest(nsIRequest* request) {
|
|||
|
||||
bool justStartedLoading = false;
|
||||
|
||||
nsLoadFlags loadFlags = 0;
|
||||
request->GetLoadFlags(&loadFlags);
|
||||
|
||||
if (!mIsLoadingDocument && (loadFlags & nsIChannel::LOAD_DOCUMENT_URI)) {
|
||||
justStartedLoading = true;
|
||||
mIsLoadingDocument = true;
|
||||
|
@ -496,6 +506,14 @@ nsDocLoader::OnStartRequest(nsIRequest* request) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsDocLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
|
||||
// Some docloaders deal with background requests in their OnStopRequest
|
||||
// override, but here we don't want to do anything with them, so return early.
|
||||
nsLoadFlags lf = 0;
|
||||
aRequest->GetLoadFlags(&lf);
|
||||
if (lf & nsIRequest::LOAD_BACKGROUND) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (MOZ_LOG_TEST(gDocLoaderLog, LogLevel::Debug)) {
|
||||
|
@ -575,8 +593,6 @@ nsDocLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
|
|||
//
|
||||
// Only if the load has been targeted (see bug 268483)...
|
||||
//
|
||||
uint32_t lf;
|
||||
channel->GetLoadFlags(&lf);
|
||||
if (lf & nsIChannel::LOAD_TARGETED) {
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
|
||||
if (httpChannel) {
|
||||
|
|
|
@ -59,7 +59,7 @@ class nsDocLoader : public nsIDocumentLoader,
|
|||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_DOCLOADER_IMPL_CID)
|
||||
|
||||
nsDocLoader();
|
||||
nsDocLoader() : nsDocLoader(false) {}
|
||||
|
||||
[[nodiscard]] virtual nsresult Init();
|
||||
[[nodiscard]] nsresult InitWithBrowsingContext(
|
||||
|
@ -159,6 +159,7 @@ class nsDocLoader : public nsIDocumentLoader,
|
|||
uint32_t ChildCount() const { return mChildList.Length(); }
|
||||
|
||||
protected:
|
||||
explicit nsDocLoader(bool aNotifyAboutBackgroundRequests);
|
||||
virtual ~nsDocLoader();
|
||||
|
||||
[[nodiscard]] virtual nsresult SetDocLoaderParent(nsDocLoader* aLoader);
|
||||
|
@ -363,6 +364,8 @@ class nsDocLoader : public nsIDocumentLoader,
|
|||
*/
|
||||
bool mDocumentOpenedButNotLoaded;
|
||||
|
||||
bool mNotifyAboutBackgroundRequests;
|
||||
|
||||
static const PLDHashTableOps sRequestInfoHashOps;
|
||||
|
||||
// A list of kids that are in the middle of their onload calls and will let
|
||||
|
|
Загрузка…
Ссылка в новой задаче