Bug 1696175 - Call DisconnectChildListeners at a later time for BFCache in the parent. r=necko-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D112981
This commit is contained in:
Peter Van der Beken
2021-05-13 15:38:01 +00:00
parent 1a70439a68
commit 9c19c5e1dc
5 changed files with 60 additions and 14 deletions

View File

@@ -88,6 +88,7 @@
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/net/DocumentChannel.h"
#include "mozilla/net/DocumentChannelChild.h"
#include "mozilla/net/ParentChannelWrapper.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
#include "ReferrerInfo.h"
@@ -383,6 +384,7 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mFailedLoadType(0),
mJSRunToCompletionDepth(0),
mMetaViewportOverride(nsIDocShell::META_VIEWPORT_OVERRIDE_NONE),
mChannelToDisconnectOnPageHide(0),
mCreatingDocument(false),
#ifdef DEBUG
mInEnsureScriptEnv(false),
@@ -4369,6 +4371,11 @@ nsDocShell::Stop(uint32_t aStopFlags) {
// just call Stop() on us as an nsIDocumentLoader... We need fewer
// redundant apis!
Stop();
// Clear out mChannelToDisconnectOnPageHide. This page won't go in the
// BFCache now, and the Stop above will have removed the DocumentChannel
// from the loadgroup.
mChannelToDisconnectOnPageHide = 0;
}
for (auto* child : mChildList.ForwardRange()) {
@@ -13625,3 +13632,20 @@ nsDocShell::OnStopRequest(nsIRequest* aRequest, nsresult aStatusCode) {
RecordSingleChannelId();
return nsDocLoader::OnStopRequest(aRequest, aStatusCode);
}
void nsDocShell::MaybeDisconnectChildListenersOnPageHide() {
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
if (mChannelToDisconnectOnPageHide != 0 && mLoadGroup) {
nsCOMPtr<nsISimpleEnumerator> requests;
mLoadGroup->GetRequests(getter_AddRefs(requests));
for (const auto& request : SimpleEnumerator<nsIRequest>(requests)) {
RefPtr<DocumentChannel> channel = do_QueryObject(request);
if (channel && channel->ChannelId() == mChannelToDisconnectOnPageHide) {
static_cast<DocumentChannelChild*>(channel.get())
->DisconnectChildListeners(NS_BINDING_ABORTED, NS_BINDING_ABORTED);
}
}
mChannelToDisconnectOnPageHide = 0;
}
}