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 27 matching lines...) Expand all Loading... |
38 #include "modules/indexeddb/IDBKey.h" | 38 #include "modules/indexeddb/IDBKey.h" |
39 #include "modules/indexeddb/IDBTracing.h" | 39 #include "modules/indexeddb/IDBTracing.h" |
40 #include "modules/indexeddb/IndexedDBClient.h" | 40 #include "modules/indexeddb/IndexedDBClient.h" |
41 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | 41 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" | 42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" |
43 #include "platform/Histogram.h" | 43 #include "platform/Histogram.h" |
44 #include "platform/weborigin/SecurityOrigin.h" | 44 #include "platform/weborigin/SecurityOrigin.h" |
45 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
46 #include "public/platform/WebSecurityOrigin.h" | 46 #include "public/platform/WebSecurityOrigin.h" |
47 #include "public/platform/modules/indexeddb/WebIDBFactory.h" | 47 #include "public/platform/modules/indexeddb/WebIDBFactory.h" |
| 48 #include <memory> |
48 | 49 |
49 namespace blink { | 50 namespace blink { |
50 | 51 |
51 static const char permissionDeniedErrorMessage[] = "The user denied permission t
o access the database."; | 52 static const char permissionDeniedErrorMessage[] = "The user denied permission t
o access the database."; |
52 | 53 |
53 IDBFactory::IDBFactory() | 54 IDBFactory::IDBFactory() |
54 { | 55 { |
55 } | 56 } |
56 | 57 |
57 static bool isContextValid(ExecutionContext* context) | 58 static bool isContextValid(ExecutionContext* context) |
(...skipping 16 matching lines...) Expand all Loading... |
74 return nullptr; | 75 return nullptr; |
75 } | 76 } |
76 | 77 |
77 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(),
nullptr); | 78 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(),
nullptr); |
78 | 79 |
79 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), "Database Listing")) { | 80 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), "Database Listing")) { |
80 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 81 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
81 return request; | 82 return request; |
82 } | 83 } |
83 | 84 |
84 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre
ate(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()->ge
tSecurityOrigin())); | 85 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre
ate(request).release(), WebSecurityOrigin(scriptState->getExecutionContext()->ge
tSecurityOrigin())); |
85 return request; | 86 return request; |
86 } | 87 } |
87 | 88 |
88 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
unsigned long long version, ExceptionState& exceptionState) | 89 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
unsigned long long version, ExceptionState& exceptionState) |
89 { | 90 { |
90 IDB_TRACE("IDBFactory::open"); | 91 IDB_TRACE("IDBFactory::open"); |
91 if (!version) { | 92 if (!version) { |
92 exceptionState.throwTypeError("The version provided must not be 0."); | 93 exceptionState.throwTypeError("The version provided must not be 0."); |
93 return nullptr; | 94 return nullptr; |
94 } | 95 } |
(...skipping 13 matching lines...) Expand all Loading... |
108 | 109 |
109 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); | 110 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); |
110 int64_t transactionId = IDBDatabase::nextTransactionId(); | 111 int64_t transactionId = IDBDatabase::nextTransactionId(); |
111 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa
llbacks, transactionId, version); | 112 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa
llbacks, transactionId, version); |
112 | 113 |
113 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { | 114 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { |
114 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 115 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
115 return request; | 116 return request; |
116 } | 117 } |
117 | 118 |
118 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB
CallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::create(da
tabaseCallbacks).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); | 119 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB
CallbacksImpl::create(request).release(), WebIDBDatabaseCallbacksImpl::create(da
tabaseCallbacks).release(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); |
119 return request; | 120 return request; |
120 } | 121 } |
121 | 122 |
122 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
ExceptionState& exceptionState) | 123 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
ExceptionState& exceptionState) |
123 { | 124 { |
124 IDB_TRACE("IDBFactory::open"); | 125 IDB_TRACE("IDBFactory::open"); |
125 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep
tionState); | 126 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep
tionState); |
126 } | 127 } |
127 | 128 |
128 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str
ing& name, ExceptionState& exceptionState) | 129 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str
ing& name, ExceptionState& exceptionState) |
129 { | 130 { |
130 IDB_TRACE("IDBFactory::deleteDatabase"); | 131 IDB_TRACE("IDBFactory::deleteDatabase"); |
131 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); | 132 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); |
132 if (!isContextValid(scriptState->getExecutionContext())) | 133 if (!isContextValid(scriptState->getExecutionContext())) |
133 return nullptr; | 134 return nullptr; |
134 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { | 135 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { |
135 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 136 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
136 return nullptr; | 137 return nullptr; |
137 } | 138 } |
138 | 139 |
139 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0
, IDBDatabaseMetadata::DefaultVersion); | 140 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0
, IDBDatabaseMetadata::DefaultVersion); |
140 | 141 |
141 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { | 142 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed
DB(scriptState->getExecutionContext(), name)) { |
142 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 143 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
143 return request; | 144 return request; |
144 } | 145 } |
145 | 146 |
146 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl:
:create(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); | 147 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl:
:create(request).release(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); |
147 return request; | 148 return request; |
148 } | 149 } |
149 | 150 |
150 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c
onst ScriptValue& secondValue, ExceptionState& exceptionState) | 151 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c
onst ScriptValue& secondValue, ExceptionState& exceptionState) |
151 { | 152 { |
152 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue,
exceptionState); | 153 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue,
exceptionState); |
153 if (exceptionState.hadException()) | 154 if (exceptionState.hadException()) |
154 return 0; | 155 return 0; |
155 ASSERT(first); | 156 ASSERT(first); |
156 if (!first->isValid()) { | 157 if (!first->isValid()) { |
157 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 158 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
158 return 0; | 159 return 0; |
159 } | 160 } |
160 | 161 |
161 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu
e, exceptionState); | 162 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu
e, exceptionState); |
162 if (exceptionState.hadException()) | 163 if (exceptionState.hadException()) |
163 return 0; | 164 return 0; |
164 ASSERT(second); | 165 ASSERT(second); |
165 if (!second->isValid()) { | 166 if (!second->isValid()) { |
166 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 167 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
167 return 0; | 168 return 0; |
168 } | 169 } |
169 | 170 |
170 return static_cast<short>(first->compare(second)); | 171 return static_cast<short>(first->compare(second)); |
171 } | 172 } |
172 | 173 |
173 } // namespace blink | 174 } // namespace blink |
OLD | NEW |