dom/indexedDB/KeyPath.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_keypath_h__
     8 #define mozilla_dom_indexeddb_keypath_h__
    10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
    12 #include "mozilla/dom/BindingDeclarations.h"
    14 BEGIN_INDEXEDDB_NAMESPACE
    16 class Key;
    18 class KeyPath
    19 {
    20 public:
    21   enum KeyPathType {
    22     NONEXISTENT,
    23     STRING,
    24     ARRAY,
    25     ENDGUARD
    26   };
    28   void SetType(KeyPathType aType);
    30   // This does not set exceptions.
    31   bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString);
    33   explicit KeyPath(int aDummy)
    34   : mType(NONEXISTENT)
    35   {
    36     MOZ_COUNT_CTOR(KeyPath);
    37   }
    39   KeyPath(const KeyPath& aOther)
    40   {
    41     MOZ_COUNT_CTOR(KeyPath);
    42     *this = aOther;
    43   }
    45   ~KeyPath()
    46   {
    47     MOZ_COUNT_DTOR(KeyPath);
    48   }
    50   static nsresult
    51   Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath);
    53   static nsresult
    54   Parse(JSContext* aCx, const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
    56   static nsresult
    57   Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath);
    59   nsresult
    60   ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const;
    62   nsresult
    63   ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
    64                     JS::Value* aOutVal) const;
    66   typedef nsresult
    67   (*ExtractOrCreateKeyCallback)(JSContext* aCx, void* aClosure);
    69   nsresult
    70   ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, Key& aKey,
    71                      ExtractOrCreateKeyCallback aCallback,
    72                      void* aClosure) const;
    74   inline bool IsValid() const {
    75     return mType != NONEXISTENT;
    76   }
    78   inline bool IsArray() const {
    79     return mType == ARRAY;
    80   }
    82   inline bool IsString() const {
    83     return mType == STRING;
    84   }
    86   inline bool IsEmpty() const {
    87     return mType == STRING && mStrings[0].IsEmpty();
    88   }
    90   bool operator==(const KeyPath& aOther) const
    91   {
    92     return mType == aOther.mType && mStrings == aOther.mStrings;
    93   }
    95   void SerializeToString(nsAString& aString) const;
    96   static KeyPath DeserializeFromString(const nsAString& aString);
    98   nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
    99   nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
   101   bool IsAllowedForObjectStore(bool aAutoIncrement) const;
   103   KeyPathType mType;
   105   nsTArray<nsString> mStrings;
   106 };
   108 END_INDEXEDDB_NAMESPACE
   110 #endif /* mozilla_dom_indexeddb_keypath_h__ */

mercurial