Bug 1549753 - Add Visit methods for visiting the tree of BrowserParent and BrowserBridgeParent. r=afarre
authorRyan Hunt <rhunt@eqrion.net>
Tue, 07 May 2019 11:08:22 -0500
changeset 532047 935abf72cddc101831a8f4dc314d1ad94a68c3c9
parent 532046 53e37cfca31e24fd6d35d65b33018336126eacc2
child 532048 5c8c16e22ba1904a8574901a1aa46406b65d4a80
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersafarre
bugs1549753
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 1549753 - Add Visit methods for visiting the tree of BrowserParent and BrowserBridgeParent. r=afarre Differential Revision: https://phabricator.services.mozilla.com/D30215
dom/ipc/BrowserParent.h
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -6,16 +6,17 @@
 
 #ifndef mozilla_dom_BrowserParent_h
 #define mozilla_dom_BrowserParent_h
 
 #include "js/TypeDecls.h"
 #include "LiveResizeListener.h"
 #include "mozilla/ContentCache.h"
 #include "mozilla/dom/ipc/IdType.h"
+#include "mozilla/dom/BrowserBridgeParent.h"
 #include "mozilla/dom/PBrowserParent.h"
 #include "mozilla/dom/PContent.h"
 #include "mozilla/dom/PFilePickerParent.h"
 #include "mozilla/dom/TabContext.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/gfx/CrossProcessPaint.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
@@ -67,17 +68,16 @@ class DataSourceSurface;
 
 namespace dom {
 
 class CanonicalBrowsingContext;
 class ClonedMessageData;
 class ContentParent;
 class Element;
 class DataTransfer;
-class BrowserBridgeParent;
 
 namespace ipc {
 class StructuredCloneData;
 }  // namespace ipc
 
 /**
  * BrowserParent implements the parent actor part of the PBrowser protocol. See
  * PBrowser for more information.
@@ -182,16 +182,56 @@ class BrowserParent final : public PBrow
   ShowInfo GetShowInfo();
 
   /**
    * 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; }
 
+  /*
+   * Visit each BrowserParent in the tree formed by PBrowser and
+   * PBrowserBridge, including `this`.
+   */
+  template <typename Callback>
+  void VisitAll(Callback aCallback) {
+    aCallback(this);
+    VisitAllDescendants(aCallback);
+  }
+
+  /*
+   * Visit each BrowserParent in the tree formed by PBrowser and
+   * PBrowserBridge, excluding `this`.
+   */
+  template <typename Callback>
+  void VisitAllDescendants(Callback aCallback) {
+    const auto& browserBridges = ManagedPBrowserBridgeParent();
+    for (auto iter = browserBridges.ConstIter(); !iter.Done(); iter.Next()) {
+      BrowserBridgeParent* browserBridge =
+          static_cast<BrowserBridgeParent*>(iter.Get()->GetKey());
+      BrowserParent* browserParent = browserBridge->GetBrowserParent();
+
+      aCallback(browserParent);
+      browserParent->VisitAllDescendants(aCallback);
+    }
+  }
+
+  /*
+   * Visit each BrowserBridgeParent that is a child of this BrowserParent.
+   */
+  template <typename Callback>
+  void VisitChildren(Callback aCallback) {
+    const auto& browserBridges = ManagedPBrowserBridgeParent();
+    for (auto iter = browserBridges.ConstIter(); !iter.Done(); iter.Next()) {
+      BrowserBridgeParent* browserBridge =
+          static_cast<BrowserBridgeParent*>(iter.Get()->GetKey());
+      aCallback(browserBridge);
+    }
+  }
+
   void SetOwnerElement(Element* aElement);
 
   void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) {
     mBrowserDOMWindow = aBrowserDOMWindow;
   }
 
   void SetHasContentOpener(bool aHasContentOpener);