BrowserHost.h (3356B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_BrowserHost_h 8 #define mozilla_dom_BrowserHost_h 9 10 #include "mozilla/dom/BrowserParent.h" 11 #include "mozilla/dom/RemoteBrowser.h" 12 #include "nsIRemoteTab.h" 13 14 class nsPIDOMWindowOuter; 15 16 namespace mozilla { 17 18 namespace a11y { 19 class DocAccessibleParent; 20 } // namespace a11y 21 22 namespace dom { 23 24 class Element; 25 26 /** 27 * BrowserHost manages a remote browser from the chrome process. 28 * 29 * It is used via the RemoteBrowser interface in nsFrameLoader and supports 30 * operations over the tree of BrowserParent/BrowserBridgeParent's. 31 * 32 * See `dom/docs/Fission-IPC-Diagram.svg` for an overview of the DOM IPC 33 * actors. 34 */ 35 class BrowserHost : public RemoteBrowser, 36 public nsIRemoteTab, 37 public nsSupportsWeakReference { 38 public: 39 typedef mozilla::layers::LayersId LayersId; 40 41 explicit BrowserHost(BrowserParent* aParent); 42 43 static BrowserHost* GetFrom(nsIRemoteTab* aRemoteTab); 44 45 // NS_DECL_ISUPPORTS_INHERITED 46 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 47 // nsIRemoteTab 48 NS_DECL_NSIREMOTETAB 49 50 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowserHost, RemoteBrowser) 51 52 // Get the IPDL actor for the root BrowserParent. This method should be 53 // avoided and consumers migrated to use this class. 54 BrowserParent* GetActor() { return mRoot; } 55 ContentParent* GetContentParent() const { 56 return mRoot ? mRoot->Manager() : nullptr; 57 } 58 59 BrowserHost* AsBrowserHost() override { return this; } 60 BrowserBridgeHost* AsBrowserBridgeHost() override { return nullptr; } 61 62 TabId GetTabId() const override; 63 LayersId GetLayersId() const override; 64 BrowsingContext* GetBrowsingContext() const override; 65 nsILoadContext* GetLoadContext() const override; 66 bool CanRecv() const override; 67 68 Element* GetOwnerElement() const { return mRoot->GetOwnerElement(); } 69 already_AddRefed<nsPIDOMWindowOuter> GetParentWindowOuter() const { 70 return mRoot->GetParentWindowOuter(); 71 } 72 a11y::DocAccessibleParent* GetTopLevelDocAccessible() const; 73 74 // Visit each BrowserParent in the tree formed by PBrowser and 75 // PBrowserBridge that is anchored by `mRoot`. 76 template <typename Callback> 77 void VisitAll(Callback aCallback) { 78 if (!mRoot) { 79 return; 80 } 81 mRoot->VisitAll(aCallback); 82 } 83 84 void LoadURL(nsDocShellLoadState* aLoadState) override; 85 void ResumeLoad(uint64_t aPendingSwitchId) override; 86 void DestroyStart() override; 87 void DestroyComplete() override; 88 89 bool Show(const OwnerShowInfo&) override; 90 void UpdateDimensions(const LayoutDeviceIntRect& aRect, 91 const LayoutDeviceIntSize& aSize) override; 92 93 void UpdateEffects(EffectsInfo aInfo) override; 94 95 private: 96 virtual ~BrowserHost() = default; 97 98 // The TabID for the root BrowserParent, we cache this so that we can access 99 // it after the remote browser has been destroyed 100 TabId mId; 101 // The root BrowserParent of this remote browser 102 RefPtr<BrowserParent> mRoot; 103 EffectsInfo mEffectsInfo; 104 }; 105 106 } // namespace dom 107 } // namespace mozilla 108 109 #endif // mozilla_dom_BrowserHost_h