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