Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / indexeddb / IDBCursor.h
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/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"
38
39 namespace blink {
40
41 class ExceptionState;
42 class IDBAny;
43 class IDBTransaction;
44 class ExecutionContext;
45 class SharedBuffer;
46 class WebBlobInfo;
47
48 class IDBCursor : public GarbageCollectedFinalized<IDBCursor>, public ScriptWrappable {
49     DEFINE_WRAPPERTYPEINFO();
50 public:
51     static WebIDBCursorDirection stringToDirection(const String& modeString, ExceptionState&);
52
53     static IDBCursor* create(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
54     virtual ~IDBCursor();
55     void trace(Visitor*);
56     void contextWillBeDestroyed() { m_backend.clear(); }
57
58     // Implement the IDL
59     const String& direction() const;
60     ScriptValue key(ScriptState*);
61     ScriptValue primaryKey(ScriptState*);
62     ScriptValue value(ScriptState*);
63     ScriptValue source(ScriptState*) const;
64
65     IDBRequest* update(ScriptState*, const ScriptValue&, ExceptionState&);
66     void advance(unsigned long, ExceptionState&);
67     void continueFunction(ScriptState*, const ScriptValue& key, ExceptionState&);
68     void continuePrimaryKey(ScriptState*, const ScriptValue& key, const ScriptValue& primaryKey, ExceptionState&);
69     IDBRequest* deleteFunction(ScriptState*, ExceptionState&);
70
71     bool isKeyDirty() const { return m_keyDirty; }
72     bool isPrimaryKeyDirty() const { return m_primaryKeyDirty; }
73     bool isValueDirty() const { return m_valueDirty; }
74
75     void continueFunction(IDBKey*, IDBKey* primaryKey, ExceptionState&);
76     void postSuccessHandlerCallback();
77     bool isDeleted() const;
78     void close();
79     void setValueReady(IDBKey*, IDBKey* primaryKey, PassRefPtr<SharedBuffer> value, PassOwnPtr<Vector<WebBlobInfo> >);
80     IDBKey* idbPrimaryKey() const { return m_primaryKey; }
81     IDBRequest* request() const { return m_request.get(); }
82     virtual bool isKeyCursor() const { return true; }
83     virtual bool isCursorWithValue() const { return false; }
84
85 protected:
86     IDBCursor(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
87
88 private:
89     IDBObjectStore* effectiveObjectStore() const;
90     void handleBlobAcks();
91
92     OwnPtr<WebIDBCursor> m_backend;
93     Member<IDBRequest> m_request;
94     const WebIDBCursorDirection m_direction;
95     Member<IDBAny> m_source;
96     Member<IDBTransaction> m_transaction;
97     bool m_gotValue;
98     bool m_keyDirty;
99     bool m_primaryKeyDirty;
100     bool m_valueDirty;
101     Member<IDBKey> m_key;
102     Member<IDBKey> m_primaryKey;
103     RefPtr<SharedBuffer> m_value;
104     OwnPtr<Vector<WebBlobInfo> > m_blobInfo;
105 };
106
107 } // namespace blink
108
109 #endif // IDBCursor_h