tor-browser

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

ContentProcessMessageManager.h (3347B)


      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_ContentProcessMessageManager_h
      8 #define mozilla_dom_ContentProcessMessageManager_h
      9 
     10 #include "mozilla/dom/MessageManagerCallback.h"
     11 #include "mozilla/dom/MessageManagerGlobal.h"
     12 #include "nsCOMPtr.h"
     13 #include "nsIScriptContext.h"
     14 #include "nsServiceManagerUtils.h"
     15 #include "nsWeakReference.h"
     16 #include "nsWrapperCache.h"
     17 #include "xpcpublic.h"
     18 
     19 class nsFrameMessageManager;
     20 
     21 namespace mozilla::dom {
     22 
     23 namespace ipc {
     24 class SharedMap;
     25 }
     26 
     27 /**
     28 * This class implements a singleton process message manager for content
     29 * processes. Each child process has exactly one instance of this class, which
     30 * hosts the process's process scripts, and may exchange messages with its
     31 * corresponding ParentProcessMessageManager on the parent side.
     32 */
     33 
     34 class ContentProcessMessageManager : public nsIMessageSender,
     35                                     public nsMessageManagerScriptExecutor,
     36                                     public nsSupportsWeakReference,
     37                                     public ipc::MessageManagerCallback,
     38                                     public MessageManagerGlobal,
     39                                     public nsWrapperCache {
     40 public:
     41  explicit ContentProcessMessageManager(nsFrameMessageManager* aMessageManager);
     42 
     43  using ipc::MessageManagerCallback::GetProcessMessageManager;
     44  using MessageManagerGlobal::GetProcessMessageManager;
     45 
     46  bool Init();
     47 
     48  static ContentProcessMessageManager* Get();
     49  static bool WasCreated();
     50 
     51  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     52  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
     53      ContentProcessMessageManager, nsIMessageSender)
     54 
     55  void MarkForCC();
     56 
     57  virtual JSObject* WrapObject(JSContext* aCx,
     58                               JS::Handle<JSObject*> aGivenProto) override;
     59 
     60  [[nodiscard]] JSObject* GetOrCreateWrapper();
     61 
     62  using MessageManagerGlobal::AddMessageListener;
     63  using MessageManagerGlobal::AddWeakMessageListener;
     64  using MessageManagerGlobal::RemoveMessageListener;
     65  using MessageManagerGlobal::RemoveWeakMessageListener;
     66 
     67  // ContentProcessMessageManager
     68  void GetInitialProcessData(JSContext* aCx,
     69                             JS::MutableHandle<JS::Value> aInitialProcessData,
     70                             ErrorResult& aError) {
     71    if (!mMessageManager) {
     72      aError.Throw(NS_ERROR_NOT_INITIALIZED);
     73      return;
     74    }
     75    mMessageManager->GetInitialProcessData(aCx, aInitialProcessData, aError);
     76  }
     77 
     78  already_AddRefed<ipc::SharedMap> GetSharedData();
     79 
     80  NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
     81 
     82  nsIGlobalObject* GetParentObject() const {
     83    return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
     84  }
     85 
     86  [[nodiscard]] virtual bool LoadScript(const nsAString& aURL);
     87 
     88  bool IsProcessScoped() const override { return true; }
     89 
     90  void SetInitialProcessData(JS::Handle<JS::Value> aInitialData);
     91 
     92 protected:
     93  virtual ~ContentProcessMessageManager();
     94 
     95 private:
     96  bool mInitialized;
     97 
     98  static bool sWasCreated;
     99 };
    100 
    101 }  // namespace mozilla::dom
    102 
    103 #endif  // mozilla_dom_ContentProcessMessageManager_h