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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "public/platform/WebBlobInfo.h" | 42 #include "public/platform/WebBlobInfo.h" |
43 #include "public/platform/WebIDBDatabase.h" | 43 #include "public/platform/WebIDBDatabase.h" |
44 #include "public/platform/WebIDBKeyRange.h" | 44 #include "public/platform/WebIDBKeyRange.h" |
45 #include <limits> | 45 #include <limits> |
46 | 46 |
47 using blink::WebIDBCursor; | 47 using blink::WebIDBCursor; |
48 using blink::WebIDBDatabase; | 48 using blink::WebIDBDatabase; |
49 | 49 |
50 namespace blink { | 50 namespace blink { |
51 | 51 |
52 IDBCursor* IDBCursor::create(PassOwnPtr<blink::WebIDBCursor> backend, blink::Web
IDBCursorDirection direction, IDBRequest* request, IDBAny* source, IDBTransactio
n* transaction) | 52 IDBCursor* IDBCursor::create(PassOwnPtr<WebIDBCursor> backend, WebIDBCursorDirec
tion direction, IDBRequest* request, IDBAny* source, IDBTransaction* transaction
) |
53 { | 53 { |
54 return new IDBCursor(backend, direction, request, source, transaction); | 54 return new IDBCursor(backend, direction, request, source, transaction); |
55 } | 55 } |
56 | 56 |
57 IDBCursor::IDBCursor(PassOwnPtr<blink::WebIDBCursor> backend, blink::WebIDBCurso
rDirection direction, IDBRequest* request, IDBAny* source, IDBTransaction* trans
action) | 57 IDBCursor::IDBCursor(PassOwnPtr<WebIDBCursor> backend, WebIDBCursorDirection dir
ection, IDBRequest* request, IDBAny* source, IDBTransaction* transaction) |
58 : m_backend(backend) | 58 : m_backend(backend) |
59 , m_request(request) | 59 , m_request(request) |
60 , m_direction(direction) | 60 , m_direction(direction) |
61 , m_source(source) | 61 , m_source(source) |
62 , m_transaction(transaction) | 62 , m_transaction(transaction) |
63 , m_gotValue(false) | 63 , m_gotValue(false) |
64 , m_keyDirty(true) | 64 , m_keyDirty(true) |
65 , m_primaryKeyDirty(true) | 65 , m_primaryKeyDirty(true) |
66 , m_valueDirty(true) | 66 , m_valueDirty(true) |
67 { | 67 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (!m_transaction->isActive()) { | 109 if (!m_transaction->isActive()) { |
110 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 110 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
111 return 0; | 111 return 0; |
112 } | 112 } |
113 if (m_transaction->isReadOnly()) { | 113 if (m_transaction->isReadOnly()) { |
114 exceptionState.throwDOMException(ReadOnlyError, "The record may not be u
pdated inside a read-only transaction."); | 114 exceptionState.throwDOMException(ReadOnlyError, "The record may not be u
pdated inside a read-only transaction."); |
115 return 0; | 115 return 0; |
116 } | 116 } |
117 | 117 |
118 IDBObjectStore* objectStore = effectiveObjectStore(); | 118 IDBObjectStore* objectStore = effectiveObjectStore(); |
119 return objectStore->put(scriptState, blink::WebIDBPutModeCursorUpdate, IDBAn
y::create(this), value, m_primaryKey, exceptionState); | 119 return objectStore->put(scriptState, WebIDBPutModeCursorUpdate, IDBAny::crea
te(this), value, m_primaryKey, exceptionState); |
120 } | 120 } |
121 | 121 |
122 void IDBCursor::advance(unsigned long count, ExceptionState& exceptionState) | 122 void IDBCursor::advance(unsigned long count, ExceptionState& exceptionState) |
123 { | 123 { |
124 IDB_TRACE("IDBCursor::advance"); | 124 IDB_TRACE("IDBCursor::advance"); |
125 if (!count) { | 125 if (!count) { |
126 exceptionState.throwTypeError("A count argument with value 0 (zero) was
supplied, must be greater than 0."); | 126 exceptionState.throwTypeError("A count argument with value 0 (zero) was
supplied, must be greater than 0."); |
127 return; | 127 return; |
128 } | 128 } |
129 if (!m_gotValue) { | 129 if (!m_gotValue) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return; | 190 return; |
191 } | 191 } |
192 | 192 |
193 if (isDeleted()) { | 193 if (isDeleted()) { |
194 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | 194 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 if (key) { | 198 if (key) { |
199 ASSERT(m_key); | 199 ASSERT(m_key); |
200 if (m_direction == blink::WebIDBCursorDirectionNext || m_direction == bl
ink::WebIDBCursorDirectionNextNoDuplicate) { | 200 if (m_direction == WebIDBCursorDirectionNext || m_direction == WebIDBCur
sorDirectionNextNoDuplicate) { |
201 const bool ok = m_key->isLessThan(key) | 201 const bool ok = m_key->isLessThan(key) |
202 || (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessTha
n(primaryKey)); | 202 || (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessTha
n(primaryKey)); |
203 if (!ok) { | 203 if (!ok) { |
204 exceptionState.throwDOMException(DataError, "The parameter is le
ss than or equal to this cursor's position."); | 204 exceptionState.throwDOMException(DataError, "The parameter is le
ss than or equal to this cursor's position."); |
205 return; | 205 return; |
206 } | 206 } |
207 | 207 |
208 } else { | 208 } else { |
209 const bool ok = key->isLessThan(m_key.get()) | 209 const bool ok = key->isLessThan(m_key.get()) |
210 || (primaryKey && key->isEqual(m_key.get()) && primaryKey->isLes
sThan(m_primaryKey.get())); | 210 || (primaryKey && key->isEqual(m_key.get()) && primaryKey->isLes
sThan(m_primaryKey.get())); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 ScriptValue scriptValue = idbAnyToScriptValue(scriptState, value); | 308 ScriptValue scriptValue = idbAnyToScriptValue(scriptState, value); |
309 handleBlobAcks(); | 309 handleBlobAcks(); |
310 return scriptValue; | 310 return scriptValue; |
311 } | 311 } |
312 | 312 |
313 ScriptValue IDBCursor::source(ScriptState* scriptState) const | 313 ScriptValue IDBCursor::source(ScriptState* scriptState) const |
314 { | 314 { |
315 return idbAnyToScriptValue(scriptState, m_source); | 315 return idbAnyToScriptValue(scriptState, m_source); |
316 } | 316 } |
317 | 317 |
318 void IDBCursor::setValueReady(IDBKey* key, IDBKey* primaryKey, PassRefPtr<Shared
Buffer> value, PassOwnPtr<Vector<blink::WebBlobInfo> > blobInfo) | 318 void IDBCursor::setValueReady(IDBKey* key, IDBKey* primaryKey, PassRefPtr<Shared
Buffer> value, PassOwnPtr<Vector<WebBlobInfo> > blobInfo) |
319 { | 319 { |
320 m_key = key; | 320 m_key = key; |
321 m_keyDirty = true; | 321 m_keyDirty = true; |
322 | 322 |
323 m_primaryKey = primaryKey; | 323 m_primaryKey = primaryKey; |
324 m_primaryKeyDirty = true; | 324 m_primaryKeyDirty = true; |
325 | 325 |
326 if (isCursorWithValue()) { | 326 if (isCursorWithValue()) { |
327 m_value = value; | 327 m_value = value; |
328 handleBlobAcks(); | 328 handleBlobAcks(); |
(...skipping 21 matching lines...) Expand all Loading... |
350 void IDBCursor::handleBlobAcks() | 350 void IDBCursor::handleBlobAcks() |
351 { | 351 { |
352 ASSERT(m_request || !m_blobInfo || !m_blobInfo->size()); | 352 ASSERT(m_request || !m_blobInfo || !m_blobInfo->size()); |
353 if (m_blobInfo.get() && m_blobInfo->size()) { | 353 if (m_blobInfo.get() && m_blobInfo->size()) { |
354 ASSERT(m_request); | 354 ASSERT(m_request); |
355 m_transaction->db()->ackReceivedBlobs(m_blobInfo.get()); | 355 m_transaction->db()->ackReceivedBlobs(m_blobInfo.get()); |
356 m_blobInfo.clear(); | 356 m_blobInfo.clear(); |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 blink::WebIDBCursorDirection IDBCursor::stringToDirection(const String& directio
nString, ExceptionState& exceptionState) | 360 WebIDBCursorDirection IDBCursor::stringToDirection(const String& directionString
, ExceptionState& exceptionState) |
361 { | 361 { |
362 if (directionString == IndexedDBNames::next) | 362 if (directionString == IndexedDBNames::next) |
363 return blink::WebIDBCursorDirectionNext; | 363 return WebIDBCursorDirectionNext; |
364 if (directionString == IndexedDBNames::nextunique) | 364 if (directionString == IndexedDBNames::nextunique) |
365 return blink::WebIDBCursorDirectionNextNoDuplicate; | 365 return WebIDBCursorDirectionNextNoDuplicate; |
366 if (directionString == IndexedDBNames::prev) | 366 if (directionString == IndexedDBNames::prev) |
367 return blink::WebIDBCursorDirectionPrev; | 367 return WebIDBCursorDirectionPrev; |
368 if (directionString == IndexedDBNames::prevunique) | 368 if (directionString == IndexedDBNames::prevunique) |
369 return blink::WebIDBCursorDirectionPrevNoDuplicate; | 369 return WebIDBCursorDirectionPrevNoDuplicate; |
370 | 370 |
371 exceptionState.throwTypeError("The direction provided ('" + directionString
+ "') is not one of 'next', 'nextunique', 'prev', or 'prevunique'."); | 371 exceptionState.throwTypeError("The direction provided ('" + directionString
+ "') is not one of 'next', 'nextunique', 'prev', or 'prevunique'."); |
372 return blink::WebIDBCursorDirectionNext; | 372 return WebIDBCursorDirectionNext; |
373 } | 373 } |
374 | 374 |
375 const String& IDBCursor::direction() const | 375 const String& IDBCursor::direction() const |
376 { | 376 { |
377 switch (m_direction) { | 377 switch (m_direction) { |
378 case blink::WebIDBCursorDirectionNext: | 378 case WebIDBCursorDirectionNext: |
379 return IndexedDBNames::next; | 379 return IndexedDBNames::next; |
380 | 380 |
381 case blink::WebIDBCursorDirectionNextNoDuplicate: | 381 case WebIDBCursorDirectionNextNoDuplicate: |
382 return IndexedDBNames::nextunique; | 382 return IndexedDBNames::nextunique; |
383 | 383 |
384 case blink::WebIDBCursorDirectionPrev: | 384 case WebIDBCursorDirectionPrev: |
385 return IndexedDBNames::prev; | 385 return IndexedDBNames::prev; |
386 | 386 |
387 case blink::WebIDBCursorDirectionPrevNoDuplicate: | 387 case WebIDBCursorDirectionPrevNoDuplicate: |
388 return IndexedDBNames::prevunique; | 388 return IndexedDBNames::prevunique; |
389 | 389 |
390 default: | 390 default: |
391 ASSERT_NOT_REACHED(); | 391 ASSERT_NOT_REACHED(); |
392 return IndexedDBNames::next; | 392 return IndexedDBNames::next; |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 } // namespace blink | 396 } // namespace blink |
OLD | NEW |