Bug 1923546 - Disable browser_dragdrop_protected_diff_origin.js temporarily on mac...
[gecko.git] / dom / ipc / jsactor / JSWindowActorProtocol.h
blobb0128d9307182156fb3b2e6aeae89f6acf73fd34
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"
13 #include "nsIURI.h"
14 #include "nsString.h"
15 #include "nsTArray.h"
16 #include "nsIObserver.h"
17 #include "nsIDOMEventListener.h"
19 namespace mozilla {
20 class ErrorResult;
22 namespace dom {
24 struct WindowActorOptions;
25 class JSWindowActorInfo;
26 class EventTarget;
27 class JSActorProtocolUtils;
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.
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,
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)
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,
52 ErrorResult& aRv);
54 struct ParentSide : public Sided {};
56 struct EventDecl {
57 nsString mName;
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);
73 void AddObservers();
74 void RemoveObservers();
75 bool Matches(BrowsingContext* aBrowsingContext, nsIURI* aURI,
76 const nsACString& aRemoteType, ErrorResult& aRv);
78 private:
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;
85 nsCString mName;
86 bool mAllFrames = false;
87 bool mIncludeChrome = false;
88 nsTArray<nsString> mMatches;
89 nsTArray<nsCString> mRemoteTypes;
90 nsTArray<nsString> mMessageManagerGroups;
92 friend class JSActorProtocolUtils;
94 ParentSide mParent;
95 ChildSide mChild;
97 RefPtr<extensions::MatchPatternSetCore> mURIMatcher;
100 } // namespace dom
101 } // namespace mozilla
103 #endif // mozilla_dom_JSWindowActorProtocol_h