tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

InProcessParent.h (2538B)


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