Bug 1534267 - Make BrowserBridgeParent* available via TabParent. r=rhunt
authorHenri Sivonen <hsivonen@hsivonen.fi>
Mon, 11 Mar 2019 18:47:20 +0000
changeset 521500 d08e73bddc51
parent 521493 7196b821847c
child 521501 88a92eb3865e
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt
bugs1534267
milestone67.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 1534267 - Make BrowserBridgeParent* available via TabParent. r=rhunt Differential Revision: https://phabricator.services.mozilla.com/D22972
dom/ipc/BrowserBridgeParent.cpp
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
--- a/dom/ipc/BrowserBridgeParent.cpp
+++ b/dom/ipc/BrowserBridgeParent.cpp
@@ -12,17 +12,21 @@ using namespace mozilla::ipc;
 using namespace mozilla::layout;
 using namespace mozilla::hal;
 
 namespace mozilla {
 namespace dom {
 
 BrowserBridgeParent::BrowserBridgeParent() : mIPCOpen(false) {}
 
-BrowserBridgeParent::~BrowserBridgeParent() {}
+BrowserBridgeParent::~BrowserBridgeParent() {
+  if (mTabParent) {
+    mTabParent->mBrowserBridgeParent = nullptr;
+  }
+}
 
 nsresult BrowserBridgeParent::Init(const nsString& aPresentationURL,
                                    const nsString& aRemoteType) {
   mIPCOpen = true;
 
   // FIXME: This should actually use a non-bogus TabContext, probably inherited
   // from our Manager().
   OriginAttributes attrs;
@@ -48,17 +52,17 @@ nsresult BrowserBridgeParent::Init(const
   TabId tabId(nsContentUtils::GenerateTabId());
   cpm->RegisterRemoteFrame(tabId, ContentParentId(0), TabId(0),
                            tabContext.AsIPCTabContext(),
                            constructorSender->ChildID());
 
   // Construct the TabParent object for our subframe.
   uint32_t chromeFlags = 0;
   RefPtr<TabParent> tabParent(
-      new TabParent(constructorSender, tabId, tabContext, chromeFlags));
+      new TabParent(constructorSender, tabId, tabContext, chromeFlags, this));
 
   PBrowserParent* browser = constructorSender->SendPBrowserConstructor(
       // DeallocPBrowserParent() releases this ref.
       tabParent.forget().take(), tabId, TabId(0), tabContext.AsIPCTabContext(),
       chromeFlags, constructorSender->ChildID(),
       constructorSender->IsForBrowser());
   if (NS_WARN_IF(!browser)) {
     MOZ_ASSERT(false, "Browser Constructor Failed");
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -139,17 +139,18 @@ namespace mozilla {
 namespace dom {
 
 TabParent::LayerToTabParentTable* TabParent::sLayerToTabParentTable = nullptr;
 
 NS_IMPL_ISUPPORTS(TabParent, nsITabParent, nsIAuthPromptProvider,
                   nsISupportsWeakReference)
 
 TabParent::TabParent(ContentParent* aManager, const TabId& aTabId,
-                     const TabContext& aContext, uint32_t aChromeFlags)
+                     const TabContext& aContext, uint32_t aChromeFlags,
+                     BrowserBridgeParent* aBrowserBridgeParent)
     : TabContext(aContext),
       mFrameElement(nullptr),
       mContentCache(*this),
       mRect(0, 0, 0, 0),
       mDimensions(0, 0),
       mOrientation(0),
       mDPI(0),
       mRounding(0),
@@ -157,16 +158,17 @@ TabParent::TabParent(ContentParent* aMan
       mUpdatedDimensions(false),
       mSizeMode(nsSizeMode_Normal),
       mManager(aManager),
       mDocShellIsActive(false),
       mMarkedDestroying(false),
       mIsDestroyed(false),
       mChromeFlags(aChromeFlags),
       mDragValid(false),
+      mBrowserBridgeParent(aBrowserBridgeParent),
       mTabId(aTabId),
       mCreatingWindow(false),
       mCursor(eCursorInvalid),
       mCustomCursorHotspotX(0),
       mCustomCursorHotspotY(0),
       mTabSetsCursor(false),
       mHasContentOpener(false)
 #ifdef DEBUG
@@ -2315,16 +2317,20 @@ TabId TabParent::GetTabIdFrom(nsIDocShel
 
 RenderFrame* TabParent::GetRenderFrame() {
   if (!mRenderFrame.IsInitialized()) {
     return nullptr;
   }
   return &mRenderFrame;
 }
 
+BrowserBridgeParent* TabParent::GetBrowserBridgeParent() const {
+  return mBrowserBridgeParent;
+}
+
 mozilla::ipc::IPCResult TabParent::RecvRequestIMEToCommitComposition(
     const bool& aCancel, bool* aIsCommitted, nsString* aCommittedString) {
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget) {
     *aIsCommitted = false;
     return IPC_OK();
   }
 
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -67,46 +67,49 @@ class DataSourceSurface;
 
 namespace dom {
 
 class CanonicalBrowsingContext;
 class ClonedMessageData;
 class ContentParent;
 class Element;
 class DataTransfer;
+class BrowserBridgeParent;
 
 namespace ipc {
 class StructuredCloneData;
 }  // namespace ipc
 
 class TabParent final : public PBrowserParent,
                         public nsIDOMEventListener,
                         public nsITabParent,
                         public nsIAuthPromptProvider,
                         public nsIKeyEventInPluginCallback,
                         public nsSupportsWeakReference,
                         public TabContext,
                         public LiveResizeListener {
   typedef mozilla::dom::ClonedMessageData ClonedMessageData;
 
   friend class PBrowserParent;
+  friend class BrowserBridgeParent;  // for clearing mBrowserBridgeParent
 
   virtual ~TabParent();
 
  public:
   // Helper class for ContentParent::RecvCreateWindow.
   struct AutoUseNewTab;
 
   // nsITabParent
   NS_DECL_NSITABPARENT
   // nsIDOMEventListener interfaces
   NS_DECL_NSIDOMEVENTLISTENER
 
   TabParent(ContentParent* aManager, const TabId& aTabId,
-            const TabContext& aContext, uint32_t aChromeFlags);
+            const TabContext& aContext, uint32_t aChromeFlags,
+            BrowserBridgeParent* aBrowserBridgeParent = nullptr);
 
   Element* GetOwnerElement() const { return mFrameElement; }
   already_AddRefed<nsPIDOMWindowOuter> GetParentWindowOuter();
 
   void SetOwnerElement(Element* aElement);
 
   void CacheFrameLoader(nsFrameLoader* aFrameLoader);
 
@@ -565,16 +568,20 @@ class TabParent final : public PBrowserP
   void AddInitialDnDDataTo(DataTransfer* aDataTransfer,
                            nsIPrincipal** aPrincipal);
 
   bool TakeDragVisualization(RefPtr<mozilla::gfx::SourceSurface>& aSurface,
                              LayoutDeviceIntRect* aDragRect);
 
   layout::RenderFrame* GetRenderFrame();
 
+  // Returns the BrowserBridgeParent if this TabParent is for an out-of-process
+  // iframe and nullptr otherwise.
+  BrowserBridgeParent* GetBrowserBridgeParent() const;
+
   mozilla::ipc::IPCResult RecvEnsureLayersConnected(
       CompositorOptions* aCompositorOptions);
 
   // LiveResizeListener implementation
   void LiveResizeStarted() override;
   void LiveResizeStopped() override;
 
   void SetReadyToHandleInputEvents() { mIsReadyToHandleInputEvents = true; }
@@ -699,16 +706,22 @@ class TabParent final : public PBrowserP
   // 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;
 
   // The root browsing context loaded in this TabParent.
   RefPtr<CanonicalBrowsingContext> mBrowsingContext;
 
+  // Pointer back to BrowserBridgeParent if there is one associated with
+  // this TabParent. This is non-owning to avoid cycles and is managed
+  // by the BrowserBridgeParent instance, which has the strong reference
+  // to this TabParent.
+  BrowserBridgeParent* mBrowserBridgeParent;
+
   TabId mTabId;
 
   // When loading a new tab or window via window.open, the child is
   // responsible for loading the URL it wants into the new TabChild. When the
   // parent receives the CreateWindow message, though, it sends a LoadURL
   // message, usually for about:blank. It's important for the about:blank load
   // to get processed because the Firefox frontend expects every new window to
   // immediately start loading something (see bug 1123090). However, we want