Bug 1548939 - Move static methods to top of BrowserParent. r=nika
authorRyan Hunt <rhunt@eqrion.net>
Mon, 29 Apr 2019 16:57:42 -0500
changeset 472886 09a84bebb63ffed84b93fcb270a9724d57539b3e
parent 472885 cd87583bb3abe9d62b442ab1200f2ccfbe4aabbb
child 472887 0214c4b7b50c1f4ab7c8f29ce83666b1fbba91a2
push id35982
push userncsoregi@mozilla.com
push dateTue, 07 May 2019 21:45:14 +0000
treeherdermozilla-central@63bc837753d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1548939
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548939 - Move static methods to top of BrowserParent. r=nika The methods in BrowserParent are a bit disorganized. There's a lot to do to fix that, but an easy first step is to move static methods to the top of the class. Differential Revision: https://phabricator.services.mozilla.com/D30155
dom/ipc/BrowserParent.cpp
dom/ipc/BrowserParent.h
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -226,24 +226,81 @@ BrowserParent::BrowserParent(ContentPare
   MOZ_ASSERT(aManager);
   // When the input event queue is disabled, we don't need to handle the case
   // that some input events are dispatched before PBrowserConstructor.
   mIsReadyToHandleInputEvents = !ContentParent::IsInputEventQueueSupported();
 }
 
 BrowserParent::~BrowserParent() {}
 
+/* static */
+void BrowserParent::InitializeStatics() {
+  MOZ_ASSERT(XRE_IsParentProcess());
+  sFocusStack = new nsTArray<BrowserParent*>();
+  ClearOnShutdown(&sFocusStack);
+}
+
+/* static */
+BrowserParent* BrowserParent::GetFocused() {
+  if (!sFocusStack) {
+    return nullptr;
+  }
+  if (sFocusStack->IsEmpty()) {
+    return nullptr;
+  }
+  return sFocusStack->LastElement();
+}
+
+/*static*/
+BrowserParent* BrowserParent::GetFrom(nsFrameLoader* aFrameLoader) {
+  if (!aFrameLoader) {
+    return nullptr;
+  }
+  PBrowserParent* remoteBrowser = aFrameLoader->GetRemoteBrowser();
+  return static_cast<BrowserParent*>(remoteBrowser);
+}
+
+/*static*/
+BrowserParent* BrowserParent::GetFrom(nsIRemoteTab* aBrowserParent) {
+  return static_cast<BrowserParent*>(aBrowserParent);
+}
+
+/*static*/
+BrowserParent* BrowserParent::GetFrom(PBrowserParent* aBrowserParent) {
+  return static_cast<BrowserParent*>(aBrowserParent);
+}
+
+/*static*/
+BrowserParent* BrowserParent::GetFrom(nsIContent* aContent) {
+  RefPtr<nsFrameLoaderOwner> loaderOwner = do_QueryObject(aContent);
+  if (!loaderOwner) {
+    return nullptr;
+  }
+  RefPtr<nsFrameLoader> frameLoader = loaderOwner->GetFrameLoader();
+  return GetFrom(frameLoader);
+}
+
+/* static */
 BrowserParent* BrowserParent::GetBrowserParentFromLayersId(
     layers::LayersId aLayersId) {
   if (!sLayerToBrowserParentTable) {
     return nullptr;
   }
   return sLayerToBrowserParentTable->Get(uint64_t(aLayersId));
 }
 
+/*static*/
+TabId BrowserParent::GetTabIdFrom(nsIDocShell* docShell) {
+  nsCOMPtr<nsIBrowserChild> browserChild(BrowserChild::GetFrom(docShell));
+  if (browserChild) {
+    return static_cast<BrowserChild*>(browserChild.get())->GetTabId();
+  }
+  return TabId(0);
+}
+
 void BrowserParent::AddBrowserParentToTable(layers::LayersId aLayersId,
                                             BrowserParent* aBrowserParent) {
   if (!sLayerToBrowserParentTable) {
     sLayerToBrowserParentTable = new LayerToBrowserParentTable();
   }
   sLayerToBrowserParentTable->Put(uint64_t(aLayersId), aBrowserParent);
 }
 
@@ -2505,34 +2562,16 @@ bool BrowserParent::SendPasteTransferabl
                                           const bool& aIsPrivateData,
                                           nsIPrincipal* aRequestingPrincipal,
                                           const uint32_t& aContentPolicyType) {
   return PBrowserParent::SendPasteTransferable(
       aDataTransfer, aIsPrivateData, aRequestingPrincipal, aContentPolicyType);
 }
 
 /* static */
-void BrowserParent::InitializeStatics() {
-  MOZ_ASSERT(XRE_IsParentProcess());
-  sFocusStack = new nsTArray<BrowserParent*>();
-  ClearOnShutdown(&sFocusStack);
-}
-
-/* static */
-BrowserParent* BrowserParent::GetFocused() {
-  if (!sFocusStack) {
-    return nullptr;
-  }
-  if (sFocusStack->IsEmpty()) {
-    return nullptr;
-  }
-  return sFocusStack->LastElement();
-}
-
-/* static */
 void BrowserParent::PushFocus(BrowserParent* aBrowserParent) {
   if (!sFocusStack) {
     MOZ_ASSERT_UNREACHABLE("PushFocus when not initialized");
     return;
   }
   if (!aBrowserParent->GetBrowserBridgeParent()) {
     // top-level Web content
     if (!sFocusStack->IsEmpty()) {
@@ -2603,54 +2642,16 @@ void BrowserParent::PopFocus(BrowserPare
   while (pos < sFocusStack->Length()) {
     BrowserParent* popped = sFocusStack->PopLastElement();
     BrowserParent* focused = GetFocused();
     LOGBROWSERFOCUS(("PopFocus changed focus to %p", focused));
     IMEStateManager::OnFocusMovedBetweenBrowsers(popped, focused);
   }
 }
 
-/*static*/
-BrowserParent* BrowserParent::GetFrom(nsFrameLoader* aFrameLoader) {
-  if (!aFrameLoader) {
-    return nullptr;
-  }
-  PBrowserParent* remoteBrowser = aFrameLoader->GetRemoteBrowser();
-  return static_cast<BrowserParent*>(remoteBrowser);
-}
-
-/*static*/
-BrowserParent* BrowserParent::GetFrom(nsIRemoteTab* aBrowserParent) {
-  return static_cast<BrowserParent*>(aBrowserParent);
-}
-
-/*static*/
-BrowserParent* BrowserParent::GetFrom(PBrowserParent* aBrowserParent) {
-  return static_cast<BrowserParent*>(aBrowserParent);
-}
-
-/*static*/
-BrowserParent* BrowserParent::GetFrom(nsIContent* aContent) {
-  RefPtr<nsFrameLoaderOwner> loaderOwner = do_QueryObject(aContent);
-  if (!loaderOwner) {
-    return nullptr;
-  }
-  RefPtr<nsFrameLoader> frameLoader = loaderOwner->GetFrameLoader();
-  return GetFrom(frameLoader);
-}
-
-/*static*/
-TabId BrowserParent::GetTabIdFrom(nsIDocShell* docShell) {
-  nsCOMPtr<nsIBrowserChild> browserChild(BrowserChild::GetFrom(docShell));
-  if (browserChild) {
-    return static_cast<BrowserChild*>(browserChild.get())->GetTabId();
-  }
-  return TabId(0);
-}
-
 RenderFrame* BrowserParent::GetRenderFrame() {
   if (!mRenderFrame.IsInitialized()) {
     return nullptr;
   }
   return &mRenderFrame;
 }
 
 BrowserBridgeParent* BrowserParent::GetBrowserBridgeParent() const {
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -111,16 +111,42 @@ class BrowserParent final : public PBrow
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowserParent, nsIRemoteTab)
 
   BrowserParent(ContentParent* aManager, const TabId& aTabId,
                 const TabContext& aContext,
                 CanonicalBrowsingContext* aBrowsingContext,
                 uint32_t aChromeFlags,
                 BrowserBridgeParent* aBrowserBridgeParent = nullptr);
 
+  // Call from LayoutStatics only
+  static void InitializeStatics();
+
+  /**
+   * Returns the focused BrowserParent or nullptr if chrome or another app
+   * is focused.
+   */
+  static BrowserParent* GetFocused();
+
+  static BrowserParent* GetFrom(nsFrameLoader* aFrameLoader);
+
+  static BrowserParent* GetFrom(nsIRemoteTab* aBrowserParent);
+
+  static BrowserParent* GetFrom(PBrowserParent* aBrowserParent);
+
+  static BrowserParent* GetFrom(nsIContent* aContent);
+
+  static BrowserParent* GetBrowserParentFromLayersId(
+      layers::LayersId aLayersId);
+
+  static TabId GetTabIdFrom(nsIDocShell* docshell);
+
+  static bool AreRecordReplayTabsActive() {
+    return gNumActiveRecordReplayTabs != 0;
+  }
+
   Element* GetOwnerElement() const { return mFrameElement; }
   already_AddRefed<nsPIDOMWindowOuter> GetParentWindowOuter();
 
   void SetOwnerElement(Element* aElement);
 
   void CacheFrameLoader(nsFrameLoader* aFrameLoader);
 
   nsIBrowserDOMWindow* GetBrowserDOMWindow() const { return mBrowserDOMWindow; }
@@ -491,35 +517,16 @@ class BrowserParent final : public PBrow
 
   bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent);
 
   bool SendPasteTransferable(const IPCDataTransfer& aDataTransfer,
                              const bool& aIsPrivateData,
                              nsIPrincipal* aRequestingPrincipal,
                              const uint32_t& aContentPolicyType);
 
-  // Call from LayoutStatics only
-  static void InitializeStatics();
-
-  /**
-   * Returns the focused BrowserParent or nullptr if chrome or another app
-   * is focused.
-   */
-  static BrowserParent* GetFocused();
-
-  static BrowserParent* GetFrom(nsFrameLoader* aFrameLoader);
-
-  static BrowserParent* GetFrom(nsIRemoteTab* aBrowserParent);
-
-  static BrowserParent* GetFrom(PBrowserParent* aBrowserParent);
-
-  static BrowserParent* GetFrom(nsIContent* aContent);
-
-  static TabId GetTabIdFrom(nsIDocShell* docshell);
-
   ContentParent* Manager() const { return mManager; }
 
   /**
    * Let managees query if Destroy() is already called so they don't send out
    * messages when the PBrowser actor is being destroyed.
    */
   bool IsDestroyed() const { return mIsDestroyed; }
 
@@ -619,20 +626,16 @@ class BrowserParent final : public PBrow
 
   // LiveResizeListener implementation
   void LiveResizeStarted() override;
   void LiveResizeStopped() override;
 
   void SetReadyToHandleInputEvents() { mIsReadyToHandleInputEvents = true; }
   bool IsReadyToHandleInputEvents() { return mIsReadyToHandleInputEvents; }
 
-  static bool AreRecordReplayTabsActive() {
-    return gNumActiveRecordReplayTabs != 0;
-  }
-
   void NavigateByKey(bool aForward, bool aForDocumentNavigation);
 
   ShowInfo GetShowInfo();
 
  protected:
   bool ReceiveMessage(
       const nsString& aMessage, bool aSync, ipc::StructuredCloneData* aData,
       mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
@@ -859,20 +862,16 @@ class BrowserParent final : public PBrow
   // How many record/replay tabs have active docshells in this process.
   static size_t gNumActiveRecordReplayTabs;
 
   // Whether this tab is contributing to gNumActiveRecordReplayTabs.
   bool mIsActiveRecordReplayTab;
 
   // Update whether this is an active record/replay tab.
   void SetIsActiveRecordReplayTab(bool aIsActive);
-
- public:
-  static BrowserParent* GetBrowserParentFromLayersId(
-      layers::LayersId aLayersId);
 };
 
 struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {
  public:
   AutoUseNewTab(BrowserParent* aNewTab, nsCString* aURLToLoad)
       : mNewTab(aNewTab), mURLToLoad(aURLToLoad) {
     MOZ_ASSERT(!aNewTab->mCreatingWindow);