| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 PassRefPtr<IDBAny> IDBDatabase::version() const | 156 PassRefPtr<IDBAny> IDBDatabase::version() const |
| 157 { | 157 { |
| 158 int64_t intVersion = m_metadata.intVersion; | 158 int64_t intVersion = m_metadata.intVersion; |
| 159 if (intVersion == IDBDatabaseMetadata::NoIntVersion) | 159 if (intVersion == IDBDatabaseMetadata::NoIntVersion) |
| 160 return IDBAny::createString(m_metadata.version); | 160 return IDBAny::createString(m_metadata.version); |
| 161 return IDBAny::create(intVersion); | 161 return IDBAny::create(intVersion); |
| 162 } | 162 } |
| 163 | 163 |
| 164 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
nst Dictionary& options, ExceptionState& es) | 164 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
nst Dictionary& options, ExceptionState& exceptionState) |
| 165 { | 165 { |
| 166 IDBKeyPath keyPath; | 166 IDBKeyPath keyPath; |
| 167 bool autoIncrement = false; | 167 bool autoIncrement = false; |
| 168 if (!options.isUndefinedOrNull()) { | 168 if (!options.isUndefinedOrNull()) { |
| 169 String keyPathString; | 169 String keyPathString; |
| 170 Vector<String> keyPathArray; | 170 Vector<String> keyPathArray; |
| 171 if (options.get("keyPath", keyPathArray)) | 171 if (options.get("keyPath", keyPathArray)) |
| 172 keyPath = IDBKeyPath(keyPathArray); | 172 keyPath = IDBKeyPath(keyPathArray); |
| 173 else if (options.getWithUndefinedOrNullCheck("keyPath", keyPathString)) | 173 else if (options.getWithUndefinedOrNullCheck("keyPath", keyPathString)) |
| 174 keyPath = IDBKeyPath(keyPathString); | 174 keyPath = IDBKeyPath(keyPathString); |
| 175 | 175 |
| 176 options.get("autoIncrement", autoIncrement); | 176 options.get("autoIncrement", autoIncrement); |
| 177 } | 177 } |
| 178 | 178 |
| 179 return createObjectStore(name, keyPath, autoIncrement, es); | 179 return createObjectStore(name, keyPath, autoIncrement, exceptionState); |
| 180 } | 180 } |
| 181 | 181 |
| 182 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
nst IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& es) | 182 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
nst IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& exceptionState) |
| 183 { | 183 { |
| 184 IDB_TRACE("IDBDatabase::createObjectStore"); | 184 IDB_TRACE("IDBDatabase::createObjectStore"); |
| 185 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBCreateObjectStoreCall, IDBMethodsMax); | 185 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBCreateObjectStoreCall, IDBMethodsMax); |
| 186 if (!m_versionChangeTransaction) { | 186 if (!m_versionChangeTransaction) { |
| 187 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra
nsactionErrorMessage); | 187 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers
ionChangeTransactionErrorMessage); |
| 188 return 0; | 188 return 0; |
| 189 } | 189 } |
| 190 if (m_versionChangeTransaction->isFinished()) { | 190 if (m_versionChangeTransaction->isFinished()) { |
| 191 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); | 191 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 192 return 0; | 192 return 0; |
| 193 } | 193 } |
| 194 if (!m_versionChangeTransaction->isActive()) { | 194 if (!m_versionChangeTransaction->isActive()) { |
| 195 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); | 195 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 196 return 0; | 196 return 0; |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (containsObjectStore(name)) { | 199 if (containsObjectStore(name)) { |
| 200 es.throwDOMException(ConstraintError, "An object store with the specifie
d name already exists."); | 200 exceptionState.throwDOMException(ConstraintError, "An object store with
the specified name already exists."); |
| 201 return 0; | 201 return 0; |
| 202 } | 202 } |
| 203 | 203 |
| 204 if (!keyPath.isNull() && !keyPath.isValid()) { | 204 if (!keyPath.isNull() && !keyPath.isValid()) { |
| 205 es.throwDOMException(SyntaxError, "The keyPath option is not a valid key
path."); | 205 exceptionState.throwDOMException(SyntaxError, "The keyPath option is not
a valid key path."); |
| 206 return 0; | 206 return 0; |
| 207 } | 207 } |
| 208 | 208 |
| 209 if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.s
tring().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) { | 209 if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.s
tring().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) { |
| 210 es.throwDOMException(InvalidAccessError, "The autoIncrement option was s
et but the keyPath option was empty or an array."); | 210 exceptionState.throwDOMException(InvalidAccessError, "The autoIncrement
option was set but the keyPath option was empty or an array."); |
| 211 return 0; | 211 return 0; |
| 212 } | 212 } |
| 213 | 213 |
| 214 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; | 214 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; |
| 215 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId
, name, keyPath, autoIncrement); | 215 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId
, name, keyPath, autoIncrement); |
| 216 | 216 |
| 217 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement,
IDBDatabaseBackendInterface::MinimumIndexId); | 217 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement,
IDBDatabaseBackendInterface::MinimumIndexId); |
| 218 RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, m_vers
ionChangeTransaction.get()); | 218 RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, m_vers
ionChangeTransaction.get()); |
| 219 m_metadata.objectStores.set(metadata.id, metadata); | 219 m_metadata.objectStores.set(metadata.id, metadata); |
| 220 ++m_metadata.maxObjectStoreId; | 220 ++m_metadata.maxObjectStoreId; |
| 221 | 221 |
| 222 m_versionChangeTransaction->objectStoreCreated(name, objectStore); | 222 m_versionChangeTransaction->objectStoreCreated(name, objectStore); |
| 223 return objectStore.release(); | 223 return objectStore.release(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es) | 226 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& exceptio
nState) |
| 227 { | 227 { |
| 228 IDB_TRACE("IDBDatabase::deleteObjectStore"); | 228 IDB_TRACE("IDBDatabase::deleteObjectStore"); |
| 229 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteObjectStoreCall, IDBMethodsMax); | 229 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteObjectStoreCall, IDBMethodsMax); |
| 230 if (!m_versionChangeTransaction) { | 230 if (!m_versionChangeTransaction) { |
| 231 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra
nsactionErrorMessage); | 231 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers
ionChangeTransactionErrorMessage); |
| 232 return; | 232 return; |
| 233 } | 233 } |
| 234 if (m_versionChangeTransaction->isFinished()) { | 234 if (m_versionChangeTransaction->isFinished()) { |
| 235 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); | 235 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 236 return; | 236 return; |
| 237 } | 237 } |
| 238 if (!m_versionChangeTransaction->isActive()) { | 238 if (!m_versionChangeTransaction->isActive()) { |
| 239 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); | 239 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 | 242 |
| 243 int64_t objectStoreId = findObjectStoreId(name); | 243 int64_t objectStoreId = findObjectStoreId(name); |
| 244 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 244 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
| 245 es.throwDOMException(NotFoundError, "The specified object store was not
found."); | 245 exceptionState.throwDOMException(NotFoundError, "The specified object st
ore was not found."); |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 | 248 |
| 249 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId
); | 249 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId
); |
| 250 m_versionChangeTransaction->objectStoreDeleted(name); | 250 m_versionChangeTransaction->objectStoreDeleted(name); |
| 251 m_metadata.objectStores.remove(objectStoreId); | 251 m_metadata.objectStores.remove(objectStoreId); |
| 252 } | 252 } |
| 253 | 253 |
| 254 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ExecutionContext* context, c
onst Vector<String>& scope, const String& modeString, ExceptionState& es) | 254 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ExecutionContext* context, c
onst Vector<String>& scope, const String& modeString, ExceptionState& exceptionS
tate) |
| 255 { | 255 { |
| 256 IDB_TRACE("IDBDatabase::transaction"); | 256 IDB_TRACE("IDBDatabase::transaction"); |
| 257 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBTransactionCall, IDBMethodsMax); | 257 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBTransactionCall, IDBMethodsMax); |
| 258 if (!scope.size()) { | 258 if (!scope.size()) { |
| 259 es.throwDOMException(InvalidAccessError, "The storeNames parameter was e
mpty."); | 259 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par
ameter was empty."); |
| 260 return 0; | 260 return 0; |
| 261 } | 261 } |
| 262 | 262 |
| 263 IndexedDB::TransactionMode mode = IDBTransaction::stringToMode(modeString, e
s); | 263 IndexedDB::TransactionMode mode = IDBTransaction::stringToMode(modeString, e
xceptionState); |
| 264 if (es.hadException()) | 264 if (exceptionState.hadException()) |
| 265 return 0; | 265 return 0; |
| 266 | 266 |
| 267 if (m_versionChangeTransaction) { | 267 if (m_versionChangeTransaction) { |
| 268 es.throwDOMException(InvalidStateError, "A version change transaction is
running."); | 268 exceptionState.throwDOMException(InvalidStateError, "A version change tr
ansaction is running."); |
| 269 return 0; | 269 return 0; |
| 270 } | 270 } |
| 271 | 271 |
| 272 if (m_closePending) { | 272 if (m_closePending) { |
| 273 es.throwDOMException(InvalidStateError, "The database connection is clos
ing."); | 273 exceptionState.throwDOMException(InvalidStateError, "The database connec
tion is closing."); |
| 274 return 0; | 274 return 0; |
| 275 } | 275 } |
| 276 | 276 |
| 277 Vector<int64_t> objectStoreIds; | 277 Vector<int64_t> objectStoreIds; |
| 278 for (size_t i = 0; i < scope.size(); ++i) { | 278 for (size_t i = 0; i < scope.size(); ++i) { |
| 279 int64_t objectStoreId = findObjectStoreId(scope[i]); | 279 int64_t objectStoreId = findObjectStoreId(scope[i]); |
| 280 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 280 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
| 281 es.throwDOMException(NotFoundError, "One of the specified object sto
res was not found."); | 281 exceptionState.throwDOMException(NotFoundError, "One of the specifie
d object stores was not found."); |
| 282 return 0; | 282 return 0; |
| 283 } | 283 } |
| 284 objectStoreIds.append(objectStoreId); | 284 objectStoreIds.append(objectStoreId); |
| 285 } | 285 } |
| 286 | 286 |
| 287 int64_t transactionId = nextTransactionId(); | 287 int64_t transactionId = nextTransactionId(); |
| 288 m_backend->createTransaction(transactionId, m_databaseCallbacks, objectStore
Ids, mode); | 288 m_backend->createTransaction(transactionId, m_databaseCallbacks, objectStore
Ids, mode); |
| 289 | 289 |
| 290 RefPtr<IDBTransaction> transaction = IDBTransaction::create(context, transac
tionId, scope, mode, this); | 290 RefPtr<IDBTransaction> transaction = IDBTransaction::create(context, transac
tionId, scope, mode, this); |
| 291 return transaction.release(); | 291 return transaction.release(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ExecutionContext* context, c
onst String& storeName, const String& mode, ExceptionState& es) | 294 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ExecutionContext* context, c
onst String& storeName, const String& mode, ExceptionState& exceptionState) |
| 295 { | 295 { |
| 296 RefPtr<DOMStringList> storeNames = DOMStringList::create(); | 296 RefPtr<DOMStringList> storeNames = DOMStringList::create(); |
| 297 storeNames->append(storeName); | 297 storeNames->append(storeName); |
| 298 return transaction(context, storeNames, mode, es); | 298 return transaction(context, storeNames, mode, exceptionState); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void IDBDatabase::forceClose() | 301 void IDBDatabase::forceClose() |
| 302 { | 302 { |
| 303 for (TransactionMap::const_iterator::Values it = m_transactions.begin().valu
es(), end = m_transactions.end().values(); it != end; ++it) | 303 for (TransactionMap::const_iterator::Values it = m_transactions.begin().valu
es(), end = m_transactions.end().values(); it != end; ++it) |
| 304 (*it)->abort(IGNORE_EXCEPTION); | 304 (*it)->abort(IGNORE_EXCEPTION); |
| 305 this->close(); | 305 this->close(); |
| 306 enqueueEvent(Event::create(EventTypeNames::close)); | 306 enqueueEvent(Event::create(EventTypeNames::close)); |
| 307 } | 307 } |
| 308 | 308 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 { | 404 { |
| 405 return EventTargetNames::IDBDatabase; | 405 return EventTargetNames::IDBDatabase; |
| 406 } | 406 } |
| 407 | 407 |
| 408 ExecutionContext* IDBDatabase::executionContext() const | 408 ExecutionContext* IDBDatabase::executionContext() const |
| 409 { | 409 { |
| 410 return ActiveDOMObject::executionContext(); | 410 return ActiveDOMObject::executionContext(); |
| 411 } | 411 } |
| 412 | 412 |
| 413 } // namespace WebCore | 413 } // namespace WebCore |
| OLD | NEW |