2013-04-16 14:16:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-08-01 23:29:34 -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 DeviceStorage_h
|
|
|
|
#define DeviceStorage_h
|
|
|
|
|
|
|
|
#include "nsIDOMDeviceStorage.h"
|
|
|
|
#include "nsIFile.h"
|
2012-07-30 07:58:26 -07:00
|
|
|
#include "nsIPrincipal.h"
|
2012-08-01 23:32:04 -07:00
|
|
|
#include "nsIObserver.h"
|
2012-08-01 23:29:34 -07:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2013-01-09 07:03:28 -08:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-12-04 18:00:39 -08:00
|
|
|
class DeviceStorageFile MOZ_FINAL
|
|
|
|
: public nsISupports {
|
|
|
|
public:
|
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
|
|
nsString mPath;
|
|
|
|
nsString mStorageType;
|
|
|
|
bool mEditable;
|
|
|
|
|
|
|
|
DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFile, const nsAString& aPath);
|
|
|
|
DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFile);
|
|
|
|
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();
|
|
|
|
|
|
|
|
nsresult Remove();
|
|
|
|
nsresult Write(nsIInputStream* aInputStream);
|
|
|
|
nsresult Write(InfallibleTArray<uint8_t>& bits);
|
|
|
|
void CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, PRTime aSince = 0);
|
|
|
|
void collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, PRTime aSince, nsAString& aRootPath);
|
|
|
|
|
|
|
|
static void DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const nsAString& aStorageType);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void NormalizeFilePath();
|
|
|
|
void AppendRelativePath();
|
|
|
|
};
|
|
|
|
|
2013-02-12 13:16:58 -08:00
|
|
|
/*
|
|
|
|
The FileUpdateDispatcher converts file-watcher-notify
|
|
|
|
observer events to file-watcher-update events. This is
|
|
|
|
used to be able to broadcast events from one child to
|
|
|
|
another child in B2G. (f.e., if one child decides to add
|
|
|
|
a file, we want to be able to able to send a onchange
|
|
|
|
notifications to every other child watching that device
|
|
|
|
storage object).
|
|
|
|
|
|
|
|
We create this object (via GetSingleton) in two places:
|
|
|
|
* ContentParent::Init (for IPC)
|
|
|
|
* nsDOMDeviceStorage::Init (for non-ipc)
|
|
|
|
*/
|
2013-01-09 07:03:28 -08:00
|
|
|
class FileUpdateDispatcher MOZ_FINAL
|
|
|
|
: public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
static FileUpdateDispatcher* GetSingleton();
|
|
|
|
private:
|
|
|
|
static mozilla::StaticRefPtr<FileUpdateDispatcher> sSingleton;
|
|
|
|
};
|
|
|
|
|
2012-08-01 23:29:34 -07:00
|
|
|
class nsDOMDeviceStorage MOZ_FINAL
|
2013-02-07 02:19:08 -08:00
|
|
|
: public nsDOMEventTargetHelper
|
|
|
|
, public nsIDOMDeviceStorage
|
2012-08-01 23:32:04 -07:00
|
|
|
, public nsIObserver
|
2012-08-01 23:29:34 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-02-07 02:19:08 -08:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2012-08-01 23:29:34 -07:00
|
|
|
NS_DECL_NSIDOMDEVICESTORAGE
|
|
|
|
|
2012-08-01 23:32:04 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2012-08-01 23:29:34 -07:00
|
|
|
NS_DECL_NSIDOMEVENTTARGET
|
2013-04-16 14:16:08 -07:00
|
|
|
virtual void AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
|
|
|
|
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
|
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
|
2012-08-01 23:29:34 -07:00
|
|
|
|
|
|
|
nsDOMDeviceStorage();
|
|
|
|
|
2013-04-02 12:52:21 -07:00
|
|
|
nsresult Init(nsPIDOMWindow* aWindow, const nsAString &aType, const nsAString &aVolName);
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2013-04-02 12:52:21 -07:00
|
|
|
void SetRootDirectoryForType(const nsAString& aType, const nsAString &aVolName);
|
|
|
|
|
|
|
|
static void GetOrderedVolumeNames(const nsAString &aType,
|
|
|
|
nsTArray<nsString> &aVolumeNames);
|
2012-08-01 23:29:34 -07:00
|
|
|
|
|
|
|
static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
|
|
|
|
const nsAString &aType,
|
2013-04-02 12:52:21 -07:00
|
|
|
nsTArray<nsRefPtr<nsDOMDeviceStorage> > &aStores);
|
2012-08-01 23:29:34 -07:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsDOMDeviceStorage();
|
|
|
|
|
|
|
|
nsresult GetInternal(const JS::Value & aName,
|
|
|
|
JSContext* aCx,
|
|
|
|
nsIDOMDOMRequest** aRetval,
|
|
|
|
bool aEditable);
|
|
|
|
|
|
|
|
nsresult EnumerateInternal(const JS::Value & aName,
|
|
|
|
const JS::Value & aOptions,
|
|
|
|
JSContext* aCx,
|
2012-11-29 21:41:40 -08:00
|
|
|
uint8_t aArgc,
|
|
|
|
bool aEditable,
|
2013-03-01 16:21:01 -08:00
|
|
|
nsIDOMDOMCursor** aRetval);
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-08-30 15:17:37 -07:00
|
|
|
nsString mStorageType;
|
|
|
|
nsCOMPtr<nsIFile> mRootDirectory;
|
2013-04-02 12:52:21 -07:00
|
|
|
nsString mVolumeName;
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-08-17 19:43:00 -07:00
|
|
|
bool mIsWatchingFile;
|
2012-08-17 19:43:00 -07:00
|
|
|
bool mAllowedToWatchFile;
|
2012-08-17 19:43:00 -07:00
|
|
|
|
2012-08-30 15:17:37 -07:00
|
|
|
nsresult Notify(const char* aReason, class DeviceStorageFile* aFile);
|
2012-08-17 19:43:00 -07:00
|
|
|
|
2012-08-01 23:29:34 -07:00
|
|
|
friend class WatchFileEvent;
|
|
|
|
friend class DeviceStorageRequest;
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2012-08-14 08:53:44 -07:00
|
|
|
void DispatchMountChangeEvent(nsAString& aType);
|
2012-08-09 15:41:18 -07:00
|
|
|
#endif
|
|
|
|
|
2012-08-01 23:29:34 -07:00
|
|
|
// nsIDOMDeviceStorage.type
|
|
|
|
enum {
|
|
|
|
DEVICE_STORAGE_TYPE_DEFAULT = 0,
|
|
|
|
DEVICE_STORAGE_TYPE_SHARED,
|
2012-08-03 06:04:35 -07:00
|
|
|
DEVICE_STORAGE_TYPE_EXTERNAL
|
2012-08-01 23:29:34 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|