dom/devicestorage/nsDeviceStorage.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 /* 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 file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsDeviceStorage_h
michael@0 6 #define nsDeviceStorage_h
michael@0 7
michael@0 8 class nsPIDOMWindow;
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "PCOMContentPermissionRequestChild.h"
michael@0 11
michael@0 12 #include "DOMRequest.h"
michael@0 13 #include "DOMCursor.h"
michael@0 14 #include "nsAutoPtr.h"
michael@0 15 #include "nsCycleCollectionParticipant.h"
michael@0 16 #include "nsDOMClassInfoID.h"
michael@0 17 #include "nsIClassInfo.h"
michael@0 18 #include "nsIContentPermissionPrompt.h"
michael@0 19 #include "nsIDOMWindow.h"
michael@0 20 #include "nsIURI.h"
michael@0 21 #include "nsInterfaceHashtable.h"
michael@0 22 #include "nsIPrincipal.h"
michael@0 23 #include "nsString.h"
michael@0 24 #include "nsWeakPtr.h"
michael@0 25 #include "nsIDOMEventListener.h"
michael@0 26 #include "nsIObserver.h"
michael@0 27 #include "nsIStringBundle.h"
michael@0 28 #include "mozilla/Mutex.h"
michael@0 29 #include "prtime.h"
michael@0 30 #include "DeviceStorage.h"
michael@0 31 #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
michael@0 32 #include "mozilla/StaticPtr.h"
michael@0 33
michael@0 34 namespace mozilla {
michael@0 35 class ErrorResult;
michael@0 36 } // namespace mozilla
michael@0 37
michael@0 38 #define POST_ERROR_EVENT_FILE_EXISTS "NoModificationAllowedError"
michael@0 39 #define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST "NotFoundError"
michael@0 40 #define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "TypeMismatchError"
michael@0 41 #define POST_ERROR_EVENT_PERMISSION_DENIED "SecurityError"
michael@0 42 #define POST_ERROR_EVENT_ILLEGAL_TYPE "TypeMismatchError"
michael@0 43 #define POST_ERROR_EVENT_UNKNOWN "Unknown"
michael@0 44
michael@0 45 enum DeviceStorageRequestType {
michael@0 46 DEVICE_STORAGE_REQUEST_READ,
michael@0 47 DEVICE_STORAGE_REQUEST_WRITE,
michael@0 48 DEVICE_STORAGE_REQUEST_CREATE,
michael@0 49 DEVICE_STORAGE_REQUEST_DELETE,
michael@0 50 DEVICE_STORAGE_REQUEST_WATCH,
michael@0 51 DEVICE_STORAGE_REQUEST_FREE_SPACE,
michael@0 52 DEVICE_STORAGE_REQUEST_USED_SPACE,
michael@0 53 DEVICE_STORAGE_REQUEST_AVAILABLE,
michael@0 54 DEVICE_STORAGE_REQUEST_STATUS,
michael@0 55 DEVICE_STORAGE_REQUEST_FORMAT,
michael@0 56 DEVICE_STORAGE_REQUEST_MOUNT,
michael@0 57 DEVICE_STORAGE_REQUEST_UNMOUNT,
michael@0 58 DEVICE_STORAGE_REQUEST_CREATEFD
michael@0 59 };
michael@0 60
michael@0 61 class DeviceStorageUsedSpaceCache MOZ_FINAL
michael@0 62 {
michael@0 63 public:
michael@0 64 static DeviceStorageUsedSpaceCache* CreateOrGet();
michael@0 65
michael@0 66 DeviceStorageUsedSpaceCache();
michael@0 67 ~DeviceStorageUsedSpaceCache();
michael@0 68
michael@0 69
michael@0 70 class InvalidateRunnable MOZ_FINAL : public nsRunnable
michael@0 71 {
michael@0 72 public:
michael@0 73 InvalidateRunnable(DeviceStorageUsedSpaceCache* aCache,
michael@0 74 const nsAString& aStorageName)
michael@0 75 : mCache(aCache)
michael@0 76 , mStorageName(aStorageName) {}
michael@0 77
michael@0 78 ~InvalidateRunnable() {}
michael@0 79
michael@0 80 NS_IMETHOD Run() MOZ_OVERRIDE
michael@0 81 {
michael@0 82 nsRefPtr<DeviceStorageUsedSpaceCache::CacheEntry> cacheEntry;
michael@0 83 cacheEntry = mCache->GetCacheEntry(mStorageName);
michael@0 84 if (cacheEntry) {
michael@0 85 cacheEntry->mDirty = true;
michael@0 86 }
michael@0 87 return NS_OK;
michael@0 88 }
michael@0 89 private:
michael@0 90 DeviceStorageUsedSpaceCache* mCache;
michael@0 91 nsString mStorageName;
michael@0 92 };
michael@0 93
michael@0 94 void Invalidate(const nsAString& aStorageName)
michael@0 95 {
michael@0 96 MOZ_ASSERT(NS_IsMainThread());
michael@0 97 MOZ_ASSERT(mIOThread);
michael@0 98
michael@0 99 nsRefPtr<InvalidateRunnable> r = new InvalidateRunnable(this, aStorageName);
michael@0 100 mIOThread->Dispatch(r, NS_DISPATCH_NORMAL);
michael@0 101 }
michael@0 102
michael@0 103 void Dispatch(nsIRunnable* aRunnable)
michael@0 104 {
michael@0 105 MOZ_ASSERT(NS_IsMainThread());
michael@0 106 MOZ_ASSERT(mIOThread);
michael@0 107
michael@0 108 mIOThread->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
michael@0 109 }
michael@0 110
michael@0 111 nsresult AccumUsedSizes(const nsAString& aStorageName,
michael@0 112 uint64_t* aPictureSize, uint64_t* aVideosSize,
michael@0 113 uint64_t* aMusicSize, uint64_t* aTotalSize);
michael@0 114
michael@0 115 void SetUsedSizes(const nsAString& aStorageName,
michael@0 116 uint64_t aPictureSize, uint64_t aVideosSize,
michael@0 117 uint64_t aMusicSize, uint64_t aTotalSize);
michael@0 118
michael@0 119 private:
michael@0 120 friend class InvalidateRunnable;
michael@0 121
michael@0 122 struct CacheEntry
michael@0 123 {
michael@0 124 // Technically, this doesn't need to be threadsafe, but the implementation
michael@0 125 // of the non-thread safe one causes ASSERTS due to the underlying thread
michael@0 126 // associated with a LazyIdleThread changing from time to time.
michael@0 127 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DeviceStorageUsedSpaceCache::CacheEntry)
michael@0 128
michael@0 129 bool mDirty;
michael@0 130 nsString mStorageName;
michael@0 131 int64_t mFreeBytes;
michael@0 132 uint64_t mPicturesUsedSize;
michael@0 133 uint64_t mVideosUsedSize;
michael@0 134 uint64_t mMusicUsedSize;
michael@0 135 uint64_t mTotalUsedSize;
michael@0 136 };
michael@0 137 already_AddRefed<CacheEntry> GetCacheEntry(const nsAString& aStorageName);
michael@0 138
michael@0 139 nsTArray<nsRefPtr<CacheEntry>> mCacheEntries;
michael@0 140
michael@0 141 nsCOMPtr<nsIThread> mIOThread;
michael@0 142
michael@0 143 static mozilla::StaticAutoPtr<DeviceStorageUsedSpaceCache> sDeviceStorageUsedSpaceCache;
michael@0 144 };
michael@0 145
michael@0 146 class DeviceStorageTypeChecker MOZ_FINAL
michael@0 147 {
michael@0 148 public:
michael@0 149 static DeviceStorageTypeChecker* CreateOrGet();
michael@0 150
michael@0 151 DeviceStorageTypeChecker();
michael@0 152 ~DeviceStorageTypeChecker();
michael@0 153
michael@0 154 void InitFromBundle(nsIStringBundle* aBundle);
michael@0 155
michael@0 156 bool Check(const nsAString& aType, nsIDOMBlob* aBlob);
michael@0 157 bool Check(const nsAString& aType, nsIFile* aFile);
michael@0 158 void GetTypeFromFile(nsIFile* aFile, nsAString& aType);
michael@0 159 void GetTypeFromFileName(const nsAString& aFileName, nsAString& aType);
michael@0 160
michael@0 161 static nsresult GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult);
michael@0 162 static nsresult GetAccessForRequest(const DeviceStorageRequestType aRequestType, nsACString& aAccessResult);
michael@0 163 static bool IsVolumeBased(const nsAString& aType);
michael@0 164
michael@0 165 private:
michael@0 166 nsString mPicturesExtensions;
michael@0 167 nsString mVideosExtensions;
michael@0 168 nsString mMusicExtensions;
michael@0 169
michael@0 170 static mozilla::StaticAutoPtr<DeviceStorageTypeChecker> sDeviceStorageTypeChecker;
michael@0 171 };
michael@0 172
michael@0 173 class ContinueCursorEvent MOZ_FINAL : public nsRunnable
michael@0 174 {
michael@0 175 public:
michael@0 176 ContinueCursorEvent(already_AddRefed<mozilla::dom::DOMRequest> aRequest);
michael@0 177 ContinueCursorEvent(mozilla::dom::DOMRequest* aRequest);
michael@0 178 ~ContinueCursorEvent();
michael@0 179 void Continue();
michael@0 180
michael@0 181 NS_IMETHOD Run() MOZ_OVERRIDE;
michael@0 182 private:
michael@0 183 already_AddRefed<DeviceStorageFile> GetNextFile();
michael@0 184 nsRefPtr<mozilla::dom::DOMRequest> mRequest;
michael@0 185 };
michael@0 186
michael@0 187 class nsDOMDeviceStorageCursor MOZ_FINAL
michael@0 188 : public mozilla::dom::DOMCursor
michael@0 189 , public nsIContentPermissionRequest
michael@0 190 , public PCOMContentPermissionRequestChild
michael@0 191 , public mozilla::dom::devicestorage::DeviceStorageRequestChildCallback
michael@0 192 {
michael@0 193 public:
michael@0 194 NS_DECL_ISUPPORTS_INHERITED
michael@0 195 NS_DECL_NSICONTENTPERMISSIONREQUEST
michael@0 196 NS_FORWARD_NSIDOMDOMCURSOR(mozilla::dom::DOMCursor::)
michael@0 197
michael@0 198 // DOMCursor
michael@0 199 virtual void Continue(mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
michael@0 200
michael@0 201 nsDOMDeviceStorageCursor(nsPIDOMWindow* aWindow,
michael@0 202 nsIPrincipal* aPrincipal,
michael@0 203 DeviceStorageFile* aFile,
michael@0 204 PRTime aSince);
michael@0 205
michael@0 206
michael@0 207 nsTArray<nsRefPtr<DeviceStorageFile> > mFiles;
michael@0 208 bool mOkToCallContinue;
michael@0 209 PRTime mSince;
michael@0 210
michael@0 211 virtual bool Recv__delete__(const bool& allow,
michael@0 212 const InfallibleTArray<PermissionChoice>& choices) MOZ_OVERRIDE;
michael@0 213 virtual void IPDLRelease() MOZ_OVERRIDE;
michael@0 214
michael@0 215 void GetStorageType(nsAString & aType);
michael@0 216
michael@0 217 void RequestComplete() MOZ_OVERRIDE;
michael@0 218
michael@0 219 private:
michael@0 220 ~nsDOMDeviceStorageCursor();
michael@0 221
michael@0 222 nsRefPtr<DeviceStorageFile> mFile;
michael@0 223 nsCOMPtr<nsIPrincipal> mPrincipal;
michael@0 224 };
michael@0 225
michael@0 226 //helpers
michael@0 227 JS::Value
michael@0 228 StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString);
michael@0 229
michael@0 230 JS::Value
michael@0 231 nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile);
michael@0 232
michael@0 233 JS::Value
michael@0 234 InterfaceToJsval(nsPIDOMWindow* aWindow, nsISupports* aObject, const nsIID* aIID);
michael@0 235
michael@0 236 #endif

mercurial