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/. */
7 #ifndef mozilla_dom_JSWindowActorProtocol_h
8 #define mozilla_dom_JSWindowActorProtocol_h
10 #include "mozilla/dom/BrowsingContext.h"
11 #include "mozilla/dom/JSActorService.h"
12 #include "mozilla/extensions/MatchPattern.h"
16 #include "nsIObserver.h"
17 #include "nsIDOMEventListener.h"
24 struct WindowActorOptions
;
25 class JSWindowActorInfo
;
27 class JSActorProtocolUtils
;
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.
34 * This object also can act as a carrier for methods and other state related to
35 * a single protocol managed by the JSActorService.
37 class JSWindowActorProtocol final
: public JSActorProtocol
,
39 public nsIDOMEventListener
{
42 NS_DECL_NSIDOMEVENTLISTENER
43 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
44 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JSWindowActorProtocol
, nsIObserver
)
46 static already_AddRefed
<JSWindowActorProtocol
> FromIPC(
47 const JSWindowActorInfo
& aInfo
);
48 JSWindowActorInfo
ToIPC();
50 static already_AddRefed
<JSWindowActorProtocol
> FromWebIDLOptions(
51 const nsACString
& aName
, const WindowActorOptions
& aOptions
,
54 struct ParentSide
: public Sided
{};
58 EventListenerFlags mFlags
;
59 Optional
<bool> mPassive
;
60 bool mCreateActor
= true;
63 struct ChildSide
: public Sided
{
64 nsTArray
<EventDecl
> mEvents
;
65 nsTArray
<nsCString
> mObservers
;
68 const ParentSide
& Parent() const override
{ return mParent
; }
69 const ChildSide
& Child() const override
{ return mChild
; }
71 void RegisterListenersFor(EventTarget
* aTarget
);
72 void UnregisterListenersFor(EventTarget
* aTarget
);
74 void RemoveObservers();
75 bool Matches(BrowsingContext
* aBrowsingContext
, nsIURI
* aURI
,
76 const nsACString
& aRemoteType
, ErrorResult
& aRv
);
79 explicit JSWindowActorProtocol(const nsACString
& aName
) : mName(aName
) {}
80 extensions::MatchPatternSetCore
* GetURIMatcher();
81 bool RemoteTypePrefixMatches(const nsDependentCSubstring
& aRemoteType
);
82 bool MessageManagerGroupMatches(BrowsingContext
* aBrowsingContext
);
83 ~JSWindowActorProtocol() = default;
86 bool mAllFrames
= false;
87 bool mIncludeChrome
= false;
88 nsTArray
<nsString
> mMatches
;
89 nsTArray
<nsCString
> mRemoteTypes
;
90 nsTArray
<nsString
> mMessageManagerGroups
;
92 friend class JSActorProtocolUtils
;
97 RefPtr
<extensions::MatchPatternSetCore
> mURIMatcher
;
101 } // namespace mozilla
103 #endif // mozilla_dom_JSWindowActorProtocol_h