Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: Source/core/events/MessageEvent.cpp

Issue 1150183007: Re-land: bindings: Use MessageEventInit for MessageEvent constructor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/events/MessageEvent.h ('k') | Source/core/events/MessageEvent.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/events/MessageEvent.cpp
diff --git a/Source/core/events/MessageEvent.cpp b/Source/core/events/MessageEvent.cpp
index 5cd5e0be0f151a9b6d3abb7df5734a5144be563a..a1d7d51d3b47494bdfd982a80aac45988451f251 100644
--- a/Source/core/events/MessageEvent.cpp
+++ b/Source/core/events/MessageEvent.cpp
@@ -39,10 +39,6 @@ static inline bool isValidSource(EventTarget* source)
return !source || source->toDOMWindow() || source->toMessagePort();
}
-MessageEventInit::MessageEventInit()
-{
-}
-
MessageEvent::MessageEvent()
: m_dataType(DataTypeScriptValue)
{
@@ -51,11 +47,18 @@ MessageEvent::MessageEvent()
MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer)
: Event(type, initializer)
, m_dataType(DataTypeScriptValue)
- , m_origin(initializer.origin)
- , m_lastEventId(initializer.lastEventId)
- , m_source(isValidSource(initializer.source.get()) ? initializer.source : nullptr)
- , m_ports(adoptPtrWillBeNoop(new MessagePortArray(initializer.ports)))
-{
+ , m_source(nullptr)
+{
+ if (initializer.hasData())
+ m_dataAsScriptValue = initializer.data();
+ if (initializer.hasOrigin())
+ m_origin = initializer.origin();
+ if (initializer.hasLastEventId())
+ m_lastEventId = initializer.lastEventId();
+ if (initializer.hasSource() && isValidSource(initializer.source().get()))
+ m_source = initializer.source();
+ if (initializer.hasPorts())
+ m_ports = adoptPtrWillBeNoop(new MessagePortArray(initializer.ports()));
ASSERT(isValidSource(m_source.get()));
}
@@ -128,14 +131,14 @@ MessageEvent::~MessageEvent()
PassRefPtrWillBeRawPtr<MessageEvent> MessageEvent::create(const AtomicString& type, const MessageEventInit& initializer, ExceptionState& exceptionState)
{
- if (initializer.source.get() && !isValidSource(initializer.source.get())) {
+ if (initializer.source().get() && !isValidSource(initializer.source().get())) {
exceptionState.throwTypeError("The optional 'source' property is neither a Window nor MessagePort.");
return nullptr;
}
return adoptRefWillBeNoop(new MessageEvent(type, initializer));
}
-void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
+void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, ScriptValue data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
{
if (dispatched())
return;
@@ -143,6 +146,7 @@ void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo
initEvent(type, canBubble, cancelable);
m_dataType = DataTypeScriptValue;
+ m_dataAsScriptValue = data;
m_origin = origin;
m_lastEventId = lastEventId;
m_source = source;
@@ -172,6 +176,26 @@ const AtomicString& MessageEvent::interfaceName() const
return EventNames::MessageEvent;
}
+MessagePortArray MessageEvent::ports(bool& isNull) const
+{
+ // TODO(bashi): Currently we return a copied array because the binding
+ // layer could modify the content of the array while executing JS callbacks.
+ // Avoid copying once we can make sure that the binding layer won't
+ // modify the content.
+ if (m_ports) {
+ isNull = false;
+ return *m_ports;
+ }
+ isNull = true;
+ return MessagePortArray();
+}
+
+MessagePortArray MessageEvent::ports() const
+{
+ bool unused;
+ return ports(unused);
+}
+
void MessageEvent::entangleMessagePorts(ExecutionContext* context)
{
m_ports = MessagePort::entanglePorts(*context, m_channels.release());
« no previous file with comments | « Source/core/events/MessageEvent.h ('k') | Source/core/events/MessageEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698