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);
Nullable<WindowProxyOrMessagePort> source;
Nullable<WindowProxyOrMessagePortOrServiceWorker> source;
source.SetValue().SetAsWindowProxy() = mSource ? mSource->AsOuter() : nullptr;
Sequence<OwningNonNull<MessagePort>> ports;

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

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

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

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

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

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* 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),
@ -22,7 +22,7 @@ interface MessageEvent : Event {
* 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.
*/
readonly attribute DOMString origin;
readonly attribute USVString origin;
/**
* 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.
*/
readonly attribute (WindowProxy or MessagePort)? source;
readonly attribute MessageEventSource? source;
/**
* 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,
any data, DOMString origin, DOMString lastEventId,
(WindowProxy or MessagePort)? source,
MessageEventSource? source,
sequence<MessagePort> ports);
};
@ -53,6 +53,8 @@ dictionary MessageEventInit : EventInit {
any data = null;
DOMString origin = "";
DOMString lastEventId = "";
(Window or MessagePort)? source = null;
MessageEventSource? source = null;
sequence<MessagePort> ports = [];
};
typedef (WindowProxy or MessagePort or ServiceWorker) MessageEventSource;