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"
|
2013-03-01 16:21:01 -08:00
|
|
|
#include "DOMCursor.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
#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 "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"
|
2013-03-17 01:51:36 -07:00
|
|
|
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
|
2013-03-17 01:51:36 -07:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
} // namespace mozilla
|
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-13 16:06:42 -08:00
|
|
|
enum DeviceStorageRequestType {
|
|
|
|
DEVICE_STORAGE_REQUEST_READ,
|
|
|
|
DEVICE_STORAGE_REQUEST_WRITE,
|
2012-11-19 12:31:21 -08:00
|
|
|
DEVICE_STORAGE_REQUEST_CREATE,
|
2012-11-13 16:06:42 -08:00
|
|
|
DEVICE_STORAGE_REQUEST_DELETE,
|
|
|
|
DEVICE_STORAGE_REQUEST_WATCH,
|
2013-01-25 11:05:24 -08:00
|
|
|
DEVICE_STORAGE_REQUEST_FREE_SPACE,
|
|
|
|
DEVICE_STORAGE_REQUEST_USED_SPACE,
|
|
|
|
DEVICE_STORAGE_REQUEST_AVAILABLE
|
2012-11-13 16:06:42 -08:00
|
|
|
};
|
|
|
|
|
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-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 07:45:52 -08:00
|
|
|
ContinueCursorEvent(nsRefPtr<mozilla::dom::DOMRequest>& aRequest);
|
|
|
|
ContinueCursorEvent(mozilla::dom::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 07:45:52 -08:00
|
|
|
nsRefPtr<mozilla::dom::DOMRequest> mRequest;
|
2012-06-19 16:14:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMDeviceStorageCursor MOZ_FINAL
|
2013-03-01 16:21:01 -08:00
|
|
|
: public mozilla::dom::DOMCursor
|
2012-06-19 16:14:39 -07:00
|
|
|
, public nsIContentPermissionRequest
|
|
|
|
, public PCOMContentPermissionRequestChild
|
2012-11-10 07:45:52 -08:00
|
|
|
, public mozilla::dom::devicestorage::DeviceStorageRequestChildCallback
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
2013-03-17 03:20:39 -07:00
|
|
|
NS_FORWARD_NSIDOMDOMCURSOR(mozilla::dom::DOMCursor::)
|
2013-03-01 16:21:01 -08:00
|
|
|
|
2013-03-17 01:51:36 -07:00
|
|
|
// DOMCursor
|
|
|
|
virtual void Continue(mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
//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
|