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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef mozilla_dom_devicestorage_DeviceStorageRequestParent_h |
michael@0 | 7 | #define mozilla_dom_devicestorage_DeviceStorageRequestParent_h |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "mozilla/dom/devicestorage/PDeviceStorageRequestParent.h" |
michael@0 | 11 | #include "mozilla/dom/ContentChild.h" |
michael@0 | 12 | #include "mozilla/dom/ContentParent.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "nsThreadUtils.h" |
michael@0 | 15 | #include "nsDeviceStorage.h" |
michael@0 | 16 | #include "nsTArray.h" |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | namespace dom { |
michael@0 | 20 | namespace devicestorage { |
michael@0 | 21 | |
michael@0 | 22 | class DeviceStorageRequestParent : public PDeviceStorageRequestParent |
michael@0 | 23 | { |
michael@0 | 24 | public: |
michael@0 | 25 | DeviceStorageRequestParent(const DeviceStorageParams& aParams); |
michael@0 | 26 | |
michael@0 | 27 | NS_IMETHOD_(MozExternalRefCountType) AddRef(); |
michael@0 | 28 | NS_IMETHOD_(MozExternalRefCountType) Release(); |
michael@0 | 29 | |
michael@0 | 30 | bool EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent); |
michael@0 | 31 | void Dispatch(); |
michael@0 | 32 | |
michael@0 | 33 | virtual void ActorDestroy(ActorDestroyReason); |
michael@0 | 34 | |
michael@0 | 35 | protected: |
michael@0 | 36 | ~DeviceStorageRequestParent(); |
michael@0 | 37 | |
michael@0 | 38 | private: |
michael@0 | 39 | ThreadSafeAutoRefCnt mRefCnt; |
michael@0 | 40 | NS_DECL_OWNINGTHREAD |
michael@0 | 41 | DeviceStorageParams mParams; |
michael@0 | 42 | |
michael@0 | 43 | class CancelableRunnable : public nsRunnable |
michael@0 | 44 | { |
michael@0 | 45 | public: |
michael@0 | 46 | CancelableRunnable(DeviceStorageRequestParent* aParent) |
michael@0 | 47 | : mParent(aParent) |
michael@0 | 48 | { |
michael@0 | 49 | mCanceled = !(mParent->AddRunnable(this)); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | virtual ~CancelableRunnable() { |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | NS_IMETHOD Run() MOZ_OVERRIDE { |
michael@0 | 56 | nsresult rv = NS_OK; |
michael@0 | 57 | if (!mCanceled) { |
michael@0 | 58 | rv = CancelableRun(); |
michael@0 | 59 | mParent->RemoveRunnable(this); |
michael@0 | 60 | } |
michael@0 | 61 | return rv; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | void Cancel() { |
michael@0 | 65 | mCanceled = true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | virtual nsresult CancelableRun() = 0; |
michael@0 | 69 | |
michael@0 | 70 | protected: |
michael@0 | 71 | nsRefPtr<DeviceStorageRequestParent> mParent; |
michael@0 | 72 | private: |
michael@0 | 73 | bool mCanceled; |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | class PostErrorEvent : public CancelableRunnable |
michael@0 | 77 | { |
michael@0 | 78 | public: |
michael@0 | 79 | PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError); |
michael@0 | 80 | virtual ~PostErrorEvent(); |
michael@0 | 81 | virtual nsresult CancelableRun(); |
michael@0 | 82 | private: |
michael@0 | 83 | nsString mError; |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | class PostSuccessEvent : public CancelableRunnable |
michael@0 | 87 | { |
michael@0 | 88 | public: |
michael@0 | 89 | PostSuccessEvent(DeviceStorageRequestParent* aParent); |
michael@0 | 90 | virtual ~PostSuccessEvent(); |
michael@0 | 91 | virtual nsresult CancelableRun(); |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | class PostBlobSuccessEvent : public CancelableRunnable |
michael@0 | 95 | { |
michael@0 | 96 | public: |
michael@0 | 97 | PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, uint32_t aLength, nsACString& aMimeType, uint64_t aLastModifiedDate); |
michael@0 | 98 | virtual ~PostBlobSuccessEvent(); |
michael@0 | 99 | virtual nsresult CancelableRun(); |
michael@0 | 100 | private: |
michael@0 | 101 | uint32_t mLength; |
michael@0 | 102 | uint64_t mLastModificationDate; |
michael@0 | 103 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 104 | nsCString mMimeType; |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | class PostEnumerationSuccessEvent : public CancelableRunnable |
michael@0 | 108 | { |
michael@0 | 109 | public: |
michael@0 | 110 | PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 111 | const nsAString& aStorageType, |
michael@0 | 112 | const nsAString& aRelPath, |
michael@0 | 113 | InfallibleTArray<DeviceStorageFileValue>& aPaths); |
michael@0 | 114 | virtual ~PostEnumerationSuccessEvent(); |
michael@0 | 115 | virtual nsresult CancelableRun(); |
michael@0 | 116 | private: |
michael@0 | 117 | const nsString mStorageType; |
michael@0 | 118 | const nsString mRelPath; |
michael@0 | 119 | InfallibleTArray<DeviceStorageFileValue> mPaths; |
michael@0 | 120 | }; |
michael@0 | 121 | |
michael@0 | 122 | class CreateFdEvent : public CancelableRunnable |
michael@0 | 123 | { |
michael@0 | 124 | public: |
michael@0 | 125 | CreateFdEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 126 | virtual ~CreateFdEvent(); |
michael@0 | 127 | virtual nsresult CancelableRun(); |
michael@0 | 128 | private: |
michael@0 | 129 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | class WriteFileEvent : public CancelableRunnable |
michael@0 | 133 | { |
michael@0 | 134 | public: |
michael@0 | 135 | WriteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, nsIInputStream* aInputStream); |
michael@0 | 136 | virtual ~WriteFileEvent(); |
michael@0 | 137 | virtual nsresult CancelableRun(); |
michael@0 | 138 | private: |
michael@0 | 139 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 140 | nsCOMPtr<nsIInputStream> mInputStream; |
michael@0 | 141 | }; |
michael@0 | 142 | |
michael@0 | 143 | class DeleteFileEvent : public CancelableRunnable |
michael@0 | 144 | { |
michael@0 | 145 | public: |
michael@0 | 146 | DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 147 | virtual ~DeleteFileEvent(); |
michael@0 | 148 | virtual nsresult CancelableRun(); |
michael@0 | 149 | private: |
michael@0 | 150 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | class FreeSpaceFileEvent : public CancelableRunnable |
michael@0 | 154 | { |
michael@0 | 155 | public: |
michael@0 | 156 | FreeSpaceFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 157 | virtual ~FreeSpaceFileEvent(); |
michael@0 | 158 | virtual nsresult CancelableRun(); |
michael@0 | 159 | private: |
michael@0 | 160 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 161 | }; |
michael@0 | 162 | |
michael@0 | 163 | class UsedSpaceFileEvent : public CancelableRunnable |
michael@0 | 164 | { |
michael@0 | 165 | public: |
michael@0 | 166 | UsedSpaceFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 167 | virtual ~UsedSpaceFileEvent(); |
michael@0 | 168 | virtual nsresult CancelableRun(); |
michael@0 | 169 | private: |
michael@0 | 170 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 171 | }; |
michael@0 | 172 | |
michael@0 | 173 | class ReadFileEvent : public CancelableRunnable |
michael@0 | 174 | { |
michael@0 | 175 | public: |
michael@0 | 176 | ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 177 | virtual ~ReadFileEvent(); |
michael@0 | 178 | virtual nsresult CancelableRun(); |
michael@0 | 179 | private: |
michael@0 | 180 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 181 | nsCString mMimeType; |
michael@0 | 182 | }; |
michael@0 | 183 | |
michael@0 | 184 | class EnumerateFileEvent : public CancelableRunnable |
michael@0 | 185 | { |
michael@0 | 186 | public: |
michael@0 | 187 | EnumerateFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, uint64_t aSince); |
michael@0 | 188 | virtual ~EnumerateFileEvent(); |
michael@0 | 189 | virtual nsresult CancelableRun(); |
michael@0 | 190 | private: |
michael@0 | 191 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 192 | uint64_t mSince; |
michael@0 | 193 | }; |
michael@0 | 194 | |
michael@0 | 195 | class PostPathResultEvent : public CancelableRunnable |
michael@0 | 196 | { |
michael@0 | 197 | public: |
michael@0 | 198 | PostPathResultEvent(DeviceStorageRequestParent* aParent, const nsAString& aPath); |
michael@0 | 199 | virtual ~PostPathResultEvent(); |
michael@0 | 200 | virtual nsresult CancelableRun(); |
michael@0 | 201 | private: |
michael@0 | 202 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 203 | nsString mPath; |
michael@0 | 204 | }; |
michael@0 | 205 | |
michael@0 | 206 | class PostFileDescriptorResultEvent : public CancelableRunnable |
michael@0 | 207 | { |
michael@0 | 208 | public: |
michael@0 | 209 | PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 210 | const FileDescriptor& aFileDescriptor); |
michael@0 | 211 | virtual ~PostFileDescriptorResultEvent(); |
michael@0 | 212 | virtual nsresult CancelableRun(); |
michael@0 | 213 | private: |
michael@0 | 214 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 215 | FileDescriptor mFileDescriptor; |
michael@0 | 216 | }; |
michael@0 | 217 | |
michael@0 | 218 | class PostFreeSpaceResultEvent : public CancelableRunnable |
michael@0 | 219 | { |
michael@0 | 220 | public: |
michael@0 | 221 | PostFreeSpaceResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 222 | uint64_t aFreeSpace); |
michael@0 | 223 | virtual ~PostFreeSpaceResultEvent(); |
michael@0 | 224 | virtual nsresult CancelableRun(); |
michael@0 | 225 | private: |
michael@0 | 226 | uint64_t mFreeSpace; |
michael@0 | 227 | }; |
michael@0 | 228 | |
michael@0 | 229 | class PostUsedSpaceResultEvent : public CancelableRunnable |
michael@0 | 230 | { |
michael@0 | 231 | public: |
michael@0 | 232 | PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 233 | const nsAString& aType, |
michael@0 | 234 | uint64_t aUsedSpace); |
michael@0 | 235 | virtual ~PostUsedSpaceResultEvent(); |
michael@0 | 236 | virtual nsresult CancelableRun(); |
michael@0 | 237 | private: |
michael@0 | 238 | nsString mType; |
michael@0 | 239 | uint64_t mUsedSpace; |
michael@0 | 240 | }; |
michael@0 | 241 | |
michael@0 | 242 | class PostAvailableResultEvent : public CancelableRunnable |
michael@0 | 243 | { |
michael@0 | 244 | public: |
michael@0 | 245 | PostAvailableResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 246 | virtual ~PostAvailableResultEvent(); |
michael@0 | 247 | virtual nsresult CancelableRun(); |
michael@0 | 248 | private: |
michael@0 | 249 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 250 | }; |
michael@0 | 251 | |
michael@0 | 252 | class PostStatusResultEvent : public CancelableRunnable |
michael@0 | 253 | { |
michael@0 | 254 | public: |
michael@0 | 255 | PostStatusResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 256 | virtual ~PostStatusResultEvent(); |
michael@0 | 257 | virtual nsresult CancelableRun(); |
michael@0 | 258 | private: |
michael@0 | 259 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 260 | }; |
michael@0 | 261 | |
michael@0 | 262 | class PostFormatResultEvent : public CancelableRunnable |
michael@0 | 263 | { |
michael@0 | 264 | public: |
michael@0 | 265 | PostFormatResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 266 | virtual ~PostFormatResultEvent(); |
michael@0 | 267 | virtual nsresult CancelableRun(); |
michael@0 | 268 | private: |
michael@0 | 269 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 270 | }; |
michael@0 | 271 | |
michael@0 | 272 | class PostMountResultEvent : public CancelableRunnable |
michael@0 | 273 | { |
michael@0 | 274 | public: |
michael@0 | 275 | PostMountResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 276 | virtual ~PostMountResultEvent(); |
michael@0 | 277 | virtual nsresult CancelableRun(); |
michael@0 | 278 | private: |
michael@0 | 279 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 280 | }; |
michael@0 | 281 | |
michael@0 | 282 | class PostUnmountResultEvent : public CancelableRunnable |
michael@0 | 283 | { |
michael@0 | 284 | public: |
michael@0 | 285 | PostUnmountResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile); |
michael@0 | 286 | virtual ~PostUnmountResultEvent(); |
michael@0 | 287 | virtual nsresult CancelableRun(); |
michael@0 | 288 | private: |
michael@0 | 289 | nsRefPtr<DeviceStorageFile> mFile; |
michael@0 | 290 | }; |
michael@0 | 291 | |
michael@0 | 292 | protected: |
michael@0 | 293 | bool AddRunnable(CancelableRunnable* aRunnable) { |
michael@0 | 294 | MutexAutoLock lock(mMutex); |
michael@0 | 295 | if (mActorDestoryed) |
michael@0 | 296 | return false; |
michael@0 | 297 | |
michael@0 | 298 | mRunnables.AppendElement(aRunnable); |
michael@0 | 299 | return true; |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | void RemoveRunnable(CancelableRunnable* aRunnable) { |
michael@0 | 303 | MutexAutoLock lock(mMutex); |
michael@0 | 304 | mRunnables.RemoveElement(aRunnable); |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | Mutex mMutex; |
michael@0 | 308 | bool mActorDestoryed; |
michael@0 | 309 | nsTArray<nsRefPtr<CancelableRunnable> > mRunnables; |
michael@0 | 310 | }; |
michael@0 | 311 | |
michael@0 | 312 | } // namespace devicestorage |
michael@0 | 313 | } // namespace dom |
michael@0 | 314 | } // namespace mozilla |
michael@0 | 315 | |
michael@0 | 316 | #endif |