| 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/indexeddb/IDBFactory.h" | 29 #include "modules/indexeddb/IDBFactory.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ExceptionState.h" | 31 #include "bindings/core/v8/ExceptionState.h" |
| 32 #include "bindings/modules/v8/V8BindingForModules.h" | 32 #include "bindings/modules/v8/V8BindingForModules.h" |
| 33 #include "core/dom/DOMException.h" | 33 #include "core/dom/DOMException.h" |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
| 36 #include "modules/indexeddb/IDBDatabase.h" | 36 #include "modules/indexeddb/IDBDatabase.h" |
| 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | |
| 38 #include "modules/indexeddb/IDBKey.h" | 37 #include "modules/indexeddb/IDBKey.h" |
| 39 #include "modules/indexeddb/IDBTracing.h" | 38 #include "modules/indexeddb/IDBTracing.h" |
| 40 #include "modules/indexeddb/IndexedDBClient.h" | 39 #include "modules/indexeddb/IndexedDBClient.h" |
| 41 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | 40 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
| 42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" | |
| 43 #include "platform/Histogram.h" | 41 #include "platform/Histogram.h" |
| 44 #include "platform/weborigin/SecurityOrigin.h" | 42 #include "platform/weborigin/SecurityOrigin.h" |
| 45 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 46 #include "public/platform/WebSecurityOrigin.h" | 44 #include "public/platform/WebSecurityOrigin.h" |
| 47 #include "public/platform/modules/indexeddb/WebIDBFactory.h" | 45 #include "public/platform/modules/indexeddb/WebIDBFactory.h" |
| 46 #include "public/platform/modules/indexeddb/indexed_db.mojom-blink.h" |
| 48 #include <memory> | 47 #include <memory> |
| 49 | 48 |
| 50 namespace blink { | 49 namespace blink { |
| 51 | 50 |
| 52 static const char permissionDeniedErrorMessage[] = "The user denied permission t
o access the database."; | 51 static const char permissionDeniedErrorMessage[] = "The user denied permission t
o access the database."; |
| 53 | 52 |
| 54 IDBFactory::IDBFactory() | 53 IDBFactory::IDBFactory() |
| 55 { | 54 { |
| 56 } | 55 } |
| 57 | 56 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 { | 99 { |
| 101 IDBDatabase::recordApiCallsHistogram(IDBOpenCall); | 100 IDBDatabase::recordApiCallsHistogram(IDBOpenCall); |
| 102 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoVersion); | 101 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoVersion); |
| 103 if (!isContextValid(scriptState->getExecutionContext())) | 102 if (!isContextValid(scriptState->getExecutionContext())) |
| 104 return nullptr; | 103 return nullptr; |
| 105 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { | 104 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { |
| 106 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 105 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
| 107 return nullptr; | 106 return nullptr; |
| 108 } | 107 } |
| 109 | 108 |
| 110 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); | |
| 111 int64_t transactionId = IDBDatabase::nextTransactionId(); | 109 int64_t transactionId = IDBDatabase::nextTransactionId(); |
| 112 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa
llbacks, transactionId, version); | 110 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, transactio
nId, version); |
| 113 | 111 |
| 114 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { | 112 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { |
| 115 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 113 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
| 116 return request; | 114 return request; |
| 117 } | 115 } |
| 118 | 116 |
| 119 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB
CallbacksImpl::create(request).release(), WebIDBDatabaseCallbacksImpl::create(da
tabaseCallbacks).release(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); | 117 mojo::ScopedInterfaceEndpointHandle clientInterfaceEndpoint; |
| 118 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB
CallbacksImpl::create(request).release(), &clientInterfaceEndpoint, WebSecurityO
rigin(scriptState->getExecutionContext()->getSecurityOrigin())); |
| 119 indexed_db::mojom::blink::DatabaseClientAssociatedRequest clientRequest; |
| 120 clientRequest.Bind(std::move(clientInterfaceEndpoint)); |
| 121 request->setClientRequest(std::move(clientRequest)); |
| 120 return request; | 122 return request; |
| 121 } | 123 } |
| 122 | 124 |
| 123 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
ExceptionState& exceptionState) | 125 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
ExceptionState& exceptionState) |
| 124 { | 126 { |
| 125 IDB_TRACE("IDBFactory::open"); | 127 IDB_TRACE("IDBFactory::open"); |
| 126 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep
tionState); | 128 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep
tionState); |
| 127 } | 129 } |
| 128 | 130 |
| 129 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str
ing& name, ExceptionState& exceptionState) | 131 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str
ing& name, ExceptionState& exceptionState) |
| 130 { | 132 { |
| 131 IDB_TRACE("IDBFactory::deleteDatabase"); | 133 IDB_TRACE("IDBFactory::deleteDatabase"); |
| 132 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); | 134 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); |
| 133 if (!isContextValid(scriptState->getExecutionContext())) | 135 if (!isContextValid(scriptState->getExecutionContext())) |
| 134 return nullptr; | 136 return nullptr; |
| 135 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { | 137 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { |
| 136 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 138 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
| 137 return nullptr; | 139 return nullptr; |
| 138 } | 140 } |
| 139 | 141 |
| 140 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0
, IDBDatabaseMetadata::DefaultVersion); | 142 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, 0, IDBData
baseMetadata::DefaultVersion); |
| 141 | 143 |
| 142 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { | 144 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { |
| 143 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 145 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
| 144 return request; | 146 return request; |
| 145 } | 147 } |
| 146 | 148 |
| 147 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl:
:create(request).release(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); | 149 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl:
:create(request).release(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); |
| 148 return request; | 150 return request; |
| 149 } | 151 } |
| 150 | 152 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 165 ASSERT(second); | 167 ASSERT(second); |
| 166 if (!second->isValid()) { | 168 if (!second->isValid()) { |
| 167 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 169 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 168 return 0; | 170 return 0; |
| 169 } | 171 } |
| 170 | 172 |
| 171 return static_cast<short>(first->compare(second)); | 173 return static_cast<short>(first->compare(second)); |
| 172 } | 174 } |
| 173 | 175 |
| 174 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |