1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/MessageEvent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_dom_MessageEvent_h_ 1.10 +#define mozilla_dom_MessageEvent_h_ 1.11 + 1.12 +#include "mozilla/dom/Event.h" 1.13 +#include "nsCycleCollectionParticipant.h" 1.14 +#include "nsIDOMMessageEvent.h" 1.15 +#include "mozilla/dom/MessagePortList.h" 1.16 + 1.17 +namespace mozilla { 1.18 +namespace dom { 1.19 + 1.20 +class MessageEventInit; 1.21 +class MessagePort; 1.22 +class MessagePortBase; 1.23 +class MessagePortList; 1.24 +class OwningWindowProxyOrMessagePort; 1.25 + 1.26 +/** 1.27 + * Implements the MessageEvent event, used for cross-document messaging and 1.28 + * server-sent events. 1.29 + * 1.30 + * See http://www.whatwg.org/specs/web-apps/current-work/#messageevent for 1.31 + * further details. 1.32 + */ 1.33 +class MessageEvent : public Event, 1.34 + public nsIDOMMessageEvent 1.35 +{ 1.36 +public: 1.37 + MessageEvent(EventTarget* aOwner, 1.38 + nsPresContext* aPresContext, 1.39 + WidgetEvent* aEvent); 1.40 + ~MessageEvent(); 1.41 + 1.42 + NS_DECL_ISUPPORTS_INHERITED 1.43 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageEvent, Event) 1.44 + 1.45 + NS_DECL_NSIDOMMESSAGEEVENT 1.46 + 1.47 + // Forward to base class 1.48 + NS_FORWARD_TO_EVENT 1.49 + 1.50 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.51 + 1.52 + void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData, 1.53 + ErrorResult& aRv); 1.54 + 1.55 + void GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const; 1.56 + 1.57 + MessagePortList* GetPorts() 1.58 + { 1.59 + return mPorts; 1.60 + } 1.61 + 1.62 + void SetPorts(MessagePortList* aPorts); 1.63 + 1.64 + // Non WebIDL methods 1.65 + void SetSource(mozilla::dom::MessagePort* aPort) 1.66 + { 1.67 + mPortSource = aPort; 1.68 + } 1.69 + 1.70 + void SetSource(nsPIDOMWindow* aWindow) 1.71 + { 1.72 + mWindowSource = aWindow; 1.73 + } 1.74 + 1.75 + static already_AddRefed<MessageEvent> 1.76 + Constructor(const GlobalObject& aGlobal, JSContext* aCx, 1.77 + const nsAString& aType, 1.78 + const MessageEventInit& aEventInit, 1.79 + ErrorResult& aRv); 1.80 + 1.81 +private: 1.82 + JS::Heap<JS::Value> mData; 1.83 + nsString mOrigin; 1.84 + nsString mLastEventId; 1.85 + nsCOMPtr<nsIDOMWindow> mWindowSource; 1.86 + nsRefPtr<MessagePortBase> mPortSource; 1.87 + nsRefPtr<MessagePortList> mPorts; 1.88 +}; 1.89 + 1.90 +} // namespace dom 1.91 +} // namespace mozilla 1.92 + 1.93 +#endif // mozilla_dom_MessageEvent_h_