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

Side by Side Diff: third_party/WebKit/Source/core/events/MessageEvent.h

Issue 2849373002: Stop storing ScriptValue in MessageEvent (Closed)
Patch Set: Fix tests Created 3 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 unified diff | Download patch
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, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 20 matching lines...) Expand all
31 31
32 #include <memory> 32 #include <memory>
33 #include "bindings/core/v8/serialization/SerializedScriptValue.h" 33 #include "bindings/core/v8/serialization/SerializedScriptValue.h"
34 #include "core/CoreExport.h" 34 #include "core/CoreExport.h"
35 #include "core/dom/DOMArrayBuffer.h" 35 #include "core/dom/DOMArrayBuffer.h"
36 #include "core/dom/MessagePort.h" 36 #include "core/dom/MessagePort.h"
37 #include "core/events/Event.h" 37 #include "core/events/Event.h"
38 #include "core/events/EventTarget.h" 38 #include "core/events/EventTarget.h"
39 #include "core/events/MessageEventInit.h" 39 #include "core/events/MessageEventInit.h"
40 #include "core/fileapi/Blob.h" 40 #include "core/fileapi/Blob.h"
41 #include "platform/bindings/DOMWrapperWorld.h"
42 #include "platform/bindings/TraceWrapperV8Reference.h"
41 #include "platform/wtf/Compiler.h" 43 #include "platform/wtf/Compiler.h"
42 44
43 namespace blink { 45 namespace blink {
44 46
45 class CORE_EXPORT MessageEvent final : public Event { 47 class CORE_EXPORT MessageEvent final : public Event {
46 DEFINE_WRAPPERTYPEINFO(); 48 DEFINE_WRAPPERTYPEINFO();
47 49
48 public: 50 public:
49 static MessageEvent* Create() { return new MessageEvent; } 51 static MessageEvent* Create() { return new MessageEvent; }
50 static MessageEvent* Create(MessagePortArray* ports, 52 static MessageEvent* Create(MessagePortArray* ports,
(...skipping 29 matching lines...) Expand all
80 static MessageEvent* Create(Blob* data, 82 static MessageEvent* Create(Blob* data,
81 const String& origin = String(), 83 const String& origin = String(),
82 const String& suborigin = String()) { 84 const String& suborigin = String()) {
83 return new MessageEvent(data, origin, suborigin); 85 return new MessageEvent(data, origin, suborigin);
84 } 86 }
85 static MessageEvent* Create(DOMArrayBuffer* data, 87 static MessageEvent* Create(DOMArrayBuffer* data,
86 const String& origin = String(), 88 const String& origin = String(),
87 const String& suborigin = String()) { 89 const String& suborigin = String()) {
88 return new MessageEvent(data, origin, suborigin); 90 return new MessageEvent(data, origin, suborigin);
89 } 91 }
90 static MessageEvent* Create(const AtomicString& type, 92 static MessageEvent* Create(ScriptState*,
93 const AtomicString& type,
91 const MessageEventInit& initializer, 94 const MessageEventInit& initializer,
92 ExceptionState&); 95 ExceptionState&);
93 ~MessageEvent() override; 96 ~MessageEvent() override;
94 97
95 void initMessageEvent(const AtomicString& type, 98 void initMessageEvent(ScriptState*,
99 const AtomicString& type,
96 bool can_bubble, 100 bool can_bubble,
97 bool cancelable, 101 bool cancelable,
98 ScriptValue data, 102 ScriptValue data,
99 const String& origin, 103 const String& origin,
100 const String& last_event_id, 104 const String& last_event_id,
101 EventTarget* source, 105 EventTarget* source,
102 MessagePortArray*); 106 MessagePortArray*);
103 void initMessageEvent(const AtomicString& type, 107 void initMessageEvent(const AtomicString& type,
104 bool can_bubble, 108 bool can_bubble,
105 bool cancelable, 109 bool cancelable,
(...skipping 16 matching lines...) Expand all
122 const String& lastEventId() const { return last_event_id_; } 126 const String& lastEventId() const { return last_event_id_; }
123 EventTarget* source() const { return source_.Get(); } 127 EventTarget* source() const { return source_.Get(); }
124 MessagePortArray ports(bool& is_null) const; 128 MessagePortArray ports(bool& is_null) const;
125 MessagePortArray ports() const; 129 MessagePortArray ports() const;
126 130
127 MessagePortChannelArray ReleaseChannels() { return std::move(channels_); } 131 MessagePortChannelArray ReleaseChannels() { return std::move(channels_); }
128 132
129 const AtomicString& InterfaceName() const override; 133 const AtomicString& InterfaceName() const override;
130 134
131 enum DataType { 135 enum DataType {
132 kDataTypeScriptValue, 136 kDataTypeV8Reference,
133 kDataTypeSerializedScriptValue, 137 kDataTypeSerializedScriptValue,
134 kDataTypeString, 138 kDataTypeString,
135 kDataTypeBlob, 139 kDataTypeBlob,
136 kDataTypeArrayBuffer 140 kDataTypeArrayBuffer
137 }; 141 };
138 DataType GetDataType() const { return data_type_; } 142 DataType GetDataType() const { return data_type_; }
139 ScriptValue DataAsScriptValue() const { 143 ScriptValue DataAsScriptValue(ScriptState*) const;
140 DCHECK_EQ(data_type_, kDataTypeScriptValue);
141 return data_as_script_value_;
142 }
143 SerializedScriptValue* DataAsSerializedScriptValue() const { 144 SerializedScriptValue* DataAsSerializedScriptValue() const {
144 DCHECK_EQ(data_type_, kDataTypeSerializedScriptValue); 145 DCHECK_EQ(data_type_, kDataTypeSerializedScriptValue);
145 return data_as_serialized_script_value_.Get(); 146 return data_as_serialized_script_value_.Get();
146 } 147 }
147 String DataAsString() const { 148 String DataAsString() const {
148 DCHECK_EQ(data_type_, kDataTypeString); 149 DCHECK_EQ(data_type_, kDataTypeString);
149 return data_as_string_; 150 return data_as_string_;
150 } 151 }
151 Blob* DataAsBlob() const { 152 Blob* DataAsBlob() const {
152 DCHECK_EQ(data_type_, kDataTypeBlob); 153 DCHECK_EQ(data_type_, kDataTypeBlob);
153 return data_as_blob_.Get(); 154 return data_as_blob_.Get();
154 } 155 }
155 DOMArrayBuffer* DataAsArrayBuffer() const { 156 DOMArrayBuffer* DataAsArrayBuffer() const {
156 DCHECK_EQ(data_type_, kDataTypeArrayBuffer); 157 DCHECK_EQ(data_type_, kDataTypeArrayBuffer);
157 return data_as_array_buffer_.Get(); 158 return data_as_array_buffer_.Get();
158 } 159 }
159 160
160 void SetSerializedData(PassRefPtr<SerializedScriptValue> data) { 161 void SetSerializedData(PassRefPtr<SerializedScriptValue> data) {
161 DCHECK(!data_as_serialized_script_value_); 162 DCHECK(!data_as_serialized_script_value_);
162 data_as_serialized_script_value_ = std::move(data); 163 data_as_serialized_script_value_ = std::move(data);
163 } 164 }
164 165
165 void EntangleMessagePorts(ExecutionContext*); 166 void EntangleMessagePorts(ExecutionContext*);
166 167
167 DECLARE_VIRTUAL_TRACE(); 168 DECLARE_VIRTUAL_TRACE();
168 169
170 DECLARE_VIRTUAL_TRACE_WRAPPERS();
171
169 WARN_UNUSED_RESULT v8::Local<v8::Object> AssociateWithWrapper( 172 WARN_UNUSED_RESULT v8::Local<v8::Object> AssociateWithWrapper(
170 v8::Isolate*, 173 v8::Isolate*,
171 const WrapperTypeInfo*, 174 const WrapperTypeInfo*,
172 v8::Local<v8::Object> wrapper) override; 175 v8::Local<v8::Object> wrapper) override;
173 176
174 private: 177 private:
175 MessageEvent(); 178 MessageEvent();
176 MessageEvent(const AtomicString&, const MessageEventInit&); 179 MessageEvent(ScriptState*, const AtomicString&, const MessageEventInit&);
177 MessageEvent(const String& origin, 180 MessageEvent(const String& origin,
178 const String& last_event_id, 181 const String& last_event_id,
179 EventTarget* source, 182 EventTarget* source,
180 MessagePortArray*, 183 MessagePortArray*,
181 const String& suborigin); 184 const String& suborigin);
182 MessageEvent(PassRefPtr<SerializedScriptValue> data, 185 MessageEvent(PassRefPtr<SerializedScriptValue> data,
183 const String& origin, 186 const String& origin,
184 const String& last_event_id, 187 const String& last_event_id,
185 EventTarget* source, 188 EventTarget* source,
186 MessagePortArray*, 189 MessagePortArray*,
187 const String& suborigin); 190 const String& suborigin);
188 MessageEvent(PassRefPtr<SerializedScriptValue> data, 191 MessageEvent(PassRefPtr<SerializedScriptValue> data,
189 const String& origin, 192 const String& origin,
190 const String& last_event_id, 193 const String& last_event_id,
191 EventTarget* source, 194 EventTarget* source,
192 MessagePortChannelArray, 195 MessagePortChannelArray,
193 const String& suborigin); 196 const String& suborigin);
194 197
195 MessageEvent(const String& data, 198 MessageEvent(const String& data,
196 const String& origin, 199 const String& origin,
197 const String& suborigin); 200 const String& suborigin);
198 MessageEvent(Blob* data, const String& origin, const String& suborigin); 201 MessageEvent(Blob* data, const String& origin, const String& suborigin);
199 MessageEvent(DOMArrayBuffer* data, 202 MessageEvent(DOMArrayBuffer* data,
200 const String& origin, 203 const String& origin,
201 const String& suborigin); 204 const String& suborigin);
202 205
203 DataType data_type_; 206 DataType data_type_;
204 ScriptValue data_as_script_value_; 207 RefPtr<DOMWrapperWorld> world_;
208 TraceWrapperV8Reference<v8::Value> data_as_v8_value_reference_;
205 RefPtr<SerializedScriptValue> data_as_serialized_script_value_; 209 RefPtr<SerializedScriptValue> data_as_serialized_script_value_;
206 String data_as_string_; 210 String data_as_string_;
207 Member<Blob> data_as_blob_; 211 Member<Blob> data_as_blob_;
208 Member<DOMArrayBuffer> data_as_array_buffer_; 212 Member<DOMArrayBuffer> data_as_array_buffer_;
209 String origin_; 213 String origin_;
210 String last_event_id_; 214 String last_event_id_;
211 Member<EventTarget> source_; 215 Member<EventTarget> source_;
212 // m_ports are the MessagePorts in an entangled state, and m_channels are 216 // m_ports are the MessagePorts in an entangled state, and m_channels are
213 // the MessageChannels in a disentangled state. Only one of them can be 217 // the MessageChannels in a disentangled state. Only one of them can be
214 // non-empty at a time. entangleMessagePorts() moves between the states. 218 // non-empty at a time. entangleMessagePorts() moves between the states.
215 Member<MessagePortArray> ports_; 219 Member<MessagePortArray> ports_;
216 MessagePortChannelArray channels_; 220 MessagePortChannelArray channels_;
217 String suborigin_; 221 String suborigin_;
218 }; 222 };
219 223
220 } // namespace blink 224 } // namespace blink
221 225
222 #endif // MessageEvent_h 226 #endif // MessageEvent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698