JSWindowActorProtocol.h (3118B)
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_JSWindowActorProtocol_h 8 #define mozilla_dom_JSWindowActorProtocol_h 9 10 #include "mozilla/dom/BrowsingContext.h" 11 #include "mozilla/dom/JSActorService.h" 12 #include "mozilla/extensions/MatchPattern.h" 13 #include "nsIDOMEventListener.h" 14 #include "nsIObserver.h" 15 #include "nsIURI.h" 16 #include "nsString.h" 17 #include "nsTArray.h" 18 19 namespace mozilla { 20 class ErrorResult; 21 22 namespace dom { 23 24 struct WindowActorOptions; 25 class JSWindowActorInfo; 26 class EventTarget; 27 class JSActorProtocolUtils; 28 29 /** 30 * Object corresponding to a single window actor protocol. This object acts as 31 * an Event listener for the actor which is called for events which would 32 * trigger actor creation. 33 * 34 * This object also can act as a carrier for methods and other state related to 35 * a single protocol managed by the JSActorService. 36 */ 37 class JSWindowActorProtocol final : public JSActorProtocol, 38 public nsIObserver, 39 public nsIDOMEventListener { 40 public: 41 NS_DECL_NSIOBSERVER 42 NS_DECL_NSIDOMEVENTLISTENER 43 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 44 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JSWindowActorProtocol, nsIObserver) 45 46 static already_AddRefed<JSWindowActorProtocol> FromIPC( 47 const JSWindowActorInfo& aInfo); 48 JSWindowActorInfo ToIPC(); 49 50 static already_AddRefed<JSWindowActorProtocol> FromWebIDLOptions( 51 const nsACString& aName, const WindowActorOptions& aOptions, 52 ErrorResult& aRv); 53 54 struct ParentSide : public Sided {}; 55 56 struct EventDecl { 57 nsString mName; 58 EventListenerFlags mFlags; 59 Optional<bool> mPassive; 60 bool mCreateActor = true; 61 }; 62 63 struct ChildSide : public Sided { 64 nsTArray<EventDecl> mEvents; 65 nsTArray<nsCString> mObservers; 66 }; 67 68 const ParentSide& Parent() const override { return mParent; } 69 const ChildSide& Child() const override { return mChild; } 70 71 void RegisterListenersFor(EventTarget* aTarget); 72 void UnregisterListenersFor(EventTarget* aTarget); 73 void AddObservers(); 74 void RemoveObservers(); 75 bool Matches(BrowsingContext* aBrowsingContext, nsIURI* aURI, 76 const nsACString& aRemoteType, ErrorResult& aRv); 77 78 private: 79 explicit JSWindowActorProtocol(const nsACString& aName) 80 : JSActorProtocol(aName) {} 81 extensions::MatchPatternSetCore* GetURIMatcher(); 82 bool MessageManagerGroupMatches(BrowsingContext* aBrowsingContext); 83 ~JSWindowActorProtocol() = default; 84 85 bool mAllFrames = false; 86 bool mIncludeChrome = false; 87 nsTArray<nsString> mMatches; 88 nsTArray<nsString> mMessageManagerGroups; 89 90 friend class JSActorProtocolUtils; 91 92 ParentSide mParent; 93 ChildSide mChild; 94 95 RefPtr<extensions::MatchPatternSetCore> mURIMatcher; 96 }; 97 98 } // namespace dom 99 } // namespace mozilla 100 101 #endif // mozilla_dom_JSWindowActorProtocol_h