1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef IDBCursor_h 27 #define IDBCursor_h 28 29 #include "bindings/v8/ScriptValue.h" 30 #include "bindings/v8/ScriptWrappable.h" 31 #include "modules/indexeddb/IDBKey.h" 32 #include "modules/indexeddb/IDBTransaction.h" 33 #include "modules/indexeddb/IndexedDB.h" 34 #include "wtf/PassRefPtr.h" 35 #include "wtf/RefCounted.h" 36 #include "wtf/RefPtr.h" 37 38 namespace WebCore { 39 40 class DOMRequestState; 41 class ExceptionState; 42 class IDBAny; 43 class IDBCallbacks; 44 class IDBCursorBackendInterface; 45 class IDBRequest; 46 class ScriptExecutionContext; 47 48 class IDBCursor : public ScriptWrappable, public RefCounted<IDBCursor> { 49 public: 50 static const AtomicString& directionNext(); 51 static const AtomicString& directionNextUnique(); 52 static const AtomicString& directionPrev(); 53 static const AtomicString& directionPrevUnique(); 54 55 static IndexedDB::CursorDirection stringToDirection(const String& modeString, ExceptionState&); 56 static const AtomicString& directionToString(unsigned short mode); 57 58 static PassRefPtr<IDBCursor> create(PassRefPtr<IDBCursorBackendInterface>, IndexedDB::CursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*); 59 virtual ~IDBCursor(); 60 61 // Implement the IDL 62 const String& direction() const { return directionToString(m_direction); } 63 const ScriptValue& key() const { return m_currentKeyValue; } 64 const ScriptValue& primaryKey() const { return m_currentPrimaryKeyValue; } 65 const ScriptValue& value() const { return m_currentValue; } 66 IDBAny* source() const { return m_source.get(); } 67 68 PassRefPtr<IDBRequest> update(ScriptState*, ScriptValue&, ExceptionState&); 69 void advance(unsigned long, ExceptionState&); 70 void continueFunction(ScriptExecutionContext*, const ScriptValue& key, ExceptionState&); 71 PassRefPtr<IDBRequest> deleteFunction(ScriptExecutionContext*, ExceptionState&); 72 73 void continueFunction(PassRefPtr<IDBKey>, ExceptionState&); 74 void postSuccessHandlerCallback(); 75 void close(); 76 void setValueReady(DOMRequestState*, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, ScriptValue&); 77 PassRefPtr<IDBKey> idbPrimaryKey() { return m_currentPrimaryKey; } 78 virtual bool isKeyCursor() const { return true; } 79 virtual bool isCursorWithValue() const { return false; } 80 81 protected: 82 IDBCursor(PassRefPtr<IDBCursorBackendInterface>, IndexedDB::CursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*); 83 84 private: 85 PassRefPtr<IDBObjectStore> effectiveObjectStore(); 86 87 bool isDeleted() const; 88 89 RefPtr<IDBCursorBackendInterface> m_backend; 90 RefPtr<IDBRequest> m_request; 91 const IndexedDB::CursorDirection m_direction; 92 RefPtr<IDBAny> m_source; 93 RefPtr<IDBTransaction> m_transaction; 94 IDBTransaction::OpenCursorNotifier m_transactionNotifier; 95 bool m_gotValue; 96 // These values are held because m_backend may advance while they 97 // are still valid for the current success handlers. 98 ScriptValue m_currentKeyValue; 99 ScriptValue m_currentPrimaryKeyValue; 100 RefPtr<IDBKey> m_currentKey; 101 RefPtr<IDBKey> m_currentPrimaryKey; 102 ScriptValue m_currentValue; 103 }; 104 105 } // namespace WebCore 106 107 #endif // IDBCursor_h 108