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