• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 dispose();
56     void trace(Visitor*);
contextWillBeDestroyed()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 
isKeyDirty()72     bool isKeyDirty() const { return m_keyDirty; }
isPrimaryKeyDirty()73     bool isPrimaryKeyDirty() const { return m_primaryKeyDirty; }
isValueDirty()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> >);
idbPrimaryKey()81     IDBKey* idbPrimaryKey() const { return m_primaryKey; }
request()82     IDBRequest* request() const { return m_request.get(); }
isKeyCursor()83     virtual bool isKeyCursor() const { return true; }
isCursorWithValue()84     virtual bool isCursorWithValue() const { return false; }
85 
86 protected:
87     IDBCursor(PassOwnPtr<WebIDBCursor>, WebIDBCursorDirection, IDBRequest*, IDBAny* source, IDBTransaction*);
88 
89 private:
90     IDBObjectStore* effectiveObjectStore() const;
91     void handleBlobAcks();
92 
93     OwnPtr<WebIDBCursor> m_backend;
94     Member<IDBRequest> m_request;
95     const WebIDBCursorDirection m_direction;
96     Member<IDBAny> m_source;
97     Member<IDBTransaction> m_transaction;
98     bool m_gotValue;
99     bool m_keyDirty;
100     bool m_primaryKeyDirty;
101     bool m_valueDirty;
102     Member<IDBKey> m_key;
103     Member<IDBKey> m_primaryKey;
104     RefPtr<SharedBuffer> m_value;
105     OwnPtr<Vector<WebBlobInfo> > m_blobInfo;
106 };
107 
108 } // namespace blink
109 
110 #endif // IDBCursor_h
111