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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef nsCategoryCache_h_ |
michael@0 | 6 | #define nsCategoryCache_h_ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/Attributes.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsICategoryManager.h" |
michael@0 | 11 | #include "nsIObserver.h" |
michael@0 | 12 | #include "nsISimpleEnumerator.h" |
michael@0 | 13 | #include "nsISupportsPrimitives.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "nsServiceManagerUtils.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "nsAutoPtr.h" |
michael@0 | 18 | #include "nsCOMArray.h" |
michael@0 | 19 | #include "nsInterfaceHashtable.h" |
michael@0 | 20 | |
michael@0 | 21 | #include "nsXPCOM.h" |
michael@0 | 22 | |
michael@0 | 23 | class NS_COM_GLUE nsCategoryObserver MOZ_FINAL : public nsIObserver |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | nsCategoryObserver(const char* aCategory); |
michael@0 | 27 | ~nsCategoryObserver(); |
michael@0 | 28 | |
michael@0 | 29 | void ListenerDied(); |
michael@0 | 30 | nsInterfaceHashtable<nsCStringHashKey, nsISupports>& GetHash() |
michael@0 | 31 | { |
michael@0 | 32 | return mHash; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | NS_DECL_ISUPPORTS |
michael@0 | 36 | NS_DECL_NSIOBSERVER |
michael@0 | 37 | private: |
michael@0 | 38 | void RemoveObservers(); |
michael@0 | 39 | |
michael@0 | 40 | nsInterfaceHashtable<nsCStringHashKey, nsISupports> mHash; |
michael@0 | 41 | nsCString mCategory; |
michael@0 | 42 | bool mObserversRemoved; |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * This is a helper class that caches services that are registered in a certain |
michael@0 | 47 | * category. The intended usage is that a service stores a variable of type |
michael@0 | 48 | * nsCategoryCache<nsIFoo> in a member variable, where nsIFoo is the interface |
michael@0 | 49 | * that these services should implement. The constructor of this class should |
michael@0 | 50 | * then get the name of the category. |
michael@0 | 51 | */ |
michael@0 | 52 | template<class T> |
michael@0 | 53 | class nsCategoryCache MOZ_FINAL |
michael@0 | 54 | { |
michael@0 | 55 | public: |
michael@0 | 56 | explicit nsCategoryCache(const char* aCategory) |
michael@0 | 57 | : mCategoryName(aCategory) |
michael@0 | 58 | { |
michael@0 | 59 | } |
michael@0 | 60 | ~nsCategoryCache() { |
michael@0 | 61 | if (mObserver) |
michael@0 | 62 | mObserver->ListenerDied(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | void GetEntries(nsCOMArray<T>& result) { |
michael@0 | 66 | // Lazy initialization, so that services in this category can't |
michael@0 | 67 | // cause reentrant getService (bug 386376) |
michael@0 | 68 | if (!mObserver) |
michael@0 | 69 | mObserver = new nsCategoryObserver(mCategoryName.get()); |
michael@0 | 70 | |
michael@0 | 71 | mObserver->GetHash().EnumerateRead(EntriesToArray, &result); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | private: |
michael@0 | 75 | // Not to be implemented |
michael@0 | 76 | nsCategoryCache(const nsCategoryCache<T>&); |
michael@0 | 77 | |
michael@0 | 78 | static PLDHashOperator EntriesToArray(const nsACString& key, |
michael@0 | 79 | nsISupports* entry, void* arg) |
michael@0 | 80 | { |
michael@0 | 81 | nsCOMArray<T>& entries = *static_cast<nsCOMArray<T>*>(arg); |
michael@0 | 82 | |
michael@0 | 83 | nsCOMPtr<T> service = do_QueryInterface(entry); |
michael@0 | 84 | if (service) { |
michael@0 | 85 | entries.AppendObject(service); |
michael@0 | 86 | } |
michael@0 | 87 | return PL_DHASH_NEXT; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | nsCString mCategoryName; |
michael@0 | 91 | nsRefPtr<nsCategoryObserver> mObserver; |
michael@0 | 92 | |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | #endif |