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 #include "bindings/v8/ScriptValue.h"
30 #include "bindings/v8/ScriptWrappable.h"
31 #include "modules/indexeddb/IDBKey.h"
32 #include "modules/indexeddb/IDBRequest.h"
33 #include "modules/indexeddb/IndexedDB.h"
34 #include "public/platform/WebIDBCursor.h"
35 #include "wtf/PassRefPtr.h"
36 #include "wtf/RefCounted.h"
37 #include "wtf/RefPtr.h"
41 class DOMRequestState;
45 class ExecutionContext;
48 class IDBCursor : public ScriptWrappable, public WTF::RefCountedBase {
50 static const AtomicString& directionNext();
51 static const AtomicString& directionNextUnique();
52 static const AtomicString& directionPrev();
53 static const AtomicString& directionPrevUnique();
55 static blink::WebIDBCursor::Direction stringToDirection(const String& modeString, ExceptionState&);
56 static const AtomicString& directionToString(unsigned short mode);
58 static PassRefPtr<IDBCursor> create(PassOwnPtr<blink::WebIDBCursor>, blink::WebIDBCursor::Direction, IDBRequest*, IDBAny* source, IDBTransaction*);
62 const String& direction() const { return directionToString(m_direction); }
63 ScriptValue key(ExecutionContext*);
64 ScriptValue primaryKey(ExecutionContext*);
65 ScriptValue value(ExecutionContext*);
66 ScriptValue source(ExecutionContext*) const;
68 PassRefPtr<IDBRequest> update(ScriptState*, ScriptValue&, ExceptionState&);
69 void advance(unsigned long, ExceptionState&);
70 void continueFunction(ExecutionContext*, const ScriptValue& key, ExceptionState&);
71 void continuePrimaryKey(ExecutionContext*, const ScriptValue& key, const ScriptValue& primaryKey, ExceptionState&);
72 PassRefPtr<IDBRequest> deleteFunction(ExecutionContext*, ExceptionState&);
74 bool isKeyDirty() const { return m_keyDirty; }
75 bool isPrimaryKeyDirty() const { return m_primaryKeyDirty; }
76 bool isValueDirty() const { return m_valueDirty; }
78 void continueFunction(PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, ExceptionState&);
79 void postSuccessHandlerCallback();
81 void setValueReady(PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> value);
82 PassRefPtr<IDBKey> idbPrimaryKey() const { return m_primaryKey; }
83 IDBRequest* request() const { return m_request.get(); }
84 virtual bool isKeyCursor() const { return true; }
85 virtual bool isCursorWithValue() const { return false; }
92 checkForReferenceCycle();
96 IDBCursor(PassOwnPtr<blink::WebIDBCursor>, blink::WebIDBCursor::Direction, IDBRequest*, IDBAny* source, IDBTransaction*);
99 PassRefPtr<IDBObjectStore> effectiveObjectStore() const;
101 void checkForReferenceCycle();
102 bool isDeleted() const;
104 OwnPtr<blink::WebIDBCursor> m_backend;
105 RefPtr<IDBRequest> m_request;
106 const blink::WebIDBCursor::Direction m_direction;
107 RefPtr<IDBAny> m_source;
108 RefPtr<IDBTransaction> m_transaction;
111 bool m_primaryKeyDirty;
113 RefPtr<IDBKey> m_key;
114 RefPtr<IDBKey> m_primaryKey;
115 RefPtr<SharedBuffer> m_value;
118 } // namespace WebCore
120 #endif // IDBCursor_h