Sat, 03 Jan 2015 20:18:00 +0100
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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsResourceSet.h" |
michael@0 | 7 | |
michael@0 | 8 | nsResourceSet::nsResourceSet(const nsResourceSet& aResourceSet) |
michael@0 | 9 | : mResources(nullptr), |
michael@0 | 10 | mCount(0), |
michael@0 | 11 | mCapacity(0) |
michael@0 | 12 | { |
michael@0 | 13 | ConstIterator last = aResourceSet.Last(); |
michael@0 | 14 | for (ConstIterator resource = aResourceSet.First(); resource != last; ++resource) |
michael@0 | 15 | Add(*resource); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | nsResourceSet& |
michael@0 | 20 | nsResourceSet::operator=(const nsResourceSet& aResourceSet) |
michael@0 | 21 | { |
michael@0 | 22 | Clear(); |
michael@0 | 23 | ConstIterator last = aResourceSet.Last(); |
michael@0 | 24 | for (ConstIterator resource = aResourceSet.First(); resource != last; ++resource) |
michael@0 | 25 | Add(*resource); |
michael@0 | 26 | return *this; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | nsResourceSet::~nsResourceSet() |
michael@0 | 30 | { |
michael@0 | 31 | MOZ_COUNT_DTOR(nsResourceSet); |
michael@0 | 32 | Clear(); |
michael@0 | 33 | delete[] mResources; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | nsresult |
michael@0 | 37 | nsResourceSet::Clear() |
michael@0 | 38 | { |
michael@0 | 39 | while (--mCount >= 0) { |
michael@0 | 40 | NS_RELEASE(mResources[mCount]); |
michael@0 | 41 | } |
michael@0 | 42 | mCount = 0; |
michael@0 | 43 | return NS_OK; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | nsresult |
michael@0 | 47 | nsResourceSet::Add(nsIRDFResource* aResource) |
michael@0 | 48 | { |
michael@0 | 49 | NS_PRECONDITION(aResource != nullptr, "null ptr"); |
michael@0 | 50 | if (! aResource) |
michael@0 | 51 | return NS_ERROR_NULL_POINTER; |
michael@0 | 52 | |
michael@0 | 53 | if (Contains(aResource)) |
michael@0 | 54 | return NS_OK; |
michael@0 | 55 | |
michael@0 | 56 | if (mCount >= mCapacity) { |
michael@0 | 57 | int32_t capacity = mCapacity + 4; |
michael@0 | 58 | nsIRDFResource** resources = new nsIRDFResource*[capacity]; |
michael@0 | 59 | if (! resources) |
michael@0 | 60 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 61 | |
michael@0 | 62 | for (int32_t i = mCount - 1; i >= 0; --i) |
michael@0 | 63 | resources[i] = mResources[i]; |
michael@0 | 64 | |
michael@0 | 65 | delete[] mResources; |
michael@0 | 66 | |
michael@0 | 67 | mResources = resources; |
michael@0 | 68 | mCapacity = capacity; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | mResources[mCount++] = aResource; |
michael@0 | 72 | NS_ADDREF(aResource); |
michael@0 | 73 | return NS_OK; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | void |
michael@0 | 77 | nsResourceSet::Remove(nsIRDFResource* aProperty) |
michael@0 | 78 | { |
michael@0 | 79 | bool found = false; |
michael@0 | 80 | |
michael@0 | 81 | nsIRDFResource** res = mResources; |
michael@0 | 82 | nsIRDFResource** limit = mResources + mCount; |
michael@0 | 83 | while (res < limit) { |
michael@0 | 84 | if (found) { |
michael@0 | 85 | *(res - 1) = *res; |
michael@0 | 86 | } |
michael@0 | 87 | else if (*res == aProperty) { |
michael@0 | 88 | NS_RELEASE(*res); |
michael@0 | 89 | found = true; |
michael@0 | 90 | } |
michael@0 | 91 | ++res; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | if (found) |
michael@0 | 95 | --mCount; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | bool |
michael@0 | 99 | nsResourceSet::Contains(nsIRDFResource* aResource) const |
michael@0 | 100 | { |
michael@0 | 101 | for (int32_t i = mCount - 1; i >= 0; --i) { |
michael@0 | 102 | if (mResources[i] == aResource) |
michael@0 | 103 | return true; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | return false; |
michael@0 | 107 | } |
michael@0 | 108 |