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.

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

mercurial