From 97ee1a3fa1405ad4c11b69d6c477ba60cda23122 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 30 Mar 2021 21:52:25 +0000 Subject: [PATCH] Bug 1594921: Don't send top-level location change events early in BrowserChild lifetime. r=nika Doing so results in unexpected load events for the initial about:blank document, which the frame script implementation did not see. Differential Revision: https://phabricator.services.mozilla.com/D110173 --- dom/ipc/BrowserChild.h | 4 ++++ .../webrequest/WebNavigationContent.cpp | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dom/ipc/BrowserChild.h b/dom/ipc/BrowserChild.h index 582c7e4e30d3..c4d29dacdd9d 100644 --- a/dom/ipc/BrowserChild.h +++ b/dom/ipc/BrowserChild.h @@ -242,6 +242,10 @@ class BrowserChild final : public nsMessageManagerScriptExecutor, bool IsTopLevel() const { return mIsTopLevel; } + bool ShouldSendWebProgressEventsToParent() const { + return mShouldSendWebProgressEventsToParent; + } + /** * MessageManagerCallback methods that we override. */ diff --git a/toolkit/components/extensions/webrequest/WebNavigationContent.cpp b/toolkit/components/extensions/webrequest/WebNavigationContent.cpp index 262740e2526f..4c1dfc9d6364 100644 --- a/toolkit/components/extensions/webrequest/WebNavigationContent.cpp +++ b/toolkit/components/extensions/webrequest/WebNavigationContent.cpp @@ -7,6 +7,7 @@ #include "mozilla/Assertions.h" #include "mozilla/ClearOnShutdown.h" +#include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/ContentFrameMessageManager.h" #include "mozilla/dom/Document.h" @@ -269,11 +270,19 @@ WebNavigationContent::OnLocationChange(nsIWebProgress* aWebProgress, isHistoryStateUpdated, isReferenceFragmentUpdated); } } else if (bc->IsTop()) { - // We have to catch the document changes from top level frames here, - // where we can detect the "server redirect" transition. - // (bug 1264936 and bug 125662) - ExtensionsChild::Get().SendDocumentChange( - bc, GetFrameTransitionData(aWebProgress, aRequest), aLocation); + MOZ_ASSERT(bc->IsInProcess()); + if (RefPtr browserChild = dom::BrowserChild::GetFrom(bc->GetDocShell())) { + // Only send progress events which happen after we've started loading + // things into the BrowserChild. This matches the behavior of the remote + // WebProgress implementation. + if (browserChild->ShouldSendWebProgressEventsToParent()) { + // We have to catch the document changes from top level frames here, + // where we can detect the "server redirect" transition. + // (bug 1264936 and bug 125662) + ExtensionsChild::Get().SendDocumentChange( + bc, GetFrameTransitionData(aWebProgress, aRequest), aLocation); + } + } } return NS_OK;