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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years 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 // 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/modules/v8/ScriptValueSerializerForModules.h" 5 #include "bindings/modules/v8/ScriptValueSerializerForModules.h"
6 6
7 #include "bindings/core/v8/SerializationTag.h" 7 #include "bindings/core/v8/SerializationTag.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/modules/v8/V8CryptoKey.h" 9 #include "bindings/modules/v8/V8CryptoKey.h"
10 #include "bindings/modules/v8/V8DOMFileSystem.h" 10 #include "bindings/modules/v8/V8FileSystem.h"
11 #include "bindings/modules/v8/V8RTCCertificate.h" 11 #include "bindings/modules/v8/V8RTCCertificate.h"
12 #include "bindings/modules/v8/serialization/WebCryptoSubTags.h" 12 #include "bindings/modules/v8/serialization/WebCryptoSubTags.h"
13 #include "modules/filesystem/DOMFileSystem.h" 13 #include "modules/filesystem/FileSystem.h"
14 #include "modules/peerconnection/RTCCertificate.h" 14 #include "modules/peerconnection/RTCCertificate.h"
15 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
16 #include "public/platform/WebRTCCertificate.h" 16 #include "public/platform/WebRTCCertificate.h"
17 #include "public/platform/WebRTCCertificateGenerator.h" 17 #include "public/platform/WebRTCCertificateGenerator.h"
18 #include "wtf/PtrUtil.h" 18 #include "wtf/PtrUtil.h"
19 #include <memory> 19 #include <memory>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 ScriptValueSerializerForModules::ScriptValueSerializerForModules( 23 ScriptValueSerializerForModules::ScriptValueSerializerForModules(
24 SerializedScriptValueWriter& writer, 24 SerializedScriptValueWriter& writer,
25 WebBlobInfoArray* blobInfo, 25 WebBlobInfoArray* blobInfo,
26 ScriptState* scriptState) 26 ScriptState* scriptState)
27 : ScriptValueSerializer(writer, blobInfo, scriptState) {} 27 : ScriptValueSerializer(writer, blobInfo, scriptState) {}
28 28
29 ScriptValueSerializer::StateBase* 29 ScriptValueSerializer::StateBase*
30 ScriptValueSerializerForModules::writeDOMFileSystem(v8::Local<v8::Value> value, 30 ScriptValueSerializerForModules::writeFileSystem(v8::Local<v8::Value> value,
31 StateBase* next) { 31 StateBase* next) {
32 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>()); 32 FileSystem* fs = V8FileSystem::toImpl(value.As<v8::Object>());
33 if (!fs) 33 if (!fs)
34 return 0; 34 return 0;
35 if (!fs->clonable()) 35 if (!fs->clonable())
36 return handleError(Status::DataCloneError, 36 return handleError(Status::DataCloneError,
37 "A FileSystem object could not be cloned.", next); 37 "A FileSystem object could not be cloned.", next);
38 38
39 toSerializedScriptValueWriterForModules(writer()).writeDOMFileSystem( 39 toSerializedScriptValueWriterForModules(writer()).writeFileSystem(
40 fs->type(), fs->name(), fs->rootURL().getString()); 40 fs->type(), fs->name(), fs->rootURL().getString());
41 return 0; 41 return 0;
42 } 42 }
43 43
44 bool ScriptValueSerializerForModules::writeCryptoKey( 44 bool ScriptValueSerializerForModules::writeCryptoKey(
45 v8::Local<v8::Value> value) { 45 v8::Local<v8::Value> value) {
46 CryptoKey* key = V8CryptoKey::toImpl(value.As<v8::Object>()); 46 CryptoKey* key = V8CryptoKey::toImpl(value.As<v8::Object>());
47 if (!key) 47 if (!key)
48 return false; 48 return false;
49 return toSerializedScriptValueWriterForModules(writer()).writeCryptoKey( 49 return toSerializedScriptValueWriterForModules(writer()).writeCryptoKey(
50 key->key()); 50 key->key());
51 } 51 }
52 52
53 ScriptValueSerializer::StateBase* 53 ScriptValueSerializer::StateBase*
54 ScriptValueSerializerForModules::writeRTCCertificate(v8::Local<v8::Value> value, 54 ScriptValueSerializerForModules::writeRTCCertificate(v8::Local<v8::Value> value,
55 StateBase* next) { 55 StateBase* next) {
56 RTCCertificate* certificate = 56 RTCCertificate* certificate =
57 V8RTCCertificate::toImpl(value.As<v8::Object>()); 57 V8RTCCertificate::toImpl(value.As<v8::Object>());
58 if (!certificate) 58 if (!certificate)
59 return handleError(Status::DataCloneError, 59 return handleError(Status::DataCloneError,
60 "An RTCCertificate object could not be cloned.", next); 60 "An RTCCertificate object could not be cloned.", next);
61 toSerializedScriptValueWriterForModules(writer()).writeRTCCertificate( 61 toSerializedScriptValueWriterForModules(writer()).writeRTCCertificate(
62 *certificate); 62 *certificate);
63 return nullptr; 63 return nullptr;
64 } 64 }
65 65
66 void SerializedScriptValueWriterForModules::writeDOMFileSystem( 66 void SerializedScriptValueWriterForModules::writeFileSystem(int type,
67 int type, 67 const String& name,
68 const String& name, 68 const String& url) {
69 const String& url) { 69 append(FileSystemTag);
70 append(DOMFileSystemTag);
71 doWriteUint32(type); 70 doWriteUint32(type);
72 doWriteWebCoreString(name); 71 doWriteWebCoreString(name);
73 doWriteWebCoreString(url); 72 doWriteWebCoreString(url);
74 } 73 }
75 74
76 bool SerializedScriptValueWriterForModules::writeCryptoKey( 75 bool SerializedScriptValueWriterForModules::writeCryptoKey(
77 const WebCryptoKey& key) { 76 const WebCryptoKey& key) {
78 append(static_cast<uint8_t>(CryptoKeyTag)); 77 append(static_cast<uint8_t>(CryptoKeyTag));
79 78
80 switch (key.algorithm().paramsType()) { 79 switch (key.algorithm().paramsType()) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 267
269 doWriteUint32(value); 268 doWriteUint32(value);
270 } 269 }
271 270
272 ScriptValueSerializer::StateBase* 271 ScriptValueSerializer::StateBase*
273 ScriptValueSerializerForModules::doSerializeObject( 272 ScriptValueSerializerForModules::doSerializeObject(
274 v8::Local<v8::Object> jsObject, 273 v8::Local<v8::Object> jsObject,
275 StateBase* next) { 274 StateBase* next) {
276 DCHECK(!jsObject.IsEmpty()); 275 DCHECK(!jsObject.IsEmpty());
277 276
278 if (V8DOMFileSystem::hasInstance(jsObject, isolate())) { 277 if (V8FileSystem::hasInstance(jsObject, isolate())) {
279 greyObject(jsObject); 278 greyObject(jsObject);
280 return writeDOMFileSystem(jsObject, next); 279 return writeFileSystem(jsObject, next);
281 } 280 }
282 if (V8CryptoKey::hasInstance(jsObject, isolate())) { 281 if (V8CryptoKey::hasInstance(jsObject, isolate())) {
283 greyObject(jsObject); 282 greyObject(jsObject);
284 if (!writeCryptoKey(jsObject)) 283 if (!writeCryptoKey(jsObject))
285 return handleError(Status::DataCloneError, "Couldn't serialize key data", 284 return handleError(Status::DataCloneError, "Couldn't serialize key data",
286 next); 285 next);
287 return nullptr; 286 return nullptr;
288 } 287 }
289 if (V8RTCCertificate::hasInstance(jsObject, isolate())) { 288 if (V8RTCCertificate::hasInstance(jsObject, isolate())) {
290 greyObject(jsObject); 289 greyObject(jsObject);
291 return writeRTCCertificate(jsObject, next); 290 return writeRTCCertificate(jsObject, next);
292 } 291 }
293 292
294 return ScriptValueSerializer::doSerializeObject(jsObject, next); 293 return ScriptValueSerializer::doSerializeObject(jsObject, next);
295 } 294 }
296 295
297 bool SerializedScriptValueReaderForModules::read( 296 bool SerializedScriptValueReaderForModules::read(
298 v8::Local<v8::Value>* value, 297 v8::Local<v8::Value>* value,
299 ScriptValueDeserializer& deserializer) { 298 ScriptValueDeserializer& deserializer) {
300 SerializationTag tag; 299 SerializationTag tag;
301 if (!readTag(&tag)) 300 if (!readTag(&tag))
302 return false; 301 return false;
303 switch (tag) { 302 switch (tag) {
304 case DOMFileSystemTag: 303 case FileSystemTag:
305 if (!readDOMFileSystem(value)) 304 if (!readFileSystem(value))
306 return false; 305 return false;
307 deserializer.pushObjectReference(*value); 306 deserializer.pushObjectReference(*value);
308 break; 307 break;
309 case CryptoKeyTag: 308 case CryptoKeyTag:
310 if (!readCryptoKey(value)) 309 if (!readCryptoKey(value))
311 return false; 310 return false;
312 deserializer.pushObjectReference(*value); 311 deserializer.pushObjectReference(*value);
313 break; 312 break;
314 case RTCCertificateTag: 313 case RTCCertificateTag:
315 if (!readRTCCertificate(value)) 314 if (!readRTCCertificate(value))
316 return false; 315 return false;
317 deserializer.pushObjectReference(*value); 316 deserializer.pushObjectReference(*value);
318 break; 317 break;
319 default: 318 default:
320 return SerializedScriptValueReader::readWithTag(tag, value, deserializer); 319 return SerializedScriptValueReader::readWithTag(tag, value, deserializer);
321 } 320 }
322 return !value->IsEmpty(); 321 return !value->IsEmpty();
323 } 322 }
324 323
325 bool SerializedScriptValueReaderForModules::readDOMFileSystem( 324 bool SerializedScriptValueReaderForModules::readFileSystem(
326 v8::Local<v8::Value>* value) { 325 v8::Local<v8::Value>* value) {
327 uint32_t type; 326 uint32_t type;
328 String name; 327 String name;
329 String url; 328 String url;
330 if (!doReadUint32(&type)) 329 if (!doReadUint32(&type))
331 return false; 330 return false;
332 if (!readWebCoreString(&name)) 331 if (!readWebCoreString(&name))
333 return false; 332 return false;
334 if (!readWebCoreString(&url)) 333 if (!readWebCoreString(&url))
335 return false; 334 return false;
336 DOMFileSystem* fs = DOMFileSystem::create( 335 FileSystem* fs = FileSystem::create(getScriptState()->getExecutionContext(),
337 getScriptState()->getExecutionContext(), name, 336 name, static_cast<FileSystemType>(type),
338 static_cast<FileSystemType>(type), KURL(ParsedURLString, url)); 337 KURL(ParsedURLString, url));
339 *value = toV8(fs, getScriptState()->context()->Global(), isolate()); 338 *value = toV8(fs, getScriptState()->context()->Global(), isolate());
340 return !value->IsEmpty(); 339 return !value->IsEmpty();
341 } 340 }
342 341
343 bool SerializedScriptValueReaderForModules::readCryptoKey( 342 bool SerializedScriptValueReaderForModules::readCryptoKey(
344 v8::Local<v8::Value>* value) { 343 v8::Local<v8::Value>* value) {
345 uint32_t rawKeyType; 344 uint32_t rawKeyType;
346 if (!doReadUint32(&rawKeyType)) 345 if (!doReadUint32(&rawKeyType))
347 return false; 346 return false;
348 347
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 : ScriptValueDeserializer(reader, 657 : ScriptValueDeserializer(reader,
659 messagePorts, 658 messagePorts,
660 arrayBufferContents, 659 arrayBufferContents,
661 imageBitmapContents) {} 660 imageBitmapContents) {}
662 661
663 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) { 662 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) {
664 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); 663 return toSerializedScriptValueReaderForModules(reader()).read(value, *this);
665 } 664 }
666 665
667 } // namespace blink 666 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698