| 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 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "modules/indexeddb/IDBIndex.h" | 27 #include "modules/indexeddb/IDBIndex.h" |
| 28 | 28 |
| 29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
| 30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
| 31 #include "core/dom/ExecutionContext.h" | 31 #include "core/dom/ExecutionContext.h" |
| 32 #include "modules/indexeddb/IDBDatabase.h" | 32 #include "modules/indexeddb/IDBDatabase.h" |
| 33 #include "modules/indexeddb/IDBKey.h" | 33 #include "modules/indexeddb/IDBKey.h" |
| 34 #include "modules/indexeddb/IDBTracing.h" | 34 #include "modules/indexeddb/IDBTracing.h" |
| 35 #include "modules/indexeddb/IDBTransaction.h" | 35 #include "modules/indexeddb/IDBTransaction.h" |
| 36 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
| 36 #include "public/platform/WebIDBKeyRange.h" | 37 #include "public/platform/WebIDBKeyRange.h" |
| 37 | 38 |
| 38 using blink::WebIDBDatabase; | 39 using blink::WebIDBDatabase; |
| 39 using blink::WebIDBCallbacks; | 40 using blink::WebIDBCallbacks; |
| 40 | 41 |
| 41 namespace WebCore { | 42 namespace WebCore { |
| 42 | 43 |
| 43 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) | 44 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) |
| 44 : m_metadata(metadata) | 45 : m_metadata(metadata) |
| 45 , m_objectStore(objectStore) | 46 , m_objectStore(objectStore) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 if (exceptionState.hadException()) | 80 if (exceptionState.hadException()) |
| 80 return 0; | 81 return 0; |
| 81 | 82 |
| 82 return openCursor(context, keyRange.release(), direction); | 83 return openCursor(context, keyRange.release(), direction); |
| 83 } | 84 } |
| 84 | 85 |
| 85 PassRefPtr<IDBRequest> IDBIndex::openCursor(ExecutionContext* context, PassRefPt
r<IDBKeyRange> keyRange, IndexedDB::CursorDirection direction) | 86 PassRefPtr<IDBRequest> IDBIndex::openCursor(ExecutionContext* context, PassRefPt
r<IDBKeyRange> keyRange, IndexedDB::CursorDirection direction) |
| 86 { | 87 { |
| 87 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 88 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 88 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 89 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 89 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBDatabase::NormalTask, new WebIDBCallbacks
(request)); | 90 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl
::create(request).leakPtr()); |
| 90 return request; | 91 return request; |
| 91 } | 92 } |
| 92 | 93 |
| 93 PassRefPtr<IDBRequest> IDBIndex::count(ExecutionContext* context, const ScriptVa
lue& range, ExceptionState& exceptionState) | 94 PassRefPtr<IDBRequest> IDBIndex::count(ExecutionContext* context, const ScriptVa
lue& range, ExceptionState& exceptionState) |
| 94 { | 95 { |
| 95 IDB_TRACE("IDBIndex::count"); | 96 IDB_TRACE("IDBIndex::count"); |
| 96 if (isDeleted()) { | 97 if (isDeleted()) { |
| 97 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 98 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 98 return 0; | 99 return 0; |
| 99 } | 100 } |
| 100 if (m_transaction->isFinished()) { | 101 if (m_transaction->isFinished()) { |
| 101 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 102 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 102 return 0; | 103 return 0; |
| 103 } | 104 } |
| 104 if (!m_transaction->isActive()) { | 105 if (!m_transaction->isActive()) { |
| 105 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 106 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 106 return 0; | 107 return 0; |
| 107 } | 108 } |
| 108 | 109 |
| 109 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); | 110 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); |
| 110 if (exceptionState.hadException()) | 111 if (exceptionState.hadException()) |
| 111 return 0; | 112 return 0; |
| 112 | 113 |
| 113 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 114 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 114 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange.release(), new WebIDBCallbacks(request)); | 115 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr()); |
| 115 return request; | 116 return request; |
| 116 } | 117 } |
| 117 | 118 |
| 118 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ExecutionContext* context, const
ScriptValue& range, const String& directionString, ExceptionState& exceptionStat
e) | 119 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ExecutionContext* context, const
ScriptValue& range, const String& directionString, ExceptionState& exceptionStat
e) |
| 119 { | 120 { |
| 120 IDB_TRACE("IDBIndex::openKeyCursor"); | 121 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 121 if (isDeleted()) { | 122 if (isDeleted()) { |
| 122 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 123 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 123 return 0; | 124 return 0; |
| 124 } | 125 } |
| 125 if (m_transaction->isFinished()) { | 126 if (m_transaction->isFinished()) { |
| 126 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 127 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 127 return 0; | 128 return 0; |
| 128 } | 129 } |
| 129 if (!m_transaction->isActive()) { | 130 if (!m_transaction->isActive()) { |
| 130 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 131 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 131 return 0; | 132 return 0; |
| 132 } | 133 } |
| 133 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, exceptionState); | 134 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, exceptionState); |
| 134 if (exceptionState.hadException()) | 135 if (exceptionState.hadException()) |
| 135 return 0; | 136 return 0; |
| 136 | 137 |
| 137 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); | 138 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); |
| 138 if (exceptionState.hadException()) | 139 if (exceptionState.hadException()) |
| 139 return 0; | 140 return 0; |
| 140 | 141 |
| 141 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 142 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 142 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 143 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
| 143 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, new WebIDB
Callbacks(request)); | 144 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCall
backsImpl::create(request).leakPtr()); |
| 144 return request; | 145 return request; |
| 145 } | 146 } |
| 146 | 147 |
| 147 PassRefPtr<IDBRequest> IDBIndex::get(ExecutionContext* context, const ScriptValu
e& key, ExceptionState& exceptionState) | 148 PassRefPtr<IDBRequest> IDBIndex::get(ExecutionContext* context, const ScriptValu
e& key, ExceptionState& exceptionState) |
| 148 { | 149 { |
| 149 IDB_TRACE("IDBIndex::get"); | 150 IDB_TRACE("IDBIndex::get"); |
| 150 if (isDeleted()) { | 151 if (isDeleted()) { |
| 151 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 152 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 152 return 0; | 153 return 0; |
| 153 } | 154 } |
| 154 if (m_transaction->isFinished()) { | 155 if (m_transaction->isFinished()) { |
| 155 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 156 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 156 return 0; | 157 return 0; |
| 157 } | 158 } |
| 158 if (!m_transaction->isActive()) { | 159 if (!m_transaction->isActive()) { |
| 159 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 160 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 160 return 0; | 161 return 0; |
| 161 } | 162 } |
| 162 | 163 |
| 163 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex
ceptionState); | 164 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex
ceptionState); |
| 164 if (exceptionState.hadException()) | 165 if (exceptionState.hadException()) |
| 165 return 0; | 166 return 0; |
| 166 if (!keyRange) { | 167 if (!keyRange) { |
| 167 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 168 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
| 168 return 0; | 169 return 0; |
| 169 } | 170 } |
| 170 | 171 |
| 171 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 172 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 172 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange.release(), false, new WebIDBCallbacks(request)); | 173 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange.release(), false, WebIDBCallbacksImpl::create(request).leakPtr()); |
| 173 return request; | 174 return request; |
| 174 } | 175 } |
| 175 | 176 |
| 176 PassRefPtr<IDBRequest> IDBIndex::getKey(ExecutionContext* context, const ScriptV
alue& key, ExceptionState& exceptionState) | 177 PassRefPtr<IDBRequest> IDBIndex::getKey(ExecutionContext* context, const ScriptV
alue& key, ExceptionState& exceptionState) |
| 177 { | 178 { |
| 178 IDB_TRACE("IDBIndex::getKey"); | 179 IDB_TRACE("IDBIndex::getKey"); |
| 179 if (isDeleted()) { | 180 if (isDeleted()) { |
| 180 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 181 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 181 return 0; | 182 return 0; |
| 182 } | 183 } |
| 183 if (m_transaction->isFinished()) { | 184 if (m_transaction->isFinished()) { |
| 184 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 185 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 185 return 0; | 186 return 0; |
| 186 } | 187 } |
| 187 if (!m_transaction->isActive()) { | 188 if (!m_transaction->isActive()) { |
| 188 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 189 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 189 return 0; | 190 return 0; |
| 190 } | 191 } |
| 191 | 192 |
| 192 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex
ceptionState); | 193 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex
ceptionState); |
| 193 if (exceptionState.hadException()) | 194 if (exceptionState.hadException()) |
| 194 return 0; | 195 return 0; |
| 195 if (!keyRange) { | 196 if (!keyRange) { |
| 196 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 197 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
| 197 return 0; | 198 return 0; |
| 198 } | 199 } |
| 199 | 200 |
| 200 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 201 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 201 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange.release(), true, new WebIDBCallbacks(request)); | 202 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange.release(), true, WebIDBCallbacksImpl::create(request).leakPtr()); |
| 202 return request; | 203 return request; |
| 203 } | 204 } |
| 204 | 205 |
| 205 WebIDBDatabase* IDBIndex::backendDB() const | 206 WebIDBDatabase* IDBIndex::backendDB() const |
| 206 { | 207 { |
| 207 return m_transaction->backendDB(); | 208 return m_transaction->backendDB(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 bool IDBIndex::isDeleted() const | 211 bool IDBIndex::isDeleted() const |
| 211 { | 212 { |
| 212 return m_deleted || m_objectStore->isDeleted(); | 213 return m_deleted || m_objectStore->isDeleted(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // namespace WebCore | 216 } // namespace WebCore |
| OLD | NEW |