Update To 11.40.268.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 ScriptState;
45 class SharedBuffer;
46 class WebBlobInfo;
47
48 class IDBCursor : public GarbageCollectedFinalized<IDBCursor>, public ScriptWrappable {
49     DEFINE_WRAPPERTYPEINFO();
50     USING_PRE_FINALIZER(IDBCursor, dispose);
51 public:
52     static WebIDBCursorDirection stringToDirection(const String& modeString, ExceptionState&);
53
54     static IDBCursor* create(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
55     virtual ~IDBCursor();
56     void trace(Visitor*);
57     void contextWillBeDestroyed() { m_backend.clear(); }
58
59     // Implement the IDL
60     const String& direction() const;
61     ScriptValue key(ScriptState*);
62     ScriptValue primaryKey(ScriptState*);
63     ScriptValue value(ScriptState*);
64     ScriptValue source(ScriptState*) const;
65
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&);
71
72     bool isKeyDirty() const { return m_keyDirty; }
73     bool isPrimaryKeyDirty() const { return m_primaryKeyDirty; }
74     bool isValueDirty() const { return m_valueDirty; }
75
76     void continueFunction(IDBKey*, IDBKey* primaryKey, ExceptionState&);
77     void postSuccessHandlerCallback();
78     bool isDeleted() const;
79     void close();
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; }
85
86 protected:
87     IDBCursor(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
88
89 private:
90     void dispose();
91     IDBObjectStore* effectiveObjectStore() const;
92     void handleBlobAcks();
93
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;
99     bool m_gotValue;
100     bool m_keyDirty;
101     bool m_primaryKeyDirty;
102     bool m_valueDirty;
103     Member<IDBKey> m_key;
104     Member<IDBKey> m_primaryKey;
105     RefPtr<SharedBuffer> m_value;
106     OwnPtr<Vector<WebBlobInfo> > m_blobInfo;
107 };
108
109 } // namespace blink
110
111 #endif // IDBCursor_h