| 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 20 matching lines...) Expand all Loading... |
| 31 #include "bindings/v8/NewScriptState.h" | 31 #include "bindings/v8/NewScriptState.h" |
| 32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include "core/dom/ExecutionContext.h" | 33 #include "core/dom/ExecutionContext.h" |
| 34 #include "core/inspector/ScriptCallStack.h" | 34 #include "core/inspector/ScriptCallStack.h" |
| 35 #include "modules/indexeddb/IDBAny.h" | 35 #include "modules/indexeddb/IDBAny.h" |
| 36 #include "modules/indexeddb/IDBDatabase.h" | 36 #include "modules/indexeddb/IDBDatabase.h" |
| 37 #include "modules/indexeddb/IDBObjectStore.h" | 37 #include "modules/indexeddb/IDBObjectStore.h" |
| 38 #include "modules/indexeddb/IDBTracing.h" | 38 #include "modules/indexeddb/IDBTracing.h" |
| 39 #include "modules/indexeddb/IDBTransaction.h" | 39 #include "modules/indexeddb/IDBTransaction.h" |
| 40 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | 40 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
| 41 #include "public/platform/WebBlobInfo.h" |
| 41 #include "public/platform/WebIDBDatabase.h" | 42 #include "public/platform/WebIDBDatabase.h" |
| 42 #include "public/platform/WebIDBKeyRange.h" | 43 #include "public/platform/WebIDBKeyRange.h" |
| 43 #include <limits> | 44 #include <limits> |
| 44 | 45 |
| 45 using blink::WebIDBCursor; | 46 using blink::WebIDBCursor; |
| 46 using blink::WebIDBDatabase; | 47 using blink::WebIDBDatabase; |
| 47 | 48 |
| 48 namespace WebCore { | 49 namespace WebCore { |
| 49 | 50 |
| 50 PassRefPtrWillBeRawPtr<IDBCursor> IDBCursor::create(PassOwnPtr<blink::WebIDBCurs
or> backend, WebIDBCursor::Direction direction, IDBRequest* request, IDBAny* sou
rce, IDBTransaction* transaction) | 51 PassRefPtrWillBeRawPtr<IDBCursor> IDBCursor::create(PassOwnPtr<blink::WebIDBCurs
or> backend, WebIDBCursor::Direction direction, IDBRequest* request, IDBAny* sou
rce, IDBTransaction* transaction) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 { | 90 { |
| 90 ASSERT(m_backend); | 91 ASSERT(m_backend); |
| 91 ASSERT(m_request); | 92 ASSERT(m_request); |
| 92 ASSERT(m_source->type() == IDBAny::IDBObjectStoreType || m_source->type() ==
IDBAny::IDBIndexType); | 93 ASSERT(m_source->type() == IDBAny::IDBObjectStoreType || m_source->type() ==
IDBAny::IDBIndexType); |
| 93 ASSERT(m_transaction); | 94 ASSERT(m_transaction); |
| 94 ScriptWrappable::init(this); | 95 ScriptWrappable::init(this); |
| 95 } | 96 } |
| 96 | 97 |
| 97 IDBCursor::~IDBCursor() | 98 IDBCursor::~IDBCursor() |
| 98 { | 99 { |
| 100 handleBlobAcks(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void IDBCursor::trace(Visitor* visitor) | 103 void IDBCursor::trace(Visitor* visitor) |
| 102 { | 104 { |
| 103 visitor->trace(m_request); | 105 visitor->trace(m_request); |
| 104 visitor->trace(m_source); | 106 visitor->trace(m_source); |
| 105 } | 107 } |
| 106 | 108 |
| 107 PassRefPtrWillBeRawPtr<IDBRequest> IDBCursor::update(ExecutionContext* execution
Context, ScriptValue& value, ExceptionState& exceptionState) | 109 PassRefPtrWillBeRawPtr<IDBRequest> IDBCursor::update(ExecutionContext* execution
Context, ScriptValue& value, ExceptionState& exceptionState) |
| 108 { | 110 { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 void IDBCursor::postSuccessHandlerCallback() | 296 void IDBCursor::postSuccessHandlerCallback() |
| 295 { | 297 { |
| 296 if (m_backend) | 298 if (m_backend) |
| 297 m_backend->postSuccessHandlerCallback(); | 299 m_backend->postSuccessHandlerCallback(); |
| 298 } | 300 } |
| 299 | 301 |
| 300 void IDBCursor::close() | 302 void IDBCursor::close() |
| 301 { | 303 { |
| 302 // The notifier may be the last reference to this cursor. | 304 // The notifier may be the last reference to this cursor. |
| 303 RefPtrWillBeRawPtr<IDBCursor> protect(this); | 305 RefPtrWillBeRawPtr<IDBCursor> protect(this); |
| 306 handleBlobAcks(); |
| 304 m_request.clear(); | 307 m_request.clear(); |
| 305 m_backend.clear(); | 308 m_backend.clear(); |
| 306 } | 309 } |
| 307 | 310 |
| 308 #if !ENABLE(OILPAN) | 311 #if !ENABLE(OILPAN) |
| 309 void IDBCursor::checkForReferenceCycle() | 312 void IDBCursor::checkForReferenceCycle() |
| 310 { | 313 { |
| 311 // If this cursor and its request have the only references | 314 // If this cursor and its request have the only references |
| 312 // to each other, then explicitly break the cycle. | 315 // to each other, then explicitly break the cycle. |
| 313 if (!m_request || m_request->getResultCursor() != this) | 316 if (!m_request || m_request->getResultCursor() != this) |
| 314 return; | 317 return; |
| 315 | 318 |
| 316 if (!hasOneRef() || !m_request->hasOneRef()) | 319 if (!hasOneRef() || !m_request->hasOneRef()) |
| 317 return; | 320 return; |
| 318 | 321 |
| 322 handleBlobAcks(); |
| 319 m_request.clear(); | 323 m_request.clear(); |
| 320 } | 324 } |
| 321 #endif | 325 #endif |
| 322 | 326 |
| 323 ScriptValue IDBCursor::key(NewScriptState* scriptState) | 327 ScriptValue IDBCursor::key(NewScriptState* scriptState) |
| 324 { | 328 { |
| 325 m_keyDirty = false; | 329 m_keyDirty = false; |
| 326 return idbKeyToScriptValue(scriptState, m_key); | 330 return idbKeyToScriptValue(scriptState, m_key); |
| 327 } | 331 } |
| 328 | 332 |
| 329 ScriptValue IDBCursor::primaryKey(NewScriptState* scriptState) | 333 ScriptValue IDBCursor::primaryKey(NewScriptState* scriptState) |
| 330 { | 334 { |
| 331 m_primaryKeyDirty = false; | 335 m_primaryKeyDirty = false; |
| 332 return idbKeyToScriptValue(scriptState, m_primaryKey); | 336 return idbKeyToScriptValue(scriptState, m_primaryKey); |
| 333 } | 337 } |
| 334 | 338 |
| 335 ScriptValue IDBCursor::value(NewScriptState* scriptState) | 339 ScriptValue IDBCursor::value(NewScriptState* scriptState) |
| 336 { | 340 { |
| 337 ASSERT(isCursorWithValue()); | 341 ASSERT(isCursorWithValue()); |
| 338 | 342 |
| 339 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore(); | 343 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore(); |
| 340 const IDBObjectStoreMetadata& metadata = objectStore->metadata(); | 344 const IDBObjectStoreMetadata& metadata = objectStore->metadata(); |
| 341 RefPtrWillBeRawPtr<IDBAny> value; | 345 RefPtrWillBeRawPtr<IDBAny> value; |
| 342 if (metadata.autoIncrement && !metadata.keyPath.isNull()) { | 346 if (metadata.autoIncrement && !metadata.keyPath.isNull()) { |
| 343 value = IDBAny::create(m_value, m_primaryKey, metadata.keyPath); | 347 value = IDBAny::create(m_value, m_blobInfo.get(), m_primaryKey, metadata
.keyPath); |
| 344 #ifndef NDEBUG | 348 #ifndef NDEBUG |
| 345 assertPrimaryKeyValidOrInjectable(scriptState, m_value, m_primaryKey, me
tadata.keyPath); | 349 assertPrimaryKeyValidOrInjectable(scriptState, m_value, m_blobInfo.get()
, m_primaryKey, metadata.keyPath); |
| 346 #endif | 350 #endif |
| 347 } else { | 351 } else { |
| 348 value = IDBAny::create(m_value); | 352 value = IDBAny::create(m_value, m_blobInfo.get()); |
| 349 } | 353 } |
| 350 | 354 |
| 351 m_valueDirty = false; | 355 m_valueDirty = false; |
| 352 return idbAnyToScriptValue(scriptState, value); | 356 ScriptValue scriptValue = idbAnyToScriptValue(scriptState, value); |
| 357 handleBlobAcks(); |
| 358 return scriptValue; |
| 353 } | 359 } |
| 354 | 360 |
| 355 ScriptValue IDBCursor::source(NewScriptState* scriptState) const | 361 ScriptValue IDBCursor::source(NewScriptState* scriptState) const |
| 356 { | 362 { |
| 357 return idbAnyToScriptValue(scriptState, m_source); | 363 return idbAnyToScriptValue(scriptState, m_source); |
| 358 } | 364 } |
| 359 | 365 |
| 360 void IDBCursor::setValueReady(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primary
Key, PassRefPtr<SharedBuffer> value) | 366 void IDBCursor::setValueReady(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primary
Key, PassRefPtr<SharedBuffer> value, PassOwnPtr<Vector<blink::WebBlobInfo> > blo
bInfo) |
| 361 { | 367 { |
| 362 m_key = key; | 368 m_key = key; |
| 363 m_keyDirty = true; | 369 m_keyDirty = true; |
| 364 | 370 |
| 365 m_primaryKey = primaryKey; | 371 m_primaryKey = primaryKey; |
| 366 m_primaryKeyDirty = true; | 372 m_primaryKeyDirty = true; |
| 367 | 373 |
| 368 if (isCursorWithValue()) { | 374 if (isCursorWithValue()) { |
| 369 m_value = value; | 375 m_value = value; |
| 376 handleBlobAcks(); |
| 377 m_blobInfo = blobInfo; |
| 370 m_valueDirty = true; | 378 m_valueDirty = true; |
| 371 } | 379 } |
| 372 | 380 |
| 373 m_gotValue = true; | 381 m_gotValue = true; |
| 374 } | 382 } |
| 375 | 383 |
| 376 PassRefPtr<IDBObjectStore> IDBCursor::effectiveObjectStore() const | 384 PassRefPtr<IDBObjectStore> IDBCursor::effectiveObjectStore() const |
| 377 { | 385 { |
| 378 if (m_source->type() == IDBAny::IDBObjectStoreType) | 386 if (m_source->type() == IDBAny::IDBObjectStoreType) |
| 379 return m_source->idbObjectStore(); | 387 return m_source->idbObjectStore(); |
| 380 RefPtr<IDBIndex> index = m_source->idbIndex(); | 388 RefPtr<IDBIndex> index = m_source->idbIndex(); |
| 381 return index->objectStore(); | 389 return index->objectStore(); |
| 382 } | 390 } |
| 383 | 391 |
| 384 bool IDBCursor::isDeleted() const | 392 bool IDBCursor::isDeleted() const |
| 385 { | 393 { |
| 386 if (m_source->type() == IDBAny::IDBObjectStoreType) | 394 if (m_source->type() == IDBAny::IDBObjectStoreType) |
| 387 return m_source->idbObjectStore()->isDeleted(); | 395 return m_source->idbObjectStore()->isDeleted(); |
| 388 return m_source->idbIndex()->isDeleted(); | 396 return m_source->idbIndex()->isDeleted(); |
| 389 } | 397 } |
| 390 | 398 |
| 399 void IDBCursor::handleBlobAcks() |
| 400 { |
| 401 ASSERT(m_request || !m_blobInfo || !m_blobInfo->size()); |
| 402 if (m_blobInfo.get() && m_blobInfo->size()) { |
| 403 ASSERT(m_request); |
| 404 m_transaction->db()->ackReceivedBlobs(m_blobInfo.get()); |
| 405 m_blobInfo.clear(); |
| 406 } |
| 407 } |
| 408 |
| 391 WebIDBCursor::Direction IDBCursor::stringToDirection(const String& directionStri
ng, ExceptionState& exceptionState) | 409 WebIDBCursor::Direction IDBCursor::stringToDirection(const String& directionStri
ng, ExceptionState& exceptionState) |
| 392 { | 410 { |
| 393 if (directionString.isNull() || directionString == IDBCursor::directionNext(
)) | 411 if (directionString.isNull() || directionString == IDBCursor::directionNext(
)) |
| 394 return WebIDBCursor::Next; | 412 return WebIDBCursor::Next; |
| 395 if (directionString == IDBCursor::directionNextUnique()) | 413 if (directionString == IDBCursor::directionNextUnique()) |
| 396 return WebIDBCursor::NextNoDuplicate; | 414 return WebIDBCursor::NextNoDuplicate; |
| 397 if (directionString == IDBCursor::directionPrev()) | 415 if (directionString == IDBCursor::directionPrev()) |
| 398 return WebIDBCursor::Prev; | 416 return WebIDBCursor::Prev; |
| 399 if (directionString == IDBCursor::directionPrevUnique()) | 417 if (directionString == IDBCursor::directionPrevUnique()) |
| 400 return WebIDBCursor::PrevNoDuplicate; | 418 return WebIDBCursor::PrevNoDuplicate; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 418 case WebIDBCursor::PrevNoDuplicate: | 436 case WebIDBCursor::PrevNoDuplicate: |
| 419 return IDBCursor::directionPrevUnique(); | 437 return IDBCursor::directionPrevUnique(); |
| 420 | 438 |
| 421 default: | 439 default: |
| 422 ASSERT_NOT_REACHED(); | 440 ASSERT_NOT_REACHED(); |
| 423 return IDBCursor::directionNext(); | 441 return IDBCursor::directionNext(); |
| 424 } | 442 } |
| 425 } | 443 } |
| 426 | 444 |
| 427 } // namespace WebCore | 445 } // namespace WebCore |
| OLD | NEW |