| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 { | 63 { |
| 64 DOMRequestState requestState(context); | 64 DOMRequestState requestState(context); |
| 65 return idbAnyToScriptValue(&requestState, IDBAny::create(m_metadata.keyPath)
); | 65 return idbAnyToScriptValue(&requestState, IDBAny::create(m_metadata.keyPath)
); |
| 66 } | 66 } |
| 67 | 67 |
| 68 PassRefPtr<IDBRequest> IDBIndex::openCursor(ExecutionContext* context, const Scr
iptValue& range, const String& directionString, ExceptionState& exceptionState) | 68 PassRefPtr<IDBRequest> IDBIndex::openCursor(ExecutionContext* context, const Scr
iptValue& range, const String& directionString, ExceptionState& exceptionState) |
| 69 { | 69 { |
| 70 IDB_TRACE("IDBIndex::openCursor"); | 70 IDB_TRACE("IDBIndex::openCursor"); |
| 71 if (isDeleted()) { | 71 if (isDeleted()) { |
| 72 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 72 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 73 return 0; | 73 return nullptr; |
| 74 } | 74 } |
| 75 if (m_transaction->isFinished()) { | 75 if (m_transaction->isFinished()) { |
| 76 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 76 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 77 return 0; | 77 return nullptr; |
| 78 } | 78 } |
| 79 if (!m_transaction->isActive()) { | 79 if (!m_transaction->isActive()) { |
| 80 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 80 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 81 return 0; | 81 return nullptr; |
| 82 } | 82 } |
| 83 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); | 83 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); |
| 84 if (exceptionState.hadException()) | 84 if (exceptionState.hadException()) |
| 85 return 0; | 85 return nullptr; |
| 86 | 86 |
| 87 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); | 87 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); |
| 88 if (exceptionState.hadException()) | 88 if (exceptionState.hadException()) |
| 89 return 0; | 89 return nullptr; |
| 90 | 90 |
| 91 return openCursor(context, keyRange.release(), direction); | 91 return openCursor(context, keyRange.release(), direction); |
| 92 } | 92 } |
| 93 | 93 |
| 94 PassRefPtr<IDBRequest> IDBIndex::openCursor(ExecutionContext* context, PassRefPt
r<IDBKeyRange> keyRange, WebIDBCursor::Direction direction) | 94 PassRefPtr<IDBRequest> IDBIndex::openCursor(ExecutionContext* context, PassRefPt
r<IDBKeyRange> keyRange, WebIDBCursor::Direction direction) |
| 95 { | 95 { |
| 96 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 96 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 97 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 97 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 98 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl
::create(request).leakPtr()); | 98 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl
::create(request).leakPtr()); |
| 99 return request; | 99 return request; |
| 100 } | 100 } |
| 101 | 101 |
| 102 PassRefPtr<IDBRequest> IDBIndex::count(ExecutionContext* context, const ScriptVa
lue& range, ExceptionState& exceptionState) | 102 PassRefPtr<IDBRequest> IDBIndex::count(ExecutionContext* context, const ScriptVa
lue& range, ExceptionState& exceptionState) |
| 103 { | 103 { |
| 104 IDB_TRACE("IDBIndex::count"); | 104 IDB_TRACE("IDBIndex::count"); |
| 105 if (isDeleted()) { | 105 if (isDeleted()) { |
| 106 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 106 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 107 return 0; | 107 return nullptr; |
| 108 } | 108 } |
| 109 if (m_transaction->isFinished()) { | 109 if (m_transaction->isFinished()) { |
| 110 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 110 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 111 return 0; | 111 return nullptr; |
| 112 } | 112 } |
| 113 if (!m_transaction->isActive()) { | 113 if (!m_transaction->isActive()) { |
| 114 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 114 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 115 return 0; | 115 return nullptr; |
| 116 } | 116 } |
| 117 | 117 |
| 118 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); | 118 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); |
| 119 if (exceptionState.hadException()) | 119 if (exceptionState.hadException()) |
| 120 return 0; | 120 return nullptr; |
| 121 | 121 |
| 122 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 122 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 123 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr()); | 123 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr()); |
| 124 return request; | 124 return request; |
| 125 } | 125 } |
| 126 | 126 |
| 127 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ExecutionContext* context, const
ScriptValue& range, const String& directionString, ExceptionState& exceptionStat
e) | 127 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ExecutionContext* context, const
ScriptValue& range, const String& directionString, ExceptionState& exceptionStat
e) |
| 128 { | 128 { |
| 129 IDB_TRACE("IDBIndex::openKeyCursor"); | 129 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 130 if (isDeleted()) { | 130 if (isDeleted()) { |
| 131 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 131 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 132 return 0; | 132 return nullptr; |
| 133 } | 133 } |
| 134 if (m_transaction->isFinished()) { | 134 if (m_transaction->isFinished()) { |
| 135 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 135 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 136 return 0; | 136 return nullptr; |
| 137 } | 137 } |
| 138 if (!m_transaction->isActive()) { | 138 if (!m_transaction->isActive()) { |
| 139 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 139 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 140 return 0; | 140 return nullptr; |
| 141 } | 141 } |
| 142 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); | 142 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); |
| 143 if (exceptionState.hadException()) | 143 if (exceptionState.hadException()) |
| 144 return 0; | 144 return nullptr; |
| 145 | 145 |
| 146 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); | 146 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range,
exceptionState); |
| 147 if (exceptionState.hadException()) | 147 if (exceptionState.hadException()) |
| 148 return 0; | 148 return nullptr; |
| 149 | 149 |
| 150 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 150 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 151 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 151 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
| 152 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCall
backsImpl::create(request).leakPtr()); | 152 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCall
backsImpl::create(request).leakPtr()); |
| 153 return request; | 153 return request; |
| 154 } | 154 } |
| 155 | 155 |
| 156 PassRefPtr<IDBRequest> IDBIndex::get(ExecutionContext* context, const ScriptValu
e& key, ExceptionState& exceptionState) | 156 PassRefPtr<IDBRequest> IDBIndex::get(ExecutionContext* context, const ScriptValu
e& key, ExceptionState& exceptionState) |
| 157 { | 157 { |
| 158 IDB_TRACE("IDBIndex::get"); | 158 IDB_TRACE("IDBIndex::get"); |
| 159 return getInternal(context, key, exceptionState, false); | 159 return getInternal(context, key, exceptionState, false); |
| 160 } | 160 } |
| 161 | 161 |
| 162 PassRefPtr<IDBRequest> IDBIndex::getKey(ExecutionContext* context, const ScriptV
alue& key, ExceptionState& exceptionState) | 162 PassRefPtr<IDBRequest> IDBIndex::getKey(ExecutionContext* context, const ScriptV
alue& key, ExceptionState& exceptionState) |
| 163 { | 163 { |
| 164 IDB_TRACE("IDBIndex::getKey"); | 164 IDB_TRACE("IDBIndex::getKey"); |
| 165 return getInternal(context, key, exceptionState, true); | 165 return getInternal(context, key, exceptionState, true); |
| 166 } | 166 } |
| 167 | 167 |
| 168 PassRefPtr<IDBRequest> IDBIndex::getInternal(ExecutionContext* context, const Sc
riptValue& key, ExceptionState& exceptionState, bool keyOnly) | 168 PassRefPtr<IDBRequest> IDBIndex::getInternal(ExecutionContext* context, const Sc
riptValue& key, ExceptionState& exceptionState, bool keyOnly) |
| 169 { | 169 { |
| 170 if (isDeleted()) { | 170 if (isDeleted()) { |
| 171 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 171 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 172 return 0; | 172 return nullptr; |
| 173 } | 173 } |
| 174 if (m_transaction->isFinished()) { | 174 if (m_transaction->isFinished()) { |
| 175 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 175 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 176 return 0; | 176 return nullptr; |
| 177 } | 177 } |
| 178 if (!m_transaction->isActive()) { | 178 if (!m_transaction->isActive()) { |
| 179 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 179 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 180 return 0; | 180 return nullptr; |
| 181 } | 181 } |
| 182 | 182 |
| 183 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex
ceptionState); | 183 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex
ceptionState); |
| 184 if (exceptionState.hadException()) | 184 if (exceptionState.hadException()) |
| 185 return 0; | 185 return nullptr; |
| 186 if (!keyRange) { | 186 if (!keyRange) { |
| 187 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 187 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
| 188 return 0; | 188 return nullptr; |
| 189 } | 189 } |
| 190 | 190 |
| 191 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 191 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 192 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange.release(), keyOnly, WebIDBCallbacksImpl::create(request).leakPtr()); | 192 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange.release(), keyOnly, WebIDBCallbacksImpl::create(request).leakPtr()); |
| 193 return request; | 193 return request; |
| 194 } | 194 } |
| 195 | 195 |
| 196 WebIDBDatabase* IDBIndex::backendDB() const | 196 WebIDBDatabase* IDBIndex::backendDB() const |
| 197 { | 197 { |
| 198 return m_transaction->backendDB(); | 198 return m_transaction->backendDB(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool IDBIndex::isDeleted() const | 201 bool IDBIndex::isDeleted() const |
| 202 { | 202 { |
| 203 return m_deleted || m_objectStore->isDeleted(); | 203 return m_deleted || m_objectStore->isDeleted(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace WebCore | 206 } // namespace WebCore |
| OLD | NEW |