From 76717d985fd39074c12ca1cc936ee3d495babbd1 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 26 Jun 2012 05:51:24 -0700 Subject: [PATCH] Bug 767905 - device storage - Move editable flag into DeviceStorageFile. r=bent --- dom/devicestorage/nsDeviceStorage.cpp | 51 +++++++++++++-------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index 5a9c20b3625..2a877c60e54 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -28,9 +28,11 @@ public: nsCOMPtr mFile; nsString mPath; + bool mEditable; DeviceStorageFile(nsIFile* aFile, const nsAString& aPath) : mPath(aPath) + , mEditable(false) { NS_ASSERTION(aFile, "Must not create a DeviceStorageFile with a null nsIFile"); // always take a clone @@ -43,6 +45,7 @@ public: } DeviceStorageFile(nsIFile* aFile) + : mEditable(false) { NS_ASSERTION(aFile, "Must not create a DeviceStorageFile with a null nsIFile"); // always take a clone @@ -56,6 +59,11 @@ public: NormalizeFilePath(); } + void + setEditable(bool aEditable) { + mEditable = aEditable; + } + NS_DECL_ISUPPORTS // we want to make sure that the names of file can't reach @@ -220,12 +228,12 @@ nsDOMDeviceStorage::SetRootFileForType(const nsAString& aType, const PRInt32 aIn return typeResult; } -static jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile, bool aEditable) +static jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aWindow, "Null Window"); - if (aEditable) { + if (aFile->mEditable) { // TODO - needs janv's file handle support. return JSVAL_NULL; } @@ -309,7 +317,6 @@ public: nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow, nsIURI* aURI, DeviceStorageFile* aFile, - bool aEditable, PRUint64 aSince); private: @@ -321,7 +328,6 @@ protected: bool mOkToCallContinue; nsRefPtr mFile; nsCOMPtr mURI; - bool mEditable; PRUint64 mSince; // to access mFiles @@ -453,7 +459,7 @@ public: else { nsRefPtr file = cursor->mFiles[0]; cursor->mFiles.RemoveElementAt(0); - val = nsIFileToJsval(cursor->GetOwner(), file, cursor->mEditable); + val = nsIFileToJsval(cursor->GetOwner(), file); cursor->mOkToCallContinue = true; } @@ -578,13 +584,11 @@ NS_IMPL_RELEASE_INHERITED(nsDOMDeviceStorageCursor, DOMRequest) nsDOMDeviceStorageCursor::nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow, nsIURI* aURI, DeviceStorageFile* aFile, - bool aEditable, PRUint64 aSince) : DOMRequest(aWindow) , mOkToCallContinue(false) , mFile(aFile) , mURI(aURI) - , mEditable(aEditable) , mSince(aSince) { } @@ -677,9 +681,8 @@ nsDOMDeviceStorageCursor::Continue() class PostResultEvent : public nsRunnable { public: - PostResultEvent(nsRefPtr& aRequest, bool aEditable, DeviceStorageFile* aFile) - : mEditable(aEditable) - , mFile(aFile) + PostResultEvent(nsRefPtr& aRequest, DeviceStorageFile* aFile) + : mFile(aFile) { mRequest.swap(aRequest); } @@ -698,7 +701,7 @@ public: jsval result = JSVAL_NULL; if (mFile) { - result = nsIFileToJsval(mRequest->GetOwner(), mFile, mEditable); + result = nsIFileToJsval(mRequest->GetOwner(), mFile); } else { result = StringToJsval(mRequest->GetOwner(), mPath); } @@ -709,7 +712,6 @@ public: } private: - bool mEditable; nsRefPtr mFile; nsString mPath; nsRefPtr mRequest; @@ -808,16 +810,12 @@ private: nsRefPtr mFile; nsRefPtr mRequest; }; - - class ReadFileEvent : public nsRunnable { public: ReadFileEvent(DeviceStorageFile* aFile, - bool aEditable, nsRefPtr& aRequest) : mFile(aFile) - , mEditable(aEditable) { mRequest.swap(aRequest); } @@ -830,7 +828,7 @@ public: nsRefPtr r; - if (!mEditable) { + if (!mFile->mEditable) { bool check = false; mFile->mFile->Exists(&check); if (!check) { @@ -839,7 +837,7 @@ public: } if (!r) { - r = new PostResultEvent(mRequest, mEditable, mFile); + r = new PostResultEvent(mRequest, mFile); } NS_DispatchToMainThread(r); return NS_OK; @@ -847,7 +845,6 @@ public: private: nsRefPtr mFile; - bool mEditable; nsRefPtr mRequest; }; @@ -902,14 +899,12 @@ public: nsIURI *aURI, DeviceStorageFile *aFile, DOMRequest* aRequest, - bool aEditable, nsIDOMBlob *aBlob = nsnull) : mRequestType(aRequestType) , mWindow(aWindow) , mURI(aURI) , mFile(aFile) , mRequest(aRequest) - , mEditable(aEditable) , mBlob(aBlob) {} NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -982,7 +977,7 @@ public: } case DEVICE_STORAGE_REQUEST_READ: { - r = new ReadFileEvent(mFile, mEditable, mRequest); + r = new ReadFileEvent(mFile, mRequest); break; } case DEVICE_STORAGE_REQUEST_DELETE: @@ -1007,7 +1002,6 @@ private: nsRefPtr mFile; nsRefPtr mRequest; - bool mEditable; nsCOMPtr mBlob; }; @@ -1165,7 +1159,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob, } else { r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_WRITE, - win, mURI, dsf, request, true, aBlob); + win, mURI, dsf, request, aBlob); } NS_DispatchToMainThread(r); return NS_OK; @@ -1215,12 +1209,13 @@ nsDOMDeviceStorage::GetInternal(const JS::Value & aPath, } nsRefPtr dsf = new DeviceStorageFile(mFile, path); + dsf->setEditable(aEditable); if (!dsf->isSafePath()) { r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf); } else { r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_READ, - win, mURI, dsf, request, aEditable); + win, mURI, dsf, request); } NS_DispatchToMainThread(r); return NS_OK; @@ -1255,7 +1250,7 @@ nsDOMDeviceStorage::Delete(const JS::Value & aPath, JSContext* aCx, nsIDOMDOMReq } else { r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_DELETE, - win, mURI, dsf, request, true); + win, mURI, dsf, request); } NS_DispatchToMainThread(r); return NS_OK; @@ -1336,7 +1331,9 @@ nsDOMDeviceStorage::EnumerateInternal(const JS::Value & aName, } nsRefPtr dsf = new DeviceStorageFile(mFile, path); - nsRefPtr cursor = new nsDOMDeviceStorageCursor(win, mURI, dsf, aEditable, since); + dsf->setEditable(aEditable); + + nsRefPtr cursor = new nsDOMDeviceStorageCursor(win, mURI, dsf, since); nsRefPtr r = new DeviceStorageCursorRequest(cursor); NS_ADDREF(*aRetval = cursor);