dom/quota/StorageMatcher.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.

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 file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_quota_patternmatcher_h__
michael@0 8 #define mozilla_dom_quota_patternmatcher_h__
michael@0 9
michael@0 10 #include "mozilla/dom/quota/QuotaCommon.h"
michael@0 11
michael@0 12 #include "ArrayCluster.h"
michael@0 13 #include "Utilities.h"
michael@0 14
michael@0 15 BEGIN_QUOTA_NAMESPACE
michael@0 16
michael@0 17 template <class ValueType, class BaseType = ArrayCluster<nsIOfflineStorage*> >
michael@0 18 class StorageMatcher : public ValueType
michael@0 19 {
michael@0 20 typedef StorageMatcher<ValueType, BaseType> SelfType;
michael@0 21
michael@0 22 struct Closure
michael@0 23 {
michael@0 24 Closure(SelfType& aSelf)
michael@0 25 : mSelf(aSelf), mPattern(EmptyCString()), mIndexes(nullptr)
michael@0 26 { }
michael@0 27
michael@0 28 Closure(SelfType& aSelf, const nsACString& aPattern)
michael@0 29 : mSelf(aSelf), mPattern(aPattern), mIndexes(nullptr)
michael@0 30 { }
michael@0 31
michael@0 32 Closure(SelfType& aSelf, const nsTArray<uint32_t>* aIndexes)
michael@0 33 : mSelf(aSelf), mPattern(EmptyCString()), mIndexes(aIndexes)
michael@0 34 { }
michael@0 35
michael@0 36 Closure(SelfType& aSelf, const nsACString& aPattern,
michael@0 37 const nsTArray<uint32_t>* aIndexes)
michael@0 38 : mSelf(aSelf), mPattern(aPattern), mIndexes(aIndexes)
michael@0 39 { }
michael@0 40
michael@0 41 SelfType& mSelf;
michael@0 42 const nsACString& mPattern;
michael@0 43 const nsTArray<uint32_t>* mIndexes;
michael@0 44 };
michael@0 45
michael@0 46 public:
michael@0 47 template <class T, class U, class V>
michael@0 48 void
michael@0 49 Find(const nsBaseHashtable<T, U, V>& aHashtable,
michael@0 50 const nsACString& aPattern)
michael@0 51 {
michael@0 52 SelfType::Clear();
michael@0 53
michael@0 54 Closure closure(*this, aPattern);
michael@0 55 aHashtable.EnumerateRead(SelfType::MatchPattern, &closure);
michael@0 56 }
michael@0 57
michael@0 58 template <class T, class U, class V>
michael@0 59 void
michael@0 60 Find(const nsBaseHashtable<T, U, V>& aHashtable,
michael@0 61 const nsTArray<uint32_t>* aIndexes)
michael@0 62 {
michael@0 63 SelfType::Clear();
michael@0 64
michael@0 65 Closure closure(*this, aIndexes);
michael@0 66 aHashtable.EnumerateRead(SelfType::MatchIndexes, &closure);
michael@0 67 }
michael@0 68
michael@0 69 template <class T, class U, class V>
michael@0 70 void
michael@0 71 Find(const nsBaseHashtable<T, U, V>& aHashtable,
michael@0 72 uint32_t aIndex)
michael@0 73 {
michael@0 74 nsAutoTArray<uint32_t, 1> indexes;
michael@0 75 indexes.AppendElement(aIndex);
michael@0 76
michael@0 77 Find(aHashtable, &indexes);
michael@0 78 }
michael@0 79
michael@0 80 template <class T, class U, class V>
michael@0 81 void
michael@0 82 Find(const nsBaseHashtable<T, U, V>& aHashtable,
michael@0 83 const nsACString& aPattern,
michael@0 84 const nsTArray<uint32_t>* aIndexes)
michael@0 85 {
michael@0 86 SelfType::Clear();
michael@0 87
michael@0 88 Closure closure(*this, aPattern, aIndexes);
michael@0 89 aHashtable.EnumerateRead(SelfType::MatchPatternAndIndexes, &closure);
michael@0 90 }
michael@0 91
michael@0 92 template <class T, class U, class V>
michael@0 93 void
michael@0 94 Find(const nsBaseHashtable<T, U, V>& aHashtable,
michael@0 95 const nsACString& aPattern,
michael@0 96 uint32_t aIndex)
michael@0 97 {
michael@0 98 nsAutoTArray<uint32_t, 1> indexes;
michael@0 99 indexes.AppendElement(aIndex);
michael@0 100
michael@0 101 Find(aHashtable, aPattern, &indexes);
michael@0 102 }
michael@0 103
michael@0 104 template <class T, class U, class V>
michael@0 105 void
michael@0 106 Find(const nsBaseHashtable<T, U, V>& aHashtable)
michael@0 107 {
michael@0 108 SelfType::Clear();
michael@0 109
michael@0 110 Closure closure(*this);
michael@0 111 aHashtable.EnumerateRead(SelfType::MatchAll, &closure);
michael@0 112 }
michael@0 113
michael@0 114 private:
michael@0 115 static PLDHashOperator
michael@0 116 MatchPattern(const nsACString& aKey,
michael@0 117 BaseType* aValue,
michael@0 118 void* aUserArg)
michael@0 119 {
michael@0 120 MOZ_ASSERT(!aKey.IsEmpty(), "Empty key!");
michael@0 121 MOZ_ASSERT(aValue, "Null pointer!");
michael@0 122 MOZ_ASSERT(aUserArg, "Null pointer!");
michael@0 123
michael@0 124 Closure* closure = static_cast<Closure*>(aUserArg);
michael@0 125
michael@0 126 if (PatternMatchesOrigin(closure->mPattern, aKey)) {
michael@0 127 aValue->AppendElementsTo(closure->mSelf);
michael@0 128 }
michael@0 129
michael@0 130 return PL_DHASH_NEXT;
michael@0 131 }
michael@0 132
michael@0 133 static PLDHashOperator
michael@0 134 MatchIndexes(const nsACString& aKey,
michael@0 135 BaseType* aValue,
michael@0 136 void* aUserArg)
michael@0 137 {
michael@0 138 MOZ_ASSERT(!aKey.IsEmpty(), "Empty key!");
michael@0 139 MOZ_ASSERT(aValue, "Null pointer!");
michael@0 140 MOZ_ASSERT(aUserArg, "Null pointer!");
michael@0 141
michael@0 142 Closure* closure = static_cast<Closure*>(aUserArg);
michael@0 143
michael@0 144 for (uint32_t index = 0; index < closure->mIndexes->Length(); index++) {
michael@0 145 aValue->AppendElementsTo(closure->mIndexes->ElementAt(index),
michael@0 146 closure->mSelf);
michael@0 147 }
michael@0 148
michael@0 149 return PL_DHASH_NEXT;
michael@0 150 }
michael@0 151
michael@0 152 static PLDHashOperator
michael@0 153 MatchPatternAndIndexes(const nsACString& aKey,
michael@0 154 BaseType* aValue,
michael@0 155 void* aUserArg)
michael@0 156 {
michael@0 157 MOZ_ASSERT(!aKey.IsEmpty(), "Empty key!");
michael@0 158 MOZ_ASSERT(aValue, "Null pointer!");
michael@0 159 MOZ_ASSERT(aUserArg, "Null pointer!");
michael@0 160
michael@0 161 Closure* closure = static_cast<Closure*>(aUserArg);
michael@0 162
michael@0 163 if (PatternMatchesOrigin(closure->mPattern, aKey)) {
michael@0 164 for (uint32_t index = 0; index < closure->mIndexes->Length(); index++) {
michael@0 165 aValue->AppendElementsTo(closure->mIndexes->ElementAt(index),
michael@0 166 closure->mSelf);
michael@0 167 }
michael@0 168 }
michael@0 169
michael@0 170 return PL_DHASH_NEXT;
michael@0 171 }
michael@0 172
michael@0 173 static PLDHashOperator
michael@0 174 MatchAll(const nsACString& aKey,
michael@0 175 BaseType* aValue,
michael@0 176 void* aUserArg)
michael@0 177 {
michael@0 178 MOZ_ASSERT(!aKey.IsEmpty(), "Empty key!");
michael@0 179 MOZ_ASSERT(aValue, "Null pointer!");
michael@0 180 MOZ_ASSERT(aUserArg, "Null pointer!");
michael@0 181
michael@0 182 Closure* closure = static_cast<Closure*>(aUserArg);
michael@0 183 aValue->AppendElementsTo(closure->mSelf);
michael@0 184
michael@0 185 return PL_DHASH_NEXT;
michael@0 186 }
michael@0 187 };
michael@0 188
michael@0 189 END_QUOTA_NAMESPACE
michael@0 190
michael@0 191 #endif // mozilla_dom_quota_patternmatcher_h__

mercurial