mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-15 06:20:41 +00:00
Backed out changeset 0284deae33b1 (bug 910498) for Windows Build Bustage on a CLOSED TREE
This commit is contained in:
parent
f88f15a62e
commit
72a28786c1
@ -14,8 +14,7 @@
|
||||
#include "nsDOMEventTargetHelper.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/dom/DOMRequest.h"
|
||||
#include "mozilla/ipc/FileDescriptor.h"
|
||||
#include "DOMRequest.h"
|
||||
|
||||
#define DEVICESTORAGE_PICTURES "pictures"
|
||||
#define DEVICESTORAGE_VIDEOS "videos"
|
||||
@ -24,7 +23,6 @@
|
||||
#define DEVICESTORAGE_SDCARD "sdcard"
|
||||
#define DEVICESTORAGE_CRASHES "crashes"
|
||||
|
||||
class DeviceStorageFile;
|
||||
class nsIInputStream;
|
||||
|
||||
namespace mozilla {
|
||||
@ -35,14 +33,6 @@ class DOMRequest;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
class DeviceStorageFileDescriptor MOZ_FINAL
|
||||
: public mozilla::RefCounted<DeviceStorageFileDescriptor>
|
||||
{
|
||||
public:
|
||||
nsRefPtr<DeviceStorageFile> mDSFile;
|
||||
mozilla::ipc::FileDescriptor mFileDescriptor;
|
||||
};
|
||||
|
||||
class DeviceStorageFile MOZ_FINAL
|
||||
: public nsISupports {
|
||||
public:
|
||||
@ -112,7 +102,6 @@ public:
|
||||
|
||||
nsresult CalculateSizeAndModifiedDate();
|
||||
nsresult CalculateMimeType();
|
||||
nsresult CreateFileDescriptor(mozilla::ipc::FileDescriptor& aFileDescriptor);
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
@ -20,27 +20,11 @@ DeviceStorageRequestChild::DeviceStorageRequestChild()
|
||||
}
|
||||
|
||||
DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest,
|
||||
DeviceStorageFile* aDSFile)
|
||||
DeviceStorageFile* aFile)
|
||||
: mRequest(aRequest)
|
||||
, mDSFile(aDSFile)
|
||||
, mFile(aFile)
|
||||
, mCallback(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(aRequest);
|
||||
MOZ_ASSERT(aDSFile);
|
||||
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
|
||||
}
|
||||
|
||||
DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest,
|
||||
DeviceStorageFile* aDSFile,
|
||||
DeviceStorageFileDescriptor* aDSFileDescriptor)
|
||||
: mRequest(aRequest)
|
||||
, mDSFile(aDSFile)
|
||||
, mDSFileDescriptor(aDSFileDescriptor)
|
||||
, mCallback(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(aRequest);
|
||||
MOZ_ASSERT(aDSFile);
|
||||
MOZ_ASSERT(aDSFileDescriptor);
|
||||
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
|
||||
}
|
||||
|
||||
@ -69,7 +53,7 @@ DeviceStorageRequestChild::
|
||||
case DeviceStorageResponseValue::TSuccessResponse:
|
||||
{
|
||||
nsString fullPath;
|
||||
mDSFile->GetFullPath(fullPath);
|
||||
mFile->GetFullPath(fullPath);
|
||||
AutoJSContext cx;
|
||||
JS::Rooted<JS::Value> result(cx,
|
||||
StringToJsval(mRequest->GetOwner(), fullPath));
|
||||
@ -77,22 +61,6 @@ DeviceStorageRequestChild::
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageResponseValue::TFileDescriptorResponse:
|
||||
{
|
||||
FileDescriptorResponse r = aValue;
|
||||
|
||||
nsString fullPath;
|
||||
mDSFile->GetFullPath(fullPath);
|
||||
AutoJSContext cx;
|
||||
JS::Rooted<JS::Value> result(cx,
|
||||
StringToJsval(mRequest->GetOwner(), fullPath));
|
||||
|
||||
mDSFileDescriptor->mDSFile = mDSFile;
|
||||
mDSFileDescriptor->mFileDescriptor = r.fileDescriptor();
|
||||
mRequest->FireSuccess(result);
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageResponseValue::TBlobResponse:
|
||||
{
|
||||
BlobResponse r = aValue;
|
||||
|
@ -7,15 +7,12 @@
|
||||
#define mozilla_dom_devicestorage_DeviceStorageRequestChild_h
|
||||
|
||||
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
|
||||
#include "DOMRequest.h"
|
||||
|
||||
class DeviceStorageFile;
|
||||
class DeviceStorageFileDescriptor;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class DOMRequest;
|
||||
|
||||
namespace devicestorage {
|
||||
|
||||
class DeviceStorageRequestChildCallback
|
||||
@ -29,8 +26,6 @@ class DeviceStorageRequestChild : public PDeviceStorageRequestChild
|
||||
public:
|
||||
DeviceStorageRequestChild();
|
||||
DeviceStorageRequestChild(DOMRequest* aRequest, DeviceStorageFile* aFile);
|
||||
DeviceStorageRequestChild(DOMRequest* aRequest, DeviceStorageFile* aFile,
|
||||
DeviceStorageFileDescriptor* aFileDescrptor);
|
||||
~DeviceStorageRequestChild();
|
||||
|
||||
void SetCallback(class DeviceStorageRequestChildCallback *aCallback);
|
||||
@ -39,8 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
nsRefPtr<DeviceStorageFile> mDSFile;
|
||||
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
|
||||
DeviceStorageRequestChildCallback* mCallback;
|
||||
};
|
||||
|
@ -35,8 +35,6 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(
|
||||
void
|
||||
DeviceStorageRequestParent::Dispatch()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
switch (mParams.type()) {
|
||||
case DeviceStorageParams::TDeviceStorageAddParams:
|
||||
{
|
||||
@ -60,22 +58,6 @@ DeviceStorageRequestParent::Dispatch()
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageParams::TDeviceStorageCreateFdParams:
|
||||
{
|
||||
DeviceStorageCreateFdParams p = mParams;
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf =
|
||||
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
||||
|
||||
nsRefPtr<CancelableRunnable> r = new CreateFdEvent(this, dsf);
|
||||
|
||||
nsCOMPtr<nsIEventTarget> target
|
||||
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
||||
NS_ASSERTION(target, "Must have stream transport service");
|
||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageParams::TDeviceStorageGetParams:
|
||||
{
|
||||
DeviceStorageGetParams p = mParams;
|
||||
@ -145,8 +127,7 @@ DeviceStorageRequestParent::Dispatch()
|
||||
new DeviceStorageFile(p.type(), p.storageName());
|
||||
nsRefPtr<PostAvailableResultEvent> r
|
||||
= new PostAvailableResultEvent(this, dsf);
|
||||
rv = NS_DispatchToMainThread(r);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
NS_DispatchToMainThread(r);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -158,8 +139,7 @@ DeviceStorageRequestParent::Dispatch()
|
||||
new DeviceStorageFile(p.type(), p.storageName());
|
||||
nsRefPtr<PostFormatResultEvent> r
|
||||
= new PostFormatResultEvent(this, dsf);
|
||||
rv = NS_DispatchToMainThread(r);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
NS_DispatchToMainThread(r);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -207,14 +187,6 @@ DeviceStorageRequestParent::EnsureRequiredPermissions(
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageParams::TDeviceStorageCreateFdParams:
|
||||
{
|
||||
DeviceStorageCreateFdParams p = mParams;
|
||||
type = p.type();
|
||||
requestType = DEVICE_STORAGE_REQUEST_CREATEFD;
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageParams::TDeviceStorageGetParams:
|
||||
{
|
||||
DeviceStorageGetParams p = mParams;
|
||||
@ -472,46 +444,6 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::CreateFdEvent::
|
||||
CreateFdEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile)
|
||||
: CancelableRunnable(aParent)
|
||||
, mFile(aFile)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::CreateFdEvent::~CreateFdEvent()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeviceStorageRequestParent::CreateFdEvent::CancelableRun()
|
||||
{
|
||||
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsRefPtr<nsRunnable> r;
|
||||
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (check) {
|
||||
nsCOMPtr<PostErrorEvent> event
|
||||
= new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
|
||||
return NS_DispatchToMainThread(event);
|
||||
}
|
||||
|
||||
FileDescriptor fileDescriptor;
|
||||
nsresult rv = mFile->CreateFileDescriptor(fileDescriptor);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
}
|
||||
else {
|
||||
r = new PostFileDescriptorResultEvent(mParent, fileDescriptor);
|
||||
}
|
||||
|
||||
return NS_DispatchToMainThread(r);
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::WriteFileEvent::
|
||||
WriteFileEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile,
|
||||
@ -535,7 +467,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
||||
|
||||
if (!mInputStream) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool check = false;
|
||||
@ -543,7 +476,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
||||
if (check) {
|
||||
nsCOMPtr<PostErrorEvent> event
|
||||
= new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = mFile->Write(mInputStream);
|
||||
@ -555,9 +489,11 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
||||
r = new PostPathResultEvent(mParent, mFile->mPath);
|
||||
}
|
||||
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
DeviceStorageRequestParent::DeleteFileEvent::
|
||||
DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
|
||||
: CancelableRunnable(aParent)
|
||||
@ -587,7 +523,8 @@ DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
|
||||
r = new PostPathResultEvent(mParent, mFile->mPath);
|
||||
}
|
||||
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::FreeSpaceFileEvent::
|
||||
@ -614,7 +551,8 @@ DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun()
|
||||
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
r = new PostFreeSpaceResultEvent(mParent, static_cast<uint64_t>(freeSpace));
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::UsedSpaceFileEvent::
|
||||
@ -650,7 +588,8 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
|
||||
} else {
|
||||
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, totalUsage);
|
||||
}
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::ReadFileEvent::
|
||||
@ -683,26 +622,30 @@ DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
|
||||
|
||||
if (!check) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int64_t fileSize;
|
||||
nsresult rv = mFile->mFile->GetFileSize(&fileSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRTime modDate;
|
||||
rv = mFile->mFile->GetLastModifiedTime(&modDate);
|
||||
if (NS_FAILED(rv)) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
r = new PostBlobSuccessEvent(mParent, mFile, static_cast<uint64_t>(fileSize),
|
||||
mMimeType, modDate);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::EnumerateFileEvent::
|
||||
@ -730,7 +673,8 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
|
||||
mFile->mFile->Exists(&check);
|
||||
if (!check) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -747,7 +691,8 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
|
||||
|
||||
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType,
|
||||
mFile->mRootDir, values);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -773,29 +718,6 @@ DeviceStorageRequestParent::PostPathResultEvent::CancelableRun()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostFileDescriptorResultEvent::
|
||||
PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent,
|
||||
const FileDescriptor& aFileDescriptor)
|
||||
: CancelableRunnable(aParent)
|
||||
, mFileDescriptor(aFileDescriptor)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostFileDescriptorResultEvent::
|
||||
~PostFileDescriptorResultEvent()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeviceStorageRequestParent::PostFileDescriptorResultEvent::CancelableRun()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
FileDescriptorResponse response(mFileDescriptor);
|
||||
unused << mParent->Send__delete__(mParent, response);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostAvailableResultEvent::
|
||||
PostAvailableResultEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile)
|
||||
|
@ -119,16 +119,6 @@ private:
|
||||
InfallibleTArray<DeviceStorageFileValue> mPaths;
|
||||
};
|
||||
|
||||
class CreateFdEvent : public CancelableRunnable
|
||||
{
|
||||
public:
|
||||
CreateFdEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
||||
virtual ~CreateFdEvent();
|
||||
virtual nsresult CancelableRun();
|
||||
private:
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
};
|
||||
|
||||
class WriteFileEvent : public CancelableRunnable
|
||||
{
|
||||
public:
|
||||
@ -203,18 +193,6 @@ private:
|
||||
nsString mPath;
|
||||
};
|
||||
|
||||
class PostFileDescriptorResultEvent : public CancelableRunnable
|
||||
{
|
||||
public:
|
||||
PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent,
|
||||
const FileDescriptor& aFileDescriptor);
|
||||
virtual ~PostFileDescriptorResultEvent();
|
||||
virtual nsresult CancelableRun();
|
||||
private:
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
FileDescriptor mFileDescriptor;
|
||||
};
|
||||
|
||||
class PostFreeSpaceResultEvent : public CancelableRunnable
|
||||
{
|
||||
public:
|
||||
|
@ -20,11 +20,6 @@ struct SuccessResponse
|
||||
{
|
||||
};
|
||||
|
||||
struct FileDescriptorResponse
|
||||
{
|
||||
FileDescriptor fileDescriptor;
|
||||
};
|
||||
|
||||
struct BlobResponse
|
||||
{
|
||||
PBlob blob;
|
||||
@ -67,7 +62,6 @@ union DeviceStorageResponseValue
|
||||
{
|
||||
ErrorResponse;
|
||||
SuccessResponse;
|
||||
FileDescriptorResponse;
|
||||
BlobResponse;
|
||||
EnumerationResponse;
|
||||
FreeSpaceStorageResponse;
|
||||
|
@ -49,7 +49,6 @@
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIDocument.h"
|
||||
#include <algorithm>
|
||||
#include "private/pprio.h"
|
||||
|
||||
#include "mozilla/dom/DeviceStorageBinding.h"
|
||||
|
||||
@ -68,7 +67,6 @@
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::devicestorage;
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
|
||||
@ -396,7 +394,6 @@ DeviceStorageTypeChecker::GetAccessForRequest(
|
||||
aAccessResult.AssignLiteral("write");
|
||||
break;
|
||||
case DEVICE_STORAGE_REQUEST_CREATE:
|
||||
case DEVICE_STORAGE_REQUEST_CREATEFD:
|
||||
aAccessResult.AssignLiteral("create");
|
||||
break;
|
||||
default:
|
||||
@ -926,20 +923,6 @@ DeviceStorageFile::AppendRelativePath(const nsAString& aPath) {
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeviceStorageFile::CreateFileDescriptor(FileDescriptor& aFileDescriptor)
|
||||
{
|
||||
PRFileDesc* fd;
|
||||
nsresult rv = mFile->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE,
|
||||
0660, &fd);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aFileDescriptor =
|
||||
FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(fd));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeviceStorageFile::Write(nsIInputStream* aInputStream)
|
||||
{
|
||||
@ -948,15 +931,12 @@ DeviceStorageFile::Write(nsIInputStream* aInputStream)
|
||||
}
|
||||
|
||||
nsresult rv = mFile->Create(nsIFile::NORMAL_FILE_TYPE, 00600);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<IOEventComplete> iocomplete = new IOEventComplete(this, "created");
|
||||
rv = NS_DispatchToMainThread(iocomplete);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
NS_DispatchToMainThread(iocomplete);
|
||||
|
||||
uint64_t bufSize = 0;
|
||||
aInputStream->Available(&bufSize);
|
||||
@ -987,14 +967,11 @@ DeviceStorageFile::Write(nsIInputStream* aInputStream)
|
||||
}
|
||||
|
||||
iocomplete = new IOEventComplete(this, "modified");
|
||||
rv = NS_DispatchToMainThread(iocomplete);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
NS_DispatchToMainThread(iocomplete);
|
||||
|
||||
bufferedOutputStream->Close();
|
||||
outputStream->Close();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
@ -1008,15 +985,12 @@ DeviceStorageFile::Write(InfallibleTArray<uint8_t>& aBits)
|
||||
}
|
||||
|
||||
nsresult rv = mFile->Create(nsIFile::NORMAL_FILE_TYPE, 00600);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<IOEventComplete> iocomplete = new IOEventComplete(this, "created");
|
||||
rv = NS_DispatchToMainThread(iocomplete);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
NS_DispatchToMainThread(iocomplete);
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outputStream;
|
||||
NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), mFile);
|
||||
@ -1030,10 +1004,7 @@ DeviceStorageFile::Write(InfallibleTArray<uint8_t>& aBits)
|
||||
outputStream->Close();
|
||||
|
||||
iocomplete = new IOEventComplete(this, "modified");
|
||||
rv = NS_DispatchToMainThread(iocomplete);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
NS_DispatchToMainThread(iocomplete);
|
||||
|
||||
if (aBits.Length() != wrote) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -1061,12 +1032,13 @@ DeviceStorageFile::Remove()
|
||||
}
|
||||
|
||||
rv = mFile->Remove(true);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<IOEventComplete> iocomplete = new IOEventComplete(this, "deleted");
|
||||
return NS_DispatchToMainThread(iocomplete);
|
||||
NS_DispatchToMainThread(iocomplete);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -1144,7 +1116,7 @@ DeviceStorageFile::collectFilesInternal(
|
||||
|
||||
if (msecs < aSince) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bool isDir;
|
||||
f->IsDirectory(&isDir);
|
||||
@ -1647,11 +1619,8 @@ ContinueCursorEvent::~ContinueCursorEvent() {}
|
||||
void
|
||||
ContinueCursorEvent::Continue()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
rv = NS_DispatchToMainThread(this);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
NS_DispatchToMainThread(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1659,8 +1628,7 @@ ContinueCursorEvent::Continue()
|
||||
|
||||
if (!file) {
|
||||
// done with enumeration.
|
||||
rv = NS_DispatchToMainThread(this);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
NS_DispatchToMainThread(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1723,7 +1691,8 @@ public:
|
||||
nsCOMPtr<PostErrorEvent> event =
|
||||
new PostErrorEvent(mRequest.forget(),
|
||||
POST_ERROR_EVENT_FILE_NOT_ENUMERABLE);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1813,7 +1782,8 @@ nsDOMDeviceStorageCursor::Cancel()
|
||||
{
|
||||
nsCOMPtr<PostErrorEvent> event
|
||||
= new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -1822,7 +1792,8 @@ nsDOMDeviceStorageCursor::Allow()
|
||||
if (!mFile->IsSafePath()) {
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
@ -1899,7 +1870,6 @@ public:
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
|
||||
~PostAvailableResultEvent() {}
|
||||
@ -1933,7 +1903,6 @@ public:
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
|
||||
~PostFormatResultEvent() {}
|
||||
@ -1967,25 +1936,19 @@ public:
|
||||
DeviceStorageFile* aFile)
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
PostResultEvent(already_AddRefed<DOMRequest> aRequest,
|
||||
const nsAString & aPath)
|
||||
: mPath(aPath)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
PostResultEvent(already_AddRefed<DOMRequest> aRequest,
|
||||
const uint64_t aValue)
|
||||
: mValue(aValue)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
~PostResultEvent() {}
|
||||
|
||||
@ -2018,57 +1981,6 @@ private:
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
};
|
||||
|
||||
class CreateFdEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
CreateFdEvent(DeviceStorageFileDescriptor* aDSFileDescriptor,
|
||||
already_AddRefed<DOMRequest> aRequest)
|
||||
: mDSFileDescriptor(aDSFileDescriptor)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mDSFileDescriptor);
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
DeviceStorageFile* dsFile = mDSFileDescriptor->mDSFile;
|
||||
MOZ_ASSERT(dsFile);
|
||||
|
||||
nsString fullPath;
|
||||
dsFile->GetFullPath(fullPath);
|
||||
MOZ_ASSERT(!fullPath.IsEmpty());
|
||||
|
||||
bool check = false;
|
||||
dsFile->mFile->Exists(&check);
|
||||
if (check) {
|
||||
nsCOMPtr<PostErrorEvent> event =
|
||||
new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_EXISTS);
|
||||
return NS_DispatchToMainThread(event);
|
||||
}
|
||||
|
||||
nsresult rv = dsFile->CreateFileDescriptor(mDSFileDescriptor->mFileDescriptor);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
dsFile->mFile->Remove(false);
|
||||
|
||||
nsCOMPtr<PostErrorEvent> event =
|
||||
new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_UNKNOWN);
|
||||
return NS_DispatchToMainThread(event);
|
||||
}
|
||||
|
||||
nsCOMPtr<PostResultEvent> event =
|
||||
new PostResultEvent(mRequest.forget(), fullPath);
|
||||
return NS_DispatchToMainThread(event);
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
};
|
||||
|
||||
class WriteFileEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
@ -2078,10 +1990,7 @@ public:
|
||||
: mBlob(aBlob)
|
||||
, mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
~WriteFileEvent() {}
|
||||
|
||||
@ -2097,7 +2006,8 @@ public:
|
||||
if (check) {
|
||||
nsCOMPtr<PostErrorEvent> event =
|
||||
new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_EXISTS);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = mFile->Write(stream);
|
||||
@ -2107,14 +2017,16 @@ public:
|
||||
|
||||
nsCOMPtr<PostErrorEvent> event =
|
||||
new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_UNKNOWN);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsString fullPath;
|
||||
mFile->GetFullPath(fullPath);
|
||||
nsCOMPtr<PostResultEvent> event =
|
||||
new PostResultEvent(mRequest.forget(), fullPath);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2131,8 +2043,6 @@ public:
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
mFile->CalculateMimeType();
|
||||
}
|
||||
|
||||
@ -2162,7 +2072,8 @@ public:
|
||||
if (!r) {
|
||||
r = new PostResultEvent(mRequest.forget(), mFile);
|
||||
}
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2177,10 +2088,7 @@ public:
|
||||
already_AddRefed<DOMRequest> aRequest)
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
~DeleteFileEvent() {}
|
||||
|
||||
@ -2201,7 +2109,8 @@ public:
|
||||
mFile->GetFullPath(fullPath);
|
||||
r = new PostResultEvent(mRequest.forget(), fullPath);
|
||||
}
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2216,10 +2125,7 @@ public:
|
||||
already_AddRefed<DOMRequest> aRequest)
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
~UsedSpaceFileEvent() {}
|
||||
|
||||
@ -2242,7 +2148,8 @@ public:
|
||||
} else {
|
||||
r = new PostResultEvent(mRequest.forget(), totalUsage);
|
||||
}
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2257,10 +2164,7 @@ public:
|
||||
already_AddRefed<DOMRequest> aRequest)
|
||||
: mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
{}
|
||||
|
||||
~FreeSpaceFileEvent() {}
|
||||
|
||||
@ -2276,7 +2180,8 @@ public:
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
r = new PostResultEvent(mRequest.forget(),
|
||||
static_cast<uint64_t>(freeSpace));
|
||||
return NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2291,65 +2196,32 @@ class DeviceStorageRequest MOZ_FINAL
|
||||
{
|
||||
public:
|
||||
|
||||
DeviceStorageRequest(const DeviceStorageRequestType aRequestType,
|
||||
nsPIDOMWindow* aWindow,
|
||||
nsIPrincipal* aPrincipal,
|
||||
DeviceStorageFile* aFile,
|
||||
DOMRequest* aRequest,
|
||||
nsDOMDeviceStorage* aDeviceStorage)
|
||||
: mRequestType(aRequestType)
|
||||
, mWindow(aWindow)
|
||||
, mPrincipal(aPrincipal)
|
||||
, mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
, mDeviceStorage(aDeviceStorage)
|
||||
{
|
||||
MOZ_ASSERT(mWindow);
|
||||
MOZ_ASSERT(mPrincipal);
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
MOZ_ASSERT(mDeviceStorage);
|
||||
}
|
||||
DeviceStorageRequest(const DeviceStorageRequestType aRequestType,
|
||||
nsPIDOMWindow *aWindow,
|
||||
nsIPrincipal *aPrincipal,
|
||||
DeviceStorageFile *aFile,
|
||||
DOMRequest* aRequest,
|
||||
nsDOMDeviceStorage *aDeviceStorage)
|
||||
: mRequestType(aRequestType)
|
||||
, mWindow(aWindow)
|
||||
, mPrincipal(aPrincipal)
|
||||
, mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
, mDeviceStorage(aDeviceStorage)
|
||||
{}
|
||||
|
||||
DeviceStorageRequest(const DeviceStorageRequestType aRequestType,
|
||||
nsPIDOMWindow* aWindow,
|
||||
nsIPrincipal* aPrincipal,
|
||||
DeviceStorageFile* aFile,
|
||||
DOMRequest* aRequest,
|
||||
nsIDOMBlob* aBlob = nullptr)
|
||||
: mRequestType(aRequestType)
|
||||
, mWindow(aWindow)
|
||||
, mPrincipal(aPrincipal)
|
||||
, mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
, mBlob(aBlob)
|
||||
{
|
||||
MOZ_ASSERT(mWindow);
|
||||
MOZ_ASSERT(mPrincipal);
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
}
|
||||
|
||||
DeviceStorageRequest(const DeviceStorageRequestType aRequestType,
|
||||
nsPIDOMWindow* aWindow,
|
||||
nsIPrincipal* aPrincipal,
|
||||
DeviceStorageFile* aFile,
|
||||
DOMRequest* aRequest,
|
||||
DeviceStorageFileDescriptor* aDSFileDescriptor)
|
||||
: mRequestType(aRequestType)
|
||||
, mWindow(aWindow)
|
||||
, mPrincipal(aPrincipal)
|
||||
, mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
, mDSFileDescriptor(aDSFileDescriptor)
|
||||
{
|
||||
MOZ_ASSERT(mRequestType == DEVICE_STORAGE_REQUEST_CREATEFD);
|
||||
MOZ_ASSERT(mWindow);
|
||||
MOZ_ASSERT(mPrincipal);
|
||||
MOZ_ASSERT(mFile);
|
||||
MOZ_ASSERT(mRequest);
|
||||
MOZ_ASSERT(mDSFileDescriptor);
|
||||
}
|
||||
DeviceStorageRequest(const DeviceStorageRequestType aRequestType,
|
||||
nsPIDOMWindow *aWindow,
|
||||
nsIPrincipal *aPrincipal,
|
||||
DeviceStorageFile *aFile,
|
||||
DOMRequest* aRequest,
|
||||
nsIDOMBlob *aBlob = nullptr)
|
||||
: mRequestType(aRequestType)
|
||||
, mWindow(aWindow)
|
||||
, mPrincipal(aPrincipal)
|
||||
, mFile(aFile)
|
||||
, mRequest(aRequest)
|
||||
, mBlob(aBlob) {}
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageRequest,
|
||||
@ -2449,59 +2321,19 @@ public:
|
||||
nsCOMPtr<PostErrorEvent> event
|
||||
= new PostErrorEvent(mRequest.forget(),
|
||||
POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
return NS_DispatchToMainThread(event);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD Allow()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
|
||||
if (!mRequest) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
|
||||
switch(mRequestType) {
|
||||
case DEVICE_STORAGE_REQUEST_CREATEFD:
|
||||
{
|
||||
if (!mFile->mFile) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
DeviceStorageTypeChecker* typeChecker
|
||||
= DeviceStorageTypeChecker::CreateOrGet();
|
||||
if (!typeChecker) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) {
|
||||
r = new PostErrorEvent(mRequest.forget(),
|
||||
POST_ERROR_EVENT_ILLEGAL_TYPE);
|
||||
return NS_DispatchToCurrentThread(r);
|
||||
}
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
|
||||
DeviceStorageCreateFdParams params;
|
||||
params.type() = mFile->mStorageType;
|
||||
params.storageName() = mFile->mStorageName;
|
||||
params.relpath() = mFile->mPath;
|
||||
|
||||
mFile->Dump("DeviceStorageCreateFdParams");
|
||||
|
||||
PDeviceStorageRequestChild* child
|
||||
= new DeviceStorageRequestChild(mRequest, mFile,
|
||||
mDSFileDescriptor.get());
|
||||
ContentChild::GetSingleton()
|
||||
->SendPDeviceStorageRequestConstructor(child, params);
|
||||
return NS_OK;
|
||||
}
|
||||
mDSFileDescriptor->mDSFile = mFile;
|
||||
r = new CreateFdEvent(mDSFileDescriptor.get(), mRequest.forget());
|
||||
break;
|
||||
}
|
||||
|
||||
case DEVICE_STORAGE_REQUEST_CREATE:
|
||||
{
|
||||
if (!mBlob || !mFile->mFile) {
|
||||
@ -2518,7 +2350,8 @@ public:
|
||||
!typeChecker->Check(mFile->mStorageType, mBlob)) {
|
||||
r = new PostErrorEvent(mRequest.forget(),
|
||||
POST_ERROR_EVENT_ILLEGAL_TYPE);
|
||||
return NS_DispatchToCurrentThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
@ -2561,7 +2394,8 @@ public:
|
||||
if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) {
|
||||
r = new PostErrorEvent(mRequest.forget(),
|
||||
POST_ERROR_EVENT_ILLEGAL_TYPE);
|
||||
return NS_DispatchToCurrentThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
@ -2595,7 +2429,8 @@ public:
|
||||
if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) {
|
||||
r = new PostErrorEvent(mRequest.forget(),
|
||||
POST_ERROR_EVENT_ILLEGAL_TYPE);
|
||||
return NS_DispatchToCurrentThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
@ -2660,7 +2495,8 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
r = new PostAvailableResultEvent(mFile, mRequest);
|
||||
return NS_DispatchToCurrentThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
case DEVICE_STORAGE_REQUEST_WATCH:
|
||||
@ -2681,7 +2517,8 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
r = new PostFormatResultEvent(mFile, mRequest);
|
||||
return NS_DispatchToCurrentThread(r);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
}
|
||||
@ -2721,7 +2558,6 @@ private:
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
nsCOMPtr<nsIDOMBlob> mBlob;
|
||||
nsRefPtr<nsDOMDeviceStorage> mDeviceStorage;
|
||||
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
||||
};
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeviceStorageRequest)
|
||||
@ -2963,8 +2799,6 @@ nsDOMDeviceStorage::GetStorage(const nsAString& aFullPath,
|
||||
already_AddRefed<nsDOMDeviceStorage>
|
||||
nsDOMDeviceStorage::GetStorageByName(const nsAString& aStorageName)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsRefPtr<nsDOMDeviceStorage> ds;
|
||||
|
||||
if (mStorageName.Equals(aStorageName)) {
|
||||
@ -3080,8 +2914,6 @@ already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// if the blob is null here, bail
|
||||
if (!aBlob) {
|
||||
return nullptr;
|
||||
@ -3101,7 +2933,6 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
nsresult rv;
|
||||
|
||||
if (IsFullPath(aPath)) {
|
||||
nsString storagePath;
|
||||
@ -3109,10 +2940,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
|
||||
if (!ds) {
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
|
||||
rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
return ds->AddNamed(aBlob, storagePath, aRv);
|
||||
@ -3133,10 +2961,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
|
||||
win, mPrincipal, dsf, request, aBlob);
|
||||
}
|
||||
|
||||
rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
@ -3163,8 +2988,6 @@ already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::GetInternal(const nsAString& aPath, bool aEditable,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3179,10 +3002,7 @@ nsDOMDeviceStorage::GetInternal(const nsAString& aPath, bool aEditable,
|
||||
if (!ds) {
|
||||
nsCOMPtr<nsIRunnable> r =
|
||||
new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
ds->GetInternal(win, storagePath, request, aEditable);
|
||||
@ -3198,8 +3018,6 @@ nsDOMDeviceStorage::GetInternal(nsPIDOMWindow *aWin,
|
||||
DOMRequest* aRequest,
|
||||
bool aEditable)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
|
||||
mStorageName,
|
||||
aPath);
|
||||
@ -3213,8 +3031,7 @@ nsDOMDeviceStorage::GetInternal(nsPIDOMWindow *aWin,
|
||||
: DEVICE_STORAGE_REQUEST_READ,
|
||||
aWin, mPrincipal, dsf, aRequest);
|
||||
}
|
||||
DebugOnly<nsresult> rv = NS_DispatchToCurrentThread(r);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
NS_DispatchToMainThread(r);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -3229,8 +3046,6 @@ nsDOMDeviceStorage::Delete(const nsAString& aPath, nsIDOMDOMRequest** aRetval)
|
||||
already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::Delete(const nsAString& aPath, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3245,10 +3060,7 @@ nsDOMDeviceStorage::Delete(const nsAString& aPath, ErrorResult& aRv)
|
||||
if (!ds) {
|
||||
nsCOMPtr<nsIRunnable> r =
|
||||
new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
ds->DeleteInternal(win, storagePath, request);
|
||||
@ -3263,8 +3075,6 @@ nsDOMDeviceStorage::DeleteInternal(nsPIDOMWindow *aWin,
|
||||
const nsAString& aPath,
|
||||
DOMRequest* aRequest)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
|
||||
mStorageName,
|
||||
@ -3275,8 +3085,7 @@ nsDOMDeviceStorage::DeleteInternal(nsPIDOMWindow *aWin,
|
||||
r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_DELETE,
|
||||
aWin, mPrincipal, dsf, aRequest);
|
||||
}
|
||||
DebugOnly<nsresult> rv = NS_DispatchToCurrentThread(r);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
NS_DispatchToMainThread(r);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -3291,8 +3100,6 @@ nsDOMDeviceStorage::FreeSpace(nsIDOMDOMRequest** aRetval)
|
||||
already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::FreeSpace(ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3306,10 +3113,7 @@ nsDOMDeviceStorage::FreeSpace(ErrorResult& aRv)
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_FREE_SPACE,
|
||||
win, mPrincipal, dsf, request);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
@ -3325,8 +3129,6 @@ nsDOMDeviceStorage::UsedSpace(nsIDOMDOMRequest** aRetval)
|
||||
already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::UsedSpace(ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3344,10 +3146,7 @@ nsDOMDeviceStorage::UsedSpace(ErrorResult& aRv)
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_USED_SPACE,
|
||||
win, mPrincipal, dsf, request);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
@ -3363,8 +3162,6 @@ nsDOMDeviceStorage::Available(nsIDOMDOMRequest** aRetval)
|
||||
already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::Available(ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3378,18 +3175,13 @@ nsDOMDeviceStorage::Available(ErrorResult& aRv)
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_AVAILABLE,
|
||||
win, mPrincipal, dsf, request);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsDOMDeviceStorage::Format(ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3403,66 +3195,26 @@ nsDOMDeviceStorage::Format(ErrorResult& aRv)
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_FORMAT,
|
||||
win, mPrincipal, dsf, request);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceStorage::CreateFileDescriptor(const nsAString& aPath,
|
||||
DeviceStorageFileDescriptor* aDSFileDescriptor,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
nsDOMDeviceStorage::GetRootDirectoryForFile(const nsAString& aName,
|
||||
nsIFile** aRootDirectory)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aDSFileDescriptor);
|
||||
nsRefPtr<nsDOMDeviceStorage> ds;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
if (IsFullPath(aName)) {
|
||||
nsString storagePath;
|
||||
ds = GetStorage(aName, storagePath);
|
||||
} else {
|
||||
ds = this;
|
||||
}
|
||||
|
||||
DeviceStorageTypeChecker* typeChecker
|
||||
= DeviceStorageTypeChecker::CreateOrGet();
|
||||
if (!typeChecker) {
|
||||
if (!ds || !ds->mRootDirectory) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
nsresult rv;
|
||||
|
||||
if (IsFullPath(aPath)) {
|
||||
nsString storagePath;
|
||||
nsRefPtr<nsDOMDeviceStorage> ds = GetStorage(aPath, storagePath);
|
||||
if (!ds) {
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
|
||||
rv = NS_DispatchToCurrentThread(r);
|
||||
request.forget(aRequest);
|
||||
return rv;
|
||||
}
|
||||
return ds->CreateFileDescriptor(storagePath, aDSFileDescriptor, aRequest);
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
|
||||
mStorageName,
|
||||
aPath);
|
||||
if (!dsf->IsSafePath()) {
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
} else if (!typeChecker->Check(mStorageType, dsf->mFile)) {
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE);
|
||||
} else {
|
||||
r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_CREATEFD,
|
||||
win, mPrincipal, dsf, request,
|
||||
aDSFileDescriptor);
|
||||
}
|
||||
|
||||
rv = NS_DispatchToCurrentThread(r);
|
||||
request.forget(aRequest);
|
||||
return rv;
|
||||
return ds->mRootDirectory->Clone(aRootDirectory);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -3701,8 +3453,6 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType,
|
||||
bool aWantsUntrusted,
|
||||
uint8_t aArgc)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
@ -3714,11 +3464,7 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType,
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_WATCH,
|
||||
win, mPrincipal, dsf, request, this);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
return nsDOMEventTargetHelper::AddEventListener(aType, aListener, aUseCapture,
|
||||
aWantsUntrusted, aArgc);
|
||||
}
|
||||
@ -3730,8 +3476,6 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType,
|
||||
const Nullable<bool>& aWantsUntrusted,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -3744,10 +3488,7 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType,
|
||||
nsCOMPtr<nsIRunnable> r
|
||||
= new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_WATCH,
|
||||
win, mPrincipal, dsf, request, this);
|
||||
nsresult rv = NS_DispatchToCurrentThread(r);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
nsDOMEventTargetHelper::AddEventListener(aType, aListener, aUseCapture,
|
||||
aWantsUntrusted, aRv);
|
||||
}
|
||||
|
@ -52,8 +52,7 @@ enum DeviceStorageRequestType {
|
||||
DEVICE_STORAGE_REQUEST_FREE_SPACE,
|
||||
DEVICE_STORAGE_REQUEST_USED_SPACE,
|
||||
DEVICE_STORAGE_REQUEST_AVAILABLE,
|
||||
DEVICE_STORAGE_REQUEST_FORMAT,
|
||||
DEVICE_STORAGE_REQUEST_CREATEFD
|
||||
DEVICE_STORAGE_REQUEST_FORMAT
|
||||
};
|
||||
|
||||
class DeviceStorageUsedSpaceCache MOZ_FINAL
|
||||
|
@ -11,12 +11,7 @@ interface nsIDOMDeviceStorageChangeEvent;
|
||||
interface nsIDOMEventListener;
|
||||
interface nsIFile;
|
||||
|
||||
%{C++
|
||||
class DeviceStorageFileDescriptor;
|
||||
%}
|
||||
[ptr] native DeviceStorageFdPtr(DeviceStorageFileDescriptor);
|
||||
|
||||
[scriptable, uuid(8b724547-3c78-4244-969a-f00a1f4ae0c3), builtinclass]
|
||||
[scriptable, uuid(7c1b2305-0f14-4c07-8a8a-359eeb850068), builtinclass]
|
||||
interface nsIDOMDeviceStorage : nsIDOMEventTarget
|
||||
{
|
||||
[implicit_jscontext] attribute jsval onchange;
|
||||
@ -39,8 +34,5 @@ interface nsIDOMDeviceStorage : nsIDOMEventTarget
|
||||
// for storing new files.
|
||||
readonly attribute bool default;
|
||||
|
||||
// Note: aFileDescriptor is reference counted, which is why we're using
|
||||
// a pointer rather than a reference.
|
||||
[noscript] nsIDOMDOMRequest createFileDescriptor(in DOMString aName,
|
||||
in DeviceStorageFdPtr aFileDescriptor);
|
||||
[noscript] nsIFile getRootDirectoryForFile(in DOMString aName);
|
||||
};
|
||||
|
@ -94,13 +94,6 @@ struct DeviceStorageAddParams
|
||||
PBlob blob;
|
||||
};
|
||||
|
||||
struct DeviceStorageCreateFdParams
|
||||
{
|
||||
nsString type;
|
||||
nsString storageName;
|
||||
nsString relpath;
|
||||
};
|
||||
|
||||
struct DeviceStorageGetParams
|
||||
{
|
||||
nsString type;
|
||||
@ -127,7 +120,6 @@ struct DeviceStorageEnumerationParams
|
||||
union DeviceStorageParams
|
||||
{
|
||||
DeviceStorageAddParams;
|
||||
DeviceStorageCreateFdParams;
|
||||
DeviceStorageGetParams;
|
||||
DeviceStorageDeleteParams;
|
||||
DeviceStorageEnumerationParams;
|
||||
|
Loading…
x
Reference in New Issue
Block a user