2012-05-21 09:18:30 -07: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;
|
2012-08-01 23:29:34 -07:00
|
|
|
#include "PCOMContentPermissionRequestChild.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
#include "DOMRequest.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-05-21 09:18:30 -07:00
|
|
|
#include "nsIClassInfo.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
#include "nsIContentPermissionPrompt.h"
|
2012-05-21 09:18:30 -07:00
|
|
|
#include "nsIDOMDeviceStorageCursor.h"
|
2012-07-31 12:28:23 -07:00
|
|
|
#include "nsIDOMDeviceStorageStat.h"
|
2012-05-21 09:18:30 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIURI.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2012-07-30 07:58:26 -07:00
|
|
|
#include "nsIPrincipal.h"
|
2012-05-21 09:18:30 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2012-08-01 23:29:34 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIObserver.h"
|
2012-09-13 22:37:00 -07:00
|
|
|
#include "nsIStringBundle.h"
|
2012-08-01 23:29:34 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2012-09-10 23:52:47 -07:00
|
|
|
#include "prtime.h"
|
2012-08-01 23:29:34 -07:00
|
|
|
#include "DeviceStorage.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2012-10-04 13:40:45 -07:00
|
|
|
#include "DeviceStorageRequestChild.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2012-10-13 08:20:14 -07: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 16:14:39 -07:00
|
|
|
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
|
|
|
|
2012-11-10 08:52:15 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::devicestorage;
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2012-11-13 16:06:42 -08:00
|
|
|
enum DeviceStorageRequestType {
|
|
|
|
DEVICE_STORAGE_REQUEST_READ,
|
|
|
|
DEVICE_STORAGE_REQUEST_WRITE,
|
|
|
|
DEVICE_STORAGE_REQUEST_DELETE,
|
|
|
|
DEVICE_STORAGE_REQUEST_WATCH,
|
|
|
|
DEVICE_STORAGE_REQUEST_STAT
|
|
|
|
};
|
|
|
|
|
2012-09-13 22:37:00 -07: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);
|
|
|
|
|
2012-09-13 22:37:00 -07:00
|
|
|
static nsresult GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult);
|
2012-11-13 16:06:42 -08:00
|
|
|
static nsresult GetAccessForRequest(const DeviceStorageRequestType aRequestType, nsACString& aAccessResult);
|
2012-09-13 22:37:00 -07:00
|
|
|
|
2012-09-13 22:37:00 -07:00
|
|
|
private:
|
|
|
|
nsString mPicturesExtensions;
|
|
|
|
nsString mVideosExtensions;
|
|
|
|
nsString mMusicExtensions;
|
|
|
|
|
|
|
|
static nsAutoPtr<DeviceStorageTypeChecker> sDeviceStorageTypeChecker;
|
|
|
|
};
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
class DeviceStorageFile MOZ_FINAL
|
|
|
|
: public nsISupports {
|
2012-06-19 16:14:39 -07:00
|
|
|
public:
|
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
|
|
nsString mPath;
|
2012-08-30 15:17:37 -07:00
|
|
|
nsString mStorageType;
|
2012-06-19 16:14:39 -07:00
|
|
|
bool mEditable;
|
|
|
|
|
2012-08-30 15:17:37 -07:00
|
|
|
DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFile, const nsAString& aPath);
|
|
|
|
DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFile);
|
2012-06-19 16:14:39 -07:00
|
|
|
void SetPath(const nsAString& aPath);
|
|
|
|
void SetEditable(bool aEditable);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// we want to make sure that the names of file can't reach
|
|
|
|
// outside of the type of storage the user asked for.
|
|
|
|
bool IsSafePath();
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-08-17 19:43:00 -07:00
|
|
|
nsresult Remove();
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult Write(nsIInputStream* aInputStream);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult Write(InfallibleTArray<uint8_t>& bits);
|
2012-09-10 23:52:47 -07:00
|
|
|
void CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, PRTime aSince = 0);
|
|
|
|
void collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, PRTime aSince, nsAString& aRootPath);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2012-09-05 14:30:36 -07:00
|
|
|
static void DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const nsAString& aStorageType);
|
2012-07-31 12:28:23 -07:00
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
private:
|
|
|
|
void NormalizeFilePath();
|
|
|
|
void AppendRelativePath();
|
|
|
|
};
|
2012-05-21 09:18:30 -07:00
|
|
|
|
2012-10-04 13:40:45 -07:00
|
|
|
class ContinueCursorEvent MOZ_FINAL : public nsRunnable
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-11-10 08:52:15 -08:00
|
|
|
ContinueCursorEvent(nsRefPtr<DOMRequest>& aRequest);
|
|
|
|
ContinueCursorEvent(DOMRequest* aRequest);
|
2012-06-19 16:14:39 -07:00
|
|
|
~ContinueCursorEvent();
|
2012-10-04 13:40:45 -07:00
|
|
|
void Continue();
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_IMETHOD Run();
|
|
|
|
private:
|
2012-10-04 13:40:45 -07:00
|
|
|
already_AddRefed<DeviceStorageFile> GetNextFile();
|
2012-11-10 08:52:15 -08:00
|
|
|
nsRefPtr<DOMRequest> mRequest;
|
2012-06-19 16:14:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMDeviceStorageCursor MOZ_FINAL
|
|
|
|
: public nsIDOMDeviceStorageCursor
|
2012-11-10 08:52:15 -08:00
|
|
|
, public DOMRequest
|
2012-06-19 16:14:39 -07:00
|
|
|
, public nsIContentPermissionRequest
|
|
|
|
, public PCOMContentPermissionRequestChild
|
2012-11-10 08:52:15 -08:00
|
|
|
, public DeviceStorageRequestChildCallback
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
|
|
|
NS_DECL_NSIDOMDEVICESTORAGECURSOR
|
|
|
|
|
|
|
|
nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow,
|
2012-07-30 07:58:26 -07:00
|
|
|
nsIPrincipal* aPrincipal,
|
2012-06-19 16:14:39 -07:00
|
|
|
DeviceStorageFile* aFile,
|
2012-09-10 23:52:47 -07:00
|
|
|
PRTime aSince);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<DeviceStorageFile> > mFiles;
|
|
|
|
bool mOkToCallContinue;
|
2012-09-10 23:52:47 -07:00
|
|
|
PRTime mSince;
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
virtual bool Recv__delete__(const bool& allow);
|
|
|
|
virtual void IPDLRelease();
|
|
|
|
|
2012-08-30 15:17:38 -07:00
|
|
|
void GetStorageType(nsAString & aType);
|
|
|
|
|
2012-10-04 13:40:45 -07:00
|
|
|
void RequestComplete();
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
private:
|
|
|
|
~nsDOMDeviceStorageCursor();
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2012-07-30 07:58:26 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2012-06-19 16:14:39 -07:00
|
|
|
};
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
class nsDOMDeviceStorageStat MOZ_FINAL
|
|
|
|
: public nsIDOMDeviceStorageStat
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMDEVICESTORAGESTAT
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMDeviceStorageStat(uint64_t aFreeBytes, uint64_t aTotalBytes, nsAString& aState);
|
2012-07-31 12:28:23 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
~nsDOMDeviceStorageStat();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mFreeBytes, mTotalBytes;
|
2012-08-14 08:53:20 -07:00
|
|
|
nsString mState;
|
2012-07-31 12:28:23 -07:00
|
|
|
};
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
//helpers
|
|
|
|
jsval StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString);
|
2012-07-31 12:28:23 -07:00
|
|
|
jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile);
|
|
|
|
jsval InterfaceToJsval(nsPIDOMWindow* aWindow, nsISupports* aObject, const nsIID* aIID);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2012-08-14 08:53:20 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsresult GetSDCardStatus(nsAString& aState);
|
|
|
|
#endif
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2012-05-21 09:18:30 -07:00
|
|
|
#endif
|