summaryrefslogtreecommitdiffstats
path: root/dom/ipc/jsactor/JSActorService.h
blob: 1e7a5fcdc7a6f1af1fe427795c0d8841c22112a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_JSActorService_h
#define mozilla_dom_JSActorService_h

#include "mozilla/dom/BrowsingContext.h"
#include "nsIURI.h"
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "nsTArray.h"
#include "mozilla/dom/JSActor.h"
#include "nsIObserver.h"
#include "nsIDOMEventListener.h"
#include "mozilla/EventListenerManager.h"

namespace mozilla {
class ErrorResult;

namespace dom {

struct ProcessActorOptions;
struct WindowActorOptions;
class JSProcessActorInfo;
class JSWindowActorInfo;
class EventTarget;
class JSWindowActorProtocol;
class JSProcessActorProtocol;

class JSActorService final {
 public:
  NS_INLINE_DECL_REFCOUNTING(JSActorService)

  static already_AddRefed<JSActorService> GetSingleton();

  // Register or unregister a chrome event target.
  void RegisterChromeEventTarget(EventTarget* aTarget);

  // NOTE: This method is static, as it may be called during shutdown.
  static void UnregisterChromeEventTarget(EventTarget* aTarget);

  // Register child's Actor for content process.
  void LoadJSActorInfos(nsTArray<JSProcessActorInfo>& aProcess,
                        nsTArray<JSWindowActorInfo>& aWindow);

  // --- Window Actor

  void RegisterWindowActor(const nsACString& aName,
                           const WindowActorOptions& aOptions,
                           ErrorResult& aRv);

  void UnregisterWindowActor(const nsACString& aName);

  // Get the named of Window Actor and the child's WindowActorOptions
  // from mDescriptors to JSWindowActorInfos.
  void GetJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos);

  already_AddRefed<JSWindowActorProtocol> GetJSWindowActorProtocol(
      const nsACString& aName);

  // -- Content Actor

  void RegisterProcessActor(const nsACString& aName,
                            const ProcessActorOptions& aOptions,
                            ErrorResult& aRv);

  void UnregisterProcessActor(const nsACString& aName);

  // Get the named of Content Actor and the child's ProcessActorOptions
  // from mDescriptors to JSProcessActorInfos.
  void GetJSProcessActorInfos(nsTArray<JSProcessActorInfo>& aInfos);

  already_AddRefed<JSProcessActorProtocol> GetJSProcessActorProtocol(
      const nsACString& aName);

 private:
  JSActorService();
  ~JSActorService();

  nsTArray<EventTarget*> mChromeEventTargets;

  // -- Window Actor
  nsRefPtrHashtable<nsCStringHashKey, JSWindowActorProtocol>
      mWindowActorDescriptors;

  // -- Process Actor
  nsRefPtrHashtable<nsCStringHashKey, JSProcessActorProtocol>
      mProcessActorDescriptors;
};

/**
 * Base class for both `JSWindowActorProtocol` and `JSProcessActorProtocol`
 * which can be used by generic code.
 */
class JSActorProtocol : public nsISupports {
 public:
  struct Sided {
    Maybe<nsCString> mModuleURI;
    Maybe<nsCString> mESModuleURI;
  };

  virtual const Sided& Parent() const = 0;
  virtual const Sided& Child() const = 0;
  bool mLoadInDevToolsLoader = false;
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_JSActorService_h