| OLD | NEW | 
|---|
| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 400     } | 400     } | 
| 401 | 401 | 
| 402     void writeBlob(const String& url, const String& type, unsigned long long siz
      e) | 402     void writeBlob(const String& url, const String& type, unsigned long long siz
      e) | 
| 403     { | 403     { | 
| 404         append(BlobTag); | 404         append(BlobTag); | 
| 405         doWriteWebCoreString(url); | 405         doWriteWebCoreString(url); | 
| 406         doWriteWebCoreString(type); | 406         doWriteWebCoreString(type); | 
| 407         doWriteUint64(size); | 407         doWriteUint64(size); | 
| 408     } | 408     } | 
| 409 | 409 | 
|  | 410     void writeBlob(int blobIndex) | 
|  | 411     { | 
|  | 412         append(BlobTag); | 
|  | 413         doWriteUint32(blobIndex); | 
|  | 414     } | 
|  | 415 | 
| 410     void writeDOMFileSystem(int type, const String& name, const String& url) | 416     void writeDOMFileSystem(int type, const String& name, const String& url) | 
| 411     { | 417     { | 
| 412         append(DOMFileSystemTag); | 418         append(DOMFileSystemTag); | 
| 413         doWriteUint32(type); | 419         doWriteUint32(type); | 
| 414         doWriteWebCoreString(name); | 420         doWriteWebCoreString(name); | 
| 415         doWriteWebCoreString(url); | 421         doWriteWebCoreString(url); | 
| 416     } | 422     } | 
| 417 | 423 | 
| 418     void writeFile(const String& path, const String& url, const String& type) | 424     void writeFile(const String& path, const String& url, const String& type) | 
| 419     { | 425     { | 
| 420         append(FileTag); | 426         append(FileTag); | 
| 421         doWriteWebCoreString(path); | 427         doWriteWebCoreString(path); | 
| 422         doWriteWebCoreString(url); | 428         doWriteWebCoreString(url); | 
| 423         doWriteWebCoreString(type); | 429         doWriteWebCoreString(type); | 
| 424     } | 430     } | 
| 425 | 431 | 
|  | 432     void writeFile(int blobIndex) | 
|  | 433     { | 
|  | 434         append(FileTag); | 
|  | 435         doWriteUint32(blobIndex); | 
|  | 436     } | 
|  | 437 | 
|  | 438     // Note: We could dedupe the files in this list, but it's probably | 
|  | 439     // pretty rare that there are any duplicates. | 
| 426     void writeFileList(const FileList& fileList) | 440     void writeFileList(const FileList& fileList) | 
| 427     { | 441     { | 
| 428         append(FileListTag); | 442         append(FileListTag); | 
| 429         uint32_t length = fileList.length(); | 443         uint32_t length = fileList.length(); | 
| 430         doWriteUint32(length); | 444         doWriteUint32(length); | 
| 431         for (unsigned i = 0; i < length; ++i) { | 445         for (unsigned i = 0; i < length; ++i) { | 
| 432             doWriteWebCoreString(fileList.item(i)->path()); | 446             doWriteWebCoreString(fileList.item(i)->path()); | 
| 433             doWriteWebCoreString(fileList.item(i)->url().string()); | 447             doWriteWebCoreString(fileList.item(i)->url().string()); | 
| 434             doWriteWebCoreString(fileList.item(i)->type()); | 448             doWriteWebCoreString(fileList.item(i)->type()); | 
| 435         } | 449         } | 
| 436     } | 450     } | 
| 437 | 451 | 
|  | 452     void writeFileList(const Vector<int>& blobIndices) | 
|  | 453     { | 
|  | 454         append(FileListTag); | 
|  | 455         uint32_t length = blobIndices.size(); | 
|  | 456         doWriteUint32(length); | 
|  | 457         for (unsigned i = 0; i < length; ++i) { | 
|  | 458             doWriteUint32(blobIndices[i]); | 
|  | 459         } | 
|  | 460     } | 
|  | 461 | 
| 438     void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 462     void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 
| 439     { | 463     { | 
| 440         append(ArrayBufferTag); | 464         append(ArrayBufferTag); | 
| 441         doWriteArrayBuffer(arrayBuffer); | 465         doWriteArrayBuffer(arrayBuffer); | 
| 442     } | 466     } | 
| 443 | 467 | 
| 444     void writeArrayBufferView(const ArrayBufferView& arrayBufferView) | 468     void writeArrayBufferView(const ArrayBufferView& arrayBufferView) | 
| 445     { | 469     { | 
| 446         append(ArrayBufferViewTag); | 470         append(ArrayBufferViewTag); | 
| 447 #ifndef NDEBUG | 471 #ifndef NDEBUG | 
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 699 public: | 723 public: | 
| 700     enum Status { | 724     enum Status { | 
| 701         Success, | 725         Success, | 
| 702         InputError, | 726         InputError, | 
| 703         DataCloneError, | 727         DataCloneError, | 
| 704         InvalidStateError, | 728         InvalidStateError, | 
| 705         JSException, | 729         JSException, | 
| 706         JSFailure | 730         JSFailure | 
| 707     }; | 731     }; | 
| 708 | 732 | 
| 709     Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray*
       arrayBuffers, Vector<String>& blobURLs, v8::TryCatch& tryCatch, v8::Isolate* is
      olate) | 733     Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray*
       arrayBuffers, Vector<BlobInfo>* blobInfo, v8::TryCatch& tryCatch, v8::Isolate* 
      isolate) | 
| 710         : m_writer(writer) | 734         : m_writer(writer) | 
| 711         , m_tryCatch(tryCatch) | 735         , m_tryCatch(tryCatch) | 
| 712         , m_depth(0) | 736         , m_depth(0) | 
| 713         , m_execDepth(0) | 737         , m_execDepth(0) | 
| 714         , m_status(Success) | 738         , m_status(Success) | 
| 715         , m_nextObjectReference(0) | 739         , m_nextObjectReference(0) | 
| 716         , m_blobURLs(blobURLs) | 740         , m_blobInfo(blobInfo) | 
| 717         , m_isolate(isolate) | 741         , m_isolate(isolate) | 
| 718     { | 742     { | 
| 719         ASSERT(!tryCatch.HasCaught()); | 743         ASSERT(!tryCatch.HasCaught()); | 
| 720         if (messagePorts) { | 744         if (messagePorts) { | 
| 721             for (size_t i = 0; i < messagePorts->size(); i++) | 745             for (size_t i = 0; i < messagePorts->size(); i++) | 
| 722                 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get
      (), m_writer.getIsolate()), i); | 746                 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get
      (), m_writer.getIsolate()), i); | 
| 723         } | 747         } | 
| 724         if (arrayBuffers) { | 748         if (arrayBuffers) { | 
| 725             for (size_t i = 0; i < arrayBuffers->size(); i++)  { | 749             for (size_t i = 0; i < arrayBuffers->size(); i++)  { | 
| 726                 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers->
      at(i).get(), m_writer.getIsolate()); | 750                 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers->
      at(i).get(), m_writer.getIsolate()); | 
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1074     { | 1098     { | 
| 1075         v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject
      >(); | 1099         v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject
      >(); | 
| 1076         m_writer.writeBooleanObject(booleanObject->BooleanValue()); | 1100         m_writer.writeBooleanObject(booleanObject->BooleanValue()); | 
| 1077     } | 1101     } | 
| 1078 | 1102 | 
| 1079     void writeBlob(v8::Handle<v8::Value> value) | 1103     void writeBlob(v8::Handle<v8::Value> value) | 
| 1080     { | 1104     { | 
| 1081         Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 1105         Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 
| 1082         if (!blob) | 1106         if (!blob) | 
| 1083             return; | 1107             return; | 
| 1084         m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); | 1108         int blobIndex = -1; | 
| 1085         m_blobURLs.append(blob->url().string()); | 1109         if (appendBlobInfo(blob->url().string(), blob->type(), blob->size(), &bl
      obIndex)) { | 
|  | 1110             ASSERT(blobIndex >= 0); | 
|  | 1111             m_writer.writeBlob(blobIndex); | 
|  | 1112         } else { | 
|  | 1113             m_writer.writeBlob(blob->url().string(), blob->type(), blob->size())
      ; | 
|  | 1114         } | 
| 1086     } | 1115     } | 
| 1087 | 1116 | 
| 1088     StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1117     StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 
| 1089     { | 1118     { | 
| 1090         DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1119         DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 
| 1091         if (!fs) | 1120         if (!fs) | 
| 1092             return 0; | 1121             return 0; | 
| 1093         if (!fs->clonable()) | 1122         if (!fs->clonable()) | 
| 1094             return handleError(DataCloneError, next); | 1123             return handleError(DataCloneError, next); | 
| 1095         m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
      ()); | 1124         m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
      ()); | 
| 1096         return 0; | 1125         return 0; | 
| 1097     } | 1126     } | 
| 1098 | 1127 | 
| 1099     void writeFile(v8::Handle<v8::Value> value) | 1128     void writeFile(v8::Handle<v8::Value> value) | 
| 1100     { | 1129     { | 
| 1101         File* file = V8File::toNative(value.As<v8::Object>()); | 1130         File* file = V8File::toNative(value.As<v8::Object>()); | 
| 1102         if (!file) | 1131         if (!file) | 
| 1103             return; | 1132             return; | 
| 1104         m_writer.writeFile(file->path(), file->url().string(), file->type()); | 1133         int blobIndex = -1; | 
| 1105         m_blobURLs.append(file->url().string()); | 1134         if (appendFileInfo(file->path(), file->name(), file->type(), &blobIndex)
      ) { | 
|  | 1135             ASSERT(blobIndex >= 0); | 
|  | 1136             m_writer.writeFile(blobIndex); | 
|  | 1137         } else { | 
|  | 1138             m_writer.writeFile(file->path(), file->url().string(), file->type())
      ; | 
|  | 1139         } | 
| 1106     } | 1140     } | 
| 1107 | 1141 | 
| 1108     void writeFileList(v8::Handle<v8::Value> value) | 1142     void writeFileList(v8::Handle<v8::Value> value) | 
| 1109     { | 1143     { | 
| 1110         FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1144         FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 
| 1111         if (!fileList) | 1145         if (!fileList) | 
| 1112             return; | 1146             return; | 
| 1113         m_writer.writeFileList(*fileList); |  | 
| 1114         unsigned length = fileList->length(); | 1147         unsigned length = fileList->length(); | 
| 1115         for (unsigned i = 0; i < length; ++i) | 1148         Vector<int> blobIndices; | 
| 1116             m_blobURLs.append(fileList->item(i)->url().string()); | 1149         bool useBlobIndices = false; | 
|  | 1150         for (unsigned i = 0; i < length; ++i) { | 
|  | 1151             int blobIndex = -1; | 
|  | 1152             const File* file = fileList->item(i); | 
|  | 1153             if (appendFileInfo(file->path(), file->name(), file->type(), &blobIn
      dex)) { | 
|  | 1154                 ASSERT(!i || useBlobIndices); | 
|  | 1155                 ASSERT(blobIndex >= 0); | 
|  | 1156                 useBlobIndices = true; | 
|  | 1157                 blobIndices.append(blobIndex); | 
|  | 1158             } | 
|  | 1159         } | 
|  | 1160         if (useBlobIndices) { | 
|  | 1161             m_writer.writeFileList(blobIndices); | 
|  | 1162         } else { | 
|  | 1163             m_writer.writeFileList(*fileList); | 
|  | 1164         } | 
| 1117     } | 1165     } | 
| 1118 | 1166 | 
| 1119     void writeImageData(v8::Handle<v8::Value> value) | 1167     void writeImageData(v8::Handle<v8::Value> value) | 
| 1120     { | 1168     { | 
| 1121         ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1169         ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 
| 1122         if (!imageData) | 1170         if (!imageData) | 
| 1123             return; | 1171             return; | 
| 1124         Uint8ClampedArray* pixelArray = imageData->data(); | 1172         Uint8ClampedArray* pixelArray = imageData->data(); | 
| 1125         m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
      ray->data(), pixelArray->length()); | 1173         m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
      ray->data(), pixelArray->length()); | 
| 1126     } | 1174     } | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1215 | 1263 | 
| 1216     // Marks object as having been visited by the serializer and assigns it a un
      ique object reference ID. | 1264     // Marks object as having been visited by the serializer and assigns it a un
      ique object reference ID. | 
| 1217     // An object may only be greyed once. | 1265     // An object may only be greyed once. | 
| 1218     void greyObject(const v8::Handle<v8::Object>& object) | 1266     void greyObject(const v8::Handle<v8::Object>& object) | 
| 1219     { | 1267     { | 
| 1220         ASSERT(!m_objectPool.contains(object)); | 1268         ASSERT(!m_objectPool.contains(object)); | 
| 1221         uint32_t objectReference = m_nextObjectReference++; | 1269         uint32_t objectReference = m_nextObjectReference++; | 
| 1222         m_objectPool.set(object, objectReference); | 1270         m_objectPool.set(object, objectReference); | 
| 1223     } | 1271     } | 
| 1224 | 1272 | 
|  | 1273     bool appendBlobInfo(const String& url, const String& type, unsigned long lon
      g size, int* index) | 
|  | 1274     { | 
|  | 1275         if (!m_blobInfo) | 
|  | 1276             return false; | 
|  | 1277         *index = m_blobInfo->size(); | 
|  | 1278         m_blobInfo->append(BlobInfo(url, type, size)); | 
|  | 1279         return true; | 
|  | 1280     } | 
|  | 1281 | 
|  | 1282     bool appendFileInfo(const String& filePath, const String& fileName, const St
      ring& type, int* index) | 
|  | 1283     { | 
|  | 1284         if (!m_blobInfo) | 
|  | 1285             return false; | 
|  | 1286         *index = m_blobInfo->size(); | 
|  | 1287         m_blobInfo->append(BlobInfo(filePath, fileName, type)); | 
|  | 1288         return true; | 
|  | 1289     } | 
|  | 1290 | 
| 1225     Writer& m_writer; | 1291     Writer& m_writer; | 
| 1226     v8::TryCatch& m_tryCatch; | 1292     v8::TryCatch& m_tryCatch; | 
| 1227     int m_depth; | 1293     int m_depth; | 
| 1228     int m_execDepth; | 1294     int m_execDepth; | 
| 1229     Status m_status; | 1295     Status m_status; | 
| 1230     typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 1296     typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 
| 1231     ObjectPool m_objectPool; | 1297     ObjectPool m_objectPool; | 
| 1232     ObjectPool m_transferredMessagePorts; | 1298     ObjectPool m_transferredMessagePorts; | 
| 1233     ObjectPool m_transferredArrayBuffers; | 1299     ObjectPool m_transferredArrayBuffers; | 
| 1234     uint32_t m_nextObjectReference; | 1300     uint32_t m_nextObjectReference; | 
| 1235     Vector<String>& m_blobURLs; | 1301     Vector<BlobInfo>* m_blobInfo; | 
| 1236     v8::Isolate* m_isolate; | 1302     v8::Isolate* m_isolate; | 
| 1237 }; | 1303 }; | 
| 1238 | 1304 | 
| 1239 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat
      eBase* next) | 1305 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat
      eBase* next) | 
| 1240 { | 1306 { | 
| 1241     if (m_execDepth + (next ? next->execDepth() : 0) > 1) { | 1307     if (m_execDepth + (next ? next->execDepth() : 0) > 1) { | 
| 1242         m_writer.writeNull(); | 1308         m_writer.writeNull(); | 
| 1243         return 0; | 1309         return 0; | 
| 1244     } | 1310     } | 
| 1245     m_writer.writeReferenceCount(m_nextObjectReference); | 1311     m_writer.writeReferenceCount(m_nextObjectReference); | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1335     virtual bool newObject() = 0; | 1401     virtual bool newObject() = 0; | 
| 1336     virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) 
      = 0; | 1402     virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) 
      = 0; | 
| 1337     virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
      ::Handle<v8::Value>*) = 0; | 1403     virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
      ::Handle<v8::Value>*) = 0; | 
| 1338     virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
      :Handle<v8::Value>*) = 0; | 1404     virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
      :Handle<v8::Value>*) = 0; | 
| 1339 }; | 1405 }; | 
| 1340 | 1406 | 
| 1341 // Reader is responsible for deserializing primitive types and | 1407 // Reader is responsible for deserializing primitive types and | 
| 1342 // restoring information about saved objects of composite types. | 1408 // restoring information about saved objects of composite types. | 
| 1343 class Reader { | 1409 class Reader { | 
| 1344 public: | 1410 public: | 
| 1345     Reader(const uint8_t* buffer, int length, v8::Isolate* isolate) | 1411     Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const Vector
      <BlobInfo>* blobInfo) | 
| 1346         : m_buffer(buffer) | 1412         : m_buffer(buffer) | 
| 1347         , m_length(length) | 1413         , m_length(length) | 
| 1348         , m_position(0) | 1414         , m_position(0) | 
| 1349         , m_version(0) | 1415         , m_version(0) | 
| 1350         , m_isolate(isolate) | 1416         , m_isolate(isolate) | 
|  | 1417         , m_blobInfo(blobInfo) | 
| 1351     { | 1418     { | 
| 1352         ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); | 1419         ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); | 
| 1353         ASSERT(length >= 0); | 1420         ASSERT(length >= 0); | 
| 1354     } | 1421     } | 
| 1355 | 1422 | 
| 1356     bool isEof() const { return m_position >= m_length; } | 1423     bool isEof() const { return m_position >= m_length; } | 
| 1357 | 1424 | 
| 1358     bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) | 1425     bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) | 
| 1359     { | 1426     { | 
| 1360         SerializationTag tag; | 1427         SerializationTag tag; | 
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1854             return false; | 1921             return false; | 
| 1855         *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx
      p::Flags>(flags)); | 1922         *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx
      p::Flags>(flags)); | 
| 1856         return true; | 1923         return true; | 
| 1857     } | 1924     } | 
| 1858 | 1925 | 
| 1859     bool readBlob(v8::Handle<v8::Value>* value) | 1926     bool readBlob(v8::Handle<v8::Value>* value) | 
| 1860     { | 1927     { | 
| 1861         String url; | 1928         String url; | 
| 1862         String type; | 1929         String type; | 
| 1863         uint64_t size; | 1930         uint64_t size; | 
| 1864         if (!readWebCoreString(&url)) | 1931         if (m_blobInfo) { | 
| 1865             return false; | 1932             uint32_t index; | 
| 1866         if (!readWebCoreString(&type)) | 1933             if (!doReadUint32(&index) || index >= m_blobInfo->size()) | 
| 1867             return false; | 1934                 return false; | 
| 1868         if (!doReadUint64(&size)) | 1935             const BlobInfo& info = (*m_blobInfo)[index]; | 
| 1869             return false; | 1936             url = info.url(); | 
| 1870         PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s
      ize); | 1937             type = info.type(); | 
| 1871         *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); | 1938             size = info.size(); | 
|  | 1939         } else { | 
|  | 1940             if (!readWebCoreString(&url)) | 
|  | 1941                 return false; | 
|  | 1942             if (!readWebCoreString(&type)) | 
|  | 1943                 return false; | 
|  | 1944             if (!doReadUint64(&size)) | 
|  | 1945                 return false; | 
|  | 1946         } | 
|  | 1947         RefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, size)
      ; | 
|  | 1948         *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate); | 
| 1872         return true; | 1949         return true; | 
| 1873     } | 1950     } | 
| 1874 | 1951 | 
| 1875     bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 1952     bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 
| 1876     { | 1953     { | 
| 1877         uint32_t type; | 1954         uint32_t type; | 
| 1878         String name; | 1955         String name; | 
| 1879         String url; | 1956         String url; | 
| 1880         if (!doReadUint32(&type)) | 1957         if (!doReadUint32(&type)) | 
| 1881             return false; | 1958             return false; | 
| 1882         if (!readWebCoreString(&name)) | 1959         if (!readWebCoreString(&name)) | 
| 1883             return false; | 1960             return false; | 
| 1884         if (!readWebCoreString(&url)) | 1961         if (!readWebCoreString(&url)) | 
| 1885             return false; | 1962             return false; | 
| 1886         RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte
      xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur
      l)); | 1963         RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte
      xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur
      l)); | 
| 1887         *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); | 1964         *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); | 
| 1888         return true; | 1965         return true; | 
| 1889     } | 1966     } | 
| 1890 | 1967 | 
|  | 1968     PassRefPtr<File> readSingleFile() | 
|  | 1969     { | 
|  | 1970         RefPtr<File> file; | 
|  | 1971         if (m_blobInfo) { | 
|  | 1972             uint32_t index; | 
|  | 1973             if (!doReadUint32(&index) || index >= m_blobInfo->size()) | 
|  | 1974                 return file; | 
|  | 1975             const BlobInfo& info = (*m_blobInfo)[index]; | 
|  | 1976             file = File::create(info.filePath(), info.fileName(), KURL(ParsedURL
      String, info.url()), info.type(), info.lastModified(), info.size()); | 
|  | 1977             return file; | 
|  | 1978         } | 
|  | 1979         String path; | 
|  | 1980         String url; | 
|  | 1981         String type; | 
|  | 1982         if (!readWebCoreString(&path)) | 
|  | 1983             return file; | 
|  | 1984         if (!readWebCoreString(&url)) | 
|  | 1985             return file; | 
|  | 1986         if (!readWebCoreString(&type)) | 
|  | 1987             return file; | 
|  | 1988         return File::create(path, KURL(ParsedURLString, url), type); | 
|  | 1989     } | 
|  | 1990 | 
| 1891     bool readFile(v8::Handle<v8::Value>* value) | 1991     bool readFile(v8::Handle<v8::Value>* value) | 
| 1892     { | 1992     { | 
| 1893         String path; | 1993         RefPtr<File> file = readSingleFile(); | 
| 1894         String url; | 1994         if (!file.get()) | 
| 1895         String type; |  | 
| 1896         if (!readWebCoreString(&path)) |  | 
| 1897             return false; | 1995             return false; | 
| 1898         if (!readWebCoreString(&url)) | 1996 | 
| 1899             return false; | 1997         *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate); | 
| 1900         if (!readWebCoreString(&type)) |  | 
| 1901             return false; |  | 
| 1902         PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), t
      ype); |  | 
| 1903         *value = toV8(file, v8::Handle<v8::Object>(), m_isolate); |  | 
| 1904         return true; | 1998         return true; | 
| 1905     } | 1999     } | 
| 1906 | 2000 | 
| 1907     bool readFileList(v8::Handle<v8::Value>* value) | 2001     bool readFileList(v8::Handle<v8::Value>* value) | 
| 1908     { | 2002     { | 
| 1909         uint32_t length; | 2003         uint32_t length; | 
| 1910         if (!doReadUint32(&length)) | 2004         if (!doReadUint32(&length)) | 
| 1911             return false; | 2005             return false; | 
| 1912         PassRefPtr<FileList> fileList = FileList::create(); | 2006         RefPtr<FileList> fileList = FileList::create(); | 
| 1913         for (unsigned i = 0; i < length; ++i) { | 2007         for (unsigned i = 0; i < length; ++i) { | 
| 1914             String path; | 2008             RefPtr<File> file = readSingleFile(); | 
| 1915             String urlString; | 2009             if (!file.get()) | 
| 1916             String type; |  | 
| 1917             if (!readWebCoreString(&path)) |  | 
| 1918                 return false; | 2010                 return false; | 
| 1919             if (!readWebCoreString(&urlString)) | 2011             fileList->append(file.get()); | 
| 1920                 return false; |  | 
| 1921             if (!readWebCoreString(&type)) |  | 
| 1922                 return false; |  | 
| 1923             fileList->append(File::create(path, KURL(ParsedURLString, urlString)
      , type)); |  | 
| 1924         } | 2012         } | 
| 1925         *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate); | 2013         *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); | 
| 1926         return true; | 2014         return true; | 
| 1927     } | 2015     } | 
| 1928 | 2016 | 
| 1929     template<class T> | 2017     template<class T> | 
| 1930     bool doReadUintHelper(T* value) | 2018     bool doReadUintHelper(T* value) | 
| 1931     { | 2019     { | 
| 1932         *value = 0; | 2020         *value = 0; | 
| 1933         uint8_t currentByte; | 2021         uint8_t currentByte; | 
| 1934         int shift = 0; | 2022         int shift = 0; | 
| 1935         do { | 2023         do { | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 1960         for (unsigned i = 0; i < sizeof(double); ++i) | 2048         for (unsigned i = 0; i < sizeof(double); ++i) | 
| 1961             numberAsByteArray[i] = m_buffer[m_position++]; | 2049             numberAsByteArray[i] = m_buffer[m_position++]; | 
| 1962         return true; | 2050         return true; | 
| 1963     } | 2051     } | 
| 1964 | 2052 | 
| 1965     const uint8_t* m_buffer; | 2053     const uint8_t* m_buffer; | 
| 1966     const unsigned m_length; | 2054     const unsigned m_length; | 
| 1967     unsigned m_position; | 2055     unsigned m_position; | 
| 1968     uint32_t m_version; | 2056     uint32_t m_version; | 
| 1969     v8::Isolate* m_isolate; | 2057     v8::Isolate* m_isolate; | 
|  | 2058     const Vector<BlobInfo>* m_blobInfo; | 
| 1970 }; | 2059 }; | 
| 1971 | 2060 | 
| 1972 | 2061 | 
| 1973 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 2062 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 
| 1974 | 2063 | 
| 1975 class Deserializer : public CompositeCreator { | 2064 class Deserializer : public CompositeCreator { | 
| 1976 public: | 2065 public: | 
| 1977     Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont
      entsArray* arrayBufferContents) | 2066     Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont
      entsArray* arrayBufferContents) | 
| 1978         : m_reader(reader) | 2067         : m_reader(reader) | 
| 1979         , m_transferredMessagePorts(messagePorts) | 2068         , m_transferredMessagePorts(messagePorts) | 
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2220     Vector<v8::Handle<v8::Value> > m_objectPool; | 2309     Vector<v8::Handle<v8::Value> > m_objectPool; | 
| 2221     Vector<uint32_t> m_openCompositeReferenceStack; | 2310     Vector<uint32_t> m_openCompositeReferenceStack; | 
| 2222     MessagePortArray* m_transferredMessagePorts; | 2311     MessagePortArray* m_transferredMessagePorts; | 
| 2223     ArrayBufferContentsArray* m_arrayBufferContents; | 2312     ArrayBufferContentsArray* m_arrayBufferContents; | 
| 2224     Vector<v8::Handle<v8::Object> > m_arrayBuffers; | 2313     Vector<v8::Handle<v8::Object> > m_arrayBuffers; | 
| 2225     uint32_t m_version; | 2314     uint32_t m_version; | 
| 2226 }; | 2315 }; | 
| 2227 | 2316 | 
| 2228 } // namespace | 2317 } // namespace | 
| 2229 | 2318 | 
|  | 2319 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
      alue> value, Vector<BlobInfo>* blobInfo, bool& didThrow) | 
|  | 2320 { | 
|  | 2321     return create(value, 0, 0, blobInfo, didThrow, v8::Isolate::GetCurrent()); | 
|  | 2322 } | 
|  | 2323 | 
| 2230 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
      alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, boo
      l& didThrow, v8::Isolate* isolate) | 2324 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
      alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, boo
      l& didThrow, v8::Isolate* isolate) | 
| 2231 { | 2325 { | 
| 2232     return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers,
       didThrow, isolate)); | 2326     return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers,
       0, didThrow, isolate)); | 
|  | 2327 } | 
|  | 2328 | 
|  | 2329 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
      alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vec
      tor<BlobInfo>* blobInfo, bool& didThrow, v8::Isolate* isolate) | 
|  | 2330 { | 
|  | 2331     return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers,
       blobInfo, didThrow, isolate)); | 
| 2233 } | 2332 } | 
| 2234 | 2333 | 
| 2235 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
      alue> value, v8::Isolate* isolate) | 2334 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
      alue> value, v8::Isolate* isolate) | 
| 2236 { | 2335 { | 
| 2237     bool didThrow; | 2336     bool didThrow; | 
| 2238     return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate)); | 2337     return adoptRef(new SerializedScriptValue(value, 0, 0, 0, didThrow, isolate)
      ); | 
| 2239 } | 2338 } | 
| 2240 | 2339 | 
| 2241 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti
      ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 2340 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti
      ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 
| 2242 { | 2341 { | 
| 2243     bool didThrow; | 2342     bool didThrow; | 
| 2244     return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate, Do
      NotThrowExceptions)); | 2343     return adoptRef(new SerializedScriptValue(value, 0, 0, 0, didThrow, isolate,
       DoNotThrowExceptions)); | 
| 2245 } | 2344 } | 
| 2246 | 2345 | 
| 2247 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St
      ring& data) | 2346 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St
      ring& data) | 
| 2248 { | 2347 { | 
| 2249     return adoptRef(new SerializedScriptValue(data)); | 2348     return adoptRef(new SerializedScriptValue(data)); | 
| 2250 } | 2349 } | 
| 2251 | 2350 | 
| 2252 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con
      st Vector<uint8_t>& data) | 2351 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con
      st Vector<uint8_t>& data) | 
| 2253 { | 2352 { | 
| 2254     // Decode wire data from big endian to host byte order. | 2353     // Decode wire data from big endian to host byte order. | 
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2420             return nullptr; | 2519             return nullptr; | 
| 2421         } | 2520         } | 
| 2422 | 2521 | 
| 2423         neuterBinding(arrayBuffers[i].get()); | 2522         neuterBinding(arrayBuffers[i].get()); | 
| 2424         for (size_t j = 0; j < neuteredViews.size(); j++) | 2523         for (size_t j = 0; j < neuteredViews.size(); j++) | 
| 2425             neuterBinding(neuteredViews[j].get()); | 2524             neuterBinding(neuteredViews[j].get()); | 
| 2426     } | 2525     } | 
| 2427     return contents.release(); | 2526     return contents.release(); | 
| 2428 } | 2527 } | 
| 2429 | 2528 | 
| 2430 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag
      ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is
      olate* isolate, ExceptionPolicy policy) | 2529 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag
      ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<BlobInfo>* blob
      Info, bool& didThrow, v8::Isolate* isolate, ExceptionPolicy policy) | 
| 2431     : m_externallyAllocatedMemory(0) | 2530     : m_blobInfo(blobInfo) | 
|  | 2531     , m_externallyAllocatedMemory(0) | 
| 2432 { | 2532 { | 
| 2433     didThrow = false; | 2533     didThrow = false; | 
| 2434     Writer writer(isolate); | 2534     Writer writer(isolate); | 
| 2435     Serializer::Status status; | 2535     Serializer::Status status; | 
| 2436     { | 2536     { | 
| 2437         v8::TryCatch tryCatch; | 2537         v8::TryCatch tryCatch; | 
| 2438         Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr
      yCatch, isolate); | 2538         Serializer serializer(writer, messagePorts, arrayBuffers, m_blobInfo, tr
      yCatch, isolate); | 
| 2439         status = serializer.serialize(value); | 2539         status = serializer.serialize(value); | 
| 2440         if (status == Serializer::JSException) { | 2540         if (status == Serializer::JSException) { | 
| 2441             didThrow = true; | 2541             didThrow = true; | 
| 2442             // If there was a JS exception thrown, re-throw it. | 2542             // If there was a JS exception thrown, re-throw it. | 
| 2443             if (policy == ThrowExceptions) | 2543             if (policy == ThrowExceptions) | 
| 2444                 tryCatch.ReThrow(); | 2544                 tryCatch.ReThrow(); | 
| 2445             return; | 2545             return; | 
| 2446         } | 2546         } | 
| 2447     } | 2547     } | 
| 2448     switch (status) { | 2548     switch (status) { | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 2479 } | 2579 } | 
| 2480 | 2580 | 
| 2481 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 2581 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 
| 2482     : m_externallyAllocatedMemory(0) | 2582     : m_externallyAllocatedMemory(0) | 
| 2483 { | 2583 { | 
| 2484     m_data = wireData.isolatedCopy(); | 2584     m_data = wireData.isolatedCopy(); | 
| 2485 } | 2585 } | 
| 2486 | 2586 | 
| 2487 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa
      gePorts) | 2587 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa
      gePorts) | 
| 2488 { | 2588 { | 
| 2489     return deserialize(v8::Isolate::GetCurrent(), messagePorts); | 2589     return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); | 
| 2490 } | 2590 } | 
| 2491 | 2591 | 
| 2492 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M
      essagePortArray* messagePorts) | 2592 v8::Handle<v8::Value> SerializedScriptValue::deserialize(const Vector<BlobInfo>*
       blobInfo) | 
|  | 2593 { | 
|  | 2594     return deserialize(v8::Isolate::GetCurrent(), 0, blobInfo); | 
|  | 2595 } | 
|  | 2596 | 
|  | 2597 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M
      essagePortArray* messagePorts, const Vector<BlobInfo>* blobInfo) | 
| 2493 { | 2598 { | 
| 2494     if (!m_data.impl()) | 2599     if (!m_data.impl()) | 
| 2495         return v8NullWithCheck(isolate); | 2600         return v8NullWithCheck(isolate); | 
| 2496     COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 2601     COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 
| 2497     m_data.ensure16Bit(); | 2602     m_data.ensure16Bit(); | 
| 2498     // FIXME: SerializedScriptValue shouldn't use String for its underlying | 2603     // FIXME: SerializedScriptValue shouldn't use String for its underlying | 
| 2499     // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 2604     // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 
| 2500     // information stored in m_data isn't even encoded in UTF-16. Instead, | 2605     // information stored in m_data isn't even encoded in UTF-16. Instead, | 
| 2501     // unicode characters are encoded as UTF-8 with two code units per UChar. | 2606     // unicode characters are encoded as UTF-8 with two code units per UChar. | 
| 2502     Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16()
      ), 2 * m_data.length(), isolate); | 2607     Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16()
      ), 2 * m_data.length(), isolate, blobInfo); | 
| 2503     Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
      et()); | 2608     Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
      et()); | 
| 2504 | 2609 | 
| 2505     // deserialize() can run arbitrary script (e.g., setters), which could resul
      t in |this| being destroyed. | 2610     // deserialize() can run arbitrary script (e.g., setters), which could resul
      t in |this| being destroyed. | 
| 2506     // Holding a RefPtr ensures we are alive (along with our internal data) thro
      ughout the operation. | 2611     // Holding a RefPtr ensures we are alive (along with our internal data) thro
      ughout the operation. | 
| 2507     RefPtr<SerializedScriptValue> protect(this); | 2612     RefPtr<SerializedScriptValue> protect(this); | 
| 2508     return deserializer.deserialize(); | 2613     return deserializer.deserialize(); | 
| 2509 } | 2614 } | 
| 2510 | 2615 | 
| 2511 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt
      ate) | 2616 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt
      ate) | 
| 2512 { | 2617 { | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 2534         v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
      ry); | 2639         v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
      ry); | 
| 2535     } | 2640     } | 
| 2536 } | 2641 } | 
| 2537 | 2642 | 
| 2538 uint32_t SerializedScriptValue::wireFormatVersion() | 2643 uint32_t SerializedScriptValue::wireFormatVersion() | 
| 2539 { | 2644 { | 
| 2540     return WebCore::wireFormatVersion; | 2645     return WebCore::wireFormatVersion; | 
| 2541 } | 2646 } | 
| 2542 | 2647 | 
| 2543 } // namespace WebCore | 2648 } // namespace WebCore | 
| OLD | NEW | 
|---|