2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(INDEXED_DATABASE)
30 #include "IDBCursor.h"
31 #include "IDBIndexInfo.h"
32 #include "IDBRequest.h"
42 struct IDBKeyRangeData;
44 class IDBIndex final : private ActiveDOMObject {
45 WTF_MAKE_NONCOPYABLE(IDBIndex);
46 WTF_MAKE_FAST_ALLOCATED;
48 IDBIndex(ScriptExecutionContext&, const IDBIndexInfo&, IDBObjectStore&);
52 const String& name() const;
53 ExceptionOr<void> setName(const String&);
54 IDBObjectStore& objectStore();
55 const IDBKeyPath& keyPath() const;
57 bool multiEntry() const;
59 void rollbackInfoForVersionChangeAbort();
61 ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, RefPtr<IDBKeyRange>&&, IDBCursorDirection);
62 ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, JSC::JSValue key, IDBCursorDirection);
63 ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, RefPtr<IDBKeyRange>&&, IDBCursorDirection);
64 ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, JSC::JSValue key, IDBCursorDirection);
66 ExceptionOr<Ref<IDBRequest>> count(JSC::ExecState&, IDBKeyRange*);
67 ExceptionOr<Ref<IDBRequest>> count(JSC::ExecState&, JSC::JSValue key);
69 ExceptionOr<Ref<IDBRequest>> get(JSC::ExecState&, IDBKeyRange*);
70 ExceptionOr<Ref<IDBRequest>> get(JSC::ExecState&, JSC::JSValue key);
71 ExceptionOr<Ref<IDBRequest>> getKey(JSC::ExecState&, IDBKeyRange*);
72 ExceptionOr<Ref<IDBRequest>> getKey(JSC::ExecState&, JSC::JSValue key);
74 ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, RefPtr<IDBKeyRange>&&, Optional<uint32_t> count);
75 ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, JSC::JSValue key, Optional<uint32_t> count);
76 ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, RefPtr<IDBKeyRange>&&, Optional<uint32_t> count);
77 ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, JSC::JSValue key, Optional<uint32_t> count);
79 const IDBIndexInfo& info() const { return m_info; }
82 bool isDeleted() const { return m_deleted; }
87 void* objectStoreAsOpaqueRoot() { return &m_objectStore; }
90 ExceptionOr<Ref<IDBRequest>> doCount(JSC::ExecState&, const IDBKeyRangeData&);
91 ExceptionOr<Ref<IDBRequest>> doGet(JSC::ExecState&, ExceptionOr<IDBKeyRangeData>);
92 ExceptionOr<Ref<IDBRequest>> doGetKey(JSC::ExecState&, ExceptionOr<IDBKeyRangeData>);
93 ExceptionOr<Ref<IDBRequest>> doOpenCursor(JSC::ExecState&, IDBCursorDirection, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
94 ExceptionOr<Ref<IDBRequest>> doOpenKeyCursor(JSC::ExecState&, IDBCursorDirection, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
95 ExceptionOr<Ref<IDBRequest>> doGetAll(JSC::ExecState&, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
96 ExceptionOr<Ref<IDBRequest>> doGetAllKeys(JSC::ExecState&, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
98 const char* activeDOMObjectName() const final;
99 bool canSuspendForDocumentSuspension() const final;
100 bool hasPendingActivity() const final;
103 IDBIndexInfo m_originalInfo;
105 bool m_deleted { false };
107 // IDBIndex objects are always owned by their referencing IDBObjectStore.
108 // Indexes will never outlive ObjectStores so its okay to keep a raw C++ reference here.
109 IDBObjectStore& m_objectStore;
112 } // namespace WebCore
114 #endif // ENABLE(INDEXED_DATABASE)