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"
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"
25 class BrowsingContext
;
26 struct MessageEventInit
;
28 class OwningWindowProxyOrMessagePortOrServiceWorker
;
30 class WindowProxyOrMessagePortOrServiceWorker
;
33 * Implements the MessageEvent event, used for cross-document messaging and
36 * See http://www.whatwg.org/specs/web-apps/current-work/#messageevent for
39 class MessageEvent final
: public Event
{
41 MessageEvent(EventTarget
* aOwner
, nsPresContext
* aPresContext
,
44 NS_DECL_ISUPPORTS_INHERITED
45 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageEvent
, Event
)
47 virtual JSObject
* WrapObjectInternal(
48 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
50 void GetData(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aData
,
52 void GetOrigin(nsAString
&) const;
53 void GetLastEventId(nsAString
&) const;
55 Nullable
<OwningWindowProxyOrMessagePortOrServiceWorker
>& aValue
) const;
57 void GetPorts(nsTArray
<RefPtr
<MessagePort
>>& aPorts
);
59 static already_AddRefed
<MessageEvent
> Constructor(
60 const GlobalObject
& aGlobal
, const nsAString
& aType
,
61 const MessageEventInit
& aEventInit
);
63 static already_AddRefed
<MessageEvent
> Constructor(
64 EventTarget
* aEventTarget
, const nsAString
& aType
,
65 const MessageEventInit
& aEventInit
);
67 void InitMessageEvent(
68 JSContext
* aCx
, const nsAString
& aType
, bool aCanBubble
, bool aCancelable
,
69 JS::Handle
<JS::Value
> aData
, const nsAString
& aOrigin
,
70 const nsAString
& aLastEventId
,
71 const Nullable
<WindowProxyOrMessagePortOrServiceWorker
>& aSource
,
72 const Sequence
<OwningNonNull
<MessagePort
>>& aPorts
) {
73 InitMessageEvent(aCx
, aType
, aCanBubble
? CanBubble::eYes
: CanBubble::eNo
,
74 aCancelable
? Cancelable::eYes
: Cancelable::eNo
, aData
,
75 aOrigin
, aLastEventId
, aSource
, aPorts
);
78 void InitMessageEvent(
79 JSContext
* aCx
, const nsAString
& aType
, mozilla::CanBubble
,
80 mozilla::Cancelable
, JS::Handle
<JS::Value
> aData
,
81 const nsAString
& aOrigin
, const nsAString
& aLastEventId
,
82 const Nullable
<WindowProxyOrMessagePortOrServiceWorker
>& aSource
,
83 const Sequence
<OwningNonNull
<MessagePort
>>& aPorts
);
89 JS::Heap
<JS::Value
> mData
;
91 nsString mLastEventId
;
92 RefPtr
<BrowsingContext
> mWindowSource
;
93 RefPtr
<MessagePort
> mPortSource
;
94 RefPtr
<ServiceWorker
> mServiceWorkerSource
;
96 nsTArray
<RefPtr
<MessagePort
>> mPorts
;
100 } // namespace mozilla
102 #endif // mozilla_dom_MessageEvent_h_