diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index e2ca9778d9d8..e12665c9e446 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -851,44 +851,20 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END class PostErrorEvent : public nsRunnable { public: - PostErrorEvent(nsRefPtr& aRequest, const char* aMessage, DeviceStorageFile* aFile) + PostErrorEvent(nsRefPtr& 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 event = new PostErrorEvent(mRequest, - POST_ERROR_EVENT_FILE_NOT_ENUMERABLE, - mFile); + nsCOMPtr 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 event = new PostErrorEvent(this, - POST_ERROR_EVENT_PERMISSION_DENIED, - mFile); + nsCOMPtr 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 r = new PostErrorEvent(this, - POST_ERROR_EVENT_ILLEGAL_FILE_NAME, - mFile); + nsCOMPtr 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 event = new PostErrorEvent(mRequest, - POST_ERROR_EVENT_FILE_EXISTS, - mFile); + nsCOMPtr 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 event = new PostErrorEvent(mRequest, - POST_ERROR_EVENT_UNKNOWN, - mFile); + nsCOMPtr 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 event = new PostErrorEvent(mRequest, - POST_ERROR_EVENT_PERMISSION_DENIED, - mFile); + nsCOMPtr event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_PERMISSION_DENIED); NS_DispatchToMainThread(event); return NS_OK; } @@ -1849,10 +1813,10 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob, nsRefPtr 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 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 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 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 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, diff --git a/dom/devicestorage/nsDeviceStorage.h b/dom/devicestorage/nsDeviceStorage.h index dfed1661e962..279c2977b0db 100644 --- a/dom/devicestorage/nsDeviceStorage.h +++ b/dom/devicestorage/nsDeviceStorage.h @@ -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; diff --git a/dom/devicestorage/test/test_addCorrectType.html b/dom/devicestorage/test/test_addCorrectType.html index 2920840f91ea..1a4cd8b3f483 100644 --- a/dom/devicestorage/test/test_addCorrectType.html +++ b/dom/devicestorage/test/test_addCorrectType.html @@ -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(); } diff --git a/dom/devicestorage/test/test_basic.html b/dom/devicestorage/test/test_basic.html index 23ce6c142407..28e453740bea 100644 --- a/dom/devicestorage/test/test_basic.html +++ b/dom/devicestorage/test/test_basic.html @@ -13,7 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103 - + Mozilla Bug 717103