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 IDBAny_h
     27 #define IDBAny_h
     28 
     29 #include "bindings/v8/ScriptWrappable.h"
     30 #include "modules/indexeddb/IDBKey.h"
     31 #include "modules/indexeddb/IDBKeyPath.h"
     32 #include "platform/SharedBuffer.h"
     33 #include "wtf/PassRefPtr.h"
     34 #include "wtf/RefCounted.h"
     35 #include "wtf/RefPtr.h"
     36 #include "wtf/text/WTFString.h"
     37 
     38 namespace blink {
     39 
     40 class WebBlobInfo;
     41 
     42 }
     43 
     44 namespace WebCore {
     45 
     46 class DOMStringList;
     47 class IDBCursor;
     48 class IDBCursorWithValue;
     49 class IDBDatabase;
     50 class IDBIndex;
     51 class IDBKeyPath;
     52 class IDBObjectStore;
     53 class IDBTransaction;
     54 
     55 class IDBAny : public GarbageCollectedFinalized<IDBAny> {
     56 public:
     57     static IDBAny* createUndefined();
     58     static IDBAny* createNull();
     59     static IDBAny* createString(const String&);
     60     template<typename T>
     61     static IDBAny* create(T* idbObject)
     62     {
     63         return new IDBAny(idbObject);
     64     }
     65     template<typename T>
     66     static IDBAny* create(const T& idbObject)
     67     {
     68         return new IDBAny(idbObject);
     69     }
     70     static IDBAny* create(PassRefPtr<SharedBuffer> value, const Vector<blink::WebBlobInfo>* blobInfo)
     71     {
     72         return new IDBAny(value, blobInfo);
     73     }
     74     template<typename T>
     75     static IDBAny* create(PassRefPtr<T> idbObject)
     76     {
     77         return new IDBAny(idbObject);
     78     }
     79     static IDBAny* create(int64_t value)
     80     {
     81         return new IDBAny(value);
     82     }
     83     static IDBAny* create(PassRefPtr<SharedBuffer> value, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const IDBKeyPath& keyPath)
     84     {
     85         return new IDBAny(value, blobInfo, key, keyPath);
     86     }
     87     ~IDBAny();
     88     void trace(Visitor*);
     89     void contextWillBeDestroyed();
     90 
     91     enum Type {
     92         UndefinedType = 0,
     93         NullType,
     94         DOMStringListType,
     95         IDBCursorType,
     96         IDBCursorWithValueType,
     97         IDBDatabaseType,
     98         IDBIndexType,
     99         IDBObjectStoreType,
    100         IDBTransactionType,
    101         BufferType,
    102         IntegerType,
    103         StringType,
    104         KeyPathType,
    105         KeyType,
    106         BufferKeyAndKeyPathType,
    107     };
    108 
    109     Type type() const { return m_type; }
    110     // Use type() to figure out which one of these you're allowed to call.
    111     DOMStringList* domStringList() const;
    112     IDBCursor* idbCursor() const;
    113     IDBCursorWithValue* idbCursorWithValue() const;
    114     IDBDatabase* idbDatabase() const;
    115     IDBIndex* idbIndex() const;
    116     IDBObjectStore* idbObjectStore() const;
    117     IDBTransaction* idbTransaction() const;
    118     SharedBuffer* buffer() const;
    119     const Vector<blink::WebBlobInfo>* blobInfo() const;
    120     int64_t integer() const;
    121     const String& string() const;
    122     const IDBKey* key() const;
    123     const IDBKeyPath& keyPath() const;
    124 
    125 private:
    126     explicit IDBAny(Type);
    127     explicit IDBAny(PassRefPtrWillBeRawPtr<DOMStringList>);
    128     explicit IDBAny(IDBCursor*);
    129     explicit IDBAny(IDBDatabase*);
    130     explicit IDBAny(IDBIndex*);
    131     explicit IDBAny(IDBObjectStore*);
    132     explicit IDBAny(IDBTransaction*);
    133     explicit IDBAny(IDBKey*);
    134     explicit IDBAny(const IDBKeyPath&);
    135     explicit IDBAny(const String&);
    136     IDBAny(PassRefPtr<SharedBuffer>, const Vector<blink::WebBlobInfo>*);
    137     IDBAny(PassRefPtr<SharedBuffer>, const Vector<blink::WebBlobInfo>*, IDBKey*, const IDBKeyPath&);
    138     explicit IDBAny(int64_t);
    139 
    140     const Type m_type;
    141 
    142     // Only one of the following should ever be in use at any given time, except that BufferType uses two and BufferKeyAndKeyPathType uses four.
    143     const RefPtrWillBeMember<DOMStringList> m_domStringList;
    144     const Member<IDBCursor> m_idbCursor;
    145     const Member<IDBDatabase> m_idbDatabase;
    146     const Member<IDBIndex> m_idbIndex;
    147     const Member<IDBObjectStore> m_idbObjectStore;
    148     const Member<IDBTransaction> m_idbTransaction;
    149     const Member<IDBKey> m_idbKey;
    150     const IDBKeyPath m_idbKeyPath;
    151     const RefPtr<SharedBuffer> m_buffer;
    152     const Vector<blink::WebBlobInfo>* m_blobInfo;
    153     const String m_string;
    154     const int64_t m_integer;
    155 };
    156 
    157 } // namespace WebCore
    158 
    159 #endif // IDBAny_h
    160