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.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsMaybeWeakPtr.h"
8 void*
9 nsMaybeWeakPtr_base::GetValueAs(const nsIID &iid) const
10 {
11 nsresult rv;
12 void *ref;
13 if (mPtr) {
14 rv = mPtr->QueryInterface(iid, &ref);
15 if (NS_SUCCEEDED(rv)) {
16 return ref;
17 }
18 }
20 nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(mPtr);
21 if (weakRef) {
22 rv = weakRef->QueryReferent(iid, &ref);
23 if (NS_SUCCEEDED(rv)) {
24 return ref;
25 }
26 }
28 return nullptr;
29 }
31 nsresult
32 NS_AppendWeakElementBase(isupports_array_type *aArray,
33 nsISupports *aElement,
34 bool aOwnsWeak)
35 {
36 nsCOMPtr<nsISupports> ref;
37 if (aOwnsWeak) {
38 nsCOMPtr<nsIWeakReference> weakRef;
39 weakRef = do_GetWeakReference(aElement);
40 reinterpret_cast<nsCOMPtr<nsISupports>*>(&weakRef)->swap(ref);
41 } else {
42 ref = aElement;
43 }
45 if (aArray->IndexOf(ref) != aArray->NoIndex) {
46 return NS_ERROR_INVALID_ARG; // already present
47 }
48 if (!aArray->AppendElement(ref)) {
49 return NS_ERROR_OUT_OF_MEMORY;
50 }
51 return NS_OK;
52 }
54 nsresult
55 NS_RemoveWeakElementBase(isupports_array_type *aArray,
56 nsISupports *aElement)
57 {
58 uint32_t index = aArray->IndexOf(aElement);
59 if (index != aArray->NoIndex) {
60 aArray->RemoveElementAt(index);
61 return NS_OK;
62 }
64 // Don't use do_GetWeakReference; it should only be called if we know
65 // the object supports weak references.
66 nsCOMPtr<nsISupportsWeakReference> supWeakRef = do_QueryInterface(aElement);
67 NS_ENSURE_TRUE(supWeakRef, NS_ERROR_INVALID_ARG);
69 nsCOMPtr<nsIWeakReference> weakRef;
70 nsresult rv = supWeakRef->GetWeakReference(getter_AddRefs(weakRef));
71 NS_ENSURE_SUCCESS(rv, rv);
73 index = aArray->IndexOf(weakRef);
74 if (index == aArray->NoIndex) {
75 return NS_ERROR_INVALID_ARG;
76 }
78 aArray->RemoveElementAt(index);
79 return NS_OK;
80 }