| 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 10 matching lines...) Expand all Loading... |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/indexeddb/IDBFactory.h" | 29 #include "modules/indexeddb/IDBFactory.h" |
| 30 | 30 |
| 31 #include <memory> |
| 31 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 32 #include "bindings/modules/v8/V8BindingForModules.h" | 33 #include "bindings/modules/v8/V8BindingForModules.h" |
| 33 #include "core/dom/DOMException.h" | 34 #include "core/dom/DOMException.h" |
| 34 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 35 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
| 37 #include "core/dom/ExecutionContext.h" |
| 36 #include "modules/indexeddb/IDBDatabase.h" | 38 #include "modules/indexeddb/IDBDatabase.h" |
| 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | 39 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
| 38 #include "modules/indexeddb/IDBKey.h" | 40 #include "modules/indexeddb/IDBKey.h" |
| 39 #include "modules/indexeddb/IDBTracing.h" | 41 #include "modules/indexeddb/IDBTracing.h" |
| 40 #include "modules/indexeddb/IndexedDBClient.h" | 42 #include "modules/indexeddb/IndexedDBClient.h" |
| 41 #include "platform/Histogram.h" | 43 #include "platform/Histogram.h" |
| 42 #include "platform/weborigin/SecurityOrigin.h" | 44 #include "platform/weborigin/SecurityOrigin.h" |
| 43 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebSecurityOrigin.h" | 46 #include "public/platform/WebSecurityOrigin.h" |
| 45 #include "public/platform/modules/indexeddb/WebIDBDatabaseCallbacks.h" | 47 #include "public/platform/modules/indexeddb/WebIDBDatabaseCallbacks.h" |
| 46 #include "public/platform/modules/indexeddb/WebIDBFactory.h" | 48 #include "public/platform/modules/indexeddb/WebIDBFactory.h" |
| 47 #include <memory> | |
| 48 | 49 |
| 49 namespace blink { | 50 namespace blink { |
| 50 | 51 |
| 51 static const char kPermissionDeniedErrorMessage[] = | 52 static const char kPermissionDeniedErrorMessage[] = |
| 52 "The user denied permission to access the database."; | 53 "The user denied permission to access the database."; |
| 53 | 54 |
| 54 IDBFactory::IDBFactory() {} | 55 IDBFactory::IDBFactory() {} |
| 55 | 56 |
| 56 static bool IsContextValid(ExecutionContext* context) { | 57 static bool IsContextValid(ExecutionContext* context) { |
| 57 DCHECK(context->IsDocument() || context->IsWorkerGlobalScope()); | 58 DCHECK(context->IsDocument() || context->IsWorkerGlobalScope()); |
| 58 if (context->IsDocument()) { | 59 if (context->IsDocument()) { |
| 59 Document* document = ToDocument(context); | 60 Document* document = ToDocument(context); |
| 60 return document->GetFrame() && document->GetPage(); | 61 return document->GetFrame() && document->GetPage(); |
| 61 } | 62 } |
| 62 return true; | 63 return true; |
| 63 } | 64 } |
| 64 | 65 |
| 65 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* script_state, | 66 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* script_state, |
| 66 ExceptionState& exception_state) { | 67 ExceptionState& exception_state) { |
| 67 IDB_TRACE("IDBFactory::getDatabaseNames"); | 68 IDB_TRACE("IDBFactory::getDatabaseNames"); |
| 68 if (!IsContextValid(script_state->GetExecutionContext())) | 69 if (!IsContextValid(ExecutionContext::From(script_state))) |
| 69 return nullptr; | 70 return nullptr; |
| 70 if (!script_state->GetExecutionContext() | 71 if (!ExecutionContext::From(script_state) |
| 71 ->GetSecurityOrigin() | 72 ->GetSecurityOrigin() |
| 72 ->CanAccessDatabase()) { | 73 ->CanAccessDatabase()) { |
| 73 exception_state.ThrowSecurityError( | 74 exception_state.ThrowSecurityError( |
| 74 "access to the Indexed Database API is denied in this context."); | 75 "access to the Indexed Database API is denied in this context."); |
| 75 return nullptr; | 76 return nullptr; |
| 76 } | 77 } |
| 77 | 78 |
| 78 IDBRequest* request = | 79 IDBRequest* request = |
| 79 IDBRequest::Create(script_state, IDBAny::CreateNull(), nullptr); | 80 IDBRequest::Create(script_state, IDBAny::CreateNull(), nullptr); |
| 80 | 81 |
| 81 if (!IndexedDBClient::From(script_state->GetExecutionContext()) | 82 if (!IndexedDBClient::From(ExecutionContext::From(script_state)) |
| 82 ->AllowIndexedDB(script_state->GetExecutionContext(), | 83 ->AllowIndexedDB(ExecutionContext::From(script_state), |
| 83 "Database Listing")) { | 84 "Database Listing")) { |
| 84 request->OnError( | 85 request->OnError( |
| 85 DOMException::Create(kUnknownError, kPermissionDeniedErrorMessage)); | 86 DOMException::Create(kUnknownError, kPermissionDeniedErrorMessage)); |
| 86 return request; | 87 return request; |
| 87 } | 88 } |
| 88 | 89 |
| 89 Platform::Current()->IdbFactory()->GetDatabaseNames( | 90 Platform::Current()->IdbFactory()->GetDatabaseNames( |
| 90 request->CreateWebCallbacks().release(), | 91 request->CreateWebCallbacks().release(), |
| 91 WebSecurityOrigin( | 92 WebSecurityOrigin( |
| 92 script_state->GetExecutionContext()->GetSecurityOrigin())); | 93 ExecutionContext::From(script_state)->GetSecurityOrigin())); |
| 93 return request; | 94 return request; |
| 94 } | 95 } |
| 95 | 96 |
| 96 IDBOpenDBRequest* IDBFactory::open(ScriptState* script_state, | 97 IDBOpenDBRequest* IDBFactory::open(ScriptState* script_state, |
| 97 const String& name, | 98 const String& name, |
| 98 unsigned long long version, | 99 unsigned long long version, |
| 99 ExceptionState& exception_state) { | 100 ExceptionState& exception_state) { |
| 100 IDB_TRACE("IDBFactory::open"); | 101 IDB_TRACE("IDBFactory::open"); |
| 101 if (!version) { | 102 if (!version) { |
| 102 exception_state.ThrowTypeError("The version provided must not be 0."); | 103 exception_state.ThrowTypeError("The version provided must not be 0."); |
| 103 return nullptr; | 104 return nullptr; |
| 104 } | 105 } |
| 105 return OpenInternal(script_state, name, version, exception_state); | 106 return OpenInternal(script_state, name, version, exception_state); |
| 106 } | 107 } |
| 107 | 108 |
| 108 IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, | 109 IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, |
| 109 const String& name, | 110 const String& name, |
| 110 int64_t version, | 111 int64_t version, |
| 111 ExceptionState& exception_state) { | 112 ExceptionState& exception_state) { |
| 112 IDBDatabase::RecordApiCallsHistogram(kIDBOpenCall); | 113 IDBDatabase::RecordApiCallsHistogram(kIDBOpenCall); |
| 113 DCHECK(version >= 1 || version == IDBDatabaseMetadata::kNoVersion); | 114 DCHECK(version >= 1 || version == IDBDatabaseMetadata::kNoVersion); |
| 114 if (!IsContextValid(script_state->GetExecutionContext())) | 115 if (!IsContextValid(ExecutionContext::From(script_state))) |
| 115 return nullptr; | 116 return nullptr; |
| 116 if (!script_state->GetExecutionContext() | 117 if (!ExecutionContext::From(script_state) |
| 117 ->GetSecurityOrigin() | 118 ->GetSecurityOrigin() |
| 118 ->CanAccessDatabase()) { | 119 ->CanAccessDatabase()) { |
| 119 exception_state.ThrowSecurityError( | 120 exception_state.ThrowSecurityError( |
| 120 "access to the Indexed Database API is denied in this context."); | 121 "access to the Indexed Database API is denied in this context."); |
| 121 return nullptr; | 122 return nullptr; |
| 122 } | 123 } |
| 123 | 124 |
| 124 IDBDatabaseCallbacks* database_callbacks = IDBDatabaseCallbacks::Create(); | 125 IDBDatabaseCallbacks* database_callbacks = IDBDatabaseCallbacks::Create(); |
| 125 int64_t transaction_id = IDBDatabase::NextTransactionId(); | 126 int64_t transaction_id = IDBDatabase::NextTransactionId(); |
| 126 IDBOpenDBRequest* request = IDBOpenDBRequest::Create( | 127 IDBOpenDBRequest* request = IDBOpenDBRequest::Create( |
| 127 script_state, database_callbacks, transaction_id, version); | 128 script_state, database_callbacks, transaction_id, version); |
| 128 | 129 |
| 129 if (!IndexedDBClient::From(script_state->GetExecutionContext()) | 130 if (!IndexedDBClient::From(ExecutionContext::From(script_state)) |
| 130 ->AllowIndexedDB(script_state->GetExecutionContext(), name)) { | 131 ->AllowIndexedDB(ExecutionContext::From(script_state), name)) { |
| 131 request->OnError( | 132 request->OnError( |
| 132 DOMException::Create(kUnknownError, kPermissionDeniedErrorMessage)); | 133 DOMException::Create(kUnknownError, kPermissionDeniedErrorMessage)); |
| 133 return request; | 134 return request; |
| 134 } | 135 } |
| 135 | 136 |
| 136 Platform::Current()->IdbFactory()->Open( | 137 Platform::Current()->IdbFactory()->Open( |
| 137 name, version, transaction_id, request->CreateWebCallbacks().release(), | 138 name, version, transaction_id, request->CreateWebCallbacks().release(), |
| 138 database_callbacks->CreateWebCallbacks().release(), | 139 database_callbacks->CreateWebCallbacks().release(), |
| 139 WebSecurityOrigin( | 140 WebSecurityOrigin( |
| 140 script_state->GetExecutionContext()->GetSecurityOrigin())); | 141 ExecutionContext::From(script_state)->GetSecurityOrigin())); |
| 141 return request; | 142 return request; |
| 142 } | 143 } |
| 143 | 144 |
| 144 IDBOpenDBRequest* IDBFactory::open(ScriptState* script_state, | 145 IDBOpenDBRequest* IDBFactory::open(ScriptState* script_state, |
| 145 const String& name, | 146 const String& name, |
| 146 ExceptionState& exception_state) { | 147 ExceptionState& exception_state) { |
| 147 IDB_TRACE("IDBFactory::open"); | 148 IDB_TRACE("IDBFactory::open"); |
| 148 return OpenInternal(script_state, name, IDBDatabaseMetadata::kNoVersion, | 149 return OpenInternal(script_state, name, IDBDatabaseMetadata::kNoVersion, |
| 149 exception_state); | 150 exception_state); |
| 150 } | 151 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 164 /*force_close=*/true); | 165 /*force_close=*/true); |
| 165 } | 166 } |
| 166 | 167 |
| 167 IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal( | 168 IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal( |
| 168 ScriptState* script_state, | 169 ScriptState* script_state, |
| 169 const String& name, | 170 const String& name, |
| 170 ExceptionState& exception_state, | 171 ExceptionState& exception_state, |
| 171 bool force_close) { | 172 bool force_close) { |
| 172 IDB_TRACE("IDBFactory::deleteDatabase"); | 173 IDB_TRACE("IDBFactory::deleteDatabase"); |
| 173 IDBDatabase::RecordApiCallsHistogram(kIDBDeleteDatabaseCall); | 174 IDBDatabase::RecordApiCallsHistogram(kIDBDeleteDatabaseCall); |
| 174 if (!IsContextValid(script_state->GetExecutionContext())) | 175 if (!IsContextValid(ExecutionContext::From(script_state))) |
| 175 return nullptr; | 176 return nullptr; |
| 176 if (!script_state->GetExecutionContext() | 177 if (!ExecutionContext::From(script_state) |
| 177 ->GetSecurityOrigin() | 178 ->GetSecurityOrigin() |
| 178 ->CanAccessDatabase()) { | 179 ->CanAccessDatabase()) { |
| 179 exception_state.ThrowSecurityError( | 180 exception_state.ThrowSecurityError( |
| 180 "access to the Indexed Database API is denied in this context."); | 181 "access to the Indexed Database API is denied in this context."); |
| 181 return nullptr; | 182 return nullptr; |
| 182 } | 183 } |
| 183 | 184 |
| 184 IDBOpenDBRequest* request = IDBOpenDBRequest::Create( | 185 IDBOpenDBRequest* request = IDBOpenDBRequest::Create( |
| 185 script_state, nullptr, 0, IDBDatabaseMetadata::kDefaultVersion); | 186 script_state, nullptr, 0, IDBDatabaseMetadata::kDefaultVersion); |
| 186 | 187 |
| 187 if (!IndexedDBClient::From(script_state->GetExecutionContext()) | 188 if (!IndexedDBClient::From(ExecutionContext::From(script_state)) |
| 188 ->AllowIndexedDB(script_state->GetExecutionContext(), name)) { | 189 ->AllowIndexedDB(ExecutionContext::From(script_state), name)) { |
| 189 request->OnError( | 190 request->OnError( |
| 190 DOMException::Create(kUnknownError, kPermissionDeniedErrorMessage)); | 191 DOMException::Create(kUnknownError, kPermissionDeniedErrorMessage)); |
| 191 return request; | 192 return request; |
| 192 } | 193 } |
| 193 | 194 |
| 194 Platform::Current()->IdbFactory()->DeleteDatabase( | 195 Platform::Current()->IdbFactory()->DeleteDatabase( |
| 195 name, request->CreateWebCallbacks().release(), | 196 name, request->CreateWebCallbacks().release(), |
| 196 WebSecurityOrigin( | 197 WebSecurityOrigin( |
| 197 script_state->GetExecutionContext()->GetSecurityOrigin()), | 198 ExecutionContext::From(script_state)->GetSecurityOrigin()), |
| 198 force_close); | 199 force_close); |
| 199 return request; | 200 return request; |
| 200 } | 201 } |
| 201 | 202 |
| 202 short IDBFactory::cmp(ScriptState* script_state, | 203 short IDBFactory::cmp(ScriptState* script_state, |
| 203 const ScriptValue& first_value, | 204 const ScriptValue& first_value, |
| 204 const ScriptValue& second_value, | 205 const ScriptValue& second_value, |
| 205 ExceptionState& exception_state) { | 206 ExceptionState& exception_state) { |
| 206 IDBKey* first = ScriptValue::To<IDBKey*>(script_state->GetIsolate(), | 207 IDBKey* first = ScriptValue::To<IDBKey*>(script_state->GetIsolate(), |
| 207 first_value, exception_state); | 208 first_value, exception_state); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 222 if (!second->IsValid()) { | 223 if (!second->IsValid()) { |
| 223 exception_state.ThrowDOMException(kDataError, | 224 exception_state.ThrowDOMException(kDataError, |
| 224 IDBDatabase::kNotValidKeyErrorMessage); | 225 IDBDatabase::kNotValidKeyErrorMessage); |
| 225 return 0; | 226 return 0; |
| 226 } | 227 } |
| 227 | 228 |
| 228 return static_cast<short>(first->Compare(second)); | 229 return static_cast<short>(first->Compare(second)); |
| 229 } | 230 } |
| 230 | 231 |
| 231 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |