dom/devicestorage/DeviceStorage.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /* vim: set ts=2 sw=2 et tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef DeviceStorage_h
michael@0 8 #define DeviceStorage_h
michael@0 9
michael@0 10 #include "nsIDOMDeviceStorage.h"
michael@0 11 #include "nsIFile.h"
michael@0 12 #include "nsIPrincipal.h"
michael@0 13 #include "nsIObserver.h"
michael@0 14 #include "mozilla/DOMEventTargetHelper.h"
michael@0 15 #include "mozilla/RefPtr.h"
michael@0 16 #include "mozilla/StaticPtr.h"
michael@0 17 #include "mozilla/dom/DOMRequest.h"
michael@0 18
michael@0 19 #define DEVICESTORAGE_PICTURES "pictures"
michael@0 20 #define DEVICESTORAGE_VIDEOS "videos"
michael@0 21 #define DEVICESTORAGE_MUSIC "music"
michael@0 22 #define DEVICESTORAGE_APPS "apps"
michael@0 23 #define DEVICESTORAGE_SDCARD "sdcard"
michael@0 24 #define DEVICESTORAGE_CRASHES "crashes"
michael@0 25
michael@0 26 class DeviceStorageFile;
michael@0 27 class nsIInputStream;
michael@0 28
michael@0 29 namespace mozilla {
michael@0 30 class EventListenerManager;
michael@0 31 namespace dom {
michael@0 32 class DeviceStorageEnumerationParameters;
michael@0 33 class DOMCursor;
michael@0 34 class DOMRequest;
michael@0 35 class Promise;
michael@0 36 class DeviceStorageFileSystem;
michael@0 37 } // namespace dom
michael@0 38 namespace ipc {
michael@0 39 class FileDescriptor;
michael@0 40 }
michael@0 41 } // namespace mozilla
michael@0 42
michael@0 43 class DeviceStorageFile MOZ_FINAL
michael@0 44 : public nsISupports {
michael@0 45 public:
michael@0 46 nsCOMPtr<nsIFile> mFile;
michael@0 47 nsString mStorageType;
michael@0 48 nsString mStorageName;
michael@0 49 nsString mRootDir;
michael@0 50 nsString mPath;
michael@0 51 bool mEditable;
michael@0 52 nsString mMimeType;
michael@0 53 uint64_t mLength;
michael@0 54 uint64_t mLastModifiedDate;
michael@0 55
michael@0 56 // Used when the path will be set later via SetPath.
michael@0 57 DeviceStorageFile(const nsAString& aStorageType,
michael@0 58 const nsAString& aStorageName);
michael@0 59 // Used for non-enumeration purposes.
michael@0 60 DeviceStorageFile(const nsAString& aStorageType,
michael@0 61 const nsAString& aStorageName,
michael@0 62 const nsAString& aPath);
michael@0 63 // Used for enumerations. When you call Enumerate, you can pass in a
michael@0 64 // directory to enumerate and the results that are returned are relative to
michael@0 65 // that directory, files related to an enumeration need to know the "root of
michael@0 66 // the enumeration" directory.
michael@0 67 DeviceStorageFile(const nsAString& aStorageType,
michael@0 68 const nsAString& aStorageName,
michael@0 69 const nsAString& aRootDir,
michael@0 70 const nsAString& aPath);
michael@0 71
michael@0 72 void SetPath(const nsAString& aPath);
michael@0 73 void SetEditable(bool aEditable);
michael@0 74
michael@0 75 static already_AddRefed<DeviceStorageFile>
michael@0 76 CreateUnique(nsAString& aFileName,
michael@0 77 uint32_t aFileType,
michael@0 78 uint32_t aFileAttributes);
michael@0 79
michael@0 80 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 81
michael@0 82 bool IsAvailable();
michael@0 83 void GetFullPath(nsAString& aFullPath);
michael@0 84
michael@0 85 // we want to make sure that the names of file can't reach
michael@0 86 // outside of the type of storage the user asked for.
michael@0 87 bool IsSafePath();
michael@0 88 bool IsSafePath(const nsAString& aPath);
michael@0 89
michael@0 90 void Dump(const char* label);
michael@0 91
michael@0 92 nsresult Remove();
michael@0 93 nsresult Write(nsIInputStream* aInputStream);
michael@0 94 nsresult Write(InfallibleTArray<uint8_t>& bits);
michael@0 95 void CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> >& aFiles,
michael@0 96 PRTime aSince = 0);
michael@0 97 void collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> >& aFiles,
michael@0 98 PRTime aSince, nsAString& aRootPath);
michael@0 99
michael@0 100 void AccumDiskUsage(uint64_t* aPicturesSoFar, uint64_t* aVideosSoFar,
michael@0 101 uint64_t* aMusicSoFar, uint64_t* aTotalSoFar);
michael@0 102
michael@0 103 void GetDiskFreeSpace(int64_t* aSoFar);
michael@0 104 void GetStatus(nsAString& aStatus);
michael@0 105 void GetStorageStatus(nsAString& aStatus);
michael@0 106 void DoFormat(nsAString& aStatus);
michael@0 107 void DoMount(nsAString& aStatus);
michael@0 108 void DoUnmount(nsAString& aStatus);
michael@0 109 static void GetRootDirectoryForType(const nsAString& aStorageType,
michael@0 110 const nsAString& aStorageName,
michael@0 111 nsIFile** aFile);
michael@0 112
michael@0 113 nsresult CalculateSizeAndModifiedDate();
michael@0 114 nsresult CalculateMimeType();
michael@0 115 nsresult CreateFileDescriptor(mozilla::ipc::FileDescriptor& aFileDescriptor);
michael@0 116
michael@0 117 private:
michael@0 118 void Init();
michael@0 119 void NormalizeFilePath();
michael@0 120 void AppendRelativePath(const nsAString& aPath);
michael@0 121 void AccumDirectoryUsage(nsIFile* aFile,
michael@0 122 uint64_t* aPicturesSoFar,
michael@0 123 uint64_t* aVideosSoFar,
michael@0 124 uint64_t* aMusicSoFar,
michael@0 125 uint64_t* aTotalSoFar);
michael@0 126 };
michael@0 127
michael@0 128 /*
michael@0 129 The FileUpdateDispatcher converts file-watcher-notify
michael@0 130 observer events to file-watcher-update events. This is
michael@0 131 used to be able to broadcast events from one child to
michael@0 132 another child in B2G. (f.e., if one child decides to add
michael@0 133 a file, we want to be able to able to send a onchange
michael@0 134 notifications to every other child watching that device
michael@0 135 storage object).
michael@0 136
michael@0 137 We create this object (via GetSingleton) in two places:
michael@0 138 * ContentParent::Init (for IPC)
michael@0 139 * nsDOMDeviceStorage::Init (for non-ipc)
michael@0 140 */
michael@0 141 class FileUpdateDispatcher MOZ_FINAL
michael@0 142 : public nsIObserver
michael@0 143 {
michael@0 144 public:
michael@0 145 NS_DECL_ISUPPORTS
michael@0 146 NS_DECL_NSIOBSERVER
michael@0 147
michael@0 148 static FileUpdateDispatcher* GetSingleton();
michael@0 149 private:
michael@0 150 static mozilla::StaticRefPtr<FileUpdateDispatcher> sSingleton;
michael@0 151 };
michael@0 152
michael@0 153 class nsDOMDeviceStorage MOZ_FINAL
michael@0 154 : public mozilla::DOMEventTargetHelper
michael@0 155 , public nsIDOMDeviceStorage
michael@0 156 , public nsIObserver
michael@0 157 {
michael@0 158 typedef mozilla::ErrorResult ErrorResult;
michael@0 159 typedef mozilla::dom::DeviceStorageEnumerationParameters
michael@0 160 EnumerationParameters;
michael@0 161 typedef mozilla::dom::DOMCursor DOMCursor;
michael@0 162 typedef mozilla::dom::DOMRequest DOMRequest;
michael@0 163 typedef mozilla::dom::Promise Promise;
michael@0 164 typedef mozilla::dom::DeviceStorageFileSystem DeviceStorageFileSystem;
michael@0 165 public:
michael@0 166 typedef nsTArray<nsString> VolumeNameArray;
michael@0 167
michael@0 168 NS_DECL_ISUPPORTS_INHERITED
michael@0 169 NS_DECL_NSIDOMDEVICESTORAGE
michael@0 170
michael@0 171 NS_DECL_NSIOBSERVER
michael@0 172 NS_DECL_NSIDOMEVENTTARGET
michael@0 173
michael@0 174 virtual mozilla::EventListenerManager*
michael@0 175 GetExistingListenerManager() const MOZ_OVERRIDE;
michael@0 176 virtual mozilla::EventListenerManager*
michael@0 177 GetOrCreateListenerManager() MOZ_OVERRIDE;
michael@0 178
michael@0 179 virtual void
michael@0 180 AddEventListener(const nsAString& aType,
michael@0 181 mozilla::dom::EventListener* aListener,
michael@0 182 bool aUseCapture,
michael@0 183 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
michael@0 184 ErrorResult& aRv) MOZ_OVERRIDE;
michael@0 185
michael@0 186 virtual void RemoveEventListener(const nsAString& aType,
michael@0 187 mozilla::dom::EventListener* aListener,
michael@0 188 bool aUseCapture,
michael@0 189 ErrorResult& aRv) MOZ_OVERRIDE;
michael@0 190
michael@0 191 nsDOMDeviceStorage(nsPIDOMWindow* aWindow);
michael@0 192
michael@0 193 nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType,
michael@0 194 const nsAString& aVolName);
michael@0 195
michael@0 196 bool IsAvailable();
michael@0 197 bool IsFullPath(const nsAString& aPath)
michael@0 198 {
michael@0 199 return aPath.Length() > 0 && aPath.CharAt(0) == '/';
michael@0 200 }
michael@0 201
michael@0 202 void SetRootDirectoryForType(const nsAString& aType,
michael@0 203 const nsAString& aVolName);
michael@0 204
michael@0 205 // WebIDL
michael@0 206 nsPIDOMWindow*
michael@0 207 GetParentObject() const
michael@0 208 {
michael@0 209 return GetOwner();
michael@0 210 }
michael@0 211 virtual JSObject*
michael@0 212 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 213
michael@0 214 IMPL_EVENT_HANDLER(change)
michael@0 215
michael@0 216 already_AddRefed<DOMRequest>
michael@0 217 Add(nsIDOMBlob* aBlob, ErrorResult& aRv);
michael@0 218 already_AddRefed<DOMRequest>
michael@0 219 AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv);
michael@0 220
michael@0 221 already_AddRefed<DOMRequest>
michael@0 222 Get(const nsAString& aPath, ErrorResult& aRv)
michael@0 223 {
michael@0 224 return GetInternal(aPath, false, aRv);
michael@0 225 }
michael@0 226 already_AddRefed<DOMRequest>
michael@0 227 GetEditable(const nsAString& aPath, ErrorResult& aRv)
michael@0 228 {
michael@0 229 return GetInternal(aPath, true, aRv);
michael@0 230 }
michael@0 231 already_AddRefed<DOMRequest>
michael@0 232 Delete(const nsAString& aPath, ErrorResult& aRv);
michael@0 233
michael@0 234 already_AddRefed<DOMCursor>
michael@0 235 Enumerate(const EnumerationParameters& aOptions, ErrorResult& aRv)
michael@0 236 {
michael@0 237 return Enumerate(NullString(), aOptions, aRv);
michael@0 238 }
michael@0 239 already_AddRefed<DOMCursor>
michael@0 240 Enumerate(const nsAString& aPath, const EnumerationParameters& aOptions,
michael@0 241 ErrorResult& aRv);
michael@0 242 already_AddRefed<DOMCursor>
michael@0 243 EnumerateEditable(const EnumerationParameters& aOptions, ErrorResult& aRv)
michael@0 244 {
michael@0 245 return EnumerateEditable(NullString(), aOptions, aRv);
michael@0 246 }
michael@0 247 already_AddRefed<DOMCursor>
michael@0 248 EnumerateEditable(const nsAString& aPath,
michael@0 249 const EnumerationParameters& aOptions, ErrorResult& aRv);
michael@0 250
michael@0 251 already_AddRefed<DOMRequest> FreeSpace(ErrorResult& aRv);
michael@0 252 already_AddRefed<DOMRequest> UsedSpace(ErrorResult& aRv);
michael@0 253 already_AddRefed<DOMRequest> Available(ErrorResult& aRv);
michael@0 254 already_AddRefed<DOMRequest> Format(ErrorResult& aRv);
michael@0 255 already_AddRefed<DOMRequest> StorageStatus(ErrorResult& aRv);
michael@0 256 already_AddRefed<DOMRequest> Mount(ErrorResult& aRv);
michael@0 257 already_AddRefed<DOMRequest> Unmount(ErrorResult& aRv);
michael@0 258
michael@0 259 bool Default();
michael@0 260
michael@0 261 // Uses XPCOM GetStorageName
michael@0 262
michael@0 263 already_AddRefed<Promise>
michael@0 264 GetRoot();
michael@0 265
michael@0 266 static void
michael@0 267 CreateDeviceStorageFor(nsPIDOMWindow* aWin,
michael@0 268 const nsAString& aType,
michael@0 269 nsDOMDeviceStorage** aStore);
michael@0 270
michael@0 271 static void
michael@0 272 CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
michael@0 273 const nsAString& aType,
michael@0 274 nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores);
michael@0 275
michael@0 276 void Shutdown();
michael@0 277
michael@0 278 static void GetOrderedVolumeNames(nsTArray<nsString>& aVolumeNames);
michael@0 279
michael@0 280 static void GetDefaultStorageName(const nsAString& aStorageType,
michael@0 281 nsAString &aStorageName);
michael@0 282
michael@0 283 static bool ParseFullPath(const nsAString& aFullPath,
michael@0 284 nsAString& aOutStorageName,
michael@0 285 nsAString& aOutStoragePath);
michael@0 286 private:
michael@0 287 ~nsDOMDeviceStorage();
michael@0 288
michael@0 289 already_AddRefed<DOMRequest>
michael@0 290 GetInternal(const nsAString& aPath, bool aEditable, ErrorResult& aRv);
michael@0 291
michael@0 292 void
michael@0 293 GetInternal(nsPIDOMWindow* aWin, const nsAString& aPath, DOMRequest* aRequest,
michael@0 294 bool aEditable);
michael@0 295
michael@0 296 void
michael@0 297 DeleteInternal(nsPIDOMWindow* aWin, const nsAString& aPath,
michael@0 298 DOMRequest* aRequest);
michael@0 299
michael@0 300 already_AddRefed<DOMCursor>
michael@0 301 EnumerateInternal(const nsAString& aName,
michael@0 302 const EnumerationParameters& aOptions, bool aEditable,
michael@0 303 ErrorResult& aRv);
michael@0 304
michael@0 305 nsString mStorageType;
michael@0 306 nsCOMPtr<nsIFile> mRootDirectory;
michael@0 307 nsString mStorageName;
michael@0 308
michael@0 309 already_AddRefed<nsDOMDeviceStorage> GetStorage(const nsAString& aFullPath,
michael@0 310 nsAString& aOutStoragePath);
michael@0 311 already_AddRefed<nsDOMDeviceStorage>
michael@0 312 GetStorageByName(const nsAString &aStorageName);
michael@0 313
michael@0 314 nsCOMPtr<nsIPrincipal> mPrincipal;
michael@0 315
michael@0 316 bool mIsWatchingFile;
michael@0 317 bool mAllowedToWatchFile;
michael@0 318
michael@0 319 nsresult Notify(const char* aReason, class DeviceStorageFile* aFile);
michael@0 320
michael@0 321 friend class WatchFileEvent;
michael@0 322 friend class DeviceStorageRequest;
michael@0 323
michael@0 324 static mozilla::StaticAutoPtr<nsTArray<nsString>> sVolumeNameCache;
michael@0 325
michael@0 326 #ifdef MOZ_WIDGET_GONK
michael@0 327 nsString mLastStatus;
michael@0 328 void DispatchMountChangeEvent(nsAString& aVolumeStatus);
michael@0 329 #endif
michael@0 330
michael@0 331 // nsIDOMDeviceStorage.type
michael@0 332 enum {
michael@0 333 DEVICE_STORAGE_TYPE_DEFAULT = 0,
michael@0 334 DEVICE_STORAGE_TYPE_SHARED,
michael@0 335 DEVICE_STORAGE_TYPE_EXTERNAL
michael@0 336 };
michael@0 337
michael@0 338 nsRefPtr<DeviceStorageFileSystem> mFileSystem;
michael@0 339 };
michael@0 340
michael@0 341 #endif

mercurial