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