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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp

Issue 1409243005: Make ImageBitmap Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Oilpan and other issues Created 5 years, 1 month 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/v8/SerializedScriptValue.h" 32 #include "bindings/core/v8/SerializedScriptValue.h"
33 33
34 #include "bindings/core/v8/DOMDataStore.h" 34 #include "bindings/core/v8/DOMDataStore.h"
35 #include "bindings/core/v8/DOMWrapperWorld.h" 35 #include "bindings/core/v8/DOMWrapperWorld.h"
36 #include "bindings/core/v8/ExceptionState.h" 36 #include "bindings/core/v8/ExceptionState.h"
37 #include "bindings/core/v8/ScriptState.h" 37 #include "bindings/core/v8/ScriptState.h"
38 #include "bindings/core/v8/ScriptValueSerializer.h" 38 #include "bindings/core/v8/ScriptValueSerializer.h"
39 #include "bindings/core/v8/SerializedScriptValueFactory.h" 39 #include "bindings/core/v8/SerializedScriptValueFactory.h"
40 #include "bindings/core/v8/V8ArrayBuffer.h" 40 #include "bindings/core/v8/V8ArrayBuffer.h"
41 #include "bindings/core/v8/V8ImageBitmap.h"
41 #include "bindings/core/v8/V8MessagePort.h" 42 #include "bindings/core/v8/V8MessagePort.h"
42 #include "bindings/core/v8/V8SharedArrayBuffer.h" 43 #include "bindings/core/v8/V8SharedArrayBuffer.h"
43 #include "core/dom/ExceptionCode.h" 44 #include "core/dom/ExceptionCode.h"
44 #include "platform/SharedBuffer.h" 45 #include "platform/SharedBuffer.h"
45 #include "platform/blob/BlobData.h" 46 #include "platform/blob/BlobData.h"
46 #include "platform/heap/Handle.h" 47 #include "platform/heap/Handle.h"
47 #include "wtf/Assertions.h" 48 #include "wtf/Assertions.h"
48 #include "wtf/ByteOrder.h" 49 #include "wtf/ByteOrder.h"
49 #include "wtf/Vector.h" 50 #include "wtf/Vector.h"
50 #include "wtf/text/StringBuffer.h" 51 #include "wtf/text/StringBuffer.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (!wrapper.IsEmpty()) 95 if (!wrapper.IsEmpty())
95 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); 96 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper));
96 } 97 }
97 } else { 98 } else {
98 v8::Local<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDat aStore().get(object, isolate); 99 v8::Local<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDat aStore().get(object, isolate);
99 if (!wrapper.IsEmpty()) 100 if (!wrapper.IsEmpty())
100 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); 101 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper));
101 } 102 }
102 } 103 }
103 104
105 PassOwnPtrWillBeRawPtr<ImageBitmapArray> SerializedScriptValue::createImageBitma ps(v8::Isolate* isolate, ImageBitmapArray& imageBitmaps, ExceptionState& excepti onState)
106 {
107 ASSERT(imageBitmaps.size());
108
109 for (size_t i = 0; i < imageBitmaps.size(); i++) {
110 if (imageBitmaps[i]->isNeutered()) {
111 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at ind ex " + String::number(i) + " is already neutered.");
112 return nullptr;
113 }
114 }
115
116 OwnPtrWillBeRawPtr<ImageBitmapArray> contents = adoptPtrWillBeNoop(new Image BitmapArray(imageBitmaps.size()));
117 WillBeHeapHashSet<RawPtrWillBeMember<ImageBitmap>> visited;
118 for (size_t i = 0; i < imageBitmaps.size(); i++) {
119 if (visited.contains(imageBitmaps[i].get()))
120 continue;
121 visited.add(imageBitmaps[i].get());
122 contents->at(i) = imageBitmaps[i]->transfer();
123 }
124
125 return contents.release();
126 }
127
104 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState) 128 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState)
105 { 129 {
106 ASSERT(arrayBuffers.size()); 130 ASSERT(arrayBuffers.size());
107 131
108 for (size_t i = 0; i < arrayBuffers.size(); i++) { 132 for (size_t i = 0; i < arrayBuffers.size(); i++) {
109 if (arrayBuffers[i]->isNeutered()) { 133 if (arrayBuffers[i]->isNeutered()) {
110 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); 134 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered.");
111 return nullptr; 135 return nullptr;
112 } 136 }
113 } 137 }
(...skipping 12 matching lines...) Expand all
126 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " could not be transferred."); 150 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " could not be transferred.");
127 return nullptr; 151 return nullptr;
128 } 152 }
129 } else { 153 } else {
130 Vector<v8::Local<v8::ArrayBuffer>, 4> bufferHandles; 154 Vector<v8::Local<v8::ArrayBuffer>, 4> bufferHandles;
131 v8::HandleScope handleScope(isolate); 155 v8::HandleScope handleScope(isolate);
132 acculumateArrayBuffersForAllWorlds(isolate, static_pointer_cast<DOMA rrayBuffer>(arrayBuffers[i]).get(), bufferHandles); 156 acculumateArrayBuffersForAllWorlds(isolate, static_pointer_cast<DOMA rrayBuffer>(arrayBuffers[i]).get(), bufferHandles);
133 bool isNeuterable = true; 157 bool isNeuterable = true;
134 for (size_t j = 0; j < bufferHandles.size(); j++) 158 for (size_t j = 0; j < bufferHandles.size(); j++)
135 isNeuterable &= bufferHandles[j]->IsNeuterable(); 159 isNeuterable &= bufferHandles[j]->IsNeuterable();
136
137 RefPtr<DOMArrayBufferBase> toTransfer = arrayBuffers[i]; 160 RefPtr<DOMArrayBufferBase> toTransfer = arrayBuffers[i];
138 if (!isNeuterable) 161 if (!isNeuterable)
139 toTransfer = DOMArrayBuffer::create(arrayBuffers[i]->buffer()); 162 toTransfer = DOMArrayBuffer::create(arrayBuffers[i]->buffer());
140 bool result = toTransfer->transfer(contents->at(i)); 163 bool result = toTransfer->transfer(contents->at(i));
141 if (!result) { 164 if (!result) {
142 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " could not be transferred."); 165 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " could not be transferred.");
143 return nullptr; 166 return nullptr;
144 } 167 }
145 168
146 if (isNeuterable) 169 if (isNeuterable)
147 for (size_t j = 0; j < bufferHandles.size(); j++) 170 for (size_t j = 0; j < bufferHandles.size(); j++)
148 bufferHandles[j]->Neuter(); 171 bufferHandles[j]->Neuter();
149 } 172 }
150
151 } 173 }
152 174
153 return contents.release(); 175 return contents.release();
154 } 176 }
155 177
156 SerializedScriptValue::SerializedScriptValue(const String& wireData) 178 SerializedScriptValue::SerializedScriptValue(const String& wireData)
157 : m_externallyAllocatedMemory(0) 179 : m_externallyAllocatedMemory(0)
158 { 180 {
159 m_data = wireData.isolatedCopy(); 181 m_data = wireData.isolatedCopy();
160 } 182 }
161 183
162 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag ePorts) 184 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag ePorts)
163 { 185 {
164 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); 186 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0);
165 } 187 }
166 188
167 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) 189 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo)
168 { 190 {
169 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m essagePorts, blobInfo); 191 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m essagePorts, blobInfo);
170 } 192 }
171 193
172 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local <v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState) 194 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local <v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState)
173 { 195 {
174 if (isUndefinedOrNull(value)) { 196 if (isUndefinedOrNull(value)) {
175 ports.resize(0); 197 ports.resize(0);
176 arrayBuffers.resize(0); 198 arrayBuffers.resize(0);
199 imageBitmaps.resize(0);
177 return true; 200 return true;
178 } 201 }
179 202
180 uint32_t length = 0; 203 uint32_t length = 0;
181 if (value->IsArray()) { 204 if (value->IsArray()) {
182 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); 205 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value);
183 length = array->Length(); 206 length = array->Length();
184 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { 207 } else if (!toV8Sequence(value, length, isolate, exceptionState)) {
185 if (!exceptionState.hadException()) 208 if (!exceptionState.hadException())
186 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex + 1)); 209 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex + 1));
(...skipping 28 matching lines...) Expand all
215 return false; 238 return false;
216 } 239 }
217 arrayBuffers.append(arrayBuffer.release()); 240 arrayBuffers.append(arrayBuffer.release());
218 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { 241 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) {
219 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer ::toImpl(v8::Local<v8::Object>::Cast(transferrable)); 242 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer ::toImpl(v8::Local<v8::Object>::Cast(transferrable));
220 if (arrayBuffers.contains(sharedArrayBuffer)) { 243 if (arrayBuffers.contains(sharedArrayBuffer)) {
221 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB uffer."); 244 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB uffer.");
222 return false; 245 return false;
223 } 246 }
224 arrayBuffers.append(sharedArrayBuffer.release()); 247 arrayBuffers.append(sharedArrayBuffer.release());
248 } else if (V8ImageBitmap::hasInstance(transferrable, isolate)) {
249 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = V8ImageBitmap::toImpl( v8::Local<v8::Object>::Cast(transferrable));
250 if (imageBitmaps.contains(imageBitmap)) {
251 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is a duplicate of an earlier ImageBitmap.");
252 return false;
253 }
254 imageBitmaps.append(imageBitmap.release());
225 } else { 255 } else {
226 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); 256 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type.");
227 return false; 257 return false;
228 } 258 }
229 } 259 }
230 return true; 260 return true;
231 } 261 }
232 262
233 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() 263 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext()
234 { 264 {
(...skipping 17 matching lines...) Expand all
252 ASSERT(v8::Isolate::GetCurrent()); 282 ASSERT(v8::Isolate::GetCurrent());
253 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); 283 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory);
254 } 284 }
255 } 285 }
256 286
257 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState) 287 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState)
258 { 288 {
259 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState); 289 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState);
260 } 290 }
261 291
292 void SerializedScriptValue::transferImageBitmaps(v8::Isolate* isolate, ImageBitm apArray& imageBitmaps, ExceptionState& exceptionState)
293 {
294 m_imageBitmapsArray = createImageBitmaps(isolate, imageBitmaps, exceptionSta te);
295 }
296
262 } // namespace blink 297 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698