mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 754350 - Clean up Device Storage error strings. r=sicking
This commit is contained in:
parent
840f053b0f
commit
9b001fcc48
@ -851,44 +851,20 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
class PostErrorEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PostErrorEvent(nsRefPtr<DOMRequest>& aRequest, const char* aMessage, DeviceStorageFile* aFile)
|
||||
PostErrorEvent(nsRefPtr<DOMRequest>& aRequest, const char* aMessage)
|
||||
{
|
||||
mRequest.swap(aRequest);
|
||||
BuildErrorString(aMessage, aFile);
|
||||
CopyASCIItoUTF16(aMessage, mError);
|
||||
}
|
||||
|
||||
PostErrorEvent(DOMRequest* aRequest, const char* aMessage, DeviceStorageFile* aFile)
|
||||
PostErrorEvent(DOMRequest* aRequest, const char* aMessage)
|
||||
: mRequest(aRequest)
|
||||
{
|
||||
BuildErrorString(aMessage, aFile);
|
||||
CopyASCIItoUTF16(aMessage, mError);
|
||||
}
|
||||
|
||||
~PostErrorEvent() {}
|
||||
|
||||
void BuildErrorString(const char* aMessage, DeviceStorageFile* aFile)
|
||||
{
|
||||
nsAutoString fullPath;
|
||||
|
||||
if (aFile && aFile->mFile) {
|
||||
aFile->mFile->GetPath(fullPath);
|
||||
}
|
||||
else {
|
||||
fullPath.Assign(NS_LITERAL_STRING("null file"));
|
||||
}
|
||||
|
||||
mError = NS_ConvertASCIItoUTF16(aMessage);
|
||||
mError.Append(NS_LITERAL_STRING(" file path = "));
|
||||
mError.Append(fullPath.get());
|
||||
mError.Append(NS_LITERAL_STRING(" path = "));
|
||||
|
||||
if (aFile) {
|
||||
mError.Append(aFile->mPath);
|
||||
}
|
||||
else {
|
||||
mError.Append(NS_LITERAL_STRING("null path"));
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
@ -1006,9 +982,7 @@ public:
|
||||
bool check;
|
||||
mFile->mFile->IsDirectory(&check);
|
||||
if (!check) {
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest,
|
||||
POST_ERROR_EVENT_FILE_NOT_ENUMERABLE,
|
||||
mFile);
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_NOT_ENUMERABLE);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1093,9 +1067,7 @@ nsDOMDeviceStorageCursor::GetElement(nsIDOMElement * *aRequestingElement)
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceStorageCursor::Cancel()
|
||||
{
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(this,
|
||||
POST_ERROR_EVENT_PERMISSION_DENIED,
|
||||
mFile);
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1104,9 +1076,7 @@ NS_IMETHODIMP
|
||||
nsDOMDeviceStorageCursor::Allow()
|
||||
{
|
||||
if (!mFile->IsSafePath()) {
|
||||
nsCOMPtr<nsIRunnable> r = new PostErrorEvent(this,
|
||||
POST_ERROR_EVENT_ILLEGAL_FILE_NAME,
|
||||
mFile);
|
||||
nsCOMPtr<nsIRunnable> r = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1288,9 +1258,7 @@ public:
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (check) {
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest,
|
||||
POST_ERROR_EVENT_FILE_EXISTS,
|
||||
mFile);
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_EXISTS);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1300,9 +1268,7 @@ public:
|
||||
if (NS_FAILED(rv)) {
|
||||
mFile->mFile->Remove(false);
|
||||
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest,
|
||||
POST_ERROR_EVENT_UNKNOWN,
|
||||
mFile);
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_UNKNOWN);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1339,7 +1305,7 @@ public:
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (!check) {
|
||||
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST, mFile);
|
||||
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1376,7 +1342,7 @@ public:
|
||||
bool check = false;
|
||||
mFile->mFile->Exists(&check);
|
||||
if (check) {
|
||||
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST, mFile);
|
||||
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
||||
}
|
||||
else {
|
||||
r = new PostResultEvent(mRequest, mFile->mPath);
|
||||
@ -1537,9 +1503,7 @@ public:
|
||||
|
||||
NS_IMETHOD Cancel()
|
||||
{
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest,
|
||||
POST_ERROR_EVENT_PERMISSION_DENIED,
|
||||
mFile);
|
||||
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
NS_DispatchToMainThread(event);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1849,10 +1813,10 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, aPath);
|
||||
if (!typeChecker->Check(mStorageType, dsf->mFile) ||
|
||||
!typeChecker->Check(mStorageType, aBlob)) {
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE, dsf);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE);
|
||||
}
|
||||
else if (!dsf->IsSafePath()) {
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
}
|
||||
else {
|
||||
r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_WRITE,
|
||||
@ -1898,10 +1862,7 @@ nsDOMDeviceStorage::GetInternal(const JS::Value & aPath,
|
||||
JSString* jsstr = JS_ValueToString(aCx, aPath);
|
||||
nsDependentJSString path;
|
||||
if (!path.init(aCx, jsstr)) {
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory);
|
||||
r = new PostErrorEvent(request,
|
||||
POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED,
|
||||
dsf);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1909,7 +1870,7 @@ nsDOMDeviceStorage::GetInternal(const JS::Value & aPath,
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, path);
|
||||
dsf->SetEditable(aEditable);
|
||||
if (!dsf->IsSafePath()) {
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
} else {
|
||||
r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_READ,
|
||||
win, mPrincipal, dsf, request);
|
||||
@ -1934,8 +1895,7 @@ nsDOMDeviceStorage::Delete(const JS::Value & aPath, JSContext* aCx, nsIDOMDOMReq
|
||||
JSString* jsstr = JS_ValueToString(aCx, aPath);
|
||||
nsDependentJSString path;
|
||||
if (!path.init(aCx, jsstr)) {
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED, dsf);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
|
||||
NS_DispatchToMainThread(r);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1943,7 +1903,7 @@ nsDOMDeviceStorage::Delete(const JS::Value & aPath, JSContext* aCx, nsIDOMDOMReq
|
||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, path);
|
||||
|
||||
if (!dsf->IsSafePath()) {
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_PERMISSION_DENIED);
|
||||
}
|
||||
else {
|
||||
r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_DELETE,
|
||||
|
@ -32,15 +32,12 @@ class nsPIDOMWindow;
|
||||
|
||||
#include "DeviceStorageRequestChild.h"
|
||||
|
||||
#define POST_ERROR_EVENT_FILE_EXISTS "File already exists"
|
||||
#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_ILLEGAL_TYPE "Illegal content type"
|
||||
#define POST_ERROR_EVENT_FILE_EXISTS "NoModificationAllowedError"
|
||||
#define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST "NotFoundError"
|
||||
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "TypeMismatchError"
|
||||
#define POST_ERROR_EVENT_PERMISSION_DENIED "SecurityError"
|
||||
#define POST_ERROR_EVENT_ILLEGAL_TYPE "TypeMismatchError"
|
||||
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
||||
#define POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED "Non-string type unsupported"
|
||||
#define POST_ERROR_EVENT_NOT_IMPLEMENTED "Not implemented"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
@ -43,6 +43,8 @@ var tests = [
|
||||
|
||||
function fail(e) {
|
||||
ok(false, "addSuccess was called");
|
||||
ok(e.target.error.name == "TypeMismatchError", "Error must be TypeMismatchError");
|
||||
|
||||
devicestorage_cleanup();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body onunload="unload()">
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
@ -22,15 +22,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
function unload() {
|
||||
delete gDataBlob;
|
||||
gDataBlob = null;
|
||||
|
||||
delete gFileReader;
|
||||
gFileReader = null;
|
||||
}
|
||||
|
||||
|
||||
devicestorage_setup();
|
||||
|
||||
var gFileName = "devicestorage/hi.png";
|
||||
|
@ -45,9 +45,11 @@ function fail(e) {
|
||||
|
||||
function next(e) {
|
||||
|
||||
if (e != undefined)
|
||||
ok(true, "addError was called");
|
||||
|
||||
if (e != undefined) {
|
||||
ok(true, "addError was called");
|
||||
ok(e.target.error.name == "SecurityError", "Error must be SecurityError");
|
||||
}
|
||||
|
||||
var f = tests.pop();
|
||||
|
||||
if (f == undefined) {
|
||||
|
@ -44,6 +44,7 @@ function addOverwritingSuccess(e) {
|
||||
|
||||
function addOverwritingError(e) {
|
||||
ok(true, "Adding to the same location should fail");
|
||||
ok(e.target.error.name == "NoModificationAllowedError", "Error must be NoModificationAllowedError");
|
||||
|
||||
var storage = navigator.getDeviceStorage("pictures");
|
||||
request = storage.delete(filename)
|
||||
|
Loading…
Reference in New Issue
Block a user