content/xul/templates/src/nsResourceSet.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: 4; 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 "nsResourceSet.h"
     8 nsResourceSet::nsResourceSet(const nsResourceSet& aResourceSet)
     9     : mResources(nullptr),
    10       mCount(0),
    11       mCapacity(0)
    12 {
    13     ConstIterator last = aResourceSet.Last();
    14     for (ConstIterator resource = aResourceSet.First(); resource != last; ++resource)
    15         Add(*resource);
    16 }
    19 nsResourceSet&
    20 nsResourceSet::operator=(const nsResourceSet& aResourceSet)
    21 {
    22     Clear();
    23     ConstIterator last = aResourceSet.Last();
    24     for (ConstIterator resource = aResourceSet.First(); resource != last; ++resource)
    25         Add(*resource);
    26     return *this;
    27 }
    29 nsResourceSet::~nsResourceSet()
    30 {
    31     MOZ_COUNT_DTOR(nsResourceSet);
    32     Clear();
    33     delete[] mResources;
    34 }
    36 nsresult
    37 nsResourceSet::Clear()
    38 {
    39     while (--mCount >= 0) {
    40         NS_RELEASE(mResources[mCount]);
    41     }
    42     mCount = 0;
    43     return NS_OK;
    44 }
    46 nsresult
    47 nsResourceSet::Add(nsIRDFResource* aResource)
    48 {
    49     NS_PRECONDITION(aResource != nullptr, "null ptr");
    50     if (! aResource)
    51         return NS_ERROR_NULL_POINTER;
    53     if (Contains(aResource))
    54         return NS_OK;
    56     if (mCount >= mCapacity) {
    57         int32_t capacity = mCapacity + 4;
    58         nsIRDFResource** resources = new nsIRDFResource*[capacity];
    59         if (! resources)
    60             return NS_ERROR_OUT_OF_MEMORY;
    62         for (int32_t i = mCount - 1; i >= 0; --i)
    63             resources[i] = mResources[i];
    65         delete[] mResources;
    67         mResources = resources;
    68         mCapacity = capacity;
    69     }
    71     mResources[mCount++] = aResource;
    72     NS_ADDREF(aResource);
    73     return NS_OK;
    74 }
    76 void
    77 nsResourceSet::Remove(nsIRDFResource* aProperty)
    78 {
    79     bool found = false;
    81     nsIRDFResource** res = mResources;
    82     nsIRDFResource** limit = mResources + mCount;
    83     while (res < limit) {
    84         if (found) {
    85             *(res - 1) = *res;
    86         }
    87         else if (*res == aProperty) {
    88             NS_RELEASE(*res);
    89             found = true;
    90         }
    91         ++res;
    92     }
    94     if (found)
    95         --mCount;
    96 }
    98 bool
    99 nsResourceSet::Contains(nsIRDFResource* aResource) const
   100 {
   101     for (int32_t i = mCount - 1; i >= 0; --i) {
   102         if (mResources[i] == aResource)
   103             return true;
   104     }
   106     return false;
   107 }

mercurial