| Index: third_party/WebKit/Source/modules/indexeddb/IDBMojoUtil.cpp
|
| diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBMojoUtil.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBMojoUtil.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0669157ccc6f53ff924ee5dc1d5c045bdb50b09e
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBMojoUtil.cpp
|
| @@ -0,0 +1,192 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "modules/indexeddb/IDBMojoUtil.h"
|
| +
|
| +#include "modules/indexeddb/IDBKey.h"
|
| +#include "modules/indexeddb/IDBKeyPath.h"
|
| +#include "modules/indexeddb/IDBKeyRange.h"
|
| +#include "public/platform/WebBlobInfo.h"
|
| +
|
| +namespace blink {
|
| +
|
| +using indexed_db::mojom::blink::BlobInfoPtr;
|
| +using indexed_db::mojom::blink::KeyPathPtr;
|
| +using indexed_db::mojom::blink::KeyPathType;
|
| +using indexed_db::mojom::blink::KeyPtr;
|
| +using indexed_db::mojom::blink::KeyRangePtr;
|
| +
|
| +WebIDBValue createValue(const indexed_db::mojom::blink::ValuePtr&)
|
| +{
|
| + return WebIDBValue();
|
| +}
|
| +
|
| +KeyPtr createKey(const IDBKey* idbKey)
|
| +{
|
| + if (idbKey->getType() == IDBKey::InvalidType || idbKey->getType() == IDBKey::MinType)
|
| + return nullptr;
|
| +
|
| + KeyPtr mojoKey = indexed_db::mojom::blink::Key::New();
|
| +
|
| + switch (idbKey->getType()) {
|
| + case IDBKey::InvalidType:
|
| + case IDBKey::MinType:
|
| + NOTREACHED();
|
| + break;
|
| + case IDBKey::ArrayType: {
|
| + mojoKey->data = indexed_db::mojom::blink::KeyData::New();
|
| + Vector<KeyPtr> data(idbKey->array().size());
|
| + for (size_t i = 0; i < idbKey->array().size(); i++)
|
| + data[i] = createKey(idbKey->array()[i]);
|
| + mojoKey->data->set_array_data(std::move(data));
|
| + mojoKey->type = indexed_db::mojom::blink::KeyType::Array;
|
| + } break;
|
| + case IDBKey::BinaryType:
|
| + mojoKey->data = indexed_db::mojom::blink::KeyData::New();
|
| + mojoKey->type = indexed_db::mojom::blink::KeyType::Binary;
|
| + break;
|
| + case IDBKey::StringType:
|
| + mojoKey->type = indexed_db::mojom::blink::KeyType::String;
|
| + mojoKey->data->set_string_data(idbKey->string());
|
| + break;
|
| + case IDBKey::DateType:
|
| + mojoKey->type = indexed_db::mojom::blink::KeyType::Date;
|
| + mojoKey->data->set_date(idbKey->date());
|
| + break;
|
| + case IDBKey::NumberType:
|
| + mojoKey->type = indexed_db::mojom::blink::KeyType::Number;
|
| + mojoKey->data->set_number(idbKey->number());
|
| + break;
|
| + }
|
| +
|
| + return mojoKey;
|
| +}
|
| +
|
| +static IDBKey::KeyArray createKeyArray(const mojo::WTFArray<KeyPtr>& array)
|
| +{
|
| + IDBKey::KeyArray keyArray;
|
| +
|
| + for (size_t i = 0; i < array.size(); i++) {
|
| + keyArray.append(createKey(array[i]));
|
| + }
|
| +
|
| + return keyArray;
|
| +}
|
| +
|
| +PassRefPtr<SharedBuffer> createData(const mojo::WTFArray<uint8_t>& data)
|
| +{
|
| + RefPtr<SharedBuffer> webData;
|
| + return webData.release();
|
| +}
|
| +
|
| +PassRefPtr<SharedBuffer> createData(const mojo::WTFArray<int8_t>& data)
|
| +{
|
| + RefPtr<SharedBuffer> webData;
|
| + return webData.release();
|
| +}
|
| +
|
| +IDBKey* createKey(const KeyPtr& mojoKey)
|
| +{
|
| + if (!mojoKey)
|
| + return nullptr;
|
| +
|
| + switch (mojoKey->type) {
|
| + case indexed_db::mojom::blink::KeyType::Invalid:
|
| + return IDBKey::createInvalid();
|
| + case indexed_db::mojom::blink::KeyType::Array:
|
| + return IDBKey::createArray(createKeyArray(mojoKey->data->get_array_data()));
|
| + case indexed_db::mojom::blink::KeyType::Binary:
|
| + return IDBKey::createBinary(createData(mojoKey->data->get_binary_data()));
|
| + case indexed_db::mojom::blink::KeyType::String:
|
| + return IDBKey::createString(mojoKey->data->get_string_data());
|
| + case indexed_db::mojom::blink::KeyType::Date:
|
| + return IDBKey::createDate(mojoKey->data->get_date());
|
| + case indexed_db::mojom::blink::KeyType::Number:
|
| + return IDBKey::createNumber(mojoKey->data->get_number());
|
| + }
|
| +}
|
| +
|
| +// TODO(cmumford): Can we use Mojo type-mapping? If not should it be moved to a utility file?
|
| +KeyRangePtr createKeyRange(const IDBKeyRange* keyRange)
|
| +{
|
| + if (!keyRange)
|
| + return nullptr;
|
| +
|
| + KeyRangePtr range = indexed_db::mojom::blink::KeyRange::New();
|
| + range->lower_open = keyRange->lowerOpen();
|
| + range->lower = createKey(keyRange->lower());
|
| + range->upper_open = keyRange->upperOpen();
|
| + range->upper = createKey(keyRange->upper());
|
| +
|
| + return range;
|
| +}
|
| +
|
| +KeyRangePtr createKeyRange(ExecutionContext* context, const ScriptValue& value, ExceptionState& exceptionState)
|
| +{
|
| + return createKeyRange(IDBKeyRange::fromScriptValue(context, value, exceptionState));
|
| +}
|
| +
|
| +IDBKeyPath createKeyPath(const indexed_db::mojom::blink::KeyPathPtr&)
|
| +{
|
| + IDBKeyPath keyPath;
|
| +
|
| + return keyPath;
|
| +}
|
| +
|
| +KeyPathPtr createKeyPath(const IDBKeyPath& value)
|
| +{
|
| + if (!value.isValid())
|
| + return nullptr;
|
| +
|
| + KeyPathPtr keyPath = indexed_db::mojom::blink::KeyPath::New();
|
| +
|
| + switch (value.getType()) {
|
| + case IDBKeyPath::NullType:
|
| + keyPath->type = KeyPathType::NONE;
|
| + break;
|
| + case IDBKeyPath::StringType:
|
| + keyPath->type = KeyPathType::STRING;
|
| + keyPath->data->set_str(value.string());
|
| + break;
|
| + case IDBKeyPath::ArrayType: {
|
| + keyPath->type = KeyPathType::ARRAY;
|
| + Vector<String> strings;
|
| + for (const auto& str : value.array())
|
| + strings.append(str);
|
| + keyPath->data->set_arr(std::move(strings));
|
| + } break;
|
| + }
|
| +
|
| + return keyPath;
|
| +}
|
| +
|
| +BlobInfoPtr createBlobInfo(const WebBlobInfo& info)
|
| +{
|
| + BlobInfoPtr blobInfo = indexed_db::mojom::blink::BlobInfo::New();
|
| +
|
| + blobInfo->is_file = info.isFile();
|
| + blobInfo->uuid = info.uuid();
|
| + blobInfo->type = info.type();
|
| + blobInfo->size = info.size();
|
| +
|
| + if (info.isFile()) {
|
| + blobInfo->file_path = info.filePath();
|
| + blobInfo->file_name = info.fileName();
|
| + blobInfo->last_modified = info.lastModified();
|
| + }
|
| +
|
| + return blobInfo;
|
| +}
|
| +
|
| +Vector<BlobInfoPtr> createBlobInfo(const Vector<WebBlobInfo>& blobInfo)
|
| +{
|
| + Vector<BlobInfoPtr> ret(blobInfo.size());
|
| +
|
| + for (size_t i = 0; i < blobInfo.size(); i++)
|
| + ret[i] = createBlobInfo(blobInfo[i]);
|
| +
|
| + return ret;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|