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/core/v8/ScriptValue.h"
30 #include "bindings/core/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 "public/platform/WebIDBTypes.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/RefPtr.h"
48 class IDBCursor : public GarbageCollectedFinalized<IDBCursor>, public ScriptWrappable {
49 DEFINE_WRAPPERTYPEINFO();
50 USING_PRE_FINALIZER(IDBCursor, dispose);
52 static WebIDBCursorDirection stringToDirection(const String& modeString, ExceptionState&);
54 static IDBCursor* create(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
57 void contextWillBeDestroyed() { m_backend.clear(); }
60 const String& direction() const;
61 ScriptValue key(ScriptState*);
62 ScriptValue primaryKey(ScriptState*);
63 ScriptValue value(ScriptState*);
64 ScriptValue source(ScriptState*) const;
66 IDBRequest* update(ScriptState*, const ScriptValue&, ExceptionState&);
67 void advance(unsigned long, ExceptionState&);
68 void continueFunction(ScriptState*, const ScriptValue& key, ExceptionState&);
69 void continuePrimaryKey(ScriptState*, const ScriptValue& key, const ScriptValue& primaryKey, ExceptionState&);
70 IDBRequest* deleteFunction(ScriptState*, ExceptionState&);
72 bool isKeyDirty() const { return m_keyDirty; }
73 bool isPrimaryKeyDirty() const { return m_primaryKeyDirty; }
74 bool isValueDirty() const { return m_valueDirty; }
76 void continueFunction(IDBKey*, IDBKey* primaryKey, ExceptionState&);
77 void postSuccessHandlerCallback();
78 bool isDeleted() const;
80 void setValueReady(IDBKey*, IDBKey* primaryKey, PassRefPtr<SharedBuffer> value, PassOwnPtr<Vector<WebBlobInfo> >);
81 IDBKey* idbPrimaryKey() const { return m_primaryKey; }
82 IDBRequest* request() const { return m_request.get(); }
83 virtual bool isKeyCursor() const { return true; }
84 virtual bool isCursorWithValue() const { return false; }
87 IDBCursor(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
91 IDBObjectStore* effectiveObjectStore() const;
92 void handleBlobAcks();
94 OwnPtr<WebIDBCursor> m_backend;
95 Member<IDBRequest> m_request;
96 const WebIDBCursorDirection m_direction;
97 Member<IDBAny> m_source;
98 Member<IDBTransaction> m_transaction;
101 bool m_primaryKeyDirty;
103 Member<IDBKey> m_key;
104 Member<IDBKey> m_primaryKey;
105 RefPtr<SharedBuffer> m_value;
106 OwnPtr<Vector<WebBlobInfo> > m_blobInfo;
111 #endif // IDBCursor_h