Bug 416771 - Use RefPtr<Element> rather than nsCOMPtr in BrowserParent. r=NeilDeakin draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 17 May 2019 17:02:58 +0200
changeset 2008479 7e228ad30ff1cad8ec683353ed687893a12dab9c
parent 2008478 211bde66fecc8c3a1c78dfbcede078383ca8b0f8
child 2008480 d0119439a8505e9d3016cc41ff3ed0a9d08e3b2c
push id363917
push useremilio@crisal.io
push dateSat, 18 May 2019 06:31:42 +0000
treeherdertry@46e3df2f90da [default view] [failures only]
reviewersNeilDeakin
bugs416771
milestone68.0a1
Bug 416771 - Use RefPtr<Element> rather than nsCOMPtr in BrowserParent. r=NeilDeakin Differential Revision: https://phabricator.services.mozilla.com/D31642
dom/ipc/BrowserParent.cpp
dom/ipc/BrowserParent.h
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -355,20 +355,18 @@ already_AddRefed<nsPIDOMWindowOuter> Bro
   if (!parent || parent->Closed()) {
     return nullptr;
   }
 
   return parent.forget();
 }
 
 already_AddRefed<nsIWidget> BrowserParent::GetTopLevelWidget() {
-  nsCOMPtr<nsIContent> content = mFrameElement;
-  if (content) {
-    PresShell* presShell = content->OwnerDoc()->GetPresShell();
-    if (presShell) {
+  if (RefPtr<Element> element = mFrameElement) {
+    if (PresShell* presShell = element->OwnerDoc()->GetPresShell()) {
       nsViewManager* vm = presShell->GetViewManager();
       nsCOMPtr<nsIWidget> widget;
       vm->GetRootWidget(getter_AddRefs(widget));
       return widget.forget();
     }
   }
   return nullptr;
 }
@@ -829,17 +827,17 @@ mozilla::ipc::IPCResult BrowserParent::R
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult BrowserParent::RecvEvent(const RemoteDOMEvent& aEvent) {
   RefPtr<Event> event = aEvent.mEvent;
   NS_ENSURE_TRUE(event, IPC_OK());
 
-  nsCOMPtr<mozilla::dom::EventTarget> target = mFrameElement;
+  RefPtr<EventTarget> target = mFrameElement;
   NS_ENSURE_TRUE(target, IPC_OK());
 
   event->SetOwner(target);
 
   target->DispatchEvent(*event);
   return IPC_OK();
 }
 
@@ -2136,17 +2134,17 @@ mozilla::ipc::IPCResult BrowserParent::R
 
   if (!mFrameElement) {
     return IPC_OK();
   }
 
   uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
   if (aCanRaise) flags |= nsIFocusManager::FLAG_RAISE;
 
-  nsCOMPtr<Element> element = mFrameElement;
+  RefPtr<Element> element = mFrameElement;
   fm->SetFocus(element, flags);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult BrowserParent::RecvEnableDisableCommands(
     const nsString& aAction, nsTArray<nsCString>&& aEnabledCommands,
     nsTArray<nsCString>&& aDisabledCommands) {
   nsCOMPtr<nsIBrowser> browser =
@@ -2841,17 +2839,17 @@ BrowserParent::GetAuthPrompt(uint32_t aP
                              void** aResult) {
   // we're either allowing auth, or it's a proxy request
   nsresult rv;
   nsCOMPtr<nsIPromptFactory> wwatch =
       do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsPIDOMWindowOuter> window;
-  nsCOMPtr<nsIContent> frame = mFrameElement;
+  RefPtr<Element> frame = mFrameElement;
   if (frame) window = frame->OwnerDoc()->GetWindow();
 
   // Get an auth prompter for our window so that the parenting
   // of the dialogs works as it should when using tabs.
   nsCOMPtr<nsISupports> prompt;
   rv = wwatch->GetPrompt(window, iid, getter_AddRefs(prompt));
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -2879,17 +2877,17 @@ already_AddRefed<nsFrameLoader> BrowserP
   if (mIsDestroyed && !aUseCachedFrameLoaderAfterDestroy) {
     return nullptr;
   }
 
   if (mFrameLoader) {
     RefPtr<nsFrameLoader> fl = mFrameLoader;
     return fl.forget();
   }
-  nsCOMPtr<Element> frameElement(mFrameElement);
+  RefPtr<Element> frameElement(mFrameElement);
   RefPtr<nsFrameLoaderOwner> frameLoaderOwner = do_QueryObject(frameElement);
   return frameLoaderOwner ? frameLoaderOwner->GetFrameLoader() : nullptr;
 }
 
 void BrowserParent::TryCacheDPIAndScale() {
   if (mDPI > 0) {
     return;
   }
@@ -3255,17 +3253,17 @@ void BrowserParent::LayerTreeUpdate(cons
                                     bool aActive) {
   // Ignore updates from old epochs. They might tell us that layers are
   // available when we've already sent a message to clear them. We can't trust
   // the update in that case since layers could disappear anytime after that.
   if (aEpoch != mLayerTreeEpoch || mIsDestroyed) {
     return;
   }
 
-  nsCOMPtr<mozilla::dom::EventTarget> target = mFrameElement;
+  RefPtr<EventTarget> target = mFrameElement;
   if (!target) {
     NS_WARNING("Could not locate target for layer tree message.");
     return;
   }
 
   mHasLayers = aActive;
 
   RefPtr<Event> event = NS_NewDOMEvent(mFrameElement, nullptr, nullptr);
@@ -3318,17 +3316,17 @@ mozilla::ipc::IPCResult BrowserParent::R
   // We sent a PaintWhileInterruptingJS message when layers were already
   // visible. In this case, we should act as if an update occurred even though
   // we already have the layers.
   LayerTreeUpdate(aEpoch, true);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult BrowserParent::RecvRemotePaintIsReady() {
-  nsCOMPtr<mozilla::dom::EventTarget> target = mFrameElement;
+  RefPtr<EventTarget> target = mFrameElement;
   if (!target) {
     NS_WARNING("Could not locate target for MozAfterRemotePaint message.");
     return IPC_OK();
   }
 
   RefPtr<Event> event = NS_NewDOMEvent(mFrameElement, nullptr, nullptr);
   event->InitEvent(NS_LITERAL_STRING("MozAfterRemotePaint"), false, false);
   event->SetTrusted(true);
@@ -3476,17 +3474,17 @@ class FakeChannel final : public nsIChan
                              nsIAuthInformation* aAuthInfo) override;
   NS_IMETHOD OnAuthCancelled(nsISupports* aContext, bool userCancel) override;
   NS_IMETHOD GetInterface(const nsIID& uuid, void** result) override {
     return QueryInterface(uuid, result);
   }
   NS_IMETHOD GetAssociatedWindow(mozIDOMWindowProxy**) NO_IMPL;
   NS_IMETHOD GetTopWindow(mozIDOMWindowProxy**) NO_IMPL;
   NS_IMETHOD GetTopFrameElement(Element** aElement) override {
-    nsCOMPtr<Element> elem = mElement;
+    RefPtr<Element> elem = mElement;
     elem.forget(aElement);
     return NS_OK;
   }
   NS_IMETHOD GetNestedFrameId(uint64_t*) NO_IMPL;
   NS_IMETHOD GetIsContent(bool*) NO_IMPL;
   NS_IMETHOD GetUsePrivateBrowsing(bool*) NO_IMPL;
   NS_IMETHOD SetUsePrivateBrowsing(bool) NO_IMPL;
   NS_IMETHOD SetPrivateBrowsing(bool) NO_IMPL;
@@ -3503,17 +3501,17 @@ class FakeChannel final : public nsIChan
   NS_IMETHOD SetUseTrackingProtection(bool) NO_IMPL;
 #undef NO_IMPL
 
  protected:
   ~FakeChannel() {}
 
   nsCOMPtr<nsIURI> mUri;
   uint64_t mCallbackId;
-  nsCOMPtr<Element> mElement;
+  RefPtr<Element> mElement;
   nsCOMPtr<nsILoadInfo> mLoadInfo;
 };
 
 NS_IMPL_ISUPPORTS(FakeChannel, nsIChannel, nsIAuthPromptCallback, nsIRequest,
                   nsIInterfaceRequestor, nsILoadContext);
 
 mozilla::ipc::IPCResult BrowserParent::RecvAsyncAuthPrompt(
     const nsCString& aUri, const nsString& aRealm,
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -773,17 +773,17 @@ class BrowserParent final : public PBrow
   static void PopFocus(BrowserParent* aBrowserParent);
 
   TabId mTabId;
 
   RefPtr<ContentParent> mManager;
   // The root browsing context loaded in this BrowserParent.
   RefPtr<CanonicalBrowsingContext> mBrowsingContext;
   nsCOMPtr<nsILoadContext> mLoadContext;
-  nsCOMPtr<Element> mFrameElement;
+  RefPtr<Element> mFrameElement;
   nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
   // We keep a strong reference to the frameloader after we've sent the
   // Destroy message and before we've received __delete__. This allows us to
   // dispatch message manager messages during this time.
   RefPtr<nsFrameLoader> mFrameLoader;
   uint32_t mChromeFlags;
 
   // Pointer back to BrowserBridgeParent if there is one associated with