| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ScriptValueSerializer.h" | 5 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Transferables.h" | 7 #include "bindings/core/v8/Transferables.h" |
| 8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 9 #include "bindings/core/v8/V8ArrayBufferView.h" | 9 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 10 #include "bindings/core/v8/V8Blob.h" | 10 #include "bindings/core/v8/V8Blob.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 append(ArrayBufferTransferTag); | 355 append(ArrayBufferTransferTag); |
| 356 doWriteUint32(index); | 356 doWriteUint32(index); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void SerializedScriptValueWriter::writeTransferredImageBitmap(uint32_t index) | 359 void SerializedScriptValueWriter::writeTransferredImageBitmap(uint32_t index) |
| 360 { | 360 { |
| 361 append(ImageBitmapTransferTag); | 361 append(ImageBitmapTransferTag); |
| 362 doWriteUint32(index); | 362 doWriteUint32(index); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void SerializedScriptValueWriter::writeTransferredOffscreenCanvas(uint32_t width
, uint32_t height, uint32_t canvasId, uint32_t clientId, uint32_t localId, uint6
4_t nonce) | 365 void SerializedScriptValueWriter::writeTransferredOffscreenCanvas(uint32_t width
, uint32_t height, uint32_t canvasId, uint32_t clientId, uint32_t localId, uint6
4_t nonceHigh, uint64_t nonceLow) |
| 366 { | 366 { |
| 367 append(OffscreenCanvasTransferTag); | 367 append(OffscreenCanvasTransferTag); |
| 368 doWriteUint32(width); | 368 doWriteUint32(width); |
| 369 doWriteUint32(height); | 369 doWriteUint32(height); |
| 370 doWriteUint32(canvasId); | 370 doWriteUint32(canvasId); |
| 371 doWriteUint32(clientId); | 371 doWriteUint32(clientId); |
| 372 doWriteUint32(localId); | 372 doWriteUint32(localId); |
| 373 doWriteUint64(nonce); | 373 doWriteUint64(nonceHigh); |
| 374 doWriteUint64(nonceLow); |
| 374 } | 375 } |
| 375 | 376 |
| 376 void SerializedScriptValueWriter::writeTransferredSharedArrayBuffer(uint32_t ind
ex) | 377 void SerializedScriptValueWriter::writeTransferredSharedArrayBuffer(uint32_t ind
ex) |
| 377 { | 378 { |
| 378 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); | 379 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); |
| 379 append(SharedArrayBufferTransferTag); | 380 append(SharedArrayBufferTransferTag); |
| 380 doWriteUint32(index); | 381 doWriteUint32(index); |
| 381 } | 382 } |
| 382 | 383 |
| 383 void SerializedScriptValueWriter::writeObjectReference(uint32_t reference) | 384 void SerializedScriptValueWriter::writeObjectReference(uint32_t reference) |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 | 1210 |
| 1210 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeTransferredOffscre
enCanvas(v8::Local<v8::Value> value, StateBase* next) | 1211 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeTransferredOffscre
enCanvas(v8::Local<v8::Value> value, StateBase* next) |
| 1211 { | 1212 { |
| 1212 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(value.As<v8::Ob
ject>()); | 1213 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(value.As<v8::Ob
ject>()); |
| 1213 if (!offscreenCanvas) | 1214 if (!offscreenCanvas) |
| 1214 return nullptr; | 1215 return nullptr; |
| 1215 if (offscreenCanvas->isNeutered()) | 1216 if (offscreenCanvas->isNeutered()) |
| 1216 return handleError(Status::DataCloneError, "An OffscreenCanvas is detach
ed and could not be cloned.", next); | 1217 return handleError(Status::DataCloneError, "An OffscreenCanvas is detach
ed and could not be cloned.", next); |
| 1217 if (offscreenCanvas->renderingContext()) | 1218 if (offscreenCanvas->renderingContext()) |
| 1218 return handleError(Status::DataCloneError, "An OffscreenCanvas with a co
ntext could not be cloned.", next); | 1219 return handleError(Status::DataCloneError, "An OffscreenCanvas with a co
ntext could not be cloned.", next); |
| 1219 m_writer.writeTransferredOffscreenCanvas(offscreenCanvas->width(), offscreen
Canvas->height(), offscreenCanvas->getAssociatedCanvasId(), offscreenCanvas->cli
entId(), offscreenCanvas->localId(), offscreenCanvas->nonce()); | 1220 m_writer.writeTransferredOffscreenCanvas(offscreenCanvas->width(), offscreen
Canvas->height(), offscreenCanvas->getAssociatedCanvasId(), offscreenCanvas->cli
entId(), offscreenCanvas->localId(), offscreenCanvas->nonceHigh(), offscreenCanv
as->nonceLow()); |
| 1220 return nullptr; | 1221 return nullptr; |
| 1221 } | 1222 } |
| 1222 | 1223 |
| 1223 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeTransferredSharedA
rrayBuffer(v8::Local<v8::Value> value, uint32_t index, StateBase* next) | 1224 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeTransferredSharedA
rrayBuffer(v8::Local<v8::Value> value, uint32_t index, StateBase* next) |
| 1224 { | 1225 { |
| 1225 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); | 1226 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); |
| 1226 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl(value.
As<v8::Object>()); | 1227 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl(value.
As<v8::Object>()); |
| 1227 if (!sharedArrayBuffer) | 1228 if (!sharedArrayBuffer) |
| 1228 return 0; | 1229 return 0; |
| 1229 m_writer.writeTransferredSharedArrayBuffer(index); | 1230 m_writer.writeTransferredSharedArrayBuffer(index); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 if (!doReadUint32(&index)) | 1572 if (!doReadUint32(&index)) |
| 1572 return false; | 1573 return false; |
| 1573 if (!deserializer.tryGetTransferredImageBitmap(index, value)) | 1574 if (!deserializer.tryGetTransferredImageBitmap(index, value)) |
| 1574 return false; | 1575 return false; |
| 1575 break; | 1576 break; |
| 1576 } | 1577 } |
| 1577 case OffscreenCanvasTransferTag: { | 1578 case OffscreenCanvasTransferTag: { |
| 1578 if (!m_version) | 1579 if (!m_version) |
| 1579 return false; | 1580 return false; |
| 1580 uint32_t width, height, canvasId, clientId, localId; | 1581 uint32_t width, height, canvasId, clientId, localId; |
| 1581 uint64_t nonce; | 1582 uint64_t nonceHigh, nonceLow; |
| 1582 if (!doReadUint32(&width)) | 1583 if (!doReadUint32(&width)) |
| 1583 return false; | 1584 return false; |
| 1584 if (!doReadUint32(&height)) | 1585 if (!doReadUint32(&height)) |
| 1585 return false; | 1586 return false; |
| 1586 if (!doReadUint32(&canvasId)) | 1587 if (!doReadUint32(&canvasId)) |
| 1587 return false; | 1588 return false; |
| 1588 if (!doReadUint32(&clientId)) | 1589 if (!doReadUint32(&clientId)) |
| 1589 return false; | 1590 return false; |
| 1590 if (!doReadUint32(&localId)) | 1591 if (!doReadUint32(&localId)) |
| 1591 return false; | 1592 return false; |
| 1592 if (!doReadUint64(&nonce)) | 1593 if (!doReadUint64(&nonceHigh) || !doReadUint64(&nonceLow)) |
| 1593 return false; | 1594 return false; |
| 1594 if (!deserializer.tryGetTransferredOffscreenCanvas(width, height, canvas
Id, clientId, localId, nonce, value)) | 1595 if (!deserializer.tryGetTransferredOffscreenCanvas(width, height, canvas
Id, clientId, localId, nonceHigh, nonceLow, value)) |
| 1595 return false; | 1596 return false; |
| 1596 break; | 1597 break; |
| 1597 } | 1598 } |
| 1598 case SharedArrayBufferTransferTag: { | 1599 case SharedArrayBufferTransferTag: { |
| 1599 if (!m_version) | 1600 if (!m_version) |
| 1600 return false; | 1601 return false; |
| 1601 uint32_t index; | 1602 uint32_t index; |
| 1602 if (!doReadUint32(&index)) | 1603 if (!doReadUint32(&index)) |
| 1603 return false; | 1604 return false; |
| 1604 if (!deserializer.tryGetTransferredSharedArrayBuffer(index, value)) | 1605 if (!deserializer.tryGetTransferredSharedArrayBuffer(index, value)) |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2400 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->conte
xt()->Global(); | 2401 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->conte
xt()->Global(); |
| 2401 result = toV8(buffer, creationContext, isolate); | 2402 result = toV8(buffer, creationContext, isolate); |
| 2402 if (result.IsEmpty()) | 2403 if (result.IsEmpty()) |
| 2403 return false; | 2404 return false; |
| 2404 m_arrayBuffers[index] = result; | 2405 m_arrayBuffers[index] = result; |
| 2405 } | 2406 } |
| 2406 *object = result; | 2407 *object = result; |
| 2407 return true; | 2408 return true; |
| 2408 } | 2409 } |
| 2409 | 2410 |
| 2410 bool ScriptValueDeserializer::tryGetTransferredOffscreenCanvas(uint32_t width, u
int32_t height, uint32_t canvasId, uint32_t clientId, uint32_t localId, uint64_t
nonce, v8::Local<v8::Value>* object) | 2411 bool ScriptValueDeserializer::tryGetTransferredOffscreenCanvas(uint32_t width, u
int32_t height, uint32_t canvasId, uint32_t clientId, uint32_t localId, uint64_t
nonceHigh, uint64_t nonceLow, v8::Local<v8::Value>* object) |
| 2411 { | 2412 { |
| 2412 OffscreenCanvas* offscreenCanvas = OffscreenCanvas::create(width, height); | 2413 OffscreenCanvas* offscreenCanvas = OffscreenCanvas::create(width, height); |
| 2413 offscreenCanvas->setAssociatedCanvasId(canvasId); | 2414 offscreenCanvas->setAssociatedCanvasId(canvasId); |
| 2414 offscreenCanvas->setSurfaceId(clientId, localId, nonce); | 2415 offscreenCanvas->setSurfaceId(clientId, localId, nonceHigh, nonceLow); |
| 2415 *object = toV8(offscreenCanvas, m_reader.getScriptState()); | 2416 *object = toV8(offscreenCanvas, m_reader.getScriptState()); |
| 2416 if ((*object).IsEmpty()) | 2417 if ((*object).IsEmpty()) |
| 2417 return false; | 2418 return false; |
| 2418 return true; | 2419 return true; |
| 2419 } | 2420 } |
| 2420 | 2421 |
| 2421 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference
, v8::Local<v8::Value>* object) | 2422 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference
, v8::Local<v8::Value>* object) |
| 2422 { | 2423 { |
| 2423 if (reference >= m_objectPool.size()) | 2424 if (reference >= m_objectPool.size()) |
| 2424 return false; | 2425 return false; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 return false; | 2490 return false; |
| 2490 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; | 2491 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; |
| 2491 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); | 2492 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); |
| 2492 if (objectReference >= m_objectPool.size()) | 2493 if (objectReference >= m_objectPool.size()) |
| 2493 return false; | 2494 return false; |
| 2494 *object = m_objectPool[objectReference]; | 2495 *object = m_objectPool[objectReference]; |
| 2495 return true; | 2496 return true; |
| 2496 } | 2497 } |
| 2497 | 2498 |
| 2498 } // namespace blink | 2499 } // namespace blink |
| OLD | NEW |