From 9adecce6d4fab19f4f3783acf0762a36f5696f19 Mon Sep 17 00:00:00 2001 From: Bogdan Tara Date: Tue, 24 Sep 2019 21:56:18 +0300 Subject: [PATCH] Backed out changeset ac6d8297cdc4 (bug 1581925) for test_bug89419.xul & test_MozDomFullscreen_event.xul failures CLOSED TREE --- .../InProcessBrowserChildMessageManager.cpp | 23 ----------- .../InProcessBrowserChildMessageManager.h | 9 ++++- dom/base/nsWindowRoot.cpp | 10 ++--- dom/chrome-webidl/JSWindowActor.webidl | 2 - dom/ipc/JSWindowActorService.cpp | 40 +++++++++---------- dom/ipc/JSWindowActorService.h | 12 +++--- 6 files changed, 38 insertions(+), 58 deletions(-) diff --git a/dom/base/InProcessBrowserChildMessageManager.cpp b/dom/base/InProcessBrowserChildMessageManager.cpp index e12d33351be6..0216a1d7dc6a 100644 --- a/dom/base/InProcessBrowserChildMessageManager.cpp +++ b/dom/base/InProcessBrowserChildMessageManager.cpp @@ -23,30 +23,11 @@ #include "mozilla/dom/SameProcessMessageQueue.h" #include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/WindowProxyHolder.h" -#include "mozilla/dom/JSWindowActorService.h" using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::dom::ipc; -/* static */ -already_AddRefed -InProcessBrowserChildMessageManager::Create(nsDocShell* aShell, - nsIContent* aOwner, - nsFrameMessageManager* aChrome) { - RefPtr mm = - new InProcessBrowserChildMessageManager(aShell, aOwner, aChrome); - - NS_ENSURE_TRUE(mm->Init(), nullptr); - - if (XRE_IsParentProcess()) { - RefPtr wasvc = JSWindowActorService::GetSingleton(); - wasvc->RegisterChromeEventTarget(mm); - } - - return mm.forget(); -} - bool InProcessBrowserChildMessageManager::DoSendBlockingMessage( JSContext* aCx, const nsAString& aMessage, StructuredCloneData& aData, JS::Handle aCpows, nsIPrincipal* aPrincipal, @@ -120,10 +101,6 @@ InProcessBrowserChildMessageManager::InProcessBrowserChildMessageManager( } InProcessBrowserChildMessageManager::~InProcessBrowserChildMessageManager() { - if (XRE_IsParentProcess()) { - JSWindowActorService::UnregisterChromeEventTarget(this); - } - mAnonymousGlobalScopes.Clear(); mozilla::DropJSObjects(this); } diff --git a/dom/base/InProcessBrowserChildMessageManager.h b/dom/base/InProcessBrowserChildMessageManager.h index 9711504be8f2..96938d5d2b1c 100644 --- a/dom/base/InProcessBrowserChildMessageManager.h +++ b/dom/base/InProcessBrowserChildMessageManager.h @@ -47,7 +47,14 @@ class InProcessBrowserChildMessageManager final public: static already_AddRefed Create( - nsDocShell* aShell, nsIContent* aOwner, nsFrameMessageManager* aChrome); + nsDocShell* aShell, nsIContent* aOwner, nsFrameMessageManager* aChrome) { + RefPtr mm = + new InProcessBrowserChildMessageManager(aShell, aOwner, aChrome); + + NS_ENSURE_TRUE(mm->Init(), nullptr); + + return mm.forget(); + } NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED( diff --git a/dom/base/nsWindowRoot.cpp b/dom/base/nsWindowRoot.cpp index 55d6a5c0040f..832fb2916365 100644 --- a/dom/base/nsWindowRoot.cpp +++ b/dom/base/nsWindowRoot.cpp @@ -44,9 +44,7 @@ nsWindowRoot::~nsWindowRoot() { mListenerManager->Disconnect(); } - if (XRE_IsContentProcess()) { - JSWindowActorService::UnregisterChromeEventTarget(this); - } + JSWindowActorService::UnregisterWindowRoot(this); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsWindowRoot, mWindow, mListenerManager, @@ -322,9 +320,9 @@ void nsWindowRoot::EnumerateBrowsers(BrowserEnumerator aEnumFunc, void* aArg) { already_AddRefed NS_NewWindowRoot(nsPIDOMWindowOuter* aWindow) { nsCOMPtr result = new nsWindowRoot(aWindow); - if (XRE_IsContentProcess()) { - RefPtr wasvc = JSWindowActorService::GetSingleton(); - wasvc->RegisterChromeEventTarget(result); + RefPtr wasvc = JSWindowActorService::GetSingleton(); + if (wasvc) { + wasvc->RegisterWindowRoot(result); } return result.forget(); diff --git a/dom/chrome-webidl/JSWindowActor.webidl b/dom/chrome-webidl/JSWindowActor.webidl index a06ab3d4609b..860a31b9e723 100644 --- a/dom/chrome-webidl/JSWindowActor.webidl +++ b/dom/chrome-webidl/JSWindowActor.webidl @@ -155,8 +155,6 @@ dictionary WindowActorChildOptions : WindowActorSidedOptions { * Events which this actor wants to be listening to. When these events fire, * it will trigger actor creation, and then forward the event to the actor. * - * NOTE: Listeners are not attached for windows loaded in chrome docshells. - * * NOTE: `once` option is not support due to we register listeners in a shared * location. */ diff --git a/dom/ipc/JSWindowActorService.cpp b/dom/ipc/JSWindowActorService.cpp index ecedb92cf3cb..7114d8e34875 100644 --- a/dom/ipc/JSWindowActorService.cpp +++ b/dom/ipc/JSWindowActorService.cpp @@ -243,8 +243,8 @@ NS_IMETHODIMP JSWindowActorProtocol::Observe(nsISupports* aSubject, return NS_OK; } -void JSWindowActorProtocol::RegisterListenersFor(EventTarget* aTarget) { - EventListenerManager* elm = aTarget->GetOrCreateListenerManager(); +void JSWindowActorProtocol::RegisterListenersFor(EventTarget* aRoot) { + EventListenerManager* elm = aRoot->GetOrCreateListenerManager(); for (auto& event : mChild.mEvents) { elm->AddEventListenerByType(EventListenerHolder(this), event.mName, @@ -252,8 +252,8 @@ void JSWindowActorProtocol::RegisterListenersFor(EventTarget* aTarget) { } } -void JSWindowActorProtocol::UnregisterListenersFor(EventTarget* aTarget) { - EventListenerManager* elm = aTarget->GetOrCreateListenerManager(); +void JSWindowActorProtocol::UnregisterListenersFor(EventTarget* aRoot) { + EventListenerManager* elm = aRoot->GetOrCreateListenerManager(); for (auto& event : mChild.mEvents) { elm->RemoveEventListenerByType(EventListenerHolder(this), event.mName, @@ -388,9 +388,9 @@ void JSWindowActorService::RegisterWindowActor( Unused << cp->SendInitJSWindowActorInfos(ipcInfos); } - // Register event listeners for any existing chrome targets. - for (EventTarget* target : mChromeEventTargets) { - proto->RegisterListenersFor(target); + // Register event listeners for any existing window roots. + for (EventTarget* root : mRoots) { + proto->RegisterListenersFor(root); } // Add observers to the protocol. @@ -410,9 +410,9 @@ void JSWindowActorService::UnregisterWindowActor(const nsAString& aName) { } } - // Remove listeners for this actor from each of our chrome targets. - for (EventTarget* target : mChromeEventTargets) { - proto->UnregisterListenersFor(target); + // Remove listeners for this actor from each of our window roots. + for (EventTarget* root : mRoots) { + proto->UnregisterListenersFor(root); } // Remove observers for this actor from observer serivce. @@ -431,9 +431,9 @@ void JSWindowActorService::LoadJSWindowActorInfos( JSWindowActorProtocol::FromIPC(aInfos[i]); mDescriptors.Put(aInfos[i].name(), proto); - // Register listeners for each chrome target. - for (EventTarget* target : mChromeEventTargets) { - proto->RegisterListenersFor(target); + // Register listeners for each window root. + for (EventTarget* root : mRoots) { + proto->RegisterListenersFor(root); } // Add observers for each actor. @@ -451,21 +451,21 @@ void JSWindowActorService::GetJSWindowActorInfos( } } -void JSWindowActorService::RegisterChromeEventTarget(EventTarget* aTarget) { - MOZ_ASSERT(!mChromeEventTargets.Contains(aTarget)); - mChromeEventTargets.AppendElement(aTarget); +void JSWindowActorService::RegisterWindowRoot(EventTarget* aRoot) { + MOZ_ASSERT(!mRoots.Contains(aRoot)); + mRoots.AppendElement(aRoot); // Register event listeners on the newly added Window Root. for (auto iter = mDescriptors.Iter(); !iter.Done(); iter.Next()) { - iter.Data()->RegisterListenersFor(aTarget); + iter.Data()->RegisterListenersFor(aRoot); } } /* static */ -void JSWindowActorService::UnregisterChromeEventTarget(EventTarget* aTarget) { +void JSWindowActorService::UnregisterWindowRoot(EventTarget* aRoot) { if (gJSWindowActorService) { - // NOTE: No need to unregister listeners here, as the target is going away. - gJSWindowActorService->mChromeEventTargets.RemoveElement(aTarget); + // NOTE: No need to unregister listeners here, as the root is going away. + gJSWindowActorService->mRoots.RemoveElement(aRoot); } } diff --git a/dom/ipc/JSWindowActorService.h b/dom/ipc/JSWindowActorService.h index 09b13b19fe92..b2487303291a 100644 --- a/dom/ipc/JSWindowActorService.h +++ b/dom/ipc/JSWindowActorService.h @@ -70,8 +70,8 @@ class JSWindowActorProtocol final : public nsIObserver, const ParentSide& Parent() const { return mParent; } const ChildSide& Child() const { return mChild; } - void RegisterListenersFor(EventTarget* aTarget); - void UnregisterListenersFor(EventTarget* aTarget); + void RegisterListenersFor(EventTarget* aRoot); + void UnregisterListenersFor(EventTarget* aRoot); void AddObservers(); void RemoveObservers(); bool Matches(BrowsingContext* aBrowsingContext, nsIURI* aURI, @@ -114,11 +114,11 @@ class JSWindowActorService final { // from mDescriptors to JSWindowActorInfos. void GetJSWindowActorInfos(nsTArray& aInfos); - // Register or unregister a chrome event target. - void RegisterChromeEventTarget(EventTarget* aTarget); + // Register or unregister a WindowRoot object from this JSWindowActorService. + void RegisterWindowRoot(EventTarget* aRoot); // NOTE: This method is static, as it may be called during shutdown. - static void UnregisterChromeEventTarget(EventTarget* aTarget); + static void UnregisterWindowRoot(EventTarget* aRoot); already_AddRefed GetProtocol(const nsAString& aName); @@ -126,7 +126,7 @@ class JSWindowActorService final { JSWindowActorService(); ~JSWindowActorService(); - nsTArray mChromeEventTargets; + nsTArray mRoots; nsRefPtrHashtable mDescriptors; };