mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Backout b3f14a850269, f9d877d78294, and c7335ca109a4 due to build bustage.
This commit is contained in:
parent
3a3341d153
commit
6e7f656ffd
@ -1,104 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
|
||||
#include "DeviceStorageRequestChild.h"
|
||||
#include "nsDeviceStorage.h"
|
||||
#include "nsDOMFile.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace devicestorage {
|
||||
|
||||
DeviceStorageRequestChild::DeviceStorageRequestChild()
|
||||
{
|
||||
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
|
||||
}
|
||||
|
||||
DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest,
|
||||
DeviceStorageFile* aFile)
|
||||
: mRequest(aRequest)
|
||||
, mFile(aFile)
|
||||
{
|
||||
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
|
||||
}
|
||||
|
||||
DeviceStorageRequestChild::~DeviceStorageRequestChild() {
|
||||
MOZ_COUNT_DTOR(DeviceStorageRequestChild);
|
||||
}
|
||||
bool
|
||||
DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aValue)
|
||||
{
|
||||
switch (aValue.type()) {
|
||||
|
||||
case DeviceStorageResponseValue::TErrorResponse:
|
||||
{
|
||||
ErrorResponse r = aValue;
|
||||
mRequest->FireError(r.error());
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageResponseValue::TSuccessResponse:
|
||||
{
|
||||
jsval result = StringToJsval(mRequest->GetOwner(), mFile->mPath);
|
||||
mRequest->FireSuccess(result);
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageResponseValue::TBlobResponse:
|
||||
{
|
||||
BlobResponse r = aValue;
|
||||
|
||||
// I am going to hell for this. bent says he'll save me.
|
||||
const InfallibleTArray<PRUint8> bits = r.bits();
|
||||
void* buffer = PR_Malloc(bits.Length());
|
||||
memcpy(buffer, (void*) bits.Elements(), bits.Length());
|
||||
|
||||
nsString mimeType;
|
||||
mimeType.AssignWithConversion(r.contentType());
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> blob = new nsDOMMemoryFile(buffer,
|
||||
bits.Length(),
|
||||
mFile->mPath,
|
||||
mimeType);
|
||||
|
||||
jsval result = BlobToJsval(mRequest->GetOwner(), blob);
|
||||
mRequest->FireSuccess(result);
|
||||
break;
|
||||
}
|
||||
|
||||
case DeviceStorageResponseValue::TEnumerationResponse:
|
||||
{
|
||||
EnumerationResponse r = aValue;
|
||||
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
|
||||
|
||||
PRUint32 count = r.paths().Length();
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIFile> f;
|
||||
NS_NewLocalFile(r.paths()[i].fullpath(), false, getter_AddRefs(f));
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
||||
dsf->SetPath(r.paths()[i].path());
|
||||
cursor->mFiles.AppendElement(dsf);
|
||||
}
|
||||
|
||||
nsCOMPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor);
|
||||
NS_DispatchToMainThread(event);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
NS_RUNTIMEABORT("not reached");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace devicestorage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,34 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 mozilla_dom_devicestorage_DeviceStorageRequestChild_h
|
||||
#define mozilla_dom_devicestorage_DeviceStorageRequestChild_h
|
||||
|
||||
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
|
||||
#include "DOMRequest.h"
|
||||
#include "nsDeviceStorage.h"
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace devicestorage {
|
||||
|
||||
class DeviceStorageRequestChild : public PDeviceStorageRequestChild
|
||||
{
|
||||
public:
|
||||
DeviceStorageRequestChild();
|
||||
DeviceStorageRequestChild(DOMRequest* aRequest, DeviceStorageFile* aFile);
|
||||
~DeviceStorageRequestChild();
|
||||
|
||||
virtual bool Recv__delete__(const DeviceStorageResponseValue& value);
|
||||
|
||||
private:
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
};
|
||||
|
||||
} // namespace devicestorage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
@ -1,360 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#include "DeviceStorageRequestParent.h"
|
||||
#include "nsDOMFile.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace devicestorage {
|
||||
|
||||
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams)
|
||||
{
|
||||
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
|
||||
|
||||
switch (aParams.type()) {
|
||||
case DeviceStorageParams::TDeviceStorageAddParams:
|
||||
{
|
||||
DeviceStorageAddParams p = aParams;
|
||||
|
||||
nsCOMPtr<nsIFile> f;
|
||||
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
||||
nsRefPtr<WriteFileEvent> r = new WriteFileEvent(this, dsf, p.bits());
|
||||
|
||||
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 = aParams;
|
||||
|
||||
nsCOMPtr<nsIFile> f;
|
||||
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
||||
nsRefPtr<ReadFileEvent> r = new ReadFileEvent(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::TDeviceStorageDeleteParams:
|
||||
{
|
||||
DeviceStorageDeleteParams p = aParams;
|
||||
|
||||
nsCOMPtr<nsIFile> f;
|
||||
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
||||
nsRefPtr<DeleteFileEvent> r = new DeleteFileEvent(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::TDeviceStorageEnumerationParams:
|
||||
{
|
||||
DeviceStorageEnumerationParams p = aParams;
|
||||
|
||||
nsCOMPtr<nsIFile> f;
|
||||
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
||||
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
||||
nsRefPtr<EnumerateFileEvent> r = new EnumerateFileEvent(this, dsf, p.since());
|
||||
|
||||
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
||||
NS_ASSERTION(target, "Must have stream transport service");
|
||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
NS_RUNTIMEABORT("not reached");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::~DeviceStorageRequestParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(DeviceStorageRequestParent);
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostErrorEvent::PostErrorEvent(DeviceStorageRequestParent* aParent,
|
||||
const char* aError)
|
||||
: mParent(aParent)
|
||||
{
|
||||
mError.AssignWithConversion(aError);
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostErrorEvent::~PostErrorEvent() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::PostErrorEvent::Run() {
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
ErrorResponse response(mError);
|
||||
unused << mParent->Send__delete__(mParent, response);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
DeviceStorageRequestParent::PostSuccessEvent::PostSuccessEvent(DeviceStorageRequestParent* aParent)
|
||||
: mParent(aParent)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostSuccessEvent::~PostSuccessEvent() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::PostSuccessEvent::Run() {
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
SuccessResponse response;
|
||||
unused << mParent->Send__delete__(mParent, response);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostBlobSuccessEvent::PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
|
||||
void* aBuffer,
|
||||
PRUint32 aLength,
|
||||
nsACString& aMimeType)
|
||||
: mParent(aParent)
|
||||
, mMimeType(aMimeType)
|
||||
{
|
||||
mBits.SetCapacity(aLength);
|
||||
void* bits = mBits.Elements();
|
||||
memcpy(bits, aBuffer, aLength);
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostBlobSuccessEvent::~PostBlobSuccessEvent() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::PostBlobSuccessEvent::Run() {
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
BlobResponse response(mBits, mMimeType);
|
||||
unused << mParent->Send__delete__(mParent, response);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
|
||||
InfallibleTArray<DeviceStorageFileValue>& aPaths)
|
||||
: mParent(aParent)
|
||||
, mPaths(aPaths)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostEnumerationSuccessEvent::~PostEnumerationSuccessEvent() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::PostEnumerationSuccessEvent::Run() {
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
EnumerationResponse response(mPaths);
|
||||
unused << mParent->Send__delete__(mParent, response);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::WriteFileEvent::WriteFileEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile,
|
||||
InfallibleTArray<PRUint8>& aBits)
|
||||
: mParent(aParent)
|
||||
, mFile(aFile)
|
||||
, mBits(aBits)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::WriteFileEvent::~WriteFileEvent()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::WriteFileEvent::Run()
|
||||
{
|
||||
nsRefPtr<nsRunnable> r;
|
||||
nsresult rv = mFile->Write(mBits);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
}
|
||||
else {
|
||||
r = new PostPathResultEvent(mParent, mFile->mPath);
|
||||
}
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
DeviceStorageRequestParent::DeleteFileEvent::DeleteFileEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile)
|
||||
: mParent(aParent)
|
||||
, mFile(aFile)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::DeleteFileEvent::~DeleteFileEvent()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::DeleteFileEvent::Run()
|
||||
{
|
||||
mFile->mFile->Remove(true);
|
||||
|
||||
nsRefPtr<nsRunnable> r;
|
||||
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (check) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
}
|
||||
else {
|
||||
r = new PostPathResultEvent(mParent, mFile->mPath);
|
||||
}
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::ReadFileEvent::ReadFileEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile)
|
||||
: mParent(aParent)
|
||||
, mFile(aFile)
|
||||
{
|
||||
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
||||
if (mimeService) {
|
||||
nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType);
|
||||
if (NS_FAILED(rv)) {
|
||||
mMimeType.Truncate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::ReadFileEvent::~ReadFileEvent()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::ReadFileEvent::Run()
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (!check) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt64 fileSize;
|
||||
nsresult rv = mFile->mFile->GetFileSize(&fileSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRFileDesc *fileHandle;
|
||||
rv = mFile->mFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fileHandle);
|
||||
|
||||
// i am going to hell. this is temp until bent provides seralizaiton of blobs.
|
||||
void* buf = (void*) malloc(fileSize);
|
||||
PRInt32 read = PR_Read(fileHandle, buf, fileSize);
|
||||
if (read != fileSize) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
r = new PostBlobSuccessEvent(mParent, buf, fileSize, mMimeType);
|
||||
|
||||
PR_Free(buf);
|
||||
PR_Close(fileHandle);
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::EnumerateFileEvent::EnumerateFileEvent(DeviceStorageRequestParent* aParent,
|
||||
DeviceStorageFile* aFile,
|
||||
PRUint32 aSince)
|
||||
: mParent(aParent)
|
||||
, mFile(aFile)
|
||||
, mSince(aSince)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::EnumerateFileEvent::~EnumerateFileEvent()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::EnumerateFileEvent::Run()
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> r;
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (!check) {
|
||||
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsTArray<nsRefPtr<DeviceStorageFile> > files;
|
||||
mFile->CollectFiles(files, mSince);
|
||||
|
||||
InfallibleTArray<DeviceStorageFileValue> values;
|
||||
|
||||
PRUint32 count = files.Length();
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsString fullpath;
|
||||
files[i]->mFile->GetPath(fullpath);
|
||||
DeviceStorageFileValue dsvf(fullpath, files[i]->mPath);
|
||||
values.AppendElement(dsvf);
|
||||
}
|
||||
|
||||
r = new PostEnumerationSuccessEvent(mParent, values);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
DeviceStorageRequestParent::PostPathResultEvent::PostPathResultEvent(DeviceStorageRequestParent* aParent,
|
||||
const nsAString& aPath)
|
||||
: mParent(aParent)
|
||||
, mPath(aPath)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceStorageRequestParent::PostPathResultEvent::~PostPathResultEvent()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeviceStorageRequestParent::PostPathResultEvent::Run()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
SuccessResponse response;
|
||||
unused << mParent->Send__delete__(mParent, response);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace devicestorage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,136 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 mozilla_dom_devicestorage_DeviceStorageRequestParent_h
|
||||
#define mozilla_dom_devicestorage_DeviceStorageRequestParent_h
|
||||
|
||||
#include "mozilla/dom/devicestorage/PDeviceStorageRequestParent.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsDeviceStorage.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace devicestorage {
|
||||
|
||||
class DeviceStorageRequestParent : public PDeviceStorageRequestParent
|
||||
{
|
||||
public:
|
||||
DeviceStorageRequestParent(const DeviceStorageParams& aParams);
|
||||
~DeviceStorageRequestParent();
|
||||
|
||||
private:
|
||||
class PostErrorEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError);
|
||||
~PostErrorEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
nsString mError;
|
||||
};
|
||||
|
||||
class PostSuccessEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PostSuccessEvent(DeviceStorageRequestParent* aParent);
|
||||
~PostSuccessEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
};
|
||||
|
||||
class PostBlobSuccessEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, void* aBuffer, PRUint32 aLength, nsACString& aMimeType);
|
||||
~PostBlobSuccessEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
InfallibleTArray<PRUint8> mBits;
|
||||
nsCString mMimeType;
|
||||
};
|
||||
|
||||
class PostEnumerationSuccessEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, InfallibleTArray<DeviceStorageFileValue>& aPaths);
|
||||
~PostEnumerationSuccessEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
InfallibleTArray<DeviceStorageFileValue> mPaths;
|
||||
};
|
||||
|
||||
class WriteFileEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
WriteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, InfallibleTArray<PRUint8>& aBits);
|
||||
~WriteFileEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
InfallibleTArray<PRUint8> mBits; // another copy?
|
||||
};
|
||||
|
||||
class DeleteFileEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
||||
~DeleteFileEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
};
|
||||
|
||||
class ReadFileEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
||||
~ReadFileEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
nsCString mMimeType;
|
||||
};
|
||||
|
||||
class EnumerateFileEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
EnumerateFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, PRUint32 aSince);
|
||||
~EnumerateFileEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
PRUint32 mSince;
|
||||
};
|
||||
|
||||
class PostPathResultEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PostPathResultEvent(DeviceStorageRequestParent* aParent, const nsAString& aPath);
|
||||
~PostPathResultEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
DeviceStorageRequestParent* mParent;
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
InfallibleTArray<PRUint8> mBits;
|
||||
nsString mPath;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // namespace devicestorage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
@ -17,17 +17,8 @@ FORCE_STATIC_LIB = 1
|
||||
|
||||
include $(topsrcdir)/dom/dom-config.mk
|
||||
|
||||
EXPORTS_NAMESPACES = mozilla/dom/devicestorage
|
||||
|
||||
EXPORTS_mozilla/dom/devicestorage = \
|
||||
DeviceStorageRequestChild.h \
|
||||
DeviceStorageRequestParent.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsDeviceStorage.cpp \
|
||||
DeviceStorageRequestParent.cpp \
|
||||
DeviceStorageRequestChild.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
@ -41,7 +32,7 @@ LOCAL_INCLUDES = \
|
||||
-I$(topsrcdir)/content/events/src \
|
||||
$(NULL)
|
||||
|
||||
TEST_DIRS += test ipc
|
||||
TEST_DIRS += test
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
@ -1,58 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
include protocol PContent;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace devicestorage {
|
||||
|
||||
|
||||
struct ErrorResponse
|
||||
{
|
||||
nsString error;
|
||||
};
|
||||
|
||||
struct SuccessResponse
|
||||
{
|
||||
};
|
||||
|
||||
struct BlobResponse
|
||||
{
|
||||
// todo going away
|
||||
PRUint8[] bits;
|
||||
nsCString contentType;
|
||||
};
|
||||
|
||||
struct DeviceStorageFileValue
|
||||
{
|
||||
// todo going away
|
||||
nsString fullpath;
|
||||
nsString path;
|
||||
};
|
||||
|
||||
struct EnumerationResponse
|
||||
{
|
||||
DeviceStorageFileValue[] paths;
|
||||
// todo bent PBlob
|
||||
};
|
||||
|
||||
union DeviceStorageResponseValue
|
||||
{
|
||||
ErrorResponse;
|
||||
SuccessResponse;
|
||||
BlobResponse;
|
||||
EnumerationResponse;
|
||||
};
|
||||
|
||||
sync protocol PDeviceStorageRequest {
|
||||
manager PContent;
|
||||
child:
|
||||
__delete__(DeviceStorageResponseValue response);
|
||||
};
|
||||
|
||||
} // namespace devicestorage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,26 +0,0 @@
|
||||
# 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/.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
relativesrcdir = dom/devicestorage/ipc
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
|
||||
TEST_FILES = \
|
||||
test_ipc.html \
|
||||
../test/devicestorage_common.js \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
libs:: $(TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") \
|
||||
$(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)\
|
@ -1,160 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for OOP DeviceStorage</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function iframeScriptFirst() {
|
||||
content.wrappedJSObject.RunSet.reloadAndRunAll({
|
||||
preventDefault: function() { }
|
||||
});
|
||||
}
|
||||
|
||||
function iframeScriptSecond() {
|
||||
let TestRunner = content.wrappedJSObject.TestRunner;
|
||||
|
||||
let oldComplete = TestRunner.onComplete;
|
||||
|
||||
TestRunner.onComplete = function() {
|
||||
TestRunner.onComplete = oldComplete;
|
||||
|
||||
sendAsyncMessage("test:DeviceStorage:ipcTestComplete", {
|
||||
result: JSON.stringify(TestRunner._failedTests)
|
||||
});
|
||||
|
||||
if (oldComplete) {
|
||||
oldComplete();
|
||||
}
|
||||
};
|
||||
|
||||
let oldLog = TestRunner.log;
|
||||
TestRunner.log = function(msg) {
|
||||
sendAsyncMessage("test:DeviceStorage:ipcTestMessage", { msg: msg });
|
||||
}
|
||||
}
|
||||
|
||||
let regex = /^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL|TEST-DEBUG-INFO) \| ([^\|]+) \|(.*)/;
|
||||
|
||||
function onTestMessage(data) {
|
||||
let message = data.json.msg;
|
||||
let match = regex.exec(message);
|
||||
if (match) {
|
||||
let state = match[1];
|
||||
let details = match[2] + " | " + match[3];
|
||||
|
||||
switch (state) {
|
||||
case "TEST-PASS":
|
||||
case "TEST-KNOWN-FAIL":
|
||||
ok(true, details);
|
||||
break;
|
||||
|
||||
case "TEST-UNEXPECTED-FAIL":
|
||||
case "TEST-UNEXPECTED-PASS":
|
||||
ok(false, details);
|
||||
break;
|
||||
|
||||
case "TEST-DEBUG-INFO":
|
||||
default:
|
||||
info(details);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onTestComplete() {
|
||||
let comp = SpecialPowers.wrap(Components);
|
||||
SimpleTest.executeSoon(function () { SimpleTest.finish(); });
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
let iframe = document.createElement("iframe");
|
||||
iframe.mozbrowser = true;
|
||||
iframe.id = "iframe";
|
||||
iframe.style.width = "100%";
|
||||
iframe.style.height = "1000px";
|
||||
|
||||
function iframeLoadSecond() {
|
||||
ok(true, "Got second iframe load event.");
|
||||
iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond);
|
||||
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
||||
mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();",
|
||||
false);
|
||||
}
|
||||
|
||||
function iframeLoadFirst() {
|
||||
ok(true, "Got first iframe load event.");
|
||||
iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst);
|
||||
iframe.addEventListener("mozbrowserloadend", iframeLoadSecond);
|
||||
|
||||
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
||||
|
||||
let comp = SpecialPowers.wrap(Components);
|
||||
|
||||
let spObserver =
|
||||
comp.classes["@mozilla.org/special-powers-observer;1"]
|
||||
.getService(comp.interfaces.nsIFrameMessageListener);
|
||||
|
||||
mm.addMessageListener("SPPrefService", spObserver);
|
||||
mm.addMessageListener("SPProcessCrashService", spObserver);
|
||||
mm.addMessageListener("SPPingService", spObserver);
|
||||
mm.addMessageListener("SpecialPowers.Quit", spObserver);
|
||||
mm.addMessageListener("SPPermissionManager", spObserver);
|
||||
|
||||
mm.addMessageListener("test:DeviceStorage:ipcTestMessage", onTestMessage);
|
||||
mm.addMessageListener("test:DeviceStorage:ipcTestComplete", onTestComplete);
|
||||
|
||||
let specialPowersBase = "chrome://specialpowers/content/";
|
||||
mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false);
|
||||
mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false);
|
||||
mm.loadFrameScript(specialPowersBase + "specialpowers.js", false);
|
||||
|
||||
mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", false);
|
||||
}
|
||||
|
||||
iframe.addEventListener("mozbrowserloadend", iframeLoadFirst);
|
||||
|
||||
// Strip this filename and one directory level and then add "/test".
|
||||
let href = window.location.href;
|
||||
href = href.substring(0, href.lastIndexOf('/'));
|
||||
href = href.substring(0, href.lastIndexOf('/'));
|
||||
iframe.src = href + "/test?consoleLevel=INFO";
|
||||
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
addEventListener("load", function() {
|
||||
let whitelist;
|
||||
try {
|
||||
whitelist =
|
||||
SpecialPowers.getCharPref("dom.mozBrowserFramesWhitelist") + ", ";
|
||||
} catch (e) {
|
||||
whitelist = "";
|
||||
}
|
||||
|
||||
whitelist += window.location.protocol + "//" + window.location.host;
|
||||
|
||||
SpecialPowers.pushPrefEnv({
|
||||
"set": [
|
||||
|
||||
["device.storage.enabled", true],
|
||||
["device.storage.testing", true],
|
||||
["device.storage.prompt.testing", true],
|
||||
|
||||
["dom.ipc.browser_frames.oop_by_default", true],
|
||||
["dom.mozBrowserFramesEnabled", true],
|
||||
["browser.pageThumbs.enabled", false],
|
||||
["dom.mozBrowserFramesWhitelist", whitelist]
|
||||
]
|
||||
}, runTests);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,7 +0,0 @@
|
||||
# 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/.
|
||||
|
||||
IPDLSRCS = \
|
||||
PDeviceStorageRequest.ipdl \
|
||||
$(NULL)
|
File diff suppressed because it is too large
Load Diff
@ -7,64 +7,19 @@
|
||||
|
||||
class nsPIDOMWindow;
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/PBrowserChild.h"
|
||||
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
|
||||
|
||||
|
||||
#include "DOMRequest.h"
|
||||
#include "PCOMContentPermissionRequestChild.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/PContentPermissionRequestChild.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsIClassInfo.h"
|
||||
#include "nsIContentPermissionPrompt.h"
|
||||
#include "nsIDOMDeviceStorage.h"
|
||||
#include "nsIDOMDeviceStorageCursor.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWeakPtr.h"
|
||||
|
||||
|
||||
#define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST "File location doesn't exists"
|
||||
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "File location is not enumerable"
|
||||
#define POST_ERROR_EVENT_PERMISSION_DENIED "Permission Denied"
|
||||
#define POST_ERROR_EVENT_ILLEGAL_FILE_NAME "Illegal file name"
|
||||
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
||||
#define POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED "Non-string type unsupported"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
class DeviceStorageFile MOZ_FINAL : public nsISupports {
|
||||
public:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
nsString mPath;
|
||||
bool mEditable;
|
||||
|
||||
DeviceStorageFile(nsIFile* aFile, const nsAString& aPath);
|
||||
DeviceStorageFile(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 Write(nsIDOMBlob* blob);
|
||||
nsresult Write(InfallibleTArray<PRUint8>& bits);
|
||||
void CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, PRUint64 aSince = 0);
|
||||
void collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, PRUint64 aSince, nsAString& aRootPath);
|
||||
|
||||
private:
|
||||
void NormalizeFilePath();
|
||||
void AppendRelativePath();
|
||||
};
|
||||
#include "nsInterfaceHashtable.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsDOMDeviceStorage MOZ_FINAL : public nsIDOMDeviceStorage
|
||||
{
|
||||
@ -83,6 +38,7 @@ public:
|
||||
private:
|
||||
~nsDOMDeviceStorage();
|
||||
|
||||
|
||||
nsresult GetInternal(const JS::Value & aName, JSContext* aCx, nsIDOMDOMRequest * *_retval NS_OUTPARAM, bool aEditable);
|
||||
|
||||
nsresult EnumerateInternal(const JS::Value & aName, const JS::Value & aOptions, JSContext* aCx, PRUint8 aArgc, bool aEditable, nsIDOMDeviceStorageCursor** aRetval);
|
||||
@ -101,52 +57,4 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
class ContinueCursorEvent MOZ_FINAL: public nsRunnable
|
||||
{
|
||||
public:
|
||||
ContinueCursorEvent(nsRefPtr<DOMRequest>& aRequest);
|
||||
ContinueCursorEvent(DOMRequest* aRequest);
|
||||
~ContinueCursorEvent();
|
||||
NS_IMETHOD Run();
|
||||
private:
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
};
|
||||
|
||||
class nsDOMDeviceStorageCursor MOZ_FINAL
|
||||
: public nsIDOMDeviceStorageCursor
|
||||
, public DOMRequest
|
||||
, public nsIContentPermissionRequest
|
||||
, public PCOMContentPermissionRequestChild
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
||||
NS_DECL_NSIDOMDEVICESTORAGECURSOR
|
||||
|
||||
nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow,
|
||||
nsIURI* aURI,
|
||||
DeviceStorageFile* aFile,
|
||||
PRUint64 aSince);
|
||||
|
||||
|
||||
nsTArray<nsRefPtr<DeviceStorageFile> > mFiles;
|
||||
bool mOkToCallContinue;
|
||||
PRUint64 mSince;
|
||||
|
||||
virtual bool Recv__delete__(const bool& allow);
|
||||
virtual void IPDLRelease();
|
||||
|
||||
private:
|
||||
~nsDOMDeviceStorageCursor();
|
||||
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
};
|
||||
|
||||
//helpers
|
||||
jsval StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString);
|
||||
jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile, bool aEditable);
|
||||
jsval BlobToJsval(nsPIDOMWindow* aWindow, nsIDOMBlob* aBlob);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -13,34 +13,19 @@ Array.prototype.remove = function(from, to) {
|
||||
};
|
||||
|
||||
function devicestorage_setup() {
|
||||
|
||||
// ensure that the directory we are writing into is empty
|
||||
try {
|
||||
const Cc = SpecialPowers.wrap(Components).classes;
|
||||
const Ci = Components.interfaces;
|
||||
var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var f = directoryService.get("TmpD", Ci.nsIFile);
|
||||
f.appendRelativePath("device-storage-testing");
|
||||
f.remove(true);
|
||||
} catch(e) {}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
try {
|
||||
oldVal = SpecialPowers.getBoolPref("device.storage.enabled");
|
||||
} catch(e) {}
|
||||
SpecialPowers.setBoolPref("device.storage.enabled", true);
|
||||
SpecialPowers.setBoolPref("device.storage.testing", true);
|
||||
SpecialPowers.setBoolPref("device.storage.prompt.testing", true);
|
||||
}
|
||||
try {
|
||||
oldVal = SpecialPowers.getBoolPref("device.storage.enabled");
|
||||
} catch(e) {}
|
||||
SpecialPowers.setBoolPref("device.storage.enabled", true);
|
||||
SpecialPowers.setBoolPref("device.storage.testing", true);
|
||||
SpecialPowers.setBoolPref("device.storage.prompt.testing", true);
|
||||
}
|
||||
|
||||
function devicestorage_cleanup() {
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
|
||||
SpecialPowers.setBoolPref("device.storage.testing", false);
|
||||
SpecialPowers.setBoolPref("device.storage.prompt.testing", false);
|
||||
}
|
||||
SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
|
||||
SpecialPowers.setBoolPref("device.storage.testing", false);
|
||||
SpecialPowers.setBoolPref("device.storage.prompt.testing", false);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
@ -55,7 +40,7 @@ function getRandomBuffer() {
|
||||
}
|
||||
|
||||
function createRandomBlob() {
|
||||
return blob = new Blob([getRandomBuffer()], {type: 'binary/random'});
|
||||
return blob = new Blob([getRandomBuffer()], {type: 'binary/random'});
|
||||
}
|
||||
|
||||
function randomFilename(l) {
|
||||
|
@ -25,8 +25,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||
devicestorage_setup();
|
||||
|
||||
var gFileName = "devicestorage/hi";
|
||||
var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies."
|
||||
var gDataBlob = new Blob([gData], {type: 'text/plain'});
|
||||
|
||||
function getAfterDeleteSuccess(e) {
|
||||
ok(false, "file was deleted not successfully");
|
||||
@ -41,9 +39,8 @@ function getAfterDeleteError(e) {
|
||||
function deleteSuccess(e) {
|
||||
|
||||
ok(e.target.result == gFileName, "File name should match");
|
||||
dump(e.target.result + "\n")
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
request = storage[0].get(e.target.result);
|
||||
request.onsuccess = getAfterDeleteSuccess;
|
||||
request.onerror = getAfterDeleteError;
|
||||
@ -56,43 +53,27 @@ function deleteError(e) {
|
||||
}
|
||||
|
||||
function getSuccess(e) {
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
|
||||
ok(e.target.result.name == gFileName, "File name should match");
|
||||
|
||||
var name = e.target.result.name;
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.readAsArrayBuffer(gDataBlob);
|
||||
reader.onload = function(e) {
|
||||
readerCallback(e);
|
||||
|
||||
request = storage[0].delete(name)
|
||||
request.onsuccess = deleteSuccess;
|
||||
request.onerror = deleteError;
|
||||
}
|
||||
}
|
||||
|
||||
function readerCallback(e) {
|
||||
|
||||
ab = e.target.result;
|
||||
|
||||
is(ab.byteLength, gData.length, "wrong arraybuffer byteLength");
|
||||
var u8v = new Uint8Array(ab);
|
||||
is(String.fromCharCode.apply(String, u8v), gData, "wrong values");
|
||||
request = storage[0].delete(e.target.result.name)
|
||||
request.onsuccess = deleteSuccess;
|
||||
request.onerror = deleteError;
|
||||
}
|
||||
|
||||
function getError(e) {
|
||||
ok(false, "getError was called : " + e.target.error.name);
|
||||
devicestorage_cleanup();
|
||||
SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function addSuccess(e) {
|
||||
|
||||
ok(e.target.result == gFileName, "File name should match");
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
request = storage[0].get(gFileName);
|
||||
request.onsuccess = getSuccess;
|
||||
request.onerror = getError;
|
||||
@ -105,12 +86,10 @@ function addError(e) {
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
ok(storage, "Should have gotten a storage");
|
||||
|
||||
request = storage[0].addNamed(gDataBlob, "devicestorage/hi");
|
||||
request = storage[0].addNamed(createRandomBlob(), "devicestorage/hi");
|
||||
ok(request, "Should have a non-null request");
|
||||
|
||||
request.onsuccess = addSuccess;
|
||||
|
@ -24,15 +24,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||
|
||||
devicestorage_setup();
|
||||
|
||||
function testingStorage() {
|
||||
return navigator.getDeviceStorage("testing")[0];
|
||||
function profileStorage() {
|
||||
return navigator.getDeviceStorage("profile")[0];
|
||||
}
|
||||
|
||||
var tests = [
|
||||
function () { return testingStorage().addNamed(createRandomBlob(), gFileName); },
|
||||
function () { return testingStorage().delete(gFileName); },
|
||||
function () { return testingStorage().get(gFileName); },
|
||||
function () { var r = testingStorage().enumerate("../"); return r; }
|
||||
function () { return profileStorage().addNamed(createRandomBlob(), gFileName); },
|
||||
function () { return profileStorage().delete(gFileName); },
|
||||
function () { return profileStorage().get(gFileName); },
|
||||
function () { var r = profileStorage().enumerate("../"); return r; }
|
||||
];
|
||||
|
||||
var gFileName = "../owned";
|
||||
|
@ -28,7 +28,7 @@ function enumerateSuccess(e) {
|
||||
|
||||
if (e.target.result == null) {
|
||||
ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array")
|
||||
dump("We still have length = " + files.length + "\n");
|
||||
dump("We still have length = " + files.length);
|
||||
devicestorage_cleanup();
|
||||
return;
|
||||
}
|
||||
@ -67,7 +67,7 @@ function addError(e) {
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
var prefix = "devicestorage/" + randomFilename(12)
|
||||
|
||||
|
@ -30,7 +30,7 @@ function enumerateSuccess(e) {
|
||||
function enumerateFailure(e) {
|
||||
}
|
||||
|
||||
var cursor = navigator.getDeviceStorage("testing")[0].enumerate();
|
||||
var cursor = navigator.getDeviceStorage("profile")[0].enumerate();
|
||||
cursor.onsuccess = enumerateSuccess;
|
||||
cursor.onerror = enumerateFailure;
|
||||
|
||||
|
@ -71,7 +71,7 @@ function addError(e) {
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
var prefix = "devicestorage/" + randomFilename(12)
|
||||
|
||||
|
@ -25,7 +25,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||
|
||||
devicestorage_setup()
|
||||
|
||||
storage = navigator.getDeviceStorage("testing");
|
||||
storage = navigator.getDeviceStorage("profile");
|
||||
|
||||
|
||||
throws = false;
|
||||
|
@ -44,7 +44,7 @@ function verifyAndDelete(prefix, files, e) {
|
||||
files.remove(index);
|
||||
|
||||
// clean up
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
var cleanup = storage[0].delete(prefix + "/" + filename);
|
||||
cleanup.onsuccess = function(e) {}
|
||||
}
|
||||
@ -57,10 +57,7 @@ function addFiles(prefix, files, date, callback) {
|
||||
var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
|
||||
for (var i=0; i<files.length; i++) {
|
||||
|
||||
var f = directoryService.get("TmpD", Ci.nsIFile);
|
||||
f.appendRelativePath("device-storage-testing");
|
||||
|
||||
var f = directoryService.get("ProfD", Components.interfaces.nsIFile);
|
||||
var path = prefix + '/' + files[i];
|
||||
path.split("/").forEach(function(p) {
|
||||
f.appendRelativePath(p);
|
||||
@ -84,7 +81,7 @@ addFiles(prefix, oldFiles, 157795200, addNewFiles);
|
||||
|
||||
function enumerateNew() {
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
|
||||
// 836031600 is a long time ago
|
||||
|
@ -39,13 +39,12 @@ function deleteError(e) {
|
||||
|
||||
function addOverwritingSuccess(e) {
|
||||
ok(false, "addOverwritingSuccess was called.");
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
|
||||
function addOverwritingError(e) {
|
||||
ok(true, "Adding to the same location should fail");
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
request = storage[0].delete(filename)
|
||||
request.onsuccess = deleteSuccess;
|
||||
request.onerror = deleteError;
|
||||
@ -54,7 +53,7 @@ function addOverwritingError(e) {
|
||||
function addSuccess(e) {
|
||||
ok(true, "addSuccess was called");
|
||||
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
|
||||
request = storage[0].addNamed(createRandomBlob(), filename);
|
||||
@ -66,13 +65,13 @@ function addSuccess(e) {
|
||||
|
||||
function addError(e) {
|
||||
// test file is already exists. clean it up and try again..
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
request = storage[0].delete(filename)
|
||||
request.onsuccess = runtest;
|
||||
}
|
||||
|
||||
function runtest() {
|
||||
var storage = navigator.getDeviceStorage("testing");
|
||||
var storage = navigator.getDeviceStorage("profile");
|
||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||
|
||||
request = storage[0].addNamed(createRandomBlob(), filename);
|
||||
|
@ -38,13 +38,32 @@ ok(throws, "getDeviceStorage takes one arg");
|
||||
storage = navigator.getDeviceStorage("kilimanjaro");
|
||||
ok(!storage, "kilimanjaro - Should not have this type of storage");
|
||||
|
||||
storage = navigator.getDeviceStorage("testing");
|
||||
ok(storage, "testing - Should have getDeviceStorage");
|
||||
storage = navigator.getDeviceStorage("temp");
|
||||
ok(storage, "temp - Should have getDeviceStorage");
|
||||
|
||||
storage = navigator.getDeviceStorage("profile");
|
||||
ok(storage, "profile - Should have getDeviceStorage");
|
||||
|
||||
var cursor = storage[0].enumerate();
|
||||
ok(cursor, "Should have a non-null cursor");
|
||||
|
||||
devicestorage_cleanup();
|
||||
var i = 4;
|
||||
cursor.onsuccess = function(e) {
|
||||
i = i - 1;
|
||||
if (i > 0) {
|
||||
ok(true, "onsuccess was called");
|
||||
e.target.continue();
|
||||
}
|
||||
else {
|
||||
ok(true, "onsuccess was called 4 times");
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
cursor.onerror = function(e) {
|
||||
ok(false, "onerror was called : " + e.target.error.name);
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
@ -79,14 +79,12 @@
|
||||
#endif
|
||||
|
||||
#include "mozilla/dom/sms/SmsChild.h"
|
||||
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
|
||||
|
||||
using namespace mozilla::hal_sandbox;
|
||||
using namespace mozilla::ipc;
|
||||
using namespace mozilla::net;
|
||||
using namespace mozilla::places;
|
||||
using namespace mozilla::docshell;
|
||||
using namespace mozilla::dom::devicestorage;
|
||||
using namespace mozilla::dom::sms;
|
||||
using namespace mozilla::dom::indexedDB;
|
||||
|
||||
@ -488,19 +486,6 @@ ContentChild::DeallocPAudio(PAudioChild* doomed)
|
||||
return true;
|
||||
}
|
||||
|
||||
PDeviceStorageRequestChild*
|
||||
ContentChild::AllocPDeviceStorageRequest(const DeviceStorageParams& aParams)
|
||||
{
|
||||
return new DeviceStorageRequestChild();
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::DeallocPDeviceStorageRequest(PDeviceStorageRequestChild* aDeviceStorage)
|
||||
{
|
||||
delete aDeviceStorage;
|
||||
return true;
|
||||
}
|
||||
|
||||
PNeckoChild*
|
||||
ContentChild::AllocPNecko()
|
||||
{
|
||||
|
@ -59,9 +59,6 @@ public:
|
||||
const bool& aIsBrowserFrame);
|
||||
virtual bool DeallocPBrowser(PBrowserChild*);
|
||||
|
||||
virtual PDeviceStorageRequestChild* AllocPDeviceStorageRequest(const DeviceStorageParams&);
|
||||
virtual bool DeallocPDeviceStorageRequest(PDeviceStorageRequestChild*);
|
||||
|
||||
virtual PCrashReporterChild*
|
||||
AllocPCrashReporter(const mozilla::dom::NativeThreadId& id,
|
||||
const PRUint32& processType);
|
||||
|
@ -76,13 +76,8 @@
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "mozilla/dom/sms/SmsParent.h"
|
||||
#include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h"
|
||||
#include "nsDebugImpl.h"
|
||||
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "IDBFactory.h"
|
||||
#include "IndexedDatabaseManager.h"
|
||||
#include "IndexedDBParent.h"
|
||||
@ -97,7 +92,6 @@ using namespace mozilla::net;
|
||||
using namespace mozilla::places;
|
||||
using mozilla::unused; // heh
|
||||
using base::KillProcess;
|
||||
using namespace mozilla::dom::devicestorage;
|
||||
using namespace mozilla::dom::sms;
|
||||
using namespace mozilla::dom::indexedDB;
|
||||
|
||||
@ -781,19 +775,6 @@ ContentParent::DeallocPBrowser(PBrowserParent* frame)
|
||||
return true;
|
||||
}
|
||||
|
||||
PDeviceStorageRequestParent*
|
||||
ContentParent::AllocPDeviceStorageRequest(const DeviceStorageParams& aParams)
|
||||
{
|
||||
return new DeviceStorageRequestParent(aParams);
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::DeallocPDeviceStorageRequest(PDeviceStorageRequestParent* doomed)
|
||||
{
|
||||
delete doomed;
|
||||
return true;
|
||||
}
|
||||
|
||||
PCrashReporterParent*
|
||||
ContentParent::AllocPCrashReporter(const NativeThreadId& tid,
|
||||
const PRUint32& processType)
|
||||
|
@ -110,9 +110,6 @@ private:
|
||||
virtual PBrowserParent* AllocPBrowser(const PRUint32& aChromeFlags, const bool& aIsBrowserFrame);
|
||||
virtual bool DeallocPBrowser(PBrowserParent* frame);
|
||||
|
||||
virtual PDeviceStorageRequestParent* AllocPDeviceStorageRequest(const DeviceStorageParams&);
|
||||
virtual bool DeallocPDeviceStorageRequest(PDeviceStorageRequestParent*);
|
||||
|
||||
virtual PCrashReporterParent* AllocPCrashReporter(const NativeThreadId& tid,
|
||||
const PRUint32& processType);
|
||||
virtual bool DeallocPCrashReporter(PCrashReporterParent* crashreporter);
|
||||
|
@ -77,7 +77,6 @@ LOCAL_INCLUDES += \
|
||||
-I$(topsrcdir)/toolkit/xre \
|
||||
-I$(topsrcdir)/hal/sandbox \
|
||||
-I$(topsrcdir)/dom/sms/src/ipc \
|
||||
-I$(topsrcdir)/dom/devicestorage \
|
||||
$(NULL)
|
||||
|
||||
DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
|
||||
|
@ -7,7 +7,6 @@
|
||||
include protocol PAudio;
|
||||
include protocol PBrowser;
|
||||
include protocol PCrashReporter;
|
||||
include protocol PDeviceStorageRequest;
|
||||
include protocol PExternalHelperApp;
|
||||
include protocol PHal;
|
||||
include protocol PIndexedDB;
|
||||
@ -66,36 +65,6 @@ struct FontListEntry {
|
||||
PRUint8 index;
|
||||
};
|
||||
|
||||
struct DeviceStorageAddParams
|
||||
{
|
||||
nsString fullpath;
|
||||
PRUint8[] bits;
|
||||
};
|
||||
|
||||
struct DeviceStorageGetParams
|
||||
{
|
||||
nsString fullpath;
|
||||
};
|
||||
|
||||
struct DeviceStorageDeleteParams
|
||||
{
|
||||
nsString fullpath;
|
||||
};
|
||||
|
||||
struct DeviceStorageEnumerationParams
|
||||
{
|
||||
nsString fullpath;
|
||||
PRUint32 since;
|
||||
};
|
||||
|
||||
union DeviceStorageParams
|
||||
{
|
||||
DeviceStorageAddParams;
|
||||
DeviceStorageGetParams;
|
||||
DeviceStorageDeleteParams;
|
||||
DeviceStorageEnumerationParams;
|
||||
};
|
||||
|
||||
rpc protocol PContent
|
||||
{
|
||||
manages PAudio;
|
||||
@ -163,8 +132,6 @@ child:
|
||||
parent:
|
||||
PAudio(PRInt32 aNumChannels, PRInt32 aRate, PRInt32 aFormat);
|
||||
|
||||
PDeviceStorageRequest(DeviceStorageParams params);
|
||||
|
||||
sync PCrashReporter(NativeThreadId tid, PRUint32 processType);
|
||||
|
||||
PHal();
|
||||
|
@ -23,7 +23,6 @@ EXPORT_LIBRARY = 1
|
||||
##
|
||||
IPDLDIRS = \
|
||||
uriloader/exthandler \
|
||||
dom/devicestorage \
|
||||
dom/indexedDB/ipc \
|
||||
dom/plugins/ipc \
|
||||
dom/ipc \
|
||||
|
Loading…
Reference in New Issue
Block a user