From 7df4ba7bbfd9276d92598588ce3cdf1a498c648e Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Tue, 7 May 2019 11:08:22 -0500 Subject: [PATCH] Bug 1549753 - Add Visit methods for visiting the tree of BrowserParent and BrowserBridgeParent. r=afarre Differential Revision: https://phabricator.services.mozilla.com/D30215 --HG-- extra : rebase_source : f885c62dc8a24974d67b2c65e19ab42576e8640e extra : histedit_source : f884a8ed29c99bd0e71f78d6adaf61a9f19ce21e --- dom/ipc/BrowserParent.h | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/dom/ipc/BrowserParent.h b/dom/ipc/BrowserParent.h index 7ab61e54bdce..f42c1b512c78 100644 --- a/dom/ipc/BrowserParent.h +++ b/dom/ipc/BrowserParent.h @@ -11,6 +11,7 @@ #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" @@ -72,7 +73,6 @@ class ClonedMessageData; class ContentParent; class Element; class DataTransfer; -class BrowserBridgeParent; namespace ipc { class StructuredCloneData; @@ -187,6 +187,46 @@ class BrowserParent final : public PBrowserParent, */ bool IsDestroyed() const { return mIsDestroyed; } + /* + * Visit each BrowserParent in the tree formed by PBrowser and + * PBrowserBridge, including `this`. + */ + template + void VisitAll(Callback aCallback) { + aCallback(this); + VisitAllDescendants(aCallback); + } + + /* + * Visit each BrowserParent in the tree formed by PBrowser and + * PBrowserBridge, excluding `this`. + */ + template + void VisitAllDescendants(Callback aCallback) { + const auto& browserBridges = ManagedPBrowserBridgeParent(); + for (auto iter = browserBridges.ConstIter(); !iter.Done(); iter.Next()) { + BrowserBridgeParent* browserBridge = + static_cast(iter.Get()->GetKey()); + BrowserParent* browserParent = browserBridge->GetBrowserParent(); + + aCallback(browserParent); + browserParent->VisitAllDescendants(aCallback); + } + } + + /* + * Visit each BrowserBridgeParent that is a child of this BrowserParent. + */ + template + void VisitChildren(Callback aCallback) { + const auto& browserBridges = ManagedPBrowserBridgeParent(); + for (auto iter = browserBridges.ConstIter(); !iter.Done(); iter.Next()) { + BrowserBridgeParent* browserBridge = + static_cast(iter.Get()->GetKey()); + aCallback(browserBridge); + } + } + void SetOwnerElement(Element* aElement); void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) {