OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/indexeddb/IDBMojoUtil.h" |
| 6 |
| 7 #include "modules/indexeddb/IDBKey.h" |
| 8 #include "modules/indexeddb/IDBKeyPath.h" |
| 9 #include "modules/indexeddb/IDBKeyRange.h" |
| 10 #include "public/platform/WebBlobInfo.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 using indexed_db::mojom::blink::BlobInfoPtr; |
| 15 using indexed_db::mojom::blink::KeyPathPtr; |
| 16 using indexed_db::mojom::blink::KeyPathType; |
| 17 using indexed_db::mojom::blink::KeyPtr; |
| 18 using indexed_db::mojom::blink::KeyRangePtr; |
| 19 |
| 20 WebIDBValue createValue(const indexed_db::mojom::blink::ValuePtr&) |
| 21 { |
| 22 return WebIDBValue(); |
| 23 } |
| 24 |
| 25 KeyPtr createKey(const IDBKey* idbKey) |
| 26 { |
| 27 if (idbKey->getType() == IDBKey::InvalidType || idbKey->getType() == IDBKey:
:MinType) |
| 28 return nullptr; |
| 29 |
| 30 KeyPtr mojoKey = indexed_db::mojom::blink::Key::New(); |
| 31 |
| 32 switch (idbKey->getType()) { |
| 33 case IDBKey::InvalidType: |
| 34 case IDBKey::MinType: |
| 35 NOTREACHED(); |
| 36 break; |
| 37 case IDBKey::ArrayType: { |
| 38 mojoKey->data = indexed_db::mojom::blink::KeyData::New(); |
| 39 Vector<KeyPtr> data(idbKey->array().size()); |
| 40 for (size_t i = 0; i < idbKey->array().size(); i++) |
| 41 data[i] = createKey(idbKey->array()[i]); |
| 42 mojoKey->data->set_array_data(std::move(data)); |
| 43 mojoKey->type = indexed_db::mojom::blink::KeyType::Array; |
| 44 } break; |
| 45 case IDBKey::BinaryType: |
| 46 mojoKey->data = indexed_db::mojom::blink::KeyData::New(); |
| 47 mojoKey->type = indexed_db::mojom::blink::KeyType::Binary; |
| 48 break; |
| 49 case IDBKey::StringType: |
| 50 mojoKey->type = indexed_db::mojom::blink::KeyType::String; |
| 51 mojoKey->data->set_string_data(idbKey->string()); |
| 52 break; |
| 53 case IDBKey::DateType: |
| 54 mojoKey->type = indexed_db::mojom::blink::KeyType::Date; |
| 55 mojoKey->data->set_date(idbKey->date()); |
| 56 break; |
| 57 case IDBKey::NumberType: |
| 58 mojoKey->type = indexed_db::mojom::blink::KeyType::Number; |
| 59 mojoKey->data->set_number(idbKey->number()); |
| 60 break; |
| 61 } |
| 62 |
| 63 return mojoKey; |
| 64 } |
| 65 |
| 66 static IDBKey::KeyArray createKeyArray(const WTF::Vector<KeyPtr>& array) |
| 67 { |
| 68 IDBKey::KeyArray keyArray; |
| 69 |
| 70 for (size_t i = 0; i < array.size(); i++) { |
| 71 keyArray.append(createKey(array[i])); |
| 72 } |
| 73 |
| 74 return keyArray; |
| 75 } |
| 76 |
| 77 PassRefPtr<SharedBuffer> createData(const WTF::Vector<uint8_t>& data) |
| 78 { |
| 79 RefPtr<SharedBuffer> webData; |
| 80 return webData.release(); |
| 81 } |
| 82 |
| 83 PassRefPtr<SharedBuffer> createData(const WTF::Vector<int8_t>& data) |
| 84 { |
| 85 RefPtr<SharedBuffer> webData; |
| 86 return webData.release(); |
| 87 } |
| 88 |
| 89 IDBKey* createKey(const KeyPtr& mojoKey) |
| 90 { |
| 91 if (!mojoKey) |
| 92 return nullptr; |
| 93 |
| 94 switch (mojoKey->type) { |
| 95 case indexed_db::mojom::blink::KeyType::Invalid: |
| 96 return IDBKey::createInvalid(); |
| 97 case indexed_db::mojom::blink::KeyType::Array: |
| 98 return IDBKey::createArray(createKeyArray(mojoKey->data->get_array_data(
))); |
| 99 case indexed_db::mojom::blink::KeyType::Binary: |
| 100 return IDBKey::createBinary(createData(mojoKey->data->get_binary_data())
); |
| 101 case indexed_db::mojom::blink::KeyType::String: |
| 102 return IDBKey::createString(mojoKey->data->get_string_data()); |
| 103 case indexed_db::mojom::blink::KeyType::Date: |
| 104 return IDBKey::createDate(mojoKey->data->get_date()); |
| 105 case indexed_db::mojom::blink::KeyType::Number: |
| 106 return IDBKey::createNumber(mojoKey->data->get_number()); |
| 107 } |
| 108 } |
| 109 |
| 110 // TODO(cmumford): Can we use Mojo type-mapping? If not should it be moved to a
utility file? |
| 111 KeyRangePtr createKeyRange(const IDBKeyRange* keyRange) |
| 112 { |
| 113 if (!keyRange) |
| 114 return nullptr; |
| 115 |
| 116 KeyRangePtr range = indexed_db::mojom::blink::KeyRange::New(); |
| 117 range->lower_open = keyRange->lowerOpen(); |
| 118 range->lower = createKey(keyRange->lower()); |
| 119 range->upper_open = keyRange->upperOpen(); |
| 120 range->upper = createKey(keyRange->upper()); |
| 121 |
| 122 return range; |
| 123 } |
| 124 |
| 125 KeyRangePtr createKeyRange(ExecutionContext* context, const ScriptValue& value,
ExceptionState& exceptionState) |
| 126 { |
| 127 return createKeyRange(IDBKeyRange::fromScriptValue(context, value, exception
State)); |
| 128 } |
| 129 |
| 130 IDBKeyPath createKeyPath(const indexed_db::mojom::blink::KeyPathPtr&) |
| 131 { |
| 132 IDBKeyPath keyPath; |
| 133 |
| 134 return keyPath; |
| 135 } |
| 136 |
| 137 KeyPathPtr createKeyPath(const IDBKeyPath& value) |
| 138 { |
| 139 if (!value.isValid()) |
| 140 return nullptr; |
| 141 |
| 142 KeyPathPtr keyPath = indexed_db::mojom::blink::KeyPath::New(); |
| 143 |
| 144 switch (value.getType()) { |
| 145 case IDBKeyPath::NullType: |
| 146 keyPath->type = KeyPathType::NONE; |
| 147 break; |
| 148 case IDBKeyPath::StringType: |
| 149 keyPath->type = KeyPathType::STRING; |
| 150 keyPath->data->set_str(value.string()); |
| 151 break; |
| 152 case IDBKeyPath::ArrayType: { |
| 153 keyPath->type = KeyPathType::ARRAY; |
| 154 Vector<String> strings; |
| 155 for (const auto& str : value.array()) |
| 156 strings.append(str); |
| 157 keyPath->data->set_arr(std::move(strings)); |
| 158 } break; |
| 159 } |
| 160 |
| 161 return keyPath; |
| 162 } |
| 163 |
| 164 BlobInfoPtr createBlobInfo(const WebBlobInfo& info) |
| 165 { |
| 166 BlobInfoPtr blobInfo = indexed_db::mojom::blink::BlobInfo::New(); |
| 167 |
| 168 blobInfo->is_file = info.isFile(); |
| 169 blobInfo->uuid = info.uuid(); |
| 170 blobInfo->type = info.type(); |
| 171 blobInfo->size = info.size(); |
| 172 |
| 173 if (info.isFile()) { |
| 174 blobInfo->file_path = info.filePath(); |
| 175 blobInfo->file_name = info.fileName(); |
| 176 blobInfo->last_modified = info.lastModified(); |
| 177 } |
| 178 |
| 179 return blobInfo; |
| 180 } |
| 181 |
| 182 Vector<BlobInfoPtr> createBlobInfo(const Vector<WebBlobInfo>& blobInfo) |
| 183 { |
| 184 Vector<BlobInfoPtr> ret(blobInfo.size()); |
| 185 |
| 186 for (size_t i = 0; i < blobInfo.size(); i++) |
| 187 ret[i] = createBlobInfo(blobInfo[i]); |
| 188 |
| 189 return ret; |
| 190 } |
| 191 |
| 192 void convertMetadata(IDBDatabaseMetadata* out, const indexed_db::mojom::blink::D
atabaseMetadataPtr& in) |
| 193 { |
| 194 // TODO(cmumford): Implement me. |
| 195 // NOTREACHED(); |
| 196 } |
| 197 |
| 198 } // namespace blink |
OLD | NEW |