JSActorService.h (3524B)
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_JSActorService_h 8 #define mozilla_dom_JSActorService_h 9 10 #include "mozilla/EventListenerManager.h" 11 #include "mozilla/dom/BrowsingContext.h" 12 #include "mozilla/dom/JSActor.h" 13 #include "nsIDOMEventListener.h" 14 #include "nsIObserver.h" 15 #include "nsIURI.h" 16 #include "nsRefPtrHashtable.h" 17 #include "nsString.h" 18 #include "nsTArray.h" 19 20 namespace mozilla { 21 class ErrorResult; 22 23 namespace dom { 24 25 struct ProcessActorOptions; 26 struct WindowActorOptions; 27 class JSProcessActorInfo; 28 class JSWindowActorInfo; 29 class EventTarget; 30 class JSWindowActorProtocol; 31 class JSProcessActorProtocol; 32 33 class JSActorService final { 34 public: 35 NS_INLINE_DECL_REFCOUNTING(JSActorService) 36 37 static already_AddRefed<JSActorService> GetSingleton(); 38 39 // Register or unregister a chrome event target. 40 void RegisterChromeEventTarget(EventTarget* aTarget); 41 42 // NOTE: This method is static, as it may be called during shutdown. 43 static void UnregisterChromeEventTarget(EventTarget* aTarget); 44 45 // Register child's Actor for content process. 46 void LoadJSActorInfos(nsTArray<JSProcessActorInfo>& aProcess, 47 nsTArray<JSWindowActorInfo>& aWindow); 48 49 // --- Window Actor 50 51 void RegisterWindowActor(const nsACString& aName, 52 const WindowActorOptions& aOptions, 53 ErrorResult& aRv); 54 55 void UnregisterWindowActor(const nsACString& aName); 56 57 // Get the named of Window Actor and the child's WindowActorOptions 58 // from mDescriptors to JSWindowActorInfos. 59 void GetJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos); 60 61 already_AddRefed<JSWindowActorProtocol> GetJSWindowActorProtocol( 62 const nsACString& aName); 63 64 // -- Content Actor 65 66 void RegisterProcessActor(const nsACString& aName, 67 const ProcessActorOptions& aOptions, 68 ErrorResult& aRv); 69 70 void UnregisterProcessActor(const nsACString& aName); 71 72 // Get the named of Content Actor and the child's ProcessActorOptions 73 // from mDescriptors to JSProcessActorInfos. 74 void GetJSProcessActorInfos(nsTArray<JSProcessActorInfo>& aInfos); 75 76 already_AddRefed<JSProcessActorProtocol> GetJSProcessActorProtocol( 77 const nsACString& aName); 78 79 private: 80 JSActorService(); 81 ~JSActorService(); 82 83 nsTArray<EventTarget*> mChromeEventTargets; 84 85 // -- Window Actor 86 nsRefPtrHashtable<nsCStringHashKey, JSWindowActorProtocol> 87 mWindowActorDescriptors; 88 89 // -- Process Actor 90 nsRefPtrHashtable<nsCStringHashKey, JSProcessActorProtocol> 91 mProcessActorDescriptors; 92 }; 93 94 /** 95 * Base class for both `JSWindowActorProtocol` and `JSProcessActorProtocol` 96 * which can be used by generic code. 97 */ 98 class JSActorProtocol : public nsISupports { 99 public: 100 struct Sided { 101 Maybe<nsCString> mESModuleURI; 102 }; 103 104 virtual const Sided& Parent() const = 0; 105 virtual const Sided& Child() const = 0; 106 bool mLoadInDevToolsLoader = false; 107 108 protected: 109 explicit JSActorProtocol(const nsACString& aName) : mName(aName) {} 110 bool RemoteTypePrefixMatches(const nsACString& aRemoteType); 111 112 nsCString mName; 113 nsTArray<nsCString> mRemoteTypes; 114 }; 115 116 } // namespace dom 117 } // namespace mozilla 118 119 #endif // mozilla_dom_JSActorService_h