content/xul/templates/src/nsTemplateMap.h

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 #ifndef nsTemplateMap_h__
     7 #define nsTemplateMap_h__
     9 #include "pldhash.h"
    10 #include "nsXULElement.h"
    12 class nsTemplateMap {
    13 protected:
    14     struct Entry {
    15         PLDHashEntryHdr mHdr;
    16         nsIContent*     mContent;
    17         nsIContent*     mTemplate;
    18     };
    20     PLDHashTable mTable;
    22     void
    23     Init() { PL_DHashTableInit(&mTable, PL_DHashGetStubOps(), nullptr, sizeof(Entry), PL_DHASH_MIN_SIZE); }
    25     void
    26     Finish() { PL_DHashTableFinish(&mTable); }
    28 public:
    29     nsTemplateMap() { Init(); }
    31     ~nsTemplateMap() { Finish(); }
    33     void
    34     Put(nsIContent* aContent, nsIContent* aTemplate) {
    35         NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mTable, aContent, PL_DHASH_LOOKUP)),
    36                      "aContent already in map");
    38         Entry* entry =
    39             reinterpret_cast<Entry*>(PL_DHashTableOperate(&mTable, aContent, PL_DHASH_ADD));
    41         if (entry) {
    42             entry->mContent = aContent;
    43             entry->mTemplate = aTemplate;
    44         }
    45     }
    47     void
    48     Remove(nsIContent* aContent) {
    49         PL_DHashTableOperate(&mTable, aContent, PL_DHASH_REMOVE);
    51         for (nsIContent* child = aContent->GetFirstChild();
    52              child;
    53              child = child->GetNextSibling()) {
    54             Remove(child);
    55         }
    56     }
    59     void
    60     GetTemplateFor(nsIContent* aContent, nsIContent** aResult) {
    61         Entry* entry =
    62             reinterpret_cast<Entry*>(PL_DHashTableOperate(&mTable, aContent, PL_DHASH_LOOKUP));
    64         if (PL_DHASH_ENTRY_IS_BUSY(&entry->mHdr))
    65             NS_IF_ADDREF(*aResult = entry->mTemplate);
    66         else
    67             *aResult = nullptr;
    68     }
    70     void
    71     Clear() { Finish(); Init(); }
    72 };
    74 #endif // nsTemplateMap_h__

mercurial