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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/events/MessageEvent.h ('k') | Source/core/events/MessageEvent.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Henry Mason (hmason@mac.com) 2 * Copyright (C) 2007 Henry Mason (hmason@mac.com)
3 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 21 matching lines...) Expand all
32 #include "bindings/core/v8/ExceptionState.h" 32 #include "bindings/core/v8/ExceptionState.h"
33 #include "bindings/core/v8/V8ArrayBuffer.h" 33 #include "bindings/core/v8/V8ArrayBuffer.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 static inline bool isValidSource(EventTarget* source) 37 static inline bool isValidSource(EventTarget* source)
38 { 38 {
39 return !source || source->toDOMWindow() || source->toMessagePort(); 39 return !source || source->toDOMWindow() || source->toMessagePort();
40 } 40 }
41 41
42 MessageEventInit::MessageEventInit()
43 {
44 }
45
46 MessageEvent::MessageEvent() 42 MessageEvent::MessageEvent()
47 : m_dataType(DataTypeScriptValue) 43 : m_dataType(DataTypeScriptValue)
48 { 44 {
49 } 45 }
50 46
51 MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& ini tializer) 47 MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& ini tializer)
52 : Event(type, initializer) 48 : Event(type, initializer)
53 , m_dataType(DataTypeScriptValue) 49 , m_dataType(DataTypeScriptValue)
54 , m_origin(initializer.origin) 50 , m_source(nullptr)
55 , m_lastEventId(initializer.lastEventId)
56 , m_source(isValidSource(initializer.source.get()) ? initializer.source : nu llptr)
57 , m_ports(adoptPtrWillBeNoop(new MessagePortArray(initializer.ports)))
58 { 51 {
52 if (initializer.hasData())
53 m_dataAsScriptValue = initializer.data();
54 if (initializer.hasOrigin())
55 m_origin = initializer.origin();
56 if (initializer.hasLastEventId())
57 m_lastEventId = initializer.lastEventId();
58 if (initializer.hasSource() && isValidSource(initializer.source().get()))
59 m_source = initializer.source();
60 if (initializer.hasPorts())
61 m_ports = adoptPtrWillBeNoop(new MessagePortArray(initializer.ports()));
59 ASSERT(isValidSource(m_source.get())); 62 ASSERT(isValidSource(m_source.get()));
60 } 63 }
61 64
62 MessageEvent::MessageEvent(const String& origin, const String& lastEventId, Pass RefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports) 65 MessageEvent::MessageEvent(const String& origin, const String& lastEventId, Pass RefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
63 : Event(EventTypeNames::message, false, false) 66 : Event(EventTypeNames::message, false, false)
64 , m_dataType(DataTypeScriptValue) 67 , m_dataType(DataTypeScriptValue)
65 , m_origin(origin) 68 , m_origin(origin)
66 , m_lastEventId(lastEventId) 69 , m_lastEventId(lastEventId)
67 , m_source(source) 70 , m_source(source)
68 , m_ports(ports) 71 , m_ports(ports)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 , m_origin(origin) 124 , m_origin(origin)
122 { 125 {
123 } 126 }
124 127
125 MessageEvent::~MessageEvent() 128 MessageEvent::~MessageEvent()
126 { 129 {
127 } 130 }
128 131
129 PassRefPtrWillBeRawPtr<MessageEvent> MessageEvent::create(const AtomicString& ty pe, const MessageEventInit& initializer, ExceptionState& exceptionState) 132 PassRefPtrWillBeRawPtr<MessageEvent> MessageEvent::create(const AtomicString& ty pe, const MessageEventInit& initializer, ExceptionState& exceptionState)
130 { 133 {
131 if (initializer.source.get() && !isValidSource(initializer.source.get())) { 134 if (initializer.source().get() && !isValidSource(initializer.source().get()) ) {
132 exceptionState.throwTypeError("The optional 'source' property is neither a Window nor MessagePort."); 135 exceptionState.throwTypeError("The optional 'source' property is neither a Window nor MessagePort.");
133 return nullptr; 136 return nullptr;
134 } 137 }
135 return adoptRefWillBeNoop(new MessageEvent(type, initializer)); 138 return adoptRefWillBeNoop(new MessageEvent(type, initializer));
136 } 139 }
137 140
138 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo ol cancelable, const String& origin, const String& lastEventId, DOMWindow* sourc e, PassOwnPtrWillBeRawPtr<MessagePortArray> ports) 141 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo ol cancelable, ScriptValue data, const String& origin, const String& lastEventId , DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
139 { 142 {
140 if (dispatched()) 143 if (dispatched())
141 return; 144 return;
142 145
143 initEvent(type, canBubble, cancelable); 146 initEvent(type, canBubble, cancelable);
144 147
145 m_dataType = DataTypeScriptValue; 148 m_dataType = DataTypeScriptValue;
149 m_dataAsScriptValue = data;
146 m_origin = origin; 150 m_origin = origin;
147 m_lastEventId = lastEventId; 151 m_lastEventId = lastEventId;
148 m_source = source; 152 m_source = source;
149 m_ports = ports; 153 m_ports = ports;
150 } 154 }
151 155
152 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo ol cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, con st String& lastEventId, DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArr ay> ports) 156 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo ol cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, con st String& lastEventId, DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArr ay> ports)
153 { 157 {
154 if (dispatched()) 158 if (dispatched())
155 return; 159 return;
156 160
157 initEvent(type, canBubble, cancelable); 161 initEvent(type, canBubble, cancelable);
158 162
159 m_dataType = DataTypeSerializedScriptValue; 163 m_dataType = DataTypeSerializedScriptValue;
160 m_dataAsSerializedScriptValue = data; 164 m_dataAsSerializedScriptValue = data;
161 m_origin = origin; 165 m_origin = origin;
162 m_lastEventId = lastEventId; 166 m_lastEventId = lastEventId;
163 m_source = source; 167 m_source = source;
164 m_ports = ports; 168 m_ports = ports;
165 169
166 if (m_dataAsSerializedScriptValue) 170 if (m_dataAsSerializedScriptValue)
167 m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptC ontext(); 171 m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptC ontext();
168 } 172 }
169 173
170 const AtomicString& MessageEvent::interfaceName() const 174 const AtomicString& MessageEvent::interfaceName() const
171 { 175 {
172 return EventNames::MessageEvent; 176 return EventNames::MessageEvent;
173 } 177 }
174 178
179 MessagePortArray MessageEvent::ports(bool& isNull) const
180 {
181 // TODO(bashi): Currently we return a copied array because the binding
182 // layer could modify the content of the array while executing JS callbacks.
183 // Avoid copying once we can make sure that the binding layer won't
184 // modify the content.
185 if (m_ports) {
186 isNull = false;
187 return *m_ports;
188 }
189 isNull = true;
190 return MessagePortArray();
191 }
192
193 MessagePortArray MessageEvent::ports() const
194 {
195 bool unused;
196 return ports(unused);
197 }
198
175 void MessageEvent::entangleMessagePorts(ExecutionContext* context) 199 void MessageEvent::entangleMessagePorts(ExecutionContext* context)
176 { 200 {
177 m_ports = MessagePort::entanglePorts(*context, m_channels.release()); 201 m_ports = MessagePort::entanglePorts(*context, m_channels.release());
178 } 202 }
179 203
180 DEFINE_TRACE(MessageEvent) 204 DEFINE_TRACE(MessageEvent)
181 { 205 {
182 visitor->trace(m_dataAsBlob); 206 visitor->trace(m_dataAsBlob);
183 visitor->trace(m_source); 207 visitor->trace(m_source);
184 #if ENABLE(OILPAN) 208 #if ENABLE(OILPAN)
(...skipping 20 matching lines...) Expand all
205 break; 229 break;
206 case MessageEvent::DataTypeArrayBuffer: 230 case MessageEvent::DataTypeArrayBuffer:
207 V8HiddenValue::setHiddenValue(isolate, wrapper, V8HiddenValue::arrayBuff erData(isolate), toV8(dataAsArrayBuffer(), wrapper, isolate)); 231 V8HiddenValue::setHiddenValue(isolate, wrapper, V8HiddenValue::arrayBuff erData(isolate), toV8(dataAsArrayBuffer(), wrapper, isolate));
208 break; 232 break;
209 } 233 }
210 234
211 return wrapper; 235 return wrapper;
212 } 236 }
213 237
214 } // namespace blink 238 } // namespace blink
OLDNEW
« 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