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

Unified Diff: Source/bindings/core/v8/ScriptValueSerializer.cpp

Issue 718383003: bindings: fixed incorrect dependency of SerializedScriptValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/core/v8/ScriptValueSerializer.cpp
diff --git a/Source/bindings/core/v8/ScriptValueSerializer.cpp b/Source/bindings/core/v8/ScriptValueSerializer.cpp
index 38455c8c93d06ea54e9ab0d119fd143cc6da7331..d0579803007e68d00737362d02e994bbc0f59cb4 100644
--- a/Source/bindings/core/v8/ScriptValueSerializer.cpp
+++ b/Source/bindings/core/v8/ScriptValueSerializer.cpp
@@ -12,8 +12,6 @@
#include "bindings/core/v8/V8FileList.h"
#include "bindings/core/v8/V8ImageData.h"
#include "bindings/core/v8/V8MessagePort.h"
-#include "bindings/modules/v8/V8CryptoKey.h"
-#include "bindings/modules/v8/V8DOMFileSystem.h"
#include "core/dom/DOMDataView.h"
#include "core/fileapi/Blob.h"
#include "core/fileapi/File.h"
@@ -197,14 +195,6 @@ void Writer::writeBlob(const String& uuid, const String& type, unsigned long lon
doWriteUint64(size);
}
-void Writer::writeDOMFileSystem(int type, const String& name, const String& url)
-{
- append(DOMFileSystemTag);
- doWriteUint32(type);
- doWriteWebCoreString(name);
- doWriteWebCoreString(url);
-}
-
tasak 2014/11/14 08:07:39 Moved to ScriptValueSerializerForModules.cpp
void Writer::writeBlobIndex(int blobIndex)
{
ASSERT(blobIndex >= 0);
@@ -242,39 +232,6 @@ void Writer::writeFileListIndex(const Vector<int>& blobIndices)
doWriteUint32(blobIndices[i]);
}
-bool Writer::writeCryptoKey(const WebCryptoKey& key)
-{
- append(static_cast<uint8_t>(CryptoKeyTag));
-
- switch (key.algorithm().paramsType()) {
- case WebCryptoKeyAlgorithmParamsTypeAes:
- doWriteAesKey(key);
- break;
- case WebCryptoKeyAlgorithmParamsTypeHmac:
- doWriteHmacKey(key);
- break;
- case WebCryptoKeyAlgorithmParamsTypeRsaHashed:
- doWriteRsaHashedKey(key);
- break;
- case WebCryptoKeyAlgorithmParamsTypeEc:
- doWriteEcKey(key);
- break;
- case WebCryptoKeyAlgorithmParamsTypeNone:
- ASSERT_NOT_REACHED();
- return false;
- }
-
- doWriteKeyUsages(key.usages(), key.extractable());
-
- WebVector<uint8_t> keyData;
- if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData))
- return false;
-
- doWriteUint32(keyData.size());
- append(keyData.data(), keyData.size());
- return true;
-}
-
void Writer::writeArrayBuffer(const ArrayBuffer& arrayBuffer)
{
append(ArrayBufferTag);
@@ -447,143 +404,6 @@ void Writer::doWriteWebCoreString(const String& string)
doWriteString(stringUTF8.data(), stringUTF8.length());
}
-void Writer::doWriteHmacKey(const WebCryptoKey& key)
-{
- ASSERT(key.algorithm().paramsType() == WebCryptoKeyAlgorithmParamsTypeHmac);
-
- append(static_cast<uint8_t>(HmacKeyTag));
- ASSERT(!(key.algorithm().hmacParams()->lengthBits() % 8));
- doWriteUint32(key.algorithm().hmacParams()->lengthBits() / 8);
- doWriteAlgorithmId(key.algorithm().hmacParams()->hash().id());
-}
-
-void Writer::doWriteAesKey(const WebCryptoKey& key)
-{
- ASSERT(key.algorithm().paramsType() == WebCryptoKeyAlgorithmParamsTypeAes);
-
- append(static_cast<uint8_t>(AesKeyTag));
- doWriteAlgorithmId(key.algorithm().id());
- // Converting the key length from bits to bytes is lossless and makes
- // it fit in 1 byte.
- ASSERT(!(key.algorithm().aesParams()->lengthBits() % 8));
- doWriteUint32(key.algorithm().aesParams()->lengthBits() / 8);
-}
-
-void Writer::doWriteRsaHashedKey(const WebCryptoKey& key)
-{
- ASSERT(key.algorithm().rsaHashedParams());
- append(static_cast<uint8_t>(RsaHashedKeyTag));
-
- doWriteAlgorithmId(key.algorithm().id());
- doWriteAsymmetricKeyType(key.type());
-
- const WebCryptoRsaHashedKeyAlgorithmParams* params = key.algorithm().rsaHashedParams();
- doWriteUint32(params->modulusLengthBits());
- doWriteUint32(params->publicExponent().size());
- append(params->publicExponent().data(), params->publicExponent().size());
- doWriteAlgorithmId(params->hash().id());
-}
-
-void Writer::doWriteEcKey(const WebCryptoKey& key)
-{
- ASSERT(key.algorithm().ecParams());
- append(static_cast<uint8_t>(EcKeyTag));
-
- doWriteAlgorithmId(key.algorithm().id());
- doWriteAsymmetricKeyType(key.type());
- doWriteNamedCurve(key.algorithm().ecParams()->namedCurve());
-}
-
-void Writer::doWriteAlgorithmId(WebCryptoAlgorithmId id)
-{
- switch (id) {
- case WebCryptoAlgorithmIdAesCbc:
- return doWriteUint32(AesCbcTag);
- case WebCryptoAlgorithmIdHmac:
- return doWriteUint32(HmacTag);
- case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
- return doWriteUint32(RsaSsaPkcs1v1_5Tag);
- case WebCryptoAlgorithmIdSha1:
- return doWriteUint32(Sha1Tag);
- case WebCryptoAlgorithmIdSha256:
- return doWriteUint32(Sha256Tag);
- case WebCryptoAlgorithmIdSha384:
- return doWriteUint32(Sha384Tag);
- case WebCryptoAlgorithmIdSha512:
- return doWriteUint32(Sha512Tag);
- case WebCryptoAlgorithmIdAesGcm:
- return doWriteUint32(AesGcmTag);
- case WebCryptoAlgorithmIdRsaOaep:
- return doWriteUint32(RsaOaepTag);
- case WebCryptoAlgorithmIdAesCtr:
- return doWriteUint32(AesCtrTag);
- case WebCryptoAlgorithmIdAesKw:
- return doWriteUint32(AesKwTag);
- case WebCryptoAlgorithmIdRsaPss:
- return doWriteUint32(RsaPssTag);
- case WebCryptoAlgorithmIdEcdsa:
- return doWriteUint32(EcdsaTag);
- }
- ASSERT_NOT_REACHED();
-}
-
-void Writer::doWriteAsymmetricKeyType(WebCryptoKeyType keyType)
-{
- switch (keyType) {
- case WebCryptoKeyTypePublic:
- doWriteUint32(PublicKeyType);
- break;
- case WebCryptoKeyTypePrivate:
- doWriteUint32(PrivateKeyType);
- break;
- case WebCryptoKeyTypeSecret:
- ASSERT_NOT_REACHED();
- }
-}
-
-void Writer::doWriteNamedCurve(WebCryptoNamedCurve namedCurve)
-{
- switch (namedCurve) {
- case WebCryptoNamedCurveP256:
- return doWriteUint32(P256Tag);
- case WebCryptoNamedCurveP384:
- return doWriteUint32(P384Tag);
- case WebCryptoNamedCurveP521:
- return doWriteUint32(P521Tag);
- }
- ASSERT_NOT_REACHED();
-}
-
-void Writer::doWriteKeyUsages(const WebCryptoKeyUsageMask usages, bool extractable)
-{
- // Reminder to update this when adding new key usages.
- COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe);
-
- uint32_t value = 0;
-
- if (extractable)
- value |= ExtractableUsage;
-
- if (usages & WebCryptoKeyUsageEncrypt)
- value |= EncryptUsage;
- if (usages & WebCryptoKeyUsageDecrypt)
- value |= DecryptUsage;
- if (usages & WebCryptoKeyUsageSign)
- value |= SignUsage;
- if (usages & WebCryptoKeyUsageVerify)
- value |= VerifyUsage;
- if (usages & WebCryptoKeyUsageDeriveKey)
- value |= DeriveKeyUsage;
- if (usages & WebCryptoKeyUsageWrapKey)
- value |= WrapKeyUsage;
- if (usages & WebCryptoKeyUsageUnwrapKey)
- value |= UnwrapKeyUsage;
- if (usages & WebCryptoKeyUsageDeriveBits)
- value |= DeriveBitsUsage;
-
- doWriteUint32(value);
-}
-
int Writer::bytesNeededToWireEncode(uint32_t value)
{
int bytes = 1;
@@ -868,13 +688,8 @@ Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Seri
return writeFile(value, next);
} else if (V8Blob::hasInstance(value, isolate())) {
return writeBlob(value, next);
- } else if (V8DOMFileSystem::hasInstance(value, isolate())) {
- return writeDOMFileSystem(value, next);
} else if (V8FileList::hasInstance(value, isolate())) {
return writeFileList(value, next);
- } else if (V8CryptoKey::hasInstance(value, isolate())) {
- if (!writeCryptoKey(value))
- return handleError(DataCloneError, "Couldn't serialize key data", next);
} else if (V8ImageData::hasInstance(value, isolate())) {
writeImageData(value);
} else if (value->IsRegExp()) {
@@ -992,17 +807,6 @@ Serializer::StateBase* Serializer::writeBlob(v8::Handle<v8::Value> value, Serial
return 0;
}
-Serializer::StateBase* Serializer::writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next)
-{
- DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>());
- if (!fs)
- return 0;
- if (!fs->clonable())
- return handleError(DataCloneError, "A FileSystem object could not be cloned.", next);
- m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string());
- return 0;
-}
-
Serializer::StateBase* Serializer::writeFile(v8::Handle<v8::Value> value, Serializer::StateBase* next)
{
File* file = V8File::toImpl(value.As<v8::Object>());
@@ -1047,14 +851,6 @@ Serializer::StateBase* Serializer::writeFileList(v8::Handle<v8::Value> value, Se
return 0;
}
-bool Serializer::writeCryptoKey(v8::Handle<v8::Value> value)
-{
- CryptoKey* key = V8CryptoKey::toImpl(value.As<v8::Object>());
- if (!key)
- return false;
- return m_writer.writeCryptoKey(key->key());
-}
-
void Serializer::writeImageData(v8::Handle<v8::Value> value)
{
ImageData* imageData = V8ImageData::toImpl(value.As<v8::Object>());
@@ -1190,6 +986,11 @@ bool Reader::read(v8::Handle<v8::Value>* value, CompositeCreator& creator)
SerializationTag tag;
if (!readTag(&tag))
return false;
+ return readWithTag(tag, value, creator);
+}
+
+bool Reader::readWithTag(SerializationTag tag, v8::Handle<v8::Value>* value, CompositeCreator& creator)
+{
switch (tag) {
case ReferenceCountTag: {
if (!m_version)
@@ -1275,22 +1076,12 @@ bool Reader::read(v8::Handle<v8::Value>* value, CompositeCreator& creator)
return false;
creator.pushObjectReference(*value);
break;
- case DOMFileSystemTag:
- if (!readDOMFileSystem(value))
- return false;
- creator.pushObjectReference(*value);
- break;
case FileListTag:
case FileListIndexTag:
if (!readFileList(value, tag == FileListIndexTag))
return false;
creator.pushObjectReference(*value);
break;
- case CryptoKeyTag:
- if (!readCryptoKey(value))
- return false;
- creator.pushObjectReference(*value);
- break;
case ImageDataTag:
if (!readImageData(value))
return false;
@@ -1405,6 +1196,9 @@ bool Reader::read(v8::Handle<v8::Value>* value, CompositeCreator& creator)
return false;
break;
}
+ case DOMFileSystemTag:
+ case CryptoKeyTag:
+ ASSERT_NOT_REACHED();
default:
return false;
}
@@ -1722,22 +1516,6 @@ bool Reader::readBlob(v8::Handle<v8::Value>* value, bool isIndexed)
return true;
}
-bool Reader::readDOMFileSystem(v8::Handle<v8::Value>* value)
-{
- uint32_t type;
- String name;
- String url;
- if (!doReadUint32(&type))
- return false;
- if (!readWebCoreString(&name))
- return false;
- if (!readWebCoreString(&url))
- return false;
- DOMFileSystem* fs = DOMFileSystem::create(m_scriptState->executionContext(), name, static_cast<FileSystemType>(type), KURL(ParsedURLString, url));
- *value = toV8(fs, m_scriptState->context()->Global(), isolate());
- return true;
-}
-
bool Reader::readFile(v8::Handle<v8::Value>* value, bool isIndexed)
{
File* file = nullptr;
@@ -1779,61 +1557,6 @@ bool Reader::readFileList(v8::Handle<v8::Value>* value, bool isIndexed)
return true;
}
-bool Reader::readCryptoKey(v8::Handle<v8::Value>* value)
-{
- uint32_t rawKeyType;
- if (!doReadUint32(&rawKeyType))
- return false;
-
- WebCryptoKeyAlgorithm algorithm;
- WebCryptoKeyType type = WebCryptoKeyTypeSecret;
-
- switch (static_cast<CryptoKeySubTag>(rawKeyType)) {
- case AesKeyTag:
- if (!doReadAesKey(algorithm, type))
- return false;
- break;
- case HmacKeyTag:
- if (!doReadHmacKey(algorithm, type))
- return false;
- break;
- case RsaHashedKeyTag:
- if (!doReadRsaHashedKey(algorithm, type))
- return false;
- break;
- case EcKeyTag:
- if (!doReadEcKey(algorithm, type))
- return false;
- break;
- default:
- return false;
- }
-
- WebCryptoKeyUsageMask usages;
- bool extractable;
- if (!doReadKeyUsages(usages, extractable))
- return false;
-
- uint32_t keyDataLength;
- if (!doReadUint32(&keyDataLength))
- return false;
-
- if (m_position + keyDataLength > m_length)
- return false;
-
- const uint8_t* keyData = m_buffer + m_position;
- m_position += keyDataLength;
-
- WebCryptoKey key = WebCryptoKey::createNull();
- if (!Platform::current()->crypto()->deserializeKeyForClone(
- algorithm, type, extractable, usages, keyData, keyDataLength, key)) {
- return false;
- }
-
- *value = toV8(CryptoKey::create(key), m_scriptState->context()->Global(), isolate());
- return true;
-}
-
File* Reader::readFileHelper()
{
if (m_version < 3)
@@ -1924,208 +1647,6 @@ PassRefPtr<BlobDataHandle> Reader::getOrCreateBlobDataHandle(const String& uuid,
return BlobDataHandle::create(uuid, type, size);
}
-bool Reader::doReadHmacKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type)
-{
- uint32_t lengthBytes;
- if (!doReadUint32(&lengthBytes))
- return false;
- WebCryptoAlgorithmId hash;
- if (!doReadAlgorithmId(hash))
- return false;
- algorithm = WebCryptoKeyAlgorithm::createHmac(hash, lengthBytes * 8);
- type = WebCryptoKeyTypeSecret;
- return !algorithm.isNull();
-}
-
-bool Reader::doReadAesKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type)
-{
- WebCryptoAlgorithmId id;
- if (!doReadAlgorithmId(id))
- return false;
- uint32_t lengthBytes;
- if (!doReadUint32(&lengthBytes))
- return false;
- algorithm = WebCryptoKeyAlgorithm::createAes(id, lengthBytes * 8);
- type = WebCryptoKeyTypeSecret;
- return !algorithm.isNull();
-}
-
-bool Reader::doReadRsaHashedKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type)
-{
- WebCryptoAlgorithmId id;
- if (!doReadAlgorithmId(id))
- return false;
-
- if (!doReadAsymmetricKeyType(type))
- return false;
-
- uint32_t modulusLengthBits;
- if (!doReadUint32(&modulusLengthBits))
- return false;
-
- uint32_t publicExponentSize;
- if (!doReadUint32(&publicExponentSize))
- return false;
-
- if (m_position + publicExponentSize > m_length)
- return false;
-
- const uint8_t* publicExponent = m_buffer + m_position;
- m_position += publicExponentSize;
-
- WebCryptoAlgorithmId hash;
- if (!doReadAlgorithmId(hash))
- return false;
- algorithm = WebCryptoKeyAlgorithm::createRsaHashed(id, modulusLengthBits, publicExponent, publicExponentSize, hash);
-
- return !algorithm.isNull();
-}
-
-bool Reader::doReadEcKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type)
-{
- WebCryptoAlgorithmId id;
- if (!doReadAlgorithmId(id))
- return false;
-
- if (!doReadAsymmetricKeyType(type))
- return false;
-
- WebCryptoNamedCurve namedCurve;
- if (!doReadNamedCurve(namedCurve))
- return false;
-
- algorithm = WebCryptoKeyAlgorithm::createEc(id, namedCurve);
- return !algorithm.isNull();
-}
-
-bool Reader::doReadAlgorithmId(WebCryptoAlgorithmId& id)
-{
- uint32_t rawId;
- if (!doReadUint32(&rawId))
- return false;
-
- switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) {
- case AesCbcTag:
- id = WebCryptoAlgorithmIdAesCbc;
- return true;
- case HmacTag:
- id = WebCryptoAlgorithmIdHmac;
- return true;
- case RsaSsaPkcs1v1_5Tag:
- id = WebCryptoAlgorithmIdRsaSsaPkcs1v1_5;
- return true;
- case Sha1Tag:
- id = WebCryptoAlgorithmIdSha1;
- return true;
- case Sha256Tag:
- id = WebCryptoAlgorithmIdSha256;
- return true;
- case Sha384Tag:
- id = WebCryptoAlgorithmIdSha384;
- return true;
- case Sha512Tag:
- id = WebCryptoAlgorithmIdSha512;
- return true;
- case AesGcmTag:
- id = WebCryptoAlgorithmIdAesGcm;
- return true;
- case RsaOaepTag:
- id = WebCryptoAlgorithmIdRsaOaep;
- return true;
- case AesCtrTag:
- id = WebCryptoAlgorithmIdAesCtr;
- return true;
- case AesKwTag:
- id = WebCryptoAlgorithmIdAesKw;
- return true;
- case RsaPssTag:
- id = WebCryptoAlgorithmIdRsaPss;
- return true;
- case EcdsaTag:
- id = WebCryptoAlgorithmIdEcdsa;
- return true;
- }
-
- return false;
-}
-
-bool Reader::doReadAsymmetricKeyType(WebCryptoKeyType& type)
-{
- uint32_t rawType;
- if (!doReadUint32(&rawType))
- return false;
-
- switch (static_cast<AssymetricCryptoKeyType>(rawType)) {
- case PublicKeyType:
- type = WebCryptoKeyTypePublic;
- return true;
- case PrivateKeyType:
- type = WebCryptoKeyTypePrivate;
- return true;
- }
-
- return false;
-}
-
-bool Reader::doReadNamedCurve(WebCryptoNamedCurve& namedCurve)
-{
- uint32_t rawName;
- if (!doReadUint32(&rawName))
- return false;
-
- switch (static_cast<NamedCurveTag>(rawName)) {
- case P256Tag:
- namedCurve = WebCryptoNamedCurveP256;
- return true;
- case P384Tag:
- namedCurve = WebCryptoNamedCurveP384;
- return true;
- case P521Tag:
- namedCurve = WebCryptoNamedCurveP521;
- return true;
- }
-
- return false;
-}
-
-bool Reader::doReadKeyUsages(WebCryptoKeyUsageMask& usages, bool& extractable)
-{
- // Reminder to update this when adding new key usages.
- COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe);
- const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | DecryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyUsage | DeriveBitsUsage;
-
- uint32_t rawUsages;
- if (!doReadUint32(&rawUsages))
- return false;
-
- // Make sure it doesn't contain an unrecognized usage value.
- if (rawUsages & ~allPossibleUsages)
- return false;
-
- usages = 0;
-
- extractable = rawUsages & ExtractableUsage;
-
- if (rawUsages & EncryptUsage)
- usages |= WebCryptoKeyUsageEncrypt;
- if (rawUsages & DecryptUsage)
- usages |= WebCryptoKeyUsageDecrypt;
- if (rawUsages & SignUsage)
- usages |= WebCryptoKeyUsageSign;
- if (rawUsages & VerifyUsage)
- usages |= WebCryptoKeyUsageVerify;
- if (rawUsages & DeriveKeyUsage)
- usages |= WebCryptoKeyUsageDeriveKey;
- if (rawUsages & WrapKeyUsage)
- usages |= WebCryptoKeyUsageWrapKey;
- if (rawUsages & UnwrapKeyUsage)
- usages |= WebCryptoKeyUsageUnwrapKey;
- if (rawUsages & DeriveBitsUsage)
- usages |= WebCryptoKeyUsageDeriveBits;
-
- return true;
-}
-
v8::Handle<v8::Value> Deserializer::deserialize()
{
v8::Isolate* isolate = m_reader.scriptState()->isolate();

Powered by Google App Engine
This is Rietveld 408576698