dom/events/MessageEvent.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:897b3fffaa9e
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/. */
5
6 #ifndef mozilla_dom_MessageEvent_h_
7 #define mozilla_dom_MessageEvent_h_
8
9 #include "mozilla/dom/Event.h"
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsIDOMMessageEvent.h"
12 #include "mozilla/dom/MessagePortList.h"
13
14 namespace mozilla {
15 namespace dom {
16
17 class MessageEventInit;
18 class MessagePort;
19 class MessagePortBase;
20 class MessagePortList;
21 class OwningWindowProxyOrMessagePort;
22
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();
38
39 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageEvent, Event)
41
42 NS_DECL_NSIDOMMESSAGEEVENT
43
44 // Forward to base class
45 NS_FORWARD_TO_EVENT
46
47 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
48
49 void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData,
50 ErrorResult& aRv);
51
52 void GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const;
53
54 MessagePortList* GetPorts()
55 {
56 return mPorts;
57 }
58
59 void SetPorts(MessagePortList* aPorts);
60
61 // Non WebIDL methods
62 void SetSource(mozilla::dom::MessagePort* aPort)
63 {
64 mPortSource = aPort;
65 }
66
67 void SetSource(nsPIDOMWindow* aWindow)
68 {
69 mWindowSource = aWindow;
70 }
71
72 static already_AddRefed<MessageEvent>
73 Constructor(const GlobalObject& aGlobal, JSContext* aCx,
74 const nsAString& aType,
75 const MessageEventInit& aEventInit,
76 ErrorResult& aRv);
77
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 };
86
87 } // namespace dom
88 } // namespace mozilla
89
90 #endif // mozilla_dom_MessageEvent_h_

mercurial