dom/indexedDB/IDBKeyRange.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial