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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_FileLocation_h
6 #define mozilla_FileLocation_h
8 #include "nsString.h"
9 #include "nsCOMPtr.h"
10 #include "nsAutoPtr.h"
11 #include "nsIFile.h"
12 #include "FileUtils.h"
14 class nsZipArchive;
15 class nsZipItem;
17 namespace mozilla {
19 class FileLocation
20 {
21 public:
22 /**
23 * FileLocation is an helper to handle different kind of file locations
24 * within Gecko:
25 * - on filesystems
26 * - in archives
27 * - in archives within archives
28 * As such, it stores a path within an archive, as well as the archive
29 * path itself, or the complete file path alone when on a filesystem.
30 * When the archive is in an archive, an nsZipArchive is stored instead
31 * of a file path.
32 */
33 FileLocation();
34 ~FileLocation();
36 /**
37 * Constructor for plain files
38 */
39 FileLocation(nsIFile *file);
41 /**
42 * Constructors for path within an archive. The archive can be given either
43 * as nsIFile or nsZipArchive.
44 */
45 FileLocation(nsIFile *zip, const char *path);
47 FileLocation(nsZipArchive *zip, const char *path);
49 /**
50 * Creates a new file location relative to another one.
51 */
52 FileLocation(const FileLocation &file, const char *path = nullptr);
54 /**
55 * Initialization functions corresponding to constructors
56 */
57 void Init(nsIFile *file);
59 void Init(nsIFile *zip, const char *path);
61 void Init(nsZipArchive *zip, const char *path);
63 /**
64 * Returns an URI string corresponding to the file location
65 */
66 void GetURIString(nsACString &result) const;
68 /**
69 * Returns the base file of the location, where base file is defined as:
70 * - The file itself when the location is on a filesystem
71 * - The archive file when the location is in an archive
72 * - The outer archive file when the location is in an archive in an archive
73 */
74 already_AddRefed<nsIFile> GetBaseFile();
76 /**
77 * Returns whether the "base file" (see GetBaseFile) is an archive
78 */
79 bool IsZip() const
80 {
81 return !mPath.IsEmpty();
82 }
84 /**
85 * Returns the path within the archive, when within an archive
86 */
87 void GetPath(nsACString &result) const
88 {
89 result = mPath;
90 }
92 /**
93 * Boolean value corresponding to whether the file location is initialized
94 * or not.
95 */
96 operator bool() const
97 {
98 return mBaseFile || mBaseZip;
99 }
101 /**
102 * Returns whether another FileLocation points to the same resource
103 */
104 bool Equals(const FileLocation &file) const;
106 /**
107 * Data associated with a FileLocation.
108 */
109 class Data
110 {
111 public:
112 /**
113 * Returns the data size
114 */
115 nsresult GetSize(uint32_t *result);
117 /**
118 * Copies the data in the given buffer
119 */
120 nsresult Copy(char *buf, uint32_t len);
121 protected:
122 friend class FileLocation;
123 nsZipItem *mItem;
124 nsRefPtr<nsZipArchive> mZip;
125 mozilla::AutoFDClose mFd;
126 };
128 /**
129 * Returns the data associated with the resource pointed at by the file
130 * location.
131 */
132 nsresult GetData(Data &data);
133 private:
134 nsCOMPtr<nsIFile> mBaseFile;
135 nsRefPtr<nsZipArchive> mBaseZip;
136 nsCString mPath;
137 }; /* class FileLocation */
139 } /* namespace mozilla */
141 #endif /* mozilla_FileLocation_h */