xpcom/ds/nsProperties.cpp

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: 2; 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 "nsProperties.h"
michael@0 7
michael@0 8 ////////////////////////////////////////////////////////////////////////////////
michael@0 9
michael@0 10 NS_IMPL_AGGREGATED(nsProperties)
michael@0 11 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties)
michael@0 12 NS_INTERFACE_MAP_ENTRY(nsIProperties)
michael@0 13 NS_INTERFACE_MAP_END
michael@0 14
michael@0 15 NS_IMETHODIMP
michael@0 16 nsProperties::Get(const char* prop, const nsIID & uuid, void* *result)
michael@0 17 {
michael@0 18 if (NS_WARN_IF(!prop))
michael@0 19 return NS_ERROR_INVALID_ARG;
michael@0 20
michael@0 21 nsCOMPtr<nsISupports> value;
michael@0 22 if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
michael@0 23 return NS_ERROR_FAILURE;
michael@0 24 }
michael@0 25 return (value) ? value->QueryInterface(uuid, result) : NS_ERROR_NO_INTERFACE;
michael@0 26 }
michael@0 27
michael@0 28 NS_IMETHODIMP
michael@0 29 nsProperties::Set(const char* prop, nsISupports* value)
michael@0 30 {
michael@0 31 if (NS_WARN_IF(!prop))
michael@0 32 return NS_ERROR_INVALID_ARG;
michael@0 33 Put(prop, value);
michael@0 34 return NS_OK;
michael@0 35 }
michael@0 36
michael@0 37 NS_IMETHODIMP
michael@0 38 nsProperties::Undefine(const char* prop)
michael@0 39 {
michael@0 40 if (NS_WARN_IF(!prop))
michael@0 41 return NS_ERROR_INVALID_ARG;
michael@0 42
michael@0 43 nsCOMPtr<nsISupports> value;
michael@0 44 if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value)))
michael@0 45 return NS_ERROR_FAILURE;
michael@0 46
michael@0 47 Remove(prop);
michael@0 48 return NS_OK;
michael@0 49 }
michael@0 50
michael@0 51 NS_IMETHODIMP
michael@0 52 nsProperties::Has(const char* prop, bool *result)
michael@0 53 {
michael@0 54 if (NS_WARN_IF(!prop))
michael@0 55 return NS_ERROR_INVALID_ARG;
michael@0 56
michael@0 57 nsCOMPtr<nsISupports> value;
michael@0 58 *result = nsProperties_HashBase::Get(prop,
michael@0 59 getter_AddRefs(value));
michael@0 60 return NS_OK;
michael@0 61 }
michael@0 62
michael@0 63 struct GetKeysEnumData
michael@0 64 {
michael@0 65 char **keys;
michael@0 66 uint32_t next;
michael@0 67 nsresult res;
michael@0 68 };
michael@0 69
michael@0 70 PLDHashOperator
michael@0 71 GetKeysEnumerate(const char *key, nsISupports* data,
michael@0 72 void *arg)
michael@0 73 {
michael@0 74 GetKeysEnumData *gkedp = (GetKeysEnumData *)arg;
michael@0 75 gkedp->keys[gkedp->next] = strdup(key);
michael@0 76
michael@0 77 if (!gkedp->keys[gkedp->next]) {
michael@0 78 gkedp->res = NS_ERROR_OUT_OF_MEMORY;
michael@0 79 return PL_DHASH_STOP;
michael@0 80 }
michael@0 81
michael@0 82 gkedp->next++;
michael@0 83 return PL_DHASH_NEXT;
michael@0 84 }
michael@0 85
michael@0 86 NS_IMETHODIMP
michael@0 87 nsProperties::GetKeys(uint32_t *count, char ***keys)
michael@0 88 {
michael@0 89 if (NS_WARN_IF(!count) || NS_WARN_IF(!keys))
michael@0 90 return NS_ERROR_INVALID_ARG;
michael@0 91
michael@0 92 uint32_t n = Count();
michael@0 93 char ** k = (char **) nsMemory::Alloc(n * sizeof(char *));
michael@0 94
michael@0 95 GetKeysEnumData gked;
michael@0 96 gked.keys = k;
michael@0 97 gked.next = 0;
michael@0 98 gked.res = NS_OK;
michael@0 99
michael@0 100 EnumerateRead(GetKeysEnumerate, &gked);
michael@0 101
michael@0 102 nsresult rv = gked.res;
michael@0 103 if (NS_FAILED(rv)) {
michael@0 104 // Free 'em all
michael@0 105 for (uint32_t i = 0; i < gked.next; i++)
michael@0 106 nsMemory::Free(k[i]);
michael@0 107 nsMemory::Free(k);
michael@0 108 return rv;
michael@0 109 }
michael@0 110
michael@0 111 *count = n;
michael@0 112 *keys = k;
michael@0 113 return NS_OK;
michael@0 114 }
michael@0 115
michael@0 116 ////////////////////////////////////////////////////////////////////////////////

mercurial