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