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 mozilla_Omnijar_h |
michael@0 | 7 | #define mozilla_Omnijar_h |
michael@0 | 8 | |
michael@0 | 9 | #include "nscore.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsString.h" |
michael@0 | 12 | #include "nsIFile.h" |
michael@0 | 13 | #include "nsZipArchive.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIURI; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | class Omnijar { |
michael@0 | 20 | private: |
michael@0 | 21 | /** |
michael@0 | 22 | * Store an nsIFile for an omni.jar. We can store two paths here, one |
michael@0 | 23 | * for GRE (corresponding to resource://gre/) and one for APP |
michael@0 | 24 | * (corresponding to resource:/// and resource://app/), but only |
michael@0 | 25 | * store one when both point to the same location (unified). |
michael@0 | 26 | */ |
michael@0 | 27 | static nsIFile *sPath[2]; |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * Cached nsZipArchives for the corresponding sPath |
michael@0 | 31 | */ |
michael@0 | 32 | static nsZipArchive *sReader[2]; |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * Has Omnijar::Init() been called? |
michael@0 | 36 | */ |
michael@0 | 37 | static bool sInitialized; |
michael@0 | 38 | |
michael@0 | 39 | public: |
michael@0 | 40 | enum Type { |
michael@0 | 41 | GRE = 0, |
michael@0 | 42 | APP = 1 |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Returns whether SetBase has been called at least once with |
michael@0 | 47 | * a valid nsIFile |
michael@0 | 48 | */ |
michael@0 | 49 | static inline bool |
michael@0 | 50 | IsInitialized() |
michael@0 | 51 | { |
michael@0 | 52 | return sInitialized; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Initializes the Omnijar API with the given directory or file for GRE and |
michael@0 | 57 | * APP. Each of the paths given can be: |
michael@0 | 58 | * - a file path, pointing to the omnijar file, |
michael@0 | 59 | * - a directory path, pointing to a directory containing an "omni.jar" file, |
michael@0 | 60 | * - nullptr for autodetection of an "omni.jar" file. |
michael@0 | 61 | */ |
michael@0 | 62 | static void Init(nsIFile *aGrePath = nullptr, nsIFile *aAppPath = nullptr); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Cleans up the Omnijar API |
michael@0 | 66 | */ |
michael@0 | 67 | static void CleanUp(); |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Returns an nsIFile pointing to the omni.jar file for GRE or APP. |
michael@0 | 71 | * Returns nullptr when there is no corresponding omni.jar. |
michael@0 | 72 | * Also returns nullptr for APP in the unified case. |
michael@0 | 73 | */ |
michael@0 | 74 | static inline already_AddRefed<nsIFile> |
michael@0 | 75 | GetPath(Type aType) |
michael@0 | 76 | { |
michael@0 | 77 | NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized"); |
michael@0 | 78 | nsCOMPtr<nsIFile> path = sPath[aType]; |
michael@0 | 79 | return path.forget(); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Returns whether GRE or APP use an omni.jar. Returns PR_False for |
michael@0 | 84 | * APP when using an omni.jar in the unified case. |
michael@0 | 85 | */ |
michael@0 | 86 | static inline bool |
michael@0 | 87 | HasOmnijar(Type aType) |
michael@0 | 88 | { |
michael@0 | 89 | NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized"); |
michael@0 | 90 | return !!sPath[aType]; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Returns a nsZipArchive pointer for the omni.jar file for GRE or |
michael@0 | 95 | * APP. Returns nullptr in the same cases GetPath() would. |
michael@0 | 96 | */ |
michael@0 | 97 | static inline already_AddRefed<nsZipArchive> |
michael@0 | 98 | GetReader(Type aType) |
michael@0 | 99 | { |
michael@0 | 100 | NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized"); |
michael@0 | 101 | nsRefPtr<nsZipArchive> reader = sReader[aType]; |
michael@0 | 102 | return reader.forget(); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Returns a nsZipArchive pointer for the given path IAOI the given |
michael@0 | 107 | * path is the omni.jar for either GRE or APP. |
michael@0 | 108 | */ |
michael@0 | 109 | static already_AddRefed<nsZipArchive> GetReader(nsIFile *aPath); |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Returns the URI string corresponding to the omni.jar or directory |
michael@0 | 113 | * for GRE or APP. i.e. jar:/path/to/omni.jar!/ for omni.jar and |
michael@0 | 114 | * /path/to/base/dir/ otherwise. Returns an empty string for APP in |
michael@0 | 115 | * the unified case. |
michael@0 | 116 | * The returned URI is guaranteed to end with a slash. |
michael@0 | 117 | */ |
michael@0 | 118 | static nsresult GetURIString(Type aType, nsACString &result); |
michael@0 | 119 | |
michael@0 | 120 | private: |
michael@0 | 121 | /** |
michael@0 | 122 | * Used internally, respectively by Init() and CleanUp() |
michael@0 | 123 | */ |
michael@0 | 124 | static void InitOne(nsIFile *aPath, Type aType); |
michael@0 | 125 | static void CleanUpOne(Type aType); |
michael@0 | 126 | |
michael@0 | 127 | }; /* class Omnijar */ |
michael@0 | 128 | |
michael@0 | 129 | } /* namespace mozilla */ |
michael@0 | 130 | |
michael@0 | 131 | #endif /* mozilla_Omnijar_h */ |