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: 2 -*- */ |
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 "nsSupportsArrayEnumerator.h" |
michael@0 | 7 | #include "nsISupportsArray.h" |
michael@0 | 8 | |
michael@0 | 9 | nsSupportsArrayEnumerator::nsSupportsArrayEnumerator(nsISupportsArray* array) |
michael@0 | 10 | : mArray(array), mCursor(0) |
michael@0 | 11 | { |
michael@0 | 12 | NS_ASSERTION(array, "null array"); |
michael@0 | 13 | NS_ADDREF(mArray); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | nsSupportsArrayEnumerator::~nsSupportsArrayEnumerator() |
michael@0 | 17 | { |
michael@0 | 18 | NS_RELEASE(mArray); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | NS_IMPL_ISUPPORTS(nsSupportsArrayEnumerator, nsIBidirectionalEnumerator, nsIEnumerator) |
michael@0 | 22 | |
michael@0 | 23 | NS_IMETHODIMP |
michael@0 | 24 | nsSupportsArrayEnumerator::First() |
michael@0 | 25 | { |
michael@0 | 26 | mCursor = 0; |
michael@0 | 27 | uint32_t cnt; |
michael@0 | 28 | nsresult rv = mArray->Count(&cnt); |
michael@0 | 29 | if (NS_FAILED(rv)) return rv; |
michael@0 | 30 | int32_t end = (int32_t)cnt; |
michael@0 | 31 | if (mCursor < end) |
michael@0 | 32 | return NS_OK; |
michael@0 | 33 | else |
michael@0 | 34 | return NS_ERROR_FAILURE; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | NS_IMETHODIMP |
michael@0 | 38 | nsSupportsArrayEnumerator::Next() |
michael@0 | 39 | { |
michael@0 | 40 | uint32_t cnt; |
michael@0 | 41 | nsresult rv = mArray->Count(&cnt); |
michael@0 | 42 | if (NS_FAILED(rv)) return rv; |
michael@0 | 43 | int32_t end = (int32_t)cnt; |
michael@0 | 44 | if (mCursor < end) // don't count upward forever |
michael@0 | 45 | mCursor++; |
michael@0 | 46 | if (mCursor < end) |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | else |
michael@0 | 49 | return NS_ERROR_FAILURE; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | NS_IMETHODIMP |
michael@0 | 53 | nsSupportsArrayEnumerator::CurrentItem(nsISupports **aItem) |
michael@0 | 54 | { |
michael@0 | 55 | NS_ASSERTION(aItem, "null out parameter"); |
michael@0 | 56 | uint32_t cnt; |
michael@0 | 57 | nsresult rv = mArray->Count(&cnt); |
michael@0 | 58 | if (NS_FAILED(rv)) return rv; |
michael@0 | 59 | if (mCursor >= 0 && mCursor < (int32_t)cnt) { |
michael@0 | 60 | return mArray->GetElementAt(mCursor, aItem); |
michael@0 | 61 | } |
michael@0 | 62 | return NS_ERROR_FAILURE; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | NS_IMETHODIMP |
michael@0 | 66 | nsSupportsArrayEnumerator::IsDone() |
michael@0 | 67 | { |
michael@0 | 68 | uint32_t cnt; |
michael@0 | 69 | nsresult rv = mArray->Count(&cnt); |
michael@0 | 70 | if (NS_FAILED(rv)) return rv; |
michael@0 | 71 | // XXX This is completely incompatible with the meaning of nsresult. |
michael@0 | 72 | // NS_ENUMERATOR_FALSE is defined to be 1. (bug 778111) |
michael@0 | 73 | return (mCursor >= 0 && mCursor < (int32_t)cnt) |
michael@0 | 74 | ? (nsresult)NS_ENUMERATOR_FALSE : NS_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 78 | |
michael@0 | 79 | NS_IMETHODIMP |
michael@0 | 80 | nsSupportsArrayEnumerator::Last() |
michael@0 | 81 | { |
michael@0 | 82 | uint32_t cnt; |
michael@0 | 83 | nsresult rv = mArray->Count(&cnt); |
michael@0 | 84 | if (NS_FAILED(rv)) return rv; |
michael@0 | 85 | mCursor = cnt - 1; |
michael@0 | 86 | return NS_OK; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | NS_IMETHODIMP |
michael@0 | 90 | nsSupportsArrayEnumerator::Prev() |
michael@0 | 91 | { |
michael@0 | 92 | if (mCursor >= 0) |
michael@0 | 93 | --mCursor; |
michael@0 | 94 | if (mCursor >= 0) |
michael@0 | 95 | return NS_OK; |
michael@0 | 96 | else |
michael@0 | 97 | return NS_ERROR_FAILURE; |
michael@0 | 98 | } |
michael@0 | 99 |