2012-05-21 16:18:30 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsDeviceStorage_h
|
|
|
|
#define nsDeviceStorage_h
|
|
|
|
|
|
|
|
class nsPIDOMWindow;
|
2013-06-05 16:15:48 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-02 06:29:34 +00:00
|
|
|
#include "PCOMContentPermissionRequestChild.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
|
|
|
|
#include "DOMRequest.h"
|
2013-03-02 00:21:01 +00:00
|
|
|
#include "DOMCursor.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-05-21 16:18:30 +00:00
|
|
|
#include "nsIClassInfo.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
#include "nsIContentPermissionPrompt.h"
|
2012-05-21 16:18:30 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIURI.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2012-07-30 14:58:26 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2012-05-21 16:18:30 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2012-08-02 06:29:34 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIObserver.h"
|
2012-09-14 05:37:00 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2012-08-02 06:29:34 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2012-09-11 06:52:47 +00:00
|
|
|
#include "prtime.h"
|
2012-08-02 06:29:34 +00:00
|
|
|
#include "DeviceStorage.h"
|
2013-03-17 08:51:36 +00:00
|
|
|
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
|
2013-05-11 09:10:18 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2013-05-02 23:26:31 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
|
2013-03-17 08:51:36 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
} // namespace mozilla
|
2012-06-19 23:14:39 +00:00
|
|
|
|
2012-10-13 15:20:14 +00:00
|
|
|
#define POST_ERROR_EVENT_FILE_EXISTS "NoModificationAllowedError"
|
|
|
|
#define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST "NotFoundError"
|
|
|
|
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "TypeMismatchError"
|
|
|
|
#define POST_ERROR_EVENT_PERMISSION_DENIED "SecurityError"
|
|
|
|
#define POST_ERROR_EVENT_ILLEGAL_TYPE "TypeMismatchError"
|
2012-06-19 23:14:39 +00:00
|
|
|
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
|
|
|
|
2012-11-14 00:06:42 +00:00
|
|
|
enum DeviceStorageRequestType {
|
|
|
|
DEVICE_STORAGE_REQUEST_READ,
|
|
|
|
DEVICE_STORAGE_REQUEST_WRITE,
|
2012-11-19 20:31:21 +00:00
|
|
|
DEVICE_STORAGE_REQUEST_CREATE,
|
2012-11-14 00:06:42 +00:00
|
|
|
DEVICE_STORAGE_REQUEST_DELETE,
|
|
|
|
DEVICE_STORAGE_REQUEST_WATCH,
|
2013-01-25 19:05:24 +00:00
|
|
|
DEVICE_STORAGE_REQUEST_FREE_SPACE,
|
|
|
|
DEVICE_STORAGE_REQUEST_USED_SPACE,
|
|
|
|
DEVICE_STORAGE_REQUEST_AVAILABLE
|
2012-11-14 00:06:42 +00:00
|
|
|
};
|
|
|
|
|
2013-05-02 23:26:31 +00:00
|
|
|
class DeviceStorageUsedSpaceCache MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DeviceStorageUsedSpaceCache* CreateOrGet();
|
|
|
|
|
|
|
|
DeviceStorageUsedSpaceCache();
|
|
|
|
~DeviceStorageUsedSpaceCache();
|
|
|
|
|
|
|
|
|
|
|
|
class InvalidateRunnable MOZ_FINAL : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-05-11 09:10:18 +00:00
|
|
|
InvalidateRunnable(DeviceStorageUsedSpaceCache* aCache,
|
|
|
|
const nsAString& aStorageName)
|
|
|
|
: mCache(aCache)
|
|
|
|
, mStorageName(aStorageName) {}
|
2013-05-02 23:26:31 +00:00
|
|
|
|
|
|
|
~InvalidateRunnable() {}
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2013-05-11 09:10:18 +00:00
|
|
|
{
|
|
|
|
mozilla::RefPtr<DeviceStorageUsedSpaceCache::CacheEntry> cacheEntry;
|
|
|
|
cacheEntry = mCache->GetCacheEntry(mStorageName);
|
|
|
|
if (cacheEntry) {
|
|
|
|
cacheEntry->mDirty = true;
|
|
|
|
}
|
2013-05-02 23:26:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
2013-05-11 09:10:18 +00:00
|
|
|
DeviceStorageUsedSpaceCache* mCache;
|
|
|
|
nsString mStorageName;
|
2013-05-02 23:26:31 +00:00
|
|
|
};
|
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
void Invalidate(const nsAString& aStorageName)
|
|
|
|
{
|
2013-05-02 23:26:31 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(mIOThread, "Null mIOThread!");
|
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
nsRefPtr<InvalidateRunnable> r = new InvalidateRunnable(this, aStorageName);
|
2013-05-02 23:26:31 +00:00
|
|
|
mIOThread->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
void Dispatch(nsIRunnable* aRunnable)
|
|
|
|
{
|
2013-05-02 23:26:31 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(mIOThread, "Null mIOThread!");
|
|
|
|
|
|
|
|
mIOThread->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
nsresult AccumUsedSizes(const nsAString& aStorageName,
|
|
|
|
uint64_t* aPictureSize, uint64_t* aVideosSize,
|
|
|
|
uint64_t* aMusicSize, uint64_t* aTotalSize);
|
|
|
|
|
|
|
|
void SetUsedSizes(const nsAString& aStorageName,
|
|
|
|
uint64_t aPictureSize, uint64_t aVideosSize,
|
2013-05-02 23:26:31 +00:00
|
|
|
uint64_t aMusicSize, uint64_t aTotalSize);
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class InvalidateRunnable;
|
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
class CacheEntry : public mozilla::RefCounted<CacheEntry>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool mDirty;
|
|
|
|
nsString mStorageName;
|
2013-06-04 14:35:33 +00:00
|
|
|
int64_t mFreeBytes;
|
2013-05-11 09:10:18 +00:00
|
|
|
uint64_t mPicturesUsedSize;
|
|
|
|
uint64_t mVideosUsedSize;
|
|
|
|
uint64_t mMusicUsedSize;
|
|
|
|
uint64_t mTotalUsedSize;
|
|
|
|
};
|
|
|
|
mozilla::TemporaryRef<CacheEntry> GetCacheEntry(const nsAString& aStorageName);
|
2013-05-02 23:26:31 +00:00
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
nsTArray<mozilla::RefPtr<CacheEntry> > mCacheEntries;
|
2013-05-02 23:26:31 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
|
|
|
|
|
|
|
static mozilla::StaticAutoPtr<DeviceStorageUsedSpaceCache> sDeviceStorageUsedSpaceCache;
|
|
|
|
};
|
|
|
|
|
2012-09-14 05:37:00 +00:00
|
|
|
class DeviceStorageTypeChecker MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DeviceStorageTypeChecker* CreateOrGet();
|
|
|
|
|
|
|
|
DeviceStorageTypeChecker();
|
|
|
|
~DeviceStorageTypeChecker();
|
|
|
|
|
|
|
|
void InitFromBundle(nsIStringBundle* aBundle);
|
|
|
|
|
|
|
|
bool Check(const nsAString& aType, nsIDOMBlob* aBlob);
|
|
|
|
bool Check(const nsAString& aType, nsIFile* aFile);
|
2013-05-02 23:26:31 +00:00
|
|
|
void GetTypeFromFile(nsIFile* aFile, nsAString& aType);
|
2013-05-11 09:10:18 +00:00
|
|
|
void GetTypeFromFileName(const nsAString& aFileName, nsAString& aType);
|
2012-09-14 05:37:00 +00:00
|
|
|
|
2012-09-14 05:37:00 +00:00
|
|
|
static nsresult GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult);
|
2012-11-14 00:06:42 +00:00
|
|
|
static nsresult GetAccessForRequest(const DeviceStorageRequestType aRequestType, nsACString& aAccessResult);
|
2013-04-02 19:52:21 +00:00
|
|
|
static bool IsVolumeBased(const nsAString& aType);
|
2012-09-14 05:37:00 +00:00
|
|
|
|
2012-09-14 05:37:00 +00:00
|
|
|
private:
|
|
|
|
nsString mPicturesExtensions;
|
|
|
|
nsString mVideosExtensions;
|
|
|
|
nsString mMusicExtensions;
|
|
|
|
|
2013-05-02 23:26:31 +00:00
|
|
|
static mozilla::StaticAutoPtr<DeviceStorageTypeChecker> sDeviceStorageTypeChecker;
|
2012-09-14 05:37:00 +00:00
|
|
|
};
|
|
|
|
|
2012-10-04 20:40:45 +00:00
|
|
|
class ContinueCursorEvent MOZ_FINAL : public nsRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-06-01 06:55:02 +00:00
|
|
|
ContinueCursorEvent(already_AddRefed<mozilla::dom::DOMRequest> aRequest);
|
2012-11-10 15:45:52 +00:00
|
|
|
ContinueCursorEvent(mozilla::dom::DOMRequest* aRequest);
|
2012-06-19 23:14:39 +00:00
|
|
|
~ContinueCursorEvent();
|
2012-10-04 20:40:45 +00:00
|
|
|
void Continue();
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE;
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
2012-10-04 20:40:45 +00:00
|
|
|
already_AddRefed<DeviceStorageFile> GetNextFile();
|
2012-11-10 15:45:52 +00:00
|
|
|
nsRefPtr<mozilla::dom::DOMRequest> mRequest;
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMDeviceStorageCursor MOZ_FINAL
|
2013-03-02 00:21:01 +00:00
|
|
|
: public mozilla::dom::DOMCursor
|
2012-06-19 23:14:39 +00:00
|
|
|
, public nsIContentPermissionRequest
|
|
|
|
, public PCOMContentPermissionRequestChild
|
2012-11-10 15:45:52 +00:00
|
|
|
, public mozilla::dom::devicestorage::DeviceStorageRequestChildCallback
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
2013-03-17 10:20:39 +00:00
|
|
|
NS_FORWARD_NSIDOMDOMCURSOR(mozilla::dom::DOMCursor::)
|
2013-03-02 00:21:01 +00:00
|
|
|
|
2013-03-17 08:51:36 +00:00
|
|
|
// DOMCursor
|
|
|
|
virtual void Continue(mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
|
2012-06-19 23:14:39 +00:00
|
|
|
|
|
|
|
nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow,
|
2012-07-30 14:58:26 +00:00
|
|
|
nsIPrincipal* aPrincipal,
|
2012-06-19 23:14:39 +00:00
|
|
|
DeviceStorageFile* aFile,
|
2012-09-11 06:52:47 +00:00
|
|
|
PRTime aSince);
|
2012-06-19 23:14:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<DeviceStorageFile> > mFiles;
|
|
|
|
bool mOkToCallContinue;
|
2012-09-11 06:52:47 +00:00
|
|
|
PRTime mSince;
|
2012-06-19 23:14:39 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
virtual bool Recv__delete__(const bool& allow) MOZ_OVERRIDE;
|
|
|
|
virtual void IPDLRelease() MOZ_OVERRIDE;
|
2012-06-19 23:14:39 +00:00
|
|
|
|
2012-08-30 22:17:38 +00:00
|
|
|
void GetStorageType(nsAString & aType);
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
void RequestComplete() MOZ_OVERRIDE;
|
2012-10-04 20:40:45 +00:00
|
|
|
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
~nsDOMDeviceStorageCursor();
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2012-07-30 14:58:26 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//helpers
|
2013-04-02 23:17:52 +00:00
|
|
|
JS::Value
|
|
|
|
StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString);
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile);
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
InterfaceToJsval(nsPIDOMWindow* aWindow, nsISupports* aObject, const nsIID* aIID);
|
2012-06-19 23:14:39 +00:00
|
|
|
|
2012-05-21 16:18:30 +00:00
|
|
|
#endif
|