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: 8; 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 "nsMaybeWeakPtr.h" |
michael@0 | 7 | |
michael@0 | 8 | void* |
michael@0 | 9 | nsMaybeWeakPtr_base::GetValueAs(const nsIID &iid) const |
michael@0 | 10 | { |
michael@0 | 11 | nsresult rv; |
michael@0 | 12 | void *ref; |
michael@0 | 13 | if (mPtr) { |
michael@0 | 14 | rv = mPtr->QueryInterface(iid, &ref); |
michael@0 | 15 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 16 | return ref; |
michael@0 | 17 | } |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(mPtr); |
michael@0 | 21 | if (weakRef) { |
michael@0 | 22 | rv = weakRef->QueryReferent(iid, &ref); |
michael@0 | 23 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 24 | return ref; |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | return nullptr; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | nsresult |
michael@0 | 32 | NS_AppendWeakElementBase(isupports_array_type *aArray, |
michael@0 | 33 | nsISupports *aElement, |
michael@0 | 34 | bool aOwnsWeak) |
michael@0 | 35 | { |
michael@0 | 36 | nsCOMPtr<nsISupports> ref; |
michael@0 | 37 | if (aOwnsWeak) { |
michael@0 | 38 | nsCOMPtr<nsIWeakReference> weakRef; |
michael@0 | 39 | weakRef = do_GetWeakReference(aElement); |
michael@0 | 40 | reinterpret_cast<nsCOMPtr<nsISupports>*>(&weakRef)->swap(ref); |
michael@0 | 41 | } else { |
michael@0 | 42 | ref = aElement; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | if (aArray->IndexOf(ref) != aArray->NoIndex) { |
michael@0 | 46 | return NS_ERROR_INVALID_ARG; // already present |
michael@0 | 47 | } |
michael@0 | 48 | if (!aArray->AppendElement(ref)) { |
michael@0 | 49 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 50 | } |
michael@0 | 51 | return NS_OK; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | nsresult |
michael@0 | 55 | NS_RemoveWeakElementBase(isupports_array_type *aArray, |
michael@0 | 56 | nsISupports *aElement) |
michael@0 | 57 | { |
michael@0 | 58 | uint32_t index = aArray->IndexOf(aElement); |
michael@0 | 59 | if (index != aArray->NoIndex) { |
michael@0 | 60 | aArray->RemoveElementAt(index); |
michael@0 | 61 | return NS_OK; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | // Don't use do_GetWeakReference; it should only be called if we know |
michael@0 | 65 | // the object supports weak references. |
michael@0 | 66 | nsCOMPtr<nsISupportsWeakReference> supWeakRef = do_QueryInterface(aElement); |
michael@0 | 67 | NS_ENSURE_TRUE(supWeakRef, NS_ERROR_INVALID_ARG); |
michael@0 | 68 | |
michael@0 | 69 | nsCOMPtr<nsIWeakReference> weakRef; |
michael@0 | 70 | nsresult rv = supWeakRef->GetWeakReference(getter_AddRefs(weakRef)); |
michael@0 | 71 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 72 | |
michael@0 | 73 | index = aArray->IndexOf(weakRef); |
michael@0 | 74 | if (index == aArray->NoIndex) { |
michael@0 | 75 | return NS_ERROR_INVALID_ARG; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | aArray->RemoveElementAt(index); |
michael@0 | 79 | return NS_OK; |
michael@0 | 80 | } |