Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / events / MessageEvent.h
blobe6afd33998ed4497e187f852c20d0ecebbfc237c
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_MessageEvent_h_
8 #define mozilla_dom_MessageEvent_h_
10 #include "js/RootingAPI.h"
11 #include "js/Value.h"
12 #include "mozilla/AlreadyAddRefed.h"
13 #include "mozilla/Assertions.h"
14 #include "mozilla/BasicEvents.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/dom/Event.h"
17 #include "nsCycleCollectionParticipant.h"
18 #include "nsISupports.h"
19 #include "nsStringFwd.h"
20 #include "nsTArray.h"
22 namespace mozilla::dom {
24 class BrowsingContext;
25 struct MessageEventInit;
26 class MessagePort;
27 class OwningWindowProxyOrMessagePortOrServiceWorker;
28 class ServiceWorker;
29 class WindowProxyOrMessagePortOrServiceWorker;
31 /**
32 * Implements the MessageEvent event, used for cross-document messaging and
33 * server-sent events.
35 * See http://www.whatwg.org/specs/web-apps/current-work/#messageevent for
36 * further details.
38 class MessageEvent final : public Event {
39 public:
40 MessageEvent(EventTarget* aOwner, nsPresContext* aPresContext,
41 WidgetEvent* aEvent);
43 NS_DECL_ISUPPORTS_INHERITED
44 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageEvent, Event)
46 JSObject* WrapObjectInternal(JSContext* aCx,
47 JS::Handle<JSObject*> aGivenProto) override;
49 MessageEvent* AsMessageEvent() override { return this; }
51 void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData,
52 ErrorResult& aRv);
53 void GetOrigin(nsAString&) const;
54 void GetLastEventId(nsAString&) const;
55 void GetSource(
56 Nullable<OwningWindowProxyOrMessagePortOrServiceWorker>& aValue) const;
58 void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts);
60 static already_AddRefed<MessageEvent> Constructor(
61 const GlobalObject& aGlobal, const nsAString& aType,
62 const MessageEventInit& aEventInit);
64 static already_AddRefed<MessageEvent> Constructor(
65 EventTarget* aEventTarget, const nsAString& aType,
66 const MessageEventInit& aEventInit);
68 void InitMessageEvent(
69 JSContext* aCx, const nsAString& aType, bool aCanBubble, bool aCancelable,
70 JS::Handle<JS::Value> aData, const nsAString& aOrigin,
71 const nsAString& aLastEventId,
72 const Nullable<WindowProxyOrMessagePortOrServiceWorker>& aSource,
73 const Sequence<OwningNonNull<MessagePort>>& aPorts) {
74 InitMessageEvent(aCx, aType, aCanBubble ? CanBubble::eYes : CanBubble::eNo,
75 aCancelable ? Cancelable::eYes : Cancelable::eNo, aData,
76 aOrigin, aLastEventId, aSource, aPorts);
79 void InitMessageEvent(
80 JSContext* aCx, const nsAString& aType, mozilla::CanBubble,
81 mozilla::Cancelable, JS::Handle<JS::Value> aData,
82 const nsAString& aOrigin, const nsAString& aLastEventId,
83 const Nullable<WindowProxyOrMessagePortOrServiceWorker>& aSource,
84 const Sequence<OwningNonNull<MessagePort>>& aPorts);
86 protected:
87 ~MessageEvent();
89 private:
90 JS::Heap<JS::Value> mData;
91 nsString mOrigin;
92 nsString mLastEventId;
93 RefPtr<BrowsingContext> mWindowSource;
94 RefPtr<MessagePort> mPortSource;
95 RefPtr<ServiceWorker> mServiceWorkerSource;
97 nsTArray<RefPtr<MessagePort>> mPorts;
100 } // namespace mozilla::dom
102 #endif // mozilla_dom_MessageEvent_h_