2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #if ENABLE(INDEXED_DATABASE)
32 #include "IDBTransaction.h"
33 #include "IndexedDB.h"
34 #include "ScriptWrappable.h"
35 #include <bindings/ScriptValue.h>
36 #include <wtf/PassRefPtr.h>
37 #include <wtf/RefCounted.h>
38 #include <wtf/RefPtr.h>
42 class DOMRequestState;
45 class IDBCursorBackend;
47 class ScriptExecutionContext;
49 typedef int ExceptionCode;
51 class IDBCursor : public ScriptWrappable, public RefCounted<IDBCursor> {
53 static const AtomicString& directionNext();
54 static const AtomicString& directionNextUnique();
55 static const AtomicString& directionPrev();
56 static const AtomicString& directionPrevUnique();
58 static IndexedDB::CursorDirection stringToDirection(const String& modeString, ExceptionCode&);
59 static const AtomicString& directionToString(IndexedDB::CursorDirection mode);
61 static PassRefPtr<IDBCursor> create(PassRefPtr<IDBCursorBackend>, IndexedDB::CursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
65 const String& direction() const;
66 const Deprecated::ScriptValue& key() const;
67 const Deprecated::ScriptValue& primaryKey() const;
68 const Deprecated::ScriptValue& value() const;
69 IDBAny* source() const;
71 PassRefPtr<IDBRequest> update(JSC::ExecState*, Deprecated::ScriptValue&, ExceptionCode&);
72 void advance(unsigned long, ExceptionCode&);
73 // FIXME: Try to modify the code generator so this overload is unneeded.
74 void continueFunction(ScriptExecutionContext*, ExceptionCode& ec) { continueFunction(static_cast<IDBKey*>(0), ec); }
75 void continueFunction(ScriptExecutionContext*, const Deprecated::ScriptValue& key, ExceptionCode&);
76 PassRefPtr<IDBRequest> deleteFunction(ScriptExecutionContext*, ExceptionCode&);
78 void continueFunction(PassRefPtr<IDBKey>, ExceptionCode&);
79 void postSuccessHandlerCallback();
81 void setValueReady(DOMRequestState*, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, Deprecated::ScriptValue&);
82 PassRefPtr<IDBKey> idbPrimaryKey() { return m_currentPrimaryKey; }
85 IDBCursor(PassRefPtr<IDBCursorBackend>, IndexedDB::CursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
86 virtual bool isKeyCursor() const { return true; }
89 PassRefPtr<IDBObjectStore> effectiveObjectStore();
91 RefPtr<IDBCursorBackend> m_backend;
92 RefPtr<IDBRequest> m_request;
93 const IndexedDB::CursorDirection m_direction;
94 RefPtr<IDBAny> m_source;
95 RefPtr<IDBTransaction> m_transaction;
96 IDBTransaction::OpenCursorNotifier m_transactionNotifier;
98 // These values are held because m_backend may advance while they
99 // are still valid for the current success handlers.
100 Deprecated::ScriptValue m_currentKeyValue;
101 Deprecated::ScriptValue m_currentPrimaryKeyValue;
102 RefPtr<IDBKey> m_currentKey;
103 RefPtr<IDBKey> m_currentPrimaryKey;
104 Deprecated::ScriptValue m_currentValue;
107 } // namespace WebCore
111 #endif // IDBCursor_h