Line data Source code
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_MessageEvent_h_
8 : #define mozilla_dom_MessageEvent_h_
9 :
10 : #include "mozilla/dom/Event.h"
11 : #include "mozilla/dom/BindingUtils.h"
12 : #include "nsCycleCollectionParticipant.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : struct MessageEventInit;
18 : class MessagePort;
19 : class OwningWindowProxyOrMessagePortOrServiceWorker;
20 : class WindowProxyOrMessagePortOrServiceWorker;
21 :
22 : namespace workers {
23 : class ServiceWorker;
24 : }
25 :
26 : /**
27 : * Implements the MessageEvent event, used for cross-document messaging and
28 : * server-sent events.
29 : *
30 : * See http://www.whatwg.org/specs/web-apps/current-work/#messageevent for
31 : * further details.
32 : */
33 : class MessageEvent final : public Event
34 : {
35 : public:
36 : MessageEvent(EventTarget* aOwner,
37 : nsPresContext* aPresContext,
38 : WidgetEvent* aEvent);
39 :
40 : NS_DECL_ISUPPORTS_INHERITED
41 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageEvent, Event)
42 :
43 : // Forward to base class
44 0 : NS_FORWARD_TO_EVENT
45 :
46 : virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
47 :
48 : void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData,
49 : ErrorResult& aRv);
50 : void GetOrigin(nsAString&) const;
51 : void GetLastEventId(nsAString&) const;
52 : void GetSource(Nullable<OwningWindowProxyOrMessagePortOrServiceWorker>& aValue) const;
53 :
54 : void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts);
55 :
56 : static already_AddRefed<MessageEvent>
57 : Constructor(const GlobalObject& aGlobal,
58 : const nsAString& aType,
59 : const MessageEventInit& aEventInit,
60 : ErrorResult& aRv);
61 :
62 : static already_AddRefed<MessageEvent>
63 : Constructor(EventTarget* aEventTarget,
64 : const nsAString& aType,
65 : const MessageEventInit& aEventInit);
66 :
67 : void InitMessageEvent(JSContext* aCx, const nsAString& aType, bool aCanBubble,
68 : bool aCancelable, JS::Handle<JS::Value> aData,
69 : const nsAString& aOrigin, const nsAString& aLastEventId,
70 : const Nullable<WindowProxyOrMessagePortOrServiceWorker>& aSource,
71 : const Sequence<OwningNonNull<MessagePort>>& aPorts);
72 :
73 : protected:
74 : ~MessageEvent();
75 :
76 : private:
77 : JS::Heap<JS::Value> mData;
78 : nsString mOrigin;
79 : nsString mLastEventId;
80 : RefPtr<nsPIDOMWindowOuter> mWindowSource;
81 : RefPtr<MessagePort> mPortSource;
82 : RefPtr<workers::ServiceWorker> mServiceWorkerSource;
83 :
84 : nsTArray<RefPtr<MessagePort>> mPorts;
85 : };
86 :
87 : } // namespace dom
88 : } // namespace mozilla
89 :
90 : #endif // mozilla_dom_MessageEvent_h_
|