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