| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2007 Henry Mason (hmason@mac.com) | |
| 3 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions | |
| 7 * are met: | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * | |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 25 * | |
| 26 */ | |
| 27 | |
| 28 #include "config.h" | |
| 29 #include "core/events/MessageEvent.h" | |
| 30 | |
| 31 #include "bindings/core/v8/ExceptionMessages.h" | |
| 32 #include "bindings/core/v8/ExceptionState.h" | |
| 33 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 static inline bool isValidSource(EventTarget* source) | |
| 38 { | |
| 39 return !source || source->toDOMWindow() || source->toMessagePort(); | |
| 40 } | |
| 41 | |
| 42 MessageEventInit::MessageEventInit() | |
| 43 { | |
| 44 } | |
| 45 | |
| 46 MessageEvent::MessageEvent() | |
| 47 : m_dataType(DataTypeScriptValue) | |
| 48 { | |
| 49 ScriptWrappable::init(this); | |
| 50 } | |
| 51 | |
| 52 MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& ini
tializer) | |
| 53 : Event(type, initializer) | |
| 54 , m_dataType(DataTypeScriptValue) | |
| 55 , m_origin(initializer.origin) | |
| 56 , m_lastEventId(initializer.lastEventId) | |
| 57 , m_source(isValidSource(initializer.source.get()) ? initializer.source : nu
llptr) | |
| 58 , m_ports(adoptPtrWillBeNoop(new MessagePortArray(initializer.ports))) | |
| 59 { | |
| 60 ScriptWrappable::init(this); | |
| 61 ASSERT(isValidSource(m_source.get())); | |
| 62 } | |
| 63 | |
| 64 MessageEvent::MessageEvent(const String& origin, const String& lastEventId, Pass
RefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray>
ports) | |
| 65 : Event(EventTypeNames::message, false, false) | |
| 66 , m_dataType(DataTypeScriptValue) | |
| 67 , m_origin(origin) | |
| 68 , m_lastEventId(lastEventId) | |
| 69 , m_source(source) | |
| 70 , m_ports(ports) | |
| 71 { | |
| 72 ScriptWrappable::init(this); | |
| 73 ASSERT(isValidSource(m_source.get())); | |
| 74 } | |
| 75 | |
| 76 MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String&
origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source,
PassOwnPtrWillBeRawPtr<MessagePortArray> ports) | |
| 77 : Event(EventTypeNames::message, false, false) | |
| 78 , m_dataType(DataTypeSerializedScriptValue) | |
| 79 , m_dataAsSerializedScriptValue(data) | |
| 80 , m_origin(origin) | |
| 81 , m_lastEventId(lastEventId) | |
| 82 , m_source(source) | |
| 83 , m_ports(ports) | |
| 84 { | |
| 85 ScriptWrappable::init(this); | |
| 86 if (m_dataAsSerializedScriptValue) | |
| 87 m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptC
ontext(); | |
| 88 ASSERT(isValidSource(m_source.get())); | |
| 89 } | |
| 90 | |
| 91 MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String&
origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source,
PassOwnPtr<MessagePortChannelArray> channels) | |
| 92 : Event(EventTypeNames::message, false, false) | |
| 93 , m_dataType(DataTypeSerializedScriptValue) | |
| 94 , m_dataAsSerializedScriptValue(data) | |
| 95 , m_origin(origin) | |
| 96 , m_lastEventId(lastEventId) | |
| 97 , m_source(source) | |
| 98 , m_channels(channels) | |
| 99 { | |
| 100 ScriptWrappable::init(this); | |
| 101 if (m_dataAsSerializedScriptValue) | |
| 102 m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptC
ontext(); | |
| 103 ASSERT(isValidSource(m_source.get())); | |
| 104 } | |
| 105 | |
| 106 MessageEvent::MessageEvent(const String& data, const String& origin) | |
| 107 : Event(EventTypeNames::message, false, false) | |
| 108 , m_dataType(DataTypeString) | |
| 109 , m_dataAsString(data) | |
| 110 , m_origin(origin) | |
| 111 { | |
| 112 ScriptWrappable::init(this); | |
| 113 } | |
| 114 | |
| 115 MessageEvent::MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin) | |
| 116 : Event(EventTypeNames::message, false, false) | |
| 117 , m_dataType(DataTypeArrayBuffer) | |
| 118 , m_dataAsArrayBuffer(data) | |
| 119 , m_origin(origin) | |
| 120 { | |
| 121 ScriptWrappable::init(this); | |
| 122 } | |
| 123 | |
| 124 MessageEvent::~MessageEvent() | |
| 125 { | |
| 126 } | |
| 127 | |
| 128 PassRefPtrWillBeRawPtr<MessageEvent> MessageEvent::create(const AtomicString& ty
pe, const MessageEventInit& initializer, ExceptionState& exceptionState) | |
| 129 { | |
| 130 if (initializer.source.get() && !isValidSource(initializer.source.get())) { | |
| 131 exceptionState.throwTypeError("The optional 'source' property is neither
a Window nor MessagePort."); | |
| 132 return nullptr; | |
| 133 } | |
| 134 return adoptRefWillBeNoop(new MessageEvent(type, initializer)); | |
| 135 } | |
| 136 | |
| 137 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo
ol cancelable, const String& origin, const String& lastEventId, LocalDOMWindow*
source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports) | |
| 138 { | |
| 139 if (dispatched()) | |
| 140 return; | |
| 141 | |
| 142 initEvent(type, canBubble, cancelable); | |
| 143 | |
| 144 m_dataType = DataTypeScriptValue; | |
| 145 m_origin = origin; | |
| 146 m_lastEventId = lastEventId; | |
| 147 m_source = source; | |
| 148 m_ports = ports; | |
| 149 } | |
| 150 | |
| 151 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo
ol cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, con
st String& lastEventId, LocalDOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePo
rtArray> ports) | |
| 152 { | |
| 153 if (dispatched()) | |
| 154 return; | |
| 155 | |
| 156 initEvent(type, canBubble, cancelable); | |
| 157 | |
| 158 m_dataType = DataTypeSerializedScriptValue; | |
| 159 m_dataAsSerializedScriptValue = data; | |
| 160 m_origin = origin; | |
| 161 m_lastEventId = lastEventId; | |
| 162 m_source = source; | |
| 163 m_ports = ports; | |
| 164 | |
| 165 if (m_dataAsSerializedScriptValue) | |
| 166 m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptC
ontext(); | |
| 167 } | |
| 168 | |
| 169 const AtomicString& MessageEvent::interfaceName() const | |
| 170 { | |
| 171 return EventNames::MessageEvent; | |
| 172 } | |
| 173 | |
| 174 void MessageEvent::entangleMessagePorts(ExecutionContext* context) | |
| 175 { | |
| 176 m_ports = MessagePort::entanglePorts(*context, m_channels.release()); | |
| 177 } | |
| 178 | |
| 179 void MessageEvent::trace(Visitor* visitor) | |
| 180 { | |
| 181 visitor->trace(m_source); | |
| 182 #if ENABLE(OILPAN) | |
| 183 visitor->trace(m_ports); | |
| 184 #endif | |
| 185 Event::trace(visitor); | |
| 186 } | |
| 187 | |
| 188 v8::Handle<v8::Object> MessageEvent::wrap(v8::Handle<v8::Object> creationContext
, v8::Isolate* isolate) | |
| 189 { | |
| 190 v8::Handle<v8::Object> wrapper = Event::wrap(creationContext, isolate); | |
| 191 | |
| 192 switch (dataType()) { | |
| 193 case MessageEvent::DataTypeScriptValue: | |
| 194 case MessageEvent::DataTypeSerializedScriptValue: | |
| 195 break; | |
| 196 case MessageEvent::DataTypeString: | |
| 197 V8HiddenValue::setHiddenValue(isolate, wrapper, V8HiddenValue::stringDat
a(isolate), v8String(isolate, dataAsString())); | |
| 198 break; | |
| 199 case MessageEvent::DataTypeArrayBuffer: | |
| 200 V8HiddenValue::setHiddenValue(isolate, wrapper, V8HiddenValue::arrayBuff
erData(isolate), toV8(dataAsArrayBuffer(), wrapper, isolate)); | |
| 201 break; | |
| 202 } | |
| 203 | |
| 204 return wrapper; | |
| 205 } | |
| 206 | |
| 207 } // namespace blink | |
| OLD | NEW |