diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/MessageEvent.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/MessageEvent.cpp')
-rw-r--r-- | Source/WebCore/dom/MessageEvent.cpp | 150 |
1 files changed, 85 insertions, 65 deletions
diff --git a/Source/WebCore/dom/MessageEvent.cpp b/Source/WebCore/dom/MessageEvent.cpp index 4388c9fec..7031833d7 100644 --- a/Source/WebCore/dom/MessageEvent.cpp +++ b/Source/WebCore/dom/MessageEvent.cpp @@ -11,10 +11,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -28,58 +28,51 @@ #include "config.h" #include "MessageEvent.h" -namespace WebCore { +#include "Blob.h" +#include "EventNames.h" +#include <runtime/JSCInlines.h> -static inline bool isValidSource(EventTarget* source) -{ - return !source || source->toDOMWindow() || source->isMessagePort(); -} +namespace WebCore { -MessageEventInit::MessageEventInit() -{ -} +using namespace JSC; -MessageEvent::MessageEvent() +inline MessageEvent::MessageEvent() : m_dataType(DataTypeScriptValue) { } -MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer) - : Event(type, initializer) +inline MessageEvent::MessageEvent(ExecState& state, const AtomicString& type, Init&& initializer, IsTrusted isTrusted) + : Event(type, initializer, isTrusted) , m_dataType(DataTypeScriptValue) - , m_dataAsScriptValue(initializer.data) + , m_dataAsScriptValue(state.vm(), initializer.data) , m_origin(initializer.origin) , m_lastEventId(initializer.lastEventId) - , m_source(isValidSource(initializer.source.get()) ? initializer.source : 0) - , m_ports(adoptPtr(new MessagePortArray(initializer.ports))) + , m_source(WTFMove(initializer.source)) + , m_ports(WTFMove(initializer.ports)) { } -MessageEvent::MessageEvent(const Deprecated::ScriptValue& data, const String& origin, const String& lastEventId, PassRefPtr<EventTarget> source, PassOwnPtr<MessagePortArray> ports) +inline MessageEvent::MessageEvent(RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, std::optional<MessageEventSource>&& source, Vector<RefPtr<MessagePort>>&& ports) : Event(eventNames().messageEvent, false, false) - , m_dataType(DataTypeScriptValue) - , m_dataAsScriptValue(data) + , m_dataType(DataTypeSerializedScriptValue) + , m_dataAsSerializedScriptValue(WTFMove(data)) , m_origin(origin) , m_lastEventId(lastEventId) - , m_source(source) - , m_ports(ports) + , m_source(WTFMove(source)) + , m_ports(WTFMove(ports)) { - ASSERT(isValidSource(m_source.get())); } -MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtr<EventTarget> source, PassOwnPtr<MessagePortArray> ports) - : Event(eventNames().messageEvent, false, false) +inline MessageEvent::MessageEvent(const AtomicString& type, RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId) + : Event(type, false, false) , m_dataType(DataTypeSerializedScriptValue) - , m_dataAsSerializedScriptValue(data) + , m_dataAsSerializedScriptValue(WTFMove(data)) , m_origin(origin) , m_lastEventId(lastEventId) - , m_source(source) - , m_ports(ports) { - ASSERT(isValidSource(m_source.get())); } -MessageEvent::MessageEvent(const String& data, const String& origin) +inline MessageEvent::MessageEvent(const String& data, const String& origin) : Event(eventNames().messageEvent, false, false) , m_dataType(DataTypeString) , m_dataAsString(data) @@ -87,27 +80,62 @@ MessageEvent::MessageEvent(const String& data, const String& origin) { } -MessageEvent::MessageEvent(PassRefPtr<Blob> data, const String& origin) +inline MessageEvent::MessageEvent(Ref<Blob>&& data, const String& origin) : Event(eventNames().messageEvent, false, false) , m_dataType(DataTypeBlob) - , m_dataAsBlob(data) + , m_dataAsBlob(WTFMove(data)) , m_origin(origin) { } -MessageEvent::MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin) +inline MessageEvent::MessageEvent(Ref<ArrayBuffer>&& data, const String& origin) : Event(eventNames().messageEvent, false, false) , m_dataType(DataTypeArrayBuffer) - , m_dataAsArrayBuffer(data) + , m_dataAsArrayBuffer(WTFMove(data)) , m_origin(origin) { } +Ref<MessageEvent> MessageEvent::create(Vector<RefPtr<MessagePort>>&& ports, RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, std::optional<MessageEventSource>&& source) +{ + return adoptRef(*new MessageEvent(WTFMove(data), origin, lastEventId, WTFMove(source), WTFMove(ports))); +} + +Ref<MessageEvent> MessageEvent::create(const AtomicString& type, RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId) +{ + return adoptRef(*new MessageEvent(type, WTFMove(data), origin, lastEventId)); +} + +Ref<MessageEvent> MessageEvent::create(const String& data, const String& origin) +{ + return adoptRef(*new MessageEvent(data, origin)); +} + +Ref<MessageEvent> MessageEvent::create(Ref<Blob>&& data, const String& origin) +{ + return adoptRef(*new MessageEvent(WTFMove(data), origin)); +} + +Ref<MessageEvent> MessageEvent::create(Ref<ArrayBuffer>&& data, const String& origin) +{ + return adoptRef(*new MessageEvent(WTFMove(data), origin)); +} + +Ref<MessageEvent> MessageEvent::createForBindings() +{ + return adoptRef(*new MessageEvent); +} + +Ref<MessageEvent> MessageEvent::create(ExecState& state, const AtomicString& type, Init&& initializer, IsTrusted isTrusted) +{ + return adoptRef(*new MessageEvent(state, type, WTFMove(initializer), isTrusted)); +} + MessageEvent::~MessageEvent() { } -void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const Deprecated::ScriptValue& data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports) +void MessageEvent::initMessageEvent(ExecState& state, const AtomicString& type, bool canBubble, bool cancelable, JSValue data, const String& origin, const String& lastEventId, std::optional<MessageEventSource>&& source, Vector<RefPtr<MessagePort>>&& ports) { if (dispatched()) return; @@ -115,26 +143,36 @@ void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo initEvent(type, canBubble, cancelable); m_dataType = DataTypeScriptValue; - m_dataAsScriptValue = data; + m_dataAsScriptValue = Deprecated::ScriptValue(state.vm(), data); + m_dataAsSerializedScriptValue = nullptr; + m_triedToSerialize = false; m_origin = origin; m_lastEventId = lastEventId; - m_source = source; - m_ports = ports; + m_source = WTFMove(source); + m_ports = WTFMove(ports); } -void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports) +EventTarget* MessageEvent::source() const { - if (dispatched()) - return; + if (!m_source) + return nullptr; - initEvent(type, canBubble, cancelable); + return WTF::switchOn(m_source.value(), + [] (const RefPtr<DOMWindow>& window) -> EventTarget* { return const_cast<DOMWindow*>(window.get()); }, + [] (const RefPtr<MessagePort>& messagePort) -> EventTarget* { return const_cast<MessagePort*>(messagePort.get()); } + ); +} - m_dataType = DataTypeSerializedScriptValue; - m_dataAsSerializedScriptValue = data; - m_origin = origin; - m_lastEventId = lastEventId; - m_source = source; - m_ports = ports; +RefPtr<SerializedScriptValue> MessageEvent::trySerializeData(ExecState* exec) +{ + ASSERT(!m_dataAsScriptValue.hasNoValue()); + + if (!m_dataAsSerializedScriptValue && !m_triedToSerialize) { + m_dataAsSerializedScriptValue = SerializedScriptValue::create(*exec, m_dataAsScriptValue.jsValue(), SerializationErrorMode::NonThrowing); + m_triedToSerialize = true; + } + + return m_dataAsSerializedScriptValue; } // FIXME: Remove this when we have custom ObjC binding support. @@ -145,24 +183,6 @@ SerializedScriptValue* MessageEvent::data() const return m_dataAsSerializedScriptValue.get(); } -MessagePort* MessageEvent::messagePort() -{ - if (!m_ports) - return 0; - ASSERT(m_ports->size() == 1); - return (*m_ports)[0].get(); -} - -void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, MessagePort* port) -{ - OwnPtr<MessagePortArray> ports; - if (port) { - ports = adoptPtr(new MessagePortArray); - ports->append(port); - } - initMessageEvent(type, canBubble, cancelable, data, origin, lastEventId, source, ports.release()); -} - EventInterface MessageEvent::eventInterface() const { return MessageEventInterfaceType; |