InProcessChild.h (2456B)
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_InProcessChild_h 8 #define mozilla_dom_InProcessChild_h 9 10 #include "mozilla/StaticPtr.h" 11 #include "mozilla/dom/JSProcessActorChild.h" 12 #include "mozilla/dom/PInProcessChild.h" 13 #include "mozilla/dom/ProcessActor.h" 14 #include "mozilla/dom/RemoteType.h" 15 #include "nsIDOMProcessChild.h" 16 17 namespace mozilla::dom { 18 class PWindowGlobalParent; 19 class PWindowGlobalChild; 20 class InProcessParent; 21 22 /** 23 * The `InProcessChild` class represents the child half of a main-thread to 24 * main-thread actor. 25 * 26 * The `PInProcess` actor should be used as an alternate manager to `PContent` 27 * for async actors which want to communicate uniformly between Content->Chrome 28 * and Chrome->Chrome situations. 29 */ 30 class InProcessChild final : public nsIDOMProcessChild, 31 public PInProcessChild, 32 public ProcessActor { 33 public: 34 friend class InProcessParent; 35 friend class PInProcessChild; 36 37 NS_DECL_ISUPPORTS 38 NS_DECL_NSIDOMPROCESSCHILD 39 40 // Get the singleton instance of this actor. 41 static InProcessChild* Singleton(); 42 43 // Get the parent side of the in-process child actor |aActor|. If |aActor| is 44 // not an in-process actor, or is not connected, this method will return 45 // |nullptr|. 46 static IProtocol* ParentActorFor(IProtocol* aActor); 47 48 const nsACString& GetRemoteType() const override { return NOT_REMOTE_TYPE; } 49 50 protected: 51 already_AddRefed<JSActor> InitJSActor(JS::Handle<JSObject*> aMaybeActor, 52 const nsACString& aName, 53 ErrorResult& aRv) override; 54 mozilla::ipc::IProtocol* AsNativeActor() override { return this; } 55 56 private: 57 // NOTE: PInProcess lifecycle management is declared as staic methods and 58 // state on InProcessParent, and implemented in InProcessImpl.cpp. 59 virtual void ActorDestroy(ActorDestroyReason aWhy) override; 60 ~InProcessChild() = default; 61 62 static StaticRefPtr<InProcessChild> sSingleton; 63 64 nsRefPtrHashtable<nsCStringHashKey, JSProcessActorChild> mProcessActors; 65 }; 66 67 } // namespace mozilla::dom 68 69 #endif // defined(mozilla_dom_InProcessChild_h)