Bug 1311324 P1 Update the MessageEvent webidl and implementation class. r=bz

This commit is contained in:
Ben Kelly 2017-03-09 15:35:21 -05:00
Родитель 96694a1c2e
Коммит 99905d5873
4 изменённых файлов: 37 добавлений и 21 удалений

Просмотреть файл

@ -145,7 +145,7 @@ PostMessageEvent::Run()
new MessageEvent(eventTarget, nullptr, nullptr); new MessageEvent(eventTarget, nullptr, nullptr);
Nullable<WindowProxyOrMessagePort> source; Nullable<WindowProxyOrMessagePortOrServiceWorker> source;
source.SetValue().SetAsWindowProxy() = mSource ? mSource->AsOuter() : nullptr; source.SetValue().SetAsWindowProxy() = mSource ? mSource->AsOuter() : nullptr;
Sequence<OwningNonNull<MessagePort>> ports; Sequence<OwningNonNull<MessagePort>> ports;

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/MessageEventBinding.h"
#include "mozilla/dom/MessagePort.h" #include "mozilla/dom/MessagePort.h"
#include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/workers/bindings/ServiceWorker.h"
#include "mozilla/HoldDropJSObjects.h" #include "mozilla/HoldDropJSObjects.h"
#include "jsapi.h" #include "jsapi.h"
@ -22,12 +23,14 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MessageEvent, Event)
tmp->mData.setUndefined(); tmp->mData.setUndefined();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindowSource) NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindowSource)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPortSource) NS_IMPL_CYCLE_COLLECTION_UNLINK(mPortSource)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mServiceWorkerSource)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPorts) NS_IMPL_CYCLE_COLLECTION_UNLINK(mPorts)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MessageEvent, Event) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MessageEvent, Event)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindowSource) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindowSource)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPortSource) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPortSource)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerSource)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPorts) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPorts)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -84,12 +87,14 @@ MessageEvent::GetLastEventId(nsAString& aLastEventId) const
} }
void void
MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePortOrServiceWorker>& aValue) const
{ {
if (mWindowSource) { if (mWindowSource) {
aValue.SetValue().SetAsWindowProxy() = mWindowSource->GetOuterWindow(); aValue.SetValue().SetAsWindowProxy() = mWindowSource;
} else if (mPortSource) { } else if (mPortSource) {
aValue.SetValue().SetAsMessagePort() = mPortSource; aValue.SetValue().SetAsMessagePort() = mPortSource;
} else if (mServiceWorkerSource) {
aValue.SetValue().SetAsServiceWorker() = mServiceWorkerSource;
} }
} }
@ -123,13 +128,15 @@ MessageEvent::Constructor(EventTarget* aEventTarget,
event->mLastEventId = aParam.mLastEventId; event->mLastEventId = aParam.mLastEventId;
if (!aParam.mSource.IsNull()) { if (!aParam.mSource.IsNull()) {
if (aParam.mSource.Value().IsWindow()) { if (aParam.mSource.Value().IsWindowProxy()) {
event->mWindowSource = aParam.mSource.Value().GetAsWindow()->AsInner(); event->mWindowSource = aParam.mSource.Value().GetAsWindowProxy();
} else { } else if (aParam.mSource.Value().IsMessagePort()) {
event->mPortSource = aParam.mSource.Value().GetAsMessagePort(); event->mPortSource = aParam.mSource.Value().GetAsMessagePort();
} else {
event->mServiceWorkerSource = aParam.mSource.Value().GetAsServiceWorker();
} }
MOZ_ASSERT(event->mWindowSource || event->mPortSource); MOZ_ASSERT(event->mWindowSource || event->mPortSource || event->mServiceWorkerSource);
} }
event->mPorts.AppendElements(aParam.mPorts); event->mPorts.AppendElements(aParam.mPorts);
@ -143,7 +150,7 @@ MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType,
JS::Handle<JS::Value> aData, JS::Handle<JS::Value> aData,
const nsAString& aOrigin, const nsAString& aOrigin,
const nsAString& aLastEventId, const nsAString& aLastEventId,
const Nullable<WindowProxyOrMessagePort>& aSource, const Nullable<WindowProxyOrMessagePortOrServiceWorker>& aSource,
const Sequence<OwningNonNull<MessagePort>>& aPorts) const Sequence<OwningNonNull<MessagePort>>& aPorts)
{ {
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
@ -156,13 +163,15 @@ MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType,
mWindowSource = nullptr; mWindowSource = nullptr;
mPortSource = nullptr; mPortSource = nullptr;
mServiceWorkerSource = nullptr;
if (!aSource.IsNull()) { if (!aSource.IsNull()) {
if (aSource.Value().IsWindowProxy()) { if (aSource.Value().IsWindowProxy()) {
auto* windowProxy = aSource.Value().GetAsWindowProxy(); mWindowSource = aSource.Value().GetAsWindowProxy();
mWindowSource = windowProxy ? windowProxy->GetCurrentInnerWindow() : nullptr; } else if (aSource.Value().IsMessagePort()) {
} else {
mPortSource = &aSource.Value().GetAsMessagePort(); mPortSource = &aSource.Value().GetAsMessagePort();
} else {
mServiceWorkerSource = &aSource.Value().GetAsServiceWorker();
} }
} }

Просмотреть файл

@ -16,8 +16,12 @@ namespace dom {
struct MessageEventInit; struct MessageEventInit;
class MessagePort; class MessagePort;
class OwningWindowProxyOrMessagePort; class OwningWindowProxyOrMessagePortOrServiceWorker;
class WindowProxyOrMessagePort; class WindowProxyOrMessagePortOrServiceWorker;
namespace workers {
class ServiceWorker;
}
/** /**
* Implements the MessageEvent event, used for cross-document messaging and * Implements the MessageEvent event, used for cross-document messaging and
@ -45,7 +49,7 @@ public:
ErrorResult& aRv); ErrorResult& aRv);
void GetOrigin(nsAString&) const; void GetOrigin(nsAString&) const;
void GetLastEventId(nsAString&) const; void GetLastEventId(nsAString&) const;
void GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const; void GetSource(Nullable<OwningWindowProxyOrMessagePortOrServiceWorker>& aValue) const;
void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts); void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts);
@ -64,7 +68,7 @@ public:
void InitMessageEvent(JSContext* aCx, const nsAString& aType, bool aCanBubble, void InitMessageEvent(JSContext* aCx, const nsAString& aType, bool aCanBubble,
bool aCancelable, JS::Handle<JS::Value> aData, bool aCancelable, JS::Handle<JS::Value> aData,
const nsAString& aOrigin, const nsAString& aLastEventId, const nsAString& aOrigin, const nsAString& aLastEventId,
const Nullable<WindowProxyOrMessagePort>& aSource, const Nullable<WindowProxyOrMessagePortOrServiceWorker>& aSource,
const Sequence<OwningNonNull<MessagePort>>& aPorts); const Sequence<OwningNonNull<MessagePort>>& aPorts);
protected: protected:
@ -74,8 +78,9 @@ private:
JS::Heap<JS::Value> mData; JS::Heap<JS::Value> mData;
nsString mOrigin; nsString mOrigin;
nsString mLastEventId; nsString mLastEventId;
RefPtr<nsPIDOMWindowInner> mWindowSource; RefPtr<nsPIDOMWindowOuter> mWindowSource;
RefPtr<MessagePort> mPortSource; RefPtr<MessagePort> mPortSource;
RefPtr<workers::ServiceWorker> mServiceWorkerSource;
nsTArray<RefPtr<MessagePort>> mPorts; nsTArray<RefPtr<MessagePort>> mPorts;
}; };

Просмотреть файл

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* For more information on this interface, please see * For more information on this interface, please see
* http://www.whatwg.org/specs/web-apps/current-work/#messageevent * https://html.spec.whatwg.org/#messageevent
*/ */
[Constructor(DOMString type, optional MessageEventInit eventInitDict), [Constructor(DOMString type, optional MessageEventInit eventInitDict),
@ -22,7 +22,7 @@ interface MessageEvent : Event {
* host, and if the port is not the default for the given scheme, * host, and if the port is not the default for the given scheme,
* ":" followed by that port. This value does not have a trailing slash. * ":" followed by that port. This value does not have a trailing slash.
*/ */
readonly attribute DOMString origin; readonly attribute USVString origin;
/** /**
* The last event ID string of the event source, for server-sent DOM events; this * The last event ID string of the event source, for server-sent DOM events; this
@ -33,7 +33,7 @@ interface MessageEvent : Event {
/** /**
* The window or port which originated this event. * The window or port which originated this event.
*/ */
readonly attribute (WindowProxy or MessagePort)? source; readonly attribute MessageEventSource? source;
/** /**
* Initializes this event with the given data, in a manner analogous to * Initializes this event with the given data, in a manner analogous to
@ -45,7 +45,7 @@ interface MessageEvent : Event {
void initMessageEvent(DOMString type, boolean bubbles, boolean cancelable, void initMessageEvent(DOMString type, boolean bubbles, boolean cancelable,
any data, DOMString origin, DOMString lastEventId, any data, DOMString origin, DOMString lastEventId,
(WindowProxy or MessagePort)? source, MessageEventSource? source,
sequence<MessagePort> ports); sequence<MessagePort> ports);
}; };
@ -53,6 +53,8 @@ dictionary MessageEventInit : EventInit {
any data = null; any data = null;
DOMString origin = ""; DOMString origin = "";
DOMString lastEventId = ""; DOMString lastEventId = "";
(Window or MessagePort)? source = null; MessageEventSource? source = null;
sequence<MessagePort> ports = []; sequence<MessagePort> ports = [];
}; };
typedef (WindowProxy or MessagePort or ServiceWorker) MessageEventSource;