mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 767905 - device storage - Move editable flag into DeviceStorageFile. r=bent
This commit is contained in:
parent
0ae48cfd1f
commit
76717d985f
@ -28,9 +28,11 @@ public:
|
||||
|
||||
nsCOMPtr<nsIFile> 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<DeviceStorageFile> mFile;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
bool mEditable;
|
||||
PRUint64 mSince;
|
||||
|
||||
// to access mFiles
|
||||
@ -453,7 +459,7 @@ public:
|
||||
else {
|
||||
nsRefPtr<DeviceStorageFile> 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<DOMRequest>& aRequest, bool aEditable, DeviceStorageFile* aFile)
|
||||
: mEditable(aEditable)
|
||||
, mFile(aFile)
|
||||
PostResultEvent(nsRefPtr<DOMRequest>& 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<DeviceStorageFile> mFile;
|
||||
nsString mPath;
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
@ -808,16 +810,12 @@ private:
|
||||
nsRefPtr<DeviceStorageFile> mFile;
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
};
|
||||
|
||||
|
||||
class ReadFileEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ReadFileEvent(DeviceStorageFile* aFile,
|
||||
bool aEditable,
|
||||
nsRefPtr<DOMRequest>& aRequest)
|
||||
: mFile(aFile)
|
||||
, mEditable(aEditable)
|
||||
{
|
||||
mRequest.swap(aRequest);
|
||||
}
|
||||
@ -830,7 +828,7 @@ public:
|
||||
|
||||
nsRefPtr<nsRunnable> 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<DeviceStorageFile> mFile;
|
||||
bool mEditable;
|
||||
nsRefPtr<DOMRequest> 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<DeviceStorageFile> mFile;
|
||||
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
bool mEditable;
|
||||
nsCOMPtr<nsIDOMBlob> 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<DeviceStorageFile> 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<DeviceStorageFile> dsf = new DeviceStorageFile(mFile, path);
|
||||
nsRefPtr<nsDOMDeviceStorageCursor> cursor = new nsDOMDeviceStorageCursor(win, mURI, dsf, aEditable, since);
|
||||
dsf->setEditable(aEditable);
|
||||
|
||||
nsRefPtr<nsDOMDeviceStorageCursor> cursor = new nsDOMDeviceStorageCursor(win, mURI, dsf, since);
|
||||
nsRefPtr<DeviceStorageCursorRequest> r = new DeviceStorageCursorRequest(cursor);
|
||||
|
||||
NS_ADDREF(*aRetval = cursor);
|
||||
|
Loading…
Reference in New Issue
Block a user