Merge m-c to inbound.

This commit is contained in:
Ryan VanderMeulen 2012-09-14 16:04:41 -04:00
commit 00963c882a
11 changed files with 337 additions and 155 deletions

View File

@ -202,15 +202,6 @@ public:
const nsAString& aDeviceAddress,
nsAString& aDevicePath) = 0;
virtual bool
AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServices,
nsTArray<uint32_t>& aServiceHandlesContainer) = 0;
virtual bool
RemoveReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServiceHandles) = 0;
virtual nsresult
CreatePairedDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aAddress,

View File

@ -170,25 +170,6 @@ BluetoothServiceChildProcess::GetDevicePath(const nsAString& aAdapterPath,
return NS_OK;
}
bool
BluetoothServiceChildProcess::AddReservedServicesInternal(
const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServices,
nsTArray<uint32_t>& aServiceHandlesContainer)
{
MOZ_NOT_REACHED("This function isn't used!");
return false;
}
bool
BluetoothServiceChildProcess::RemoveReservedServicesInternal(
const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServiceHandles)
{
MOZ_NOT_REACHED("This function isn't used!");
return false;
}
nsresult
BluetoothServiceChildProcess::CreatePairedDeviceInternal(
const nsAString& aAdapterPath,

View File

@ -72,17 +72,6 @@ public:
const nsAString& aDeviceAddress,
nsAString& aDevicePath) MOZ_OVERRIDE;
virtual bool
AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServices,
nsTArray<uint32_t>& aServiceHandlesContainer)
MOZ_OVERRIDE;
virtual bool
RemoveReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServiceHandles)
MOZ_OVERRIDE;
virtual nsresult
CreatePairedDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aAddress,

View File

@ -569,14 +569,9 @@ AddReservedServices(const nsAString& aAdapterPath)
uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HandsfreeAG >> 32));
uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HeadsetAG >> 32));
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
NS_WARNING("BluetoothService not available!");
return ;
}
sServiceHandles.Clear();
bs->AddReservedServicesInternal(aAdapterPath, uuids, sServiceHandles);
BluetoothDBusService::AddReservedServicesInternal(aAdapterPath, uuids,
sServiceHandles);
}
void
@ -1503,6 +1498,7 @@ ExtractHandles(DBusMessage *aReply, nsTArray<uint32_t>& aOutHandles)
}
}
// static
bool
BluetoothDBusService::AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServices,
@ -1530,6 +1526,7 @@ BluetoothDBusService::AddReservedServicesInternal(const nsAString& aAdapterPath,
return true;
}
// static
bool
BluetoothDBusService::RemoveReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServiceHandles)

View File

@ -47,12 +47,12 @@ public:
const nsAString& aDeviceAddress,
nsAString& aDevicePath);
virtual bool
static bool
AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServices,
nsTArray<uint32_t>& aServiceHandlesContainer);
virtual bool
static bool
RemoveReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServiceHandles);

View File

@ -50,9 +50,6 @@ private:
bool aEditable,
nsIDOMDeviceStorageCursor** aRetval);
static bool IsMimeTypeCorrectForStorageType(nsAString& aType,
nsIDOMBlob* aBlob);
nsString mStorageType;
nsCOMPtr<nsIFile> mRootDirectory;

View File

@ -313,13 +313,13 @@ DeviceStorageRequestParent::StatFileEvent::CancelableRun()
nsCOMPtr<nsIRunnable> r;
uint64_t diskUsage = 0;
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage);
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage, mFile->mStorageType);
int64_t freeSpace = 0;
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
if (NS_FAILED(rv)) {
freeSpace = 0;
}
r = new PostStatResultEvent(mParent, freeSpace, diskUsage);
NS_DispatchToMainThread(r);
return NS_OK;

View File

@ -8,9 +8,11 @@
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/PContentPermissionRequestChild.h"
#include "mozilla/ClearOnShutdown.h"
#include "nsDeviceStorage.h"
#include "nsAutoPtr.h"
#include "nsDOMEvent.h"
#include "nsServiceManagerUtils.h"
#include "nsIFile.h"
@ -50,12 +52,134 @@
#endif
#define DEVICESTORAGE_PROPERTIES "chrome://global/content/devicestorage.properties"
#define DEVICESTORAGE_PICTURES "pictures"
#define DEVICESTORAGE_VIDEOS "videos"
#define DEVICESTORAGE_MUSIC "music"
using namespace mozilla::dom;
using namespace mozilla::dom::devicestorage;
#include "nsDirectoryServiceDefs.h"
nsAutoPtr<DeviceStorageTypeChecker> DeviceStorageTypeChecker::sDeviceStorageTypeChecker;
DeviceStorageTypeChecker::DeviceStorageTypeChecker()
{
}
DeviceStorageTypeChecker::~DeviceStorageTypeChecker()
{
}
DeviceStorageTypeChecker*
DeviceStorageTypeChecker::CreateOrGet()
{
if (sDeviceStorageTypeChecker) {
return sDeviceStorageTypeChecker;
}
NS_ASSERTION(NS_IsMainThread(), "This can only be created on the main thread!");
nsCOMPtr<nsIStringBundleService> stringService = mozilla::services::GetStringBundleService();
if (!stringService) {
return nullptr;
}
nsCOMPtr<nsIStringBundle> filterBundle;
if (NS_FAILED(stringService->CreateBundle(DEVICESTORAGE_PROPERTIES, getter_AddRefs(filterBundle)))) {
return nullptr;
}
DeviceStorageTypeChecker* result = new DeviceStorageTypeChecker();
result->InitFromBundle(filterBundle);
sDeviceStorageTypeChecker = result;
ClearOnShutdown(&sDeviceStorageTypeChecker);
return result;
}
void
DeviceStorageTypeChecker::InitFromBundle(nsIStringBundle* aBundle)
{
aBundle->GetStringFromName(NS_ConvertASCIItoUTF16(DEVICESTORAGE_PICTURES).get(), getter_Copies(mPicturesExtensions));
aBundle->GetStringFromName(NS_ConvertASCIItoUTF16(DEVICESTORAGE_MUSIC).get(), getter_Copies(mMusicExtensions));
aBundle->GetStringFromName(NS_ConvertASCIItoUTF16(DEVICESTORAGE_VIDEOS).get(), getter_Copies(mVideosExtensions));
}
bool
DeviceStorageTypeChecker::Check(const nsAString& aType, nsIDOMBlob* aBlob)
{
NS_ASSERTION(aBlob, "Calling Check without a blob");
nsString mimeType;
if (NS_FAILED(aBlob->GetType(mimeType))) {
return false;
}
if (aType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
return StringBeginsWith(mimeType, NS_LITERAL_STRING("image/"));
}
if (aType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
return StringBeginsWith(mimeType, NS_LITERAL_STRING("video/"));
}
if (aType.EqualsLiteral(DEVICESTORAGE_MUSIC)) {
return StringBeginsWith(mimeType, NS_LITERAL_STRING("audio/"));
}
return false;
}
bool
DeviceStorageTypeChecker::Check(const nsAString& aType, nsIFile* aFile)
{
NS_ASSERTION(aFile, "Calling Check without a file");
nsString path;
aFile->GetPath(path);
int32_t dotIdx = path.RFindChar(PRUnichar('.'));
if (dotIdx == kNotFound) {
return false;
}
nsAutoString extensionMatch;
extensionMatch.AssignLiteral("*");
extensionMatch.Append(Substring(path, dotIdx));
extensionMatch.AppendLiteral(";");
if (aType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
return FindInReadable(extensionMatch, mPicturesExtensions);
}
if (aType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
return FindInReadable(extensionMatch, mVideosExtensions);
}
if (aType.EqualsLiteral(DEVICESTORAGE_MUSIC)) {
return FindInReadable(extensionMatch, mMusicExtensions);
}
return false;
}
nsresult
DeviceStorageTypeChecker::GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult)
{
if (!aType.EqualsLiteral(DEVICESTORAGE_PICTURES) &&
!aType.EqualsLiteral(DEVICESTORAGE_VIDEOS) &&
!aType.EqualsLiteral(DEVICESTORAGE_MUSIC)) {
// unknown type
return NS_ERROR_FAILURE;
}
aPermissionResult.AssignLiteral("device-storage:");
aPermissionResult.Append(NS_ConvertUTF16toUTF8(aType));
return NS_OK;
}
class IOEventComplete : public nsRunnable
{
public:
@ -83,8 +207,8 @@ private:
};
DeviceStorageFile::DeviceStorageFile(const nsAString& aStorageType,
nsIFile* aFile,
const nsAString& aPath)
nsIFile* aFile,
const nsAString& aPath)
: mPath(aPath)
, mStorageType(aStorageType)
, mEditable(false)
@ -96,6 +220,9 @@ DeviceStorageFile::DeviceStorageFile(const nsAString& aStorageType,
AppendRelativePath();
NormalizeFilePath();
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
NS_ASSERTION(typeChecker, "DeviceStorageTypeChecker is null");
}
DeviceStorageFile::DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFile)
@ -106,6 +233,9 @@ DeviceStorageFile::DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFi
// always take a clone
nsCOMPtr<nsIFile> file;
aFile->Clone(getter_AddRefs(mFile));
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
NS_ASSERTION(typeChecker, "DeviceStorageTypeChecker is null");
}
void
@ -150,45 +280,6 @@ DeviceStorageFile::IsSafePath()
return true;
}
bool
DeviceStorageFile::IsType(nsAString& aType)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
// String bundles are cached by the bundle service.
nsCOMPtr<nsIStringBundleService> stringService = mozilla::services::GetStringBundleService();
if (!stringService) {
return false;
}
nsCOMPtr<nsIStringBundle> filterBundle;
if (NS_FAILED(stringService->CreateBundle(DEVICESTORAGE_PROPERTIES,
getter_AddRefs(filterBundle)))) {
return false;
}
nsString path;
mFile->GetPath(path);
int32_t dotIdx = path.RFindChar(PRUnichar('.'));
if (dotIdx == kNotFound) {
return false;
}
nsAutoString extensionMatch;
extensionMatch.AssignASCII("*");
extensionMatch.Append(Substring(path, dotIdx));
extensionMatch.AppendASCII(";");
nsString extensionListStr;
if (NS_FAILED(filterBundle->GetStringFromName(aType.BeginReading(),
getter_Copies(extensionListStr)))) {
return false;
}
return FindInReadable(extensionMatch, extensionListStr);
}
void
DeviceStorageFile::NormalizeFilePath() {
#if defined(XP_WIN)
@ -260,8 +351,8 @@ DeviceStorageFile::Write(nsIInputStream* aInputStream)
while (bufSize) {
uint32_t wrote;
rv = bufferedOutputStream->WriteFrom(aInputStream,
static_cast<uint32_t>(NS_MIN<uint64_t>(bufSize, PR_UINT32_MAX)),
&wrote);
static_cast<uint32_t>(NS_MIN<uint64_t>(bufSize, PR_UINT32_MAX)),
&wrote);
if (NS_FAILED(rv)) {
break;
}
@ -405,7 +496,7 @@ DeviceStorageFile::collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &
}
void
DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar)
DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const nsAString& aStorageType)
{
if (!aFile) {
return;
@ -422,6 +513,11 @@ DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar)
nsCOMPtr<nsIDirectoryEnumerator> files = do_QueryInterface(e);
NS_ASSERTION(files, "GetDirectoryEntries must return a nsIDirectoryEnumerator");
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
if (!typeChecker) {
return;
}
nsCOMPtr<nsIFile> f;
while (NS_SUCCEEDED(files->GetNextFile(getter_AddRefs(f))) && f) {
bool isDir;
@ -441,16 +537,22 @@ DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar)
if (NS_FAILED(rv)) {
continue;
}
if (isLink) {
// for now, lets just totally ignore symlinks.
NS_WARNING("DirectoryDiskUsage ignores symlinks");
} else if (isDir) {
DirectoryDiskUsage(f, aSoFar);
DirectoryDiskUsage(f, aSoFar, aStorageType);
} else if (isFile) {
if (!typeChecker->Check(aStorageType, f)) {
continue;
}
int64_t size;
rv = f->GetFileSize(&size);
if (NS_SUCCEEDED(rv)) {
*aSoFar += size;
*aSoFar += size;
}
}
}
@ -478,11 +580,11 @@ GetSDCardStatus(nsAString& aState) {
}
if (state == nsIVolume::STATE_MOUNTED) {
aState.AssignASCII("available");
aState.AssignLiteral("available");
} else if (state == nsIVolume::STATE_SHARED || state == nsIVolume::STATE_SHAREDMNT) {
aState.AssignASCII("shared");
aState.AssignLiteral("shared");
} else {
aState.AssignASCII("unavailable");
aState.AssignLiteral("unavailable");
}
return NS_OK;
}
@ -776,10 +878,15 @@ ContinueCursorEvent::Run() {
nsString cursorStorageType;
cursor->GetStorageType(cursorStorageType);
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
if (!typeChecker) {
return NS_ERROR_FAILURE;
}
while (cursor->mFiles.Length() > 0) {
nsRefPtr<DeviceStorageFile> file = cursor->mFiles[0];
cursor->mFiles.RemoveElementAt(0);
if (!file->IsType(cursorStorageType)) {
if (!typeChecker->Check(cursorStorageType, file->mFile)) {
continue;
}
val = nsIFileToJsval(cursor->GetOwner(), file);
@ -869,8 +976,7 @@ nsDOMDeviceStorageCursor::GetStorageType(nsAString & aType)
NS_IMETHODIMP
nsDOMDeviceStorageCursor::GetType(nsACString & aType)
{
aType = "device-storage";
return NS_OK;
return DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, aType);
}
NS_IMETHODIMP
@ -1008,8 +1114,8 @@ public:
nsRefPtr<nsIDOMDeviceStorageStat> domstat = new nsDOMDeviceStorageStat(mFreeBytes, mTotalBytes, state);
jsval result = InterfaceToJsval(mRequest->GetOwner(),
domstat,
&NS_GET_IID(nsIDOMDeviceStorageStat));
domstat,
&NS_GET_IID(nsIDOMDeviceStorageStat));
mRequest->FireSuccess(result);
mRequest = nullptr;
@ -1193,7 +1299,7 @@ public:
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
nsCOMPtr<nsIRunnable> r;
uint64_t diskUsage = 0;
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage);
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage, mFile->mStorageType);
int64_t freeSpace = 0;
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
if (NS_FAILED(rv)) {
@ -1276,7 +1382,11 @@ public:
// Corresponding release occurs in DeallocPContentPermissionRequest.
AddRef();
nsCString type = NS_LITERAL_CSTRING("device-storage");
nsCString type;
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, type);
if (NS_FAILED(rv)) {
return rv;
}
child->SendPContentPermissionRequestConstructor(this, type, IPC::Principal(mPrincipal));
Sendprompt();
@ -1292,7 +1402,11 @@ public:
NS_IMETHOD GetType(nsACString & aType)
{
aType = "device-storage";
nsCString type;
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, aType);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
@ -1348,16 +1462,16 @@ public:
if (XRE_GetProcessType() != GeckoProcessType_Default) {
BlobChild* actor = ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlob);
if (!actor) {
return NS_ERROR_FAILURE;
}
BlobChild* actor = ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlob);
if (!actor) {
return NS_ERROR_FAILURE;
}
DeviceStorageAddParams params;
params.blobChild() = actor;
params.type() = mFile->mStorageType;
params.name() = mFile->mPath;
params.fullpath() = fullpath;
params.blobChild() = actor;
params.type() = mFile->mStorageType;
params.name() = mFile->mPath;
params.fullpath() = fullpath;
PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile);
ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params);
@ -1398,7 +1512,7 @@ public:
PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile);
DeviceStorageStatParams params(mFile->mStorageType, fullpath);
ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params);
return NS_OK;
return NS_OK;
}
r = new StatFileEvent(mFile, mRequest);
break;
@ -1406,8 +1520,8 @@ public:
case DEVICE_STORAGE_REQUEST_WATCH:
{
mDeviceStorage->mAllowedToWatchFile = true;
return NS_OK;
mDeviceStorage->mAllowedToWatchFile = true;
return NS_OK;
}
}
@ -1548,31 +1662,6 @@ nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
}
}
bool
nsDOMDeviceStorage::IsMimeTypeCorrectForStorageType(nsAString& aType, nsIDOMBlob* aBlob)
{
NS_ASSERTION(aBlob, "Calling IsMimeTypeCorrectForStorageType without a blob");
nsString mimeType;
if (NS_FAILED(aBlob->GetType(mimeType))) {
return false;
}
if (aType.Equals(NS_LITERAL_STRING("pictures"))) {
return StringBeginsWith(mimeType, NS_LITERAL_STRING("image/"));
}
if (aType.Equals(NS_LITERAL_STRING("videos"))) {
return StringBeginsWith(mimeType, NS_LITERAL_STRING("video/"));
}
if (aType.Equals(NS_LITERAL_STRING("music"))) {
return StringBeginsWith(mimeType, NS_LITERAL_STRING("audio/"));
}
return false;
}
NS_IMETHODIMP
nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval)
{
@ -1623,13 +1712,19 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
return NS_ERROR_UNEXPECTED;
}
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
if (!typeChecker) {
return NS_ERROR_FAILURE;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*_retval = request);
nsCOMPtr<nsIRunnable> r;
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, aPath);
if (!dsf->IsType(mStorageType) || !IsMimeTypeCorrectForStorageType(mStorageType, aBlob)) {
if (!typeChecker->Check(mStorageType, dsf->mFile) ||
!typeChecker->Check(mStorageType, aBlob)) {
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE, dsf);
}
else if (!dsf->IsSafePath()) {
@ -1637,7 +1732,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
}
else {
r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_WRITE,
win, mPrincipal, dsf, request, aBlob);
win, mPrincipal, dsf, request, aBlob);
}
NS_DispatchToMainThread(r);
@ -1747,10 +1842,10 @@ nsDOMDeviceStorage::Stat(nsIDOMDOMRequest** aRetval)
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory);
nsCOMPtr<nsIRunnable> r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_STAT,
win,
mPrincipal,
dsf,
request);
win,
mPrincipal,
dsf,
request);
NS_DispatchToMainThread(r);
return NS_OK;
}
@ -1854,7 +1949,11 @@ nsDOMDeviceStorage::EnumerateInternal(const JS::Value & aName,
// Corresponding release occurs in DeallocPContentPermissionRequest.
r->AddRef();
nsCString type = NS_LITERAL_CSTRING("device-storage");
nsCString type;
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(mStorageType, type);
if (NS_FAILED(rv)) {
return rv;
}
child->SendPContentPermissionRequestConstructor(r, type, IPC::Principal(mPrincipal));
r->Sendprompt();

View File

@ -25,6 +25,7 @@ class nsPIDOMWindow;
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsIObserver.h"
#include "nsIStringBundle.h"
#include "mozilla/Mutex.h"
#include "prtime.h"
#include "DeviceStorage.h"
@ -41,6 +42,29 @@ class nsPIDOMWindow;
using namespace mozilla::dom;
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);
static nsresult GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult);
private:
nsString mPicturesExtensions;
nsString mVideosExtensions;
nsString mMusicExtensions;
static nsAutoPtr<DeviceStorageTypeChecker> sDeviceStorageTypeChecker;
};
class DeviceStorageFile MOZ_FINAL
: public nsISupports {
public:
@ -59,7 +83,6 @@ public:
// 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();
bool IsType(nsAString& aType);
nsresult Remove();
nsresult Write(nsIInputStream* aInputStream);
@ -67,7 +90,7 @@ public:
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);
static void DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const nsAString& aStorageType);
private:
void NormalizeFilePath();

View File

@ -13,6 +13,10 @@ include $(DEPTH)/config/autoconf.mk
# man, our mime database sucks hard. followup bug # 788273
# test_add.html \
# Possible race between the time we write a file, and the
# time it takes to be reflected by statfs(). Bug # 791287
# test_diskSpace.html \
MOCHITEST_FILES = \
test_sanity.html \
test_addCorrectType.html \

View File

@ -0,0 +1,101 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html> <!--
https://bugzilla.mozilla.org/show_bug.cgi?id=717103
-->
<head>
<title>Test for the device storage API </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="devicestorage_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
devicestorage_setup();
var freeBytes = -1;
var stats = 0;
function stat(s, file_list_length) {
if (freeBytes == -1) {
freeBytes = s.target.result.freeBytes;
}
ok(freeBytes == s.target.result.freeBytes, "Free bytes should be the same");
ok(file_list_length * 1024 == s.target.result.totalBytes, "space taken up by files should match")
stats = stats + 1;
if (stats == 2) {
devicestorage_cleanup();
}
}
function addSuccess(e) {
added = added - 1;
if (added == 0) {
request = pictures.stat();
request.onsuccess = function(s) {stat(s, picture_files.length)};
request = videos.stat();
request.onsuccess = function(s) {stat(s, video_files.length)};
request = music.stat();
request.onsuccess = function(s) {stat(s, music_files.length)};
}
}
function addError(e) {
ok(false, "addError was called : " + e.target.error.name);
devicestorage_cleanup();
}
ok(true, "hi");
var pictures = navigator.getDeviceStorage("pictures");
var picture_files = [ "a.png", "b.png", "c.png", "d.png", "e.png" ];
var videos = navigator.getDeviceStorage("videos");
var video_files = [ "a.ogv", "b.ogv" ];
var music = navigator.getDeviceStorage("music");
var music_files = [ "a.mp3", "b.mp3", "c.mp3" ];
var added = picture_files.length + video_files.length + music_files.length;
for (var i=0; i < picture_files.length; i++) {
request = pictures.addNamed(createRandomBlob('image/png'), picture_files[i]);
request.onsuccess = addSuccess;
request.onerror = addError;
}
for (var i=0; i < video_files.length; i++) {
request = videos.addNamed(createRandomBlob('video/ogv'), video_files[i]);
request.onsuccess = addSuccess;
request.onerror = addError;
}
for (var i=0; i < music_files.length; i++) {
request = music.addNamed(createRandomBlob('audio/mp3'), music_files[i]);
request.onsuccess = addSuccess;
request.onerror = addError;
}
</script>
</pre>
</body>
</html>