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 30 matching lines...) Expand all Loading... |
41 #include "modules/indexeddb/IDBKeyPath.h" | 41 #include "modules/indexeddb/IDBKeyPath.h" |
42 #include "modules/indexeddb/IDBObjectStore.h" | 42 #include "modules/indexeddb/IDBObjectStore.h" |
43 #include "modules/indexeddb/IDBTracing.h" | 43 #include "modules/indexeddb/IDBTracing.h" |
44 #include "modules/indexeddb/IDBTransaction.h" | 44 #include "modules/indexeddb/IDBTransaction.h" |
45 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 45 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
46 #include <limits> | 46 #include <limits> |
47 #include "wtf/Atomics.h" | 47 #include "wtf/Atomics.h" |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 const char IDBDatabase::notFoundErrorMessage[] = "An operation failed because th
e requested database object could not be found."; | 51 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st
ore has been deleted."; |
| 52 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor.
"; |
| 53 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe
cified."; |
| 54 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not
found."; |
| 55 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object
store was not found."; |
| 56 const char IDBDatabase::noValueErrorMessage[] = "The cursor is being iterated or
has iterated past its end."; |
| 57 const char IDBDatabase::notValidKeyErrorMessage[] = "The parameter is not a vali
d key."; |
| 58 const char IDBDatabase::notVersionChangeTransactionErrorMessage[] = "The databas
e is not running a version change transaction."; |
| 59 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has
been deleted."; |
| 60 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not
finished."; |
| 61 const char IDBDatabase::sourceDeletedErrorMessage[] = "The cursor's source or ef
fective object store has been deleted."; |
| 62 const char IDBDatabase::transactionInactiveErrorMessage[] = "The transaction is
not active."; |
| 63 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has
finished."; |
52 | 64 |
53 PassRefPtr<IDBDatabase> IDBDatabase::create(ScriptExecutionContext* context, Pas
sRefPtr<IDBDatabaseBackendInterface> database, PassRefPtr<IDBDatabaseCallbacks>
callbacks) | 65 PassRefPtr<IDBDatabase> IDBDatabase::create(ScriptExecutionContext* context, Pas
sRefPtr<IDBDatabaseBackendInterface> database, PassRefPtr<IDBDatabaseCallbacks>
callbacks) |
54 { | 66 { |
55 RefPtr<IDBDatabase> idbDatabase(adoptRef(new IDBDatabase(context, database,
callbacks))); | 67 RefPtr<IDBDatabase> idbDatabase(adoptRef(new IDBDatabase(context, database,
callbacks))); |
56 idbDatabase->suspendIfNeeded(); | 68 idbDatabase->suspendIfNeeded(); |
57 return idbDatabase.release(); | 69 return idbDatabase.release(); |
58 } | 70 } |
59 | 71 |
60 IDBDatabase::IDBDatabase(ScriptExecutionContext* context, PassRefPtr<IDBDatabase
BackendInterface> backend, PassRefPtr<IDBDatabaseCallbacks> callbacks) | 72 IDBDatabase::IDBDatabase(ScriptExecutionContext* context, PassRefPtr<IDBDatabase
BackendInterface> backend, PassRefPtr<IDBDatabaseCallbacks> callbacks) |
61 : ActiveDOMObject(context) | 73 : ActiveDOMObject(context) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 181 } |
170 | 182 |
171 return createObjectStore(name, keyPath, autoIncrement, es); | 183 return createObjectStore(name, keyPath, autoIncrement, es); |
172 } | 184 } |
173 | 185 |
174 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
nst IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& es) | 186 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
nst IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& es) |
175 { | 187 { |
176 IDB_TRACE("IDBDatabase::createObjectStore"); | 188 IDB_TRACE("IDBDatabase::createObjectStore"); |
177 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBCreateObjectStoreCall, IDBMethodsMax); | 189 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBCreateObjectStoreCall, IDBMethodsMax); |
178 if (!m_versionChangeTransaction) { | 190 if (!m_versionChangeTransaction) { |
179 es.throwDOMException(InvalidStateError); | 191 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra
nsactionErrorMessage); |
| 192 return 0; |
| 193 } |
| 194 if (m_versionChangeTransaction->isFinished()) { |
| 195 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
180 return 0; | 196 return 0; |
181 } | 197 } |
182 if (!m_versionChangeTransaction->isActive()) { | 198 if (!m_versionChangeTransaction->isActive()) { |
183 es.throwDOMException(TransactionInactiveError); | 199 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
184 return 0; | 200 return 0; |
185 } | 201 } |
186 | 202 |
187 if (containsObjectStore(name)) { | 203 if (containsObjectStore(name)) { |
188 es.throwDOMException(ConstraintError); | 204 es.throwDOMException(ConstraintError, "An object store with the specifie
d name already exists."); |
189 return 0; | 205 return 0; |
190 } | 206 } |
191 | 207 |
192 if (!keyPath.isNull() && !keyPath.isValid()) { | 208 if (!keyPath.isNull() && !keyPath.isValid()) { |
193 es.throwDOMException(SyntaxError); | 209 es.throwDOMException(SyntaxError, "The keyPath option is not a valid key
path."); |
194 return 0; | 210 return 0; |
195 } | 211 } |
196 | 212 |
197 if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.s
tring().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) { | 213 if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.s
tring().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) { |
198 es.throwDOMException(InvalidAccessError); | 214 es.throwDOMException(InvalidAccessError, "The autoIncrement option was s
et but the keyPath option was empty or an array."); |
199 return 0; | 215 return 0; |
200 } | 216 } |
201 | 217 |
202 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; | 218 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; |
203 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId
, name, keyPath, autoIncrement); | 219 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId
, name, keyPath, autoIncrement); |
204 | 220 |
205 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement,
IDBDatabaseBackendInterface::MinimumIndexId); | 221 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement,
IDBDatabaseBackendInterface::MinimumIndexId); |
206 RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, m_vers
ionChangeTransaction.get()); | 222 RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, m_vers
ionChangeTransaction.get()); |
207 m_metadata.objectStores.set(metadata.id, metadata); | 223 m_metadata.objectStores.set(metadata.id, metadata); |
208 ++m_metadata.maxObjectStoreId; | 224 ++m_metadata.maxObjectStoreId; |
209 | 225 |
210 m_versionChangeTransaction->objectStoreCreated(name, objectStore); | 226 m_versionChangeTransaction->objectStoreCreated(name, objectStore); |
211 return objectStore.release(); | 227 return objectStore.release(); |
212 } | 228 } |
213 | 229 |
214 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es) | 230 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es) |
215 { | 231 { |
216 IDB_TRACE("IDBDatabase::deleteObjectStore"); | 232 IDB_TRACE("IDBDatabase::deleteObjectStore"); |
217 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBDeleteObjectStoreCall, IDBMethodsMax); | 233 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBDeleteObjectStoreCall, IDBMethodsMax); |
218 if (!m_versionChangeTransaction) { | 234 if (!m_versionChangeTransaction) { |
219 es.throwDOMException(InvalidStateError); | 235 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra
nsactionErrorMessage); |
| 236 return; |
| 237 } |
| 238 if (m_versionChangeTransaction->isFinished()) { |
| 239 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
220 return; | 240 return; |
221 } | 241 } |
222 if (!m_versionChangeTransaction->isActive()) { | 242 if (!m_versionChangeTransaction->isActive()) { |
223 es.throwDOMException(TransactionInactiveError); | 243 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
224 return; | 244 return; |
225 } | 245 } |
226 | 246 |
227 int64_t objectStoreId = findObjectStoreId(name); | 247 int64_t objectStoreId = findObjectStoreId(name); |
228 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 248 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
229 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage); | 249 es.throwDOMException(NotFoundError, "The specified object store was not
found."); |
230 return; | 250 return; |
231 } | 251 } |
232 | 252 |
233 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId
); | 253 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId
); |
234 m_versionChangeTransaction->objectStoreDeleted(name); | 254 m_versionChangeTransaction->objectStoreDeleted(name); |
235 m_metadata.objectStores.remove(objectStoreId); | 255 m_metadata.objectStores.remove(objectStoreId); |
236 } | 256 } |
237 | 257 |
238 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont
ext, const Vector<String>& scope, const String& modeString, ExceptionState& es) | 258 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont
ext, const Vector<String>& scope, const String& modeString, ExceptionState& es) |
239 { | 259 { |
240 IDB_TRACE("IDBDatabase::transaction"); | 260 IDB_TRACE("IDBDatabase::transaction"); |
241 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBTransactionCall, IDBMethodsMax); | 261 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBTransactionCall, IDBMethodsMax); |
242 if (!scope.size()) { | 262 if (!scope.size()) { |
243 es.throwDOMException(InvalidAccessError); | 263 es.throwDOMException(InvalidAccessError, "The storeNames parameter was e
mpty."); |
244 return 0; | 264 return 0; |
245 } | 265 } |
246 | 266 |
247 IndexedDB::TransactionMode mode = IDBTransaction::stringToMode(modeString, e
s); | 267 IndexedDB::TransactionMode mode = IDBTransaction::stringToMode(modeString, e
s); |
248 if (es.hadException()) | 268 if (es.hadException()) |
249 return 0; | 269 return 0; |
250 | 270 |
251 if (m_versionChangeTransaction || m_closePending) { | 271 if (m_versionChangeTransaction) { |
252 es.throwDOMException(InvalidStateError); | 272 es.throwDOMException(InvalidStateError, "A version change transaction is
running."); |
253 return 0; | 273 return 0; |
254 } | 274 } |
255 | 275 |
| 276 if (m_closePending) { |
| 277 es.throwDOMException(InvalidStateError, "The database connection is clos
ing."); |
| 278 return 0; |
| 279 } |
| 280 |
256 Vector<int64_t> objectStoreIds; | 281 Vector<int64_t> objectStoreIds; |
257 for (size_t i = 0; i < scope.size(); ++i) { | 282 for (size_t i = 0; i < scope.size(); ++i) { |
258 int64_t objectStoreId = findObjectStoreId(scope[i]); | 283 int64_t objectStoreId = findObjectStoreId(scope[i]); |
259 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 284 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
260 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessag
e); | 285 es.throwDOMException(NotFoundError, "One of the specified object sto
res was not found."); |
261 return 0; | 286 return 0; |
262 } | 287 } |
263 objectStoreIds.append(objectStoreId); | 288 objectStoreIds.append(objectStoreId); |
264 } | 289 } |
265 | 290 |
266 int64_t transactionId = nextTransactionId(); | 291 int64_t transactionId = nextTransactionId(); |
267 m_backend->createTransaction(transactionId, m_databaseCallbacks, objectStore
Ids, mode); | 292 m_backend->createTransaction(transactionId, m_databaseCallbacks, objectStore
Ids, mode); |
268 | 293 |
269 RefPtr<IDBTransaction> transaction = IDBTransaction::create(context, transac
tionId, scope, mode, this); | 294 RefPtr<IDBTransaction> transaction = IDBTransaction::create(context, transac
tionId, scope, mode, this); |
270 return transaction.release(); | 295 return transaction.release(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 { | 417 { |
393 return &m_eventTargetData; | 418 return &m_eventTargetData; |
394 } | 419 } |
395 | 420 |
396 EventTargetData* IDBDatabase::ensureEventTargetData() | 421 EventTargetData* IDBDatabase::ensureEventTargetData() |
397 { | 422 { |
398 return &m_eventTargetData; | 423 return &m_eventTargetData; |
399 } | 424 } |
400 | 425 |
401 } // namespace WebCore | 426 } // namespace WebCore |
OLD | NEW |