dom/indexedDB/IDBKeyRange.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_indexeddb_idbkeyrange_h__
michael@0 8 #define mozilla_dom_indexeddb_idbkeyrange_h__
michael@0 9
michael@0 10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
michael@0 11 #include "mozilla/dom/indexedDB/Key.h"
michael@0 12
michael@0 13 #include "nsISupports.h"
michael@0 14
michael@0 15 #include "mozilla/ErrorResult.h"
michael@0 16 #include "nsCycleCollectionParticipant.h"
michael@0 17
michael@0 18 class mozIStorageStatement;
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21 namespace dom {
michael@0 22 class GlobalObject;
michael@0 23 } // namespace dom
michael@0 24 } // namespace mozilla
michael@0 25
michael@0 26 BEGIN_INDEXEDDB_NAMESPACE
michael@0 27
michael@0 28 namespace ipc {
michael@0 29 class KeyRange;
michael@0 30 } // namespace ipc
michael@0 31
michael@0 32 class IDBKeyRange MOZ_FINAL : public nsISupports
michael@0 33 {
michael@0 34 public:
michael@0 35 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 36 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange)
michael@0 37
michael@0 38 static nsresult FromJSVal(JSContext* aCx,
michael@0 39 JS::Handle<JS::Value> aVal,
michael@0 40 IDBKeyRange** aKeyRange);
michael@0 41
michael@0 42 template <class T>
michael@0 43 static already_AddRefed<IDBKeyRange>
michael@0 44 FromSerializedKeyRange(const T& aKeyRange);
michael@0 45
michael@0 46 const Key& Lower() const
michael@0 47 {
michael@0 48 return mLower;
michael@0 49 }
michael@0 50
michael@0 51 Key& Lower()
michael@0 52 {
michael@0 53 return mLower;
michael@0 54 }
michael@0 55
michael@0 56 const Key& Upper() const
michael@0 57 {
michael@0 58 return mIsOnly ? mLower : mUpper;
michael@0 59 }
michael@0 60
michael@0 61 Key& Upper()
michael@0 62 {
michael@0 63 return mIsOnly ? mLower : mUpper;
michael@0 64 }
michael@0 65
michael@0 66 // TODO: Remove these in favour of LowerOpen() / UpperOpen(), bug 900578.
michael@0 67 bool IsLowerOpen() const
michael@0 68 {
michael@0 69 return mLowerOpen;
michael@0 70 }
michael@0 71
michael@0 72 bool IsUpperOpen() const
michael@0 73 {
michael@0 74 return mUpperOpen;
michael@0 75 }
michael@0 76
michael@0 77 bool IsOnly() const
michael@0 78 {
michael@0 79 return mIsOnly;
michael@0 80 }
michael@0 81
michael@0 82 void GetBindingClause(const nsACString& aKeyColumnName,
michael@0 83 nsACString& _retval) const
michael@0 84 {
michael@0 85 NS_NAMED_LITERAL_CSTRING(andStr, " AND ");
michael@0 86 NS_NAMED_LITERAL_CSTRING(spacecolon, " :");
michael@0 87 NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key");
michael@0 88
michael@0 89 if (IsOnly()) {
michael@0 90 // Both keys are set and they're equal.
michael@0 91 _retval = andStr + aKeyColumnName + NS_LITERAL_CSTRING(" =") +
michael@0 92 spacecolon + lowerKey;
michael@0 93 }
michael@0 94 else {
michael@0 95 nsAutoCString clause;
michael@0 96
michael@0 97 if (!Lower().IsUnset()) {
michael@0 98 // Lower key is set.
michael@0 99 clause.Append(andStr + aKeyColumnName);
michael@0 100 clause.AppendLiteral(" >");
michael@0 101 if (!IsLowerOpen()) {
michael@0 102 clause.AppendLiteral("=");
michael@0 103 }
michael@0 104 clause.Append(spacecolon + lowerKey);
michael@0 105 }
michael@0 106
michael@0 107 if (!Upper().IsUnset()) {
michael@0 108 // Upper key is set.
michael@0 109 clause.Append(andStr + aKeyColumnName);
michael@0 110 clause.AppendLiteral(" <");
michael@0 111 if (!IsUpperOpen()) {
michael@0 112 clause.AppendLiteral("=");
michael@0 113 }
michael@0 114 clause.Append(spacecolon + NS_LITERAL_CSTRING("upper_key"));
michael@0 115 }
michael@0 116
michael@0 117 _retval = clause;
michael@0 118 }
michael@0 119 }
michael@0 120
michael@0 121 nsresult BindToStatement(mozIStorageStatement* aStatement) const
michael@0 122 {
michael@0 123 NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key");
michael@0 124
michael@0 125 if (IsOnly()) {
michael@0 126 return Lower().BindToStatement(aStatement, lowerKey);
michael@0 127 }
michael@0 128
michael@0 129 nsresult rv;
michael@0 130
michael@0 131 if (!Lower().IsUnset()) {
michael@0 132 rv = Lower().BindToStatement(aStatement, lowerKey);
michael@0 133 NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
michael@0 134 }
michael@0 135
michael@0 136 if (!Upper().IsUnset()) {
michael@0 137 rv = Upper().BindToStatement(aStatement, NS_LITERAL_CSTRING("upper_key"));
michael@0 138 NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
michael@0 139 }
michael@0 140
michael@0 141 return NS_OK;
michael@0 142 }
michael@0 143
michael@0 144 template <class T>
michael@0 145 void ToSerializedKeyRange(T& aKeyRange);
michael@0 146
michael@0 147 void DropJSObjects();
michael@0 148
michael@0 149 // WebIDL
michael@0 150 JSObject*
michael@0 151 WrapObject(JSContext* aCx);
michael@0 152
michael@0 153 nsISupports*
michael@0 154 GetParentObject() const
michael@0 155 {
michael@0 156 return mGlobal;
michael@0 157 }
michael@0 158
michael@0 159 void
michael@0 160 GetLower(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
michael@0 161 ErrorResult& aRv);
michael@0 162
michael@0 163 void
michael@0 164 GetUpper(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
michael@0 165 ErrorResult& aRv);
michael@0 166
michael@0 167 bool
michael@0 168 LowerOpen() const
michael@0 169 {
michael@0 170 return mLowerOpen;
michael@0 171 }
michael@0 172
michael@0 173 bool
michael@0 174 UpperOpen() const
michael@0 175 {
michael@0 176 return mUpperOpen;
michael@0 177 }
michael@0 178
michael@0 179 static already_AddRefed<IDBKeyRange>
michael@0 180 Only(const GlobalObject& aGlobal, JSContext* aCx,
michael@0 181 JS::Handle<JS::Value> aValue, ErrorResult& aRv);
michael@0 182
michael@0 183 static already_AddRefed<IDBKeyRange>
michael@0 184 LowerBound(const GlobalObject& aGlobal, JSContext* aCx,
michael@0 185 JS::Handle<JS::Value> aValue, bool aOpen, ErrorResult& aRv);
michael@0 186
michael@0 187 static already_AddRefed<IDBKeyRange>
michael@0 188 UpperBound(const GlobalObject& aGlobal, JSContext* aCx,
michael@0 189 JS::Handle<JS::Value> aValue, bool aOpen, ErrorResult& aRv);
michael@0 190
michael@0 191 static already_AddRefed<IDBKeyRange>
michael@0 192 Bound(const GlobalObject& aGlobal, JSContext* aCx,
michael@0 193 JS::Handle<JS::Value> aLower, JS::Handle<JS::Value> aUpper,
michael@0 194 bool aLowerOpen, bool aUpperOpen, ErrorResult& aRv);
michael@0 195
michael@0 196 private:
michael@0 197 IDBKeyRange(nsISupports* aGlobal,
michael@0 198 bool aLowerOpen,
michael@0 199 bool aUpperOpen,
michael@0 200 bool aIsOnly)
michael@0 201 : mGlobal(aGlobal), mCachedLowerVal(JSVAL_VOID), mCachedUpperVal(JSVAL_VOID),
michael@0 202 mLowerOpen(aLowerOpen), mUpperOpen(aUpperOpen), mIsOnly(aIsOnly),
michael@0 203 mHaveCachedLowerVal(false), mHaveCachedUpperVal(false), mRooted(false)
michael@0 204 { }
michael@0 205
michael@0 206 ~IDBKeyRange();
michael@0 207
michael@0 208 nsCOMPtr<nsISupports> mGlobal;
michael@0 209 Key mLower;
michael@0 210 Key mUpper;
michael@0 211 JS::Heap<JS::Value> mCachedLowerVal;
michael@0 212 JS::Heap<JS::Value> mCachedUpperVal;
michael@0 213 const bool mLowerOpen;
michael@0 214 const bool mUpperOpen;
michael@0 215 const bool mIsOnly;
michael@0 216 bool mHaveCachedLowerVal;
michael@0 217 bool mHaveCachedUpperVal;
michael@0 218 bool mRooted;
michael@0 219 };
michael@0 220
michael@0 221 END_INDEXEDDB_NAMESPACE
michael@0 222
michael@0 223 #endif // mozilla_dom_indexeddb_idbkeyrange_h__

mercurial