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.

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

mercurial