diff --git a/dom/devicestorage/DeviceStorageRequestParent.cpp b/dom/devicestorage/DeviceStorageRequestParent.cpp index c5252a1d581..4e19c6f1e85 100644 --- a/dom/devicestorage/DeviceStorageRequestParent.cpp +++ b/dom/devicestorage/DeviceStorageRequestParent.cpp @@ -248,14 +248,6 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun() return NS_OK; } - bool check = false; - mFile->mFile->Exists(&check); - if (check) { - nsCOMPtr event = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS); - NS_DispatchToMainThread(event); - return NS_OK; - } - nsresult rv = mFile->Write(mInputStream); if (NS_FAILED(rv)) { diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index e12665c9e44..d15b46b4b15 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -851,20 +851,44 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END class PostErrorEvent : public nsRunnable { public: - PostErrorEvent(nsRefPtr& aRequest, const char* aMessage) + PostErrorEvent(nsRefPtr& aRequest, const char* aMessage, DeviceStorageFile* aFile) { mRequest.swap(aRequest); - CopyASCIItoUTF16(aMessage, mError); + BuildErrorString(aMessage, aFile); } - PostErrorEvent(DOMRequest* aRequest, const char* aMessage) + PostErrorEvent(DOMRequest* aRequest, const char* aMessage, DeviceStorageFile* aFile) : mRequest(aRequest) { - CopyASCIItoUTF16(aMessage, mError); + BuildErrorString(aMessage, aFile); } ~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!"); @@ -982,7 +1006,9 @@ public: bool check; mFile->mFile->IsDirectory(&check); if (!check) { - nsCOMPtr event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_NOT_ENUMERABLE); + nsCOMPtr event = new PostErrorEvent(mRequest, + POST_ERROR_EVENT_FILE_NOT_ENUMERABLE, + mFile); NS_DispatchToMainThread(event); return NS_OK; } @@ -1067,7 +1093,9 @@ nsDOMDeviceStorageCursor::GetElement(nsIDOMElement * *aRequestingElement) NS_IMETHODIMP nsDOMDeviceStorageCursor::Cancel() { - nsCOMPtr event = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED); + nsCOMPtr event = new PostErrorEvent(this, + POST_ERROR_EVENT_PERMISSION_DENIED, + mFile); NS_DispatchToMainThread(event); return NS_OK; } @@ -1076,7 +1104,9 @@ NS_IMETHODIMP nsDOMDeviceStorageCursor::Allow() { if (!mFile->IsSafePath()) { - nsCOMPtr r = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED); + nsCOMPtr r = new PostErrorEvent(this, + POST_ERROR_EVENT_ILLEGAL_FILE_NAME, + mFile); NS_DispatchToMainThread(r); return NS_OK; } @@ -1255,20 +1285,14 @@ public: nsCOMPtr stream; mBlob->GetInternalStream(getter_AddRefs(stream)); - bool check = false; - mFile->mFile->Exists(&check); - if (check) { - nsCOMPtr event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_EXISTS); - NS_DispatchToMainThread(event); - return NS_OK; - } - nsresult rv = mFile->Write(stream); if (NS_FAILED(rv)) { mFile->mFile->Remove(false); - nsCOMPtr event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_UNKNOWN); + nsCOMPtr event = new PostErrorEvent(mRequest, + POST_ERROR_EVENT_UNKNOWN, + mFile); NS_DispatchToMainThread(event); return NS_OK; } @@ -1305,7 +1329,7 @@ public: bool check = false; mFile->mFile->Exists(&check); if (!check) { - r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); + r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST, mFile); } } @@ -1342,7 +1366,7 @@ public: bool check = false; mFile->mFile->Exists(&check); if (check) { - r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); + r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST, mFile); } else { r = new PostResultEvent(mRequest, mFile->mPath); @@ -1503,7 +1527,9 @@ public: NS_IMETHOD Cancel() { - nsCOMPtr event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_PERMISSION_DENIED); + nsCOMPtr event = new PostErrorEvent(mRequest, + POST_ERROR_EVENT_PERMISSION_DENIED, + mFile); NS_DispatchToMainThread(event); return NS_OK; } @@ -1813,10 +1839,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); + r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE, dsf); } else if (!dsf->IsSafePath()) { - r = new PostErrorEvent(request, POST_ERROR_EVENT_PERMISSION_DENIED); + r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf); } else { r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_WRITE, @@ -1862,7 +1888,10 @@ nsDOMDeviceStorage::GetInternal(const JS::Value & aPath, JSString* jsstr = JS_ValueToString(aCx, aPath); nsDependentJSString path; if (!path.init(aCx, jsstr)) { - r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN); + nsRefPtr dsf = new DeviceStorageFile(mStorageType, mRootDirectory); + r = new PostErrorEvent(request, + POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED, + dsf); NS_DispatchToMainThread(r); return NS_OK; } @@ -1870,7 +1899,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_PERMISSION_DENIED); + r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf); } else { r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_READ, win, mPrincipal, dsf, request); @@ -1895,7 +1924,8 @@ nsDOMDeviceStorage::Delete(const JS::Value & aPath, JSContext* aCx, nsIDOMDOMReq JSString* jsstr = JS_ValueToString(aCx, aPath); nsDependentJSString path; if (!path.init(aCx, jsstr)) { - r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN); + nsRefPtr dsf = new DeviceStorageFile(mStorageType, mRootDirectory); + r = new PostErrorEvent(request, POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED, dsf); NS_DispatchToMainThread(r); return NS_OK; } @@ -1903,7 +1933,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_PERMISSION_DENIED); + r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf); } else { r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_DELETE, diff --git a/dom/devicestorage/nsDeviceStorage.h b/dom/devicestorage/nsDeviceStorage.h index 279c2977b0d..cad3e23e9e6 100644 --- a/dom/devicestorage/nsDeviceStorage.h +++ b/dom/devicestorage/nsDeviceStorage.h @@ -32,12 +32,14 @@ class nsPIDOMWindow; #include "DeviceStorageRequestChild.h" -#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_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_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 1a4cd8b3f48..2920840f91e 100644 --- a/dom/devicestorage/test/test_addCorrectType.html +++ b/dom/devicestorage/test/test_addCorrectType.html @@ -43,8 +43,6 @@ 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 28e453740be..23ce6c14240 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