Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_MessageEvent_h_
7 #define mozilla_dom_MessageEvent_h_
9 #include "mozilla/dom/Event.h"
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsIDOMMessageEvent.h"
12 #include "mozilla/dom/MessagePortList.h"
14 namespace mozilla {
15 namespace dom {
17 class MessageEventInit;
18 class MessagePort;
19 class MessagePortBase;
20 class MessagePortList;
21 class OwningWindowProxyOrMessagePort;
23 /**
24 * Implements the MessageEvent event, used for cross-document messaging and
25 * server-sent events.
26 *
27 * See http://www.whatwg.org/specs/web-apps/current-work/#messageevent for
28 * further details.
29 */
30 class MessageEvent : public Event,
31 public nsIDOMMessageEvent
32 {
33 public:
34 MessageEvent(EventTarget* aOwner,
35 nsPresContext* aPresContext,
36 WidgetEvent* aEvent);
37 ~MessageEvent();
39 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageEvent, Event)
42 NS_DECL_NSIDOMMESSAGEEVENT
44 // Forward to base class
45 NS_FORWARD_TO_EVENT
47 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
49 void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData,
50 ErrorResult& aRv);
52 void GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const;
54 MessagePortList* GetPorts()
55 {
56 return mPorts;
57 }
59 void SetPorts(MessagePortList* aPorts);
61 // Non WebIDL methods
62 void SetSource(mozilla::dom::MessagePort* aPort)
63 {
64 mPortSource = aPort;
65 }
67 void SetSource(nsPIDOMWindow* aWindow)
68 {
69 mWindowSource = aWindow;
70 }
72 static already_AddRefed<MessageEvent>
73 Constructor(const GlobalObject& aGlobal, JSContext* aCx,
74 const nsAString& aType,
75 const MessageEventInit& aEventInit,
76 ErrorResult& aRv);
78 private:
79 JS::Heap<JS::Value> mData;
80 nsString mOrigin;
81 nsString mLastEventId;
82 nsCOMPtr<nsIDOMWindow> mWindowSource;
83 nsRefPtr<MessagePortBase> mPortSource;
84 nsRefPtr<MessagePortList> mPorts;
85 };
87 } // namespace dom
88 } // namespace mozilla
90 #endif // mozilla_dom_MessageEvent_h_