nsresult FileReader::OnLoadEnd(nsresult aStatus) { // Cancel the progress event timer ClearProgressEventTimer(); // FileReader must be in DONE stage after an operation mReadyState = DONE; nsAutoString successEvent, termEvent; nsresult rv = DoOnLoadEnd(aStatus, successEvent, termEvent); NS_ENSURE_SUCCESS(rv, rv); // Set the status field as appropriate if (NS_FAILED(aStatus)) { DispatchError(aStatus, termEvent); return NS_OK; } // Dispatch event to signify end of a successful operation DispatchProgressEvent(successEvent); DispatchProgressEvent(termEvent); return NS_OK; }
void FileReader::Abort(ErrorResult& aRv) { if (mReadyState != LOADING) { // XXX The spec doesn't say this aRv.Throw(NS_ERROR_DOM_FILE_ABORT_ERR); return; } ClearProgressEventTimer(); mReadyState = DONE; // XXX The spec doesn't say this mError = new DOMError(GetOwner(), NS_LITERAL_STRING("AbortError")); // Revert status and result attributes SetDOMStringToNull(mResult); mResultArrayBuffer = nullptr; mAsyncStream = nullptr; mBlob = nullptr; //Clean up memory buffer FreeFileData(); // Dispatch the events DispatchProgressEvent(NS_LITERAL_STRING(ABORT_STR)); DispatchProgressEvent(NS_LITERAL_STRING(LOADEND_STR)); }
NS_IMETHODIMP FileIOObject::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, nsresult aStatus) { // If we're here as a result of a call from Abort(), // simply ignore the request. if (aRequest != mChannel) return NS_OK; // Cancel the progress event timer ClearProgressEventTimer(); // FileIOObject must be in DONE stage after an operation mReadyState = 2; nsString successEvent, termEvent; nsresult rv = DoOnStopRequest(aRequest, aContext, aStatus, successEvent, termEvent); NS_ENSURE_SUCCESS(rv, rv); // Set the status field as appropriate if (NS_FAILED(aStatus)) { DispatchError(aStatus, termEvent); return NS_OK; } // Dispatch event to signify end of a successful operation DispatchProgressEvent(successEvent); DispatchProgressEvent(termEvent); return NS_OK; }
void FileReader::Abort() { if (mReadyState == EMPTY || mReadyState == DONE) { return; } MOZ_ASSERT(mReadyState == LOADING); ClearProgressEventTimer(); mReadyState = DONE; // XXX The spec doesn't say this mError = DOMException::Create(NS_ERROR_DOM_ABORT_ERR); // Revert status and result attributes SetDOMStringToNull(mResult); mResultArrayBuffer = nullptr; mAsyncStream = nullptr; mBlob = nullptr; //Clean up memory buffer FreeFileData(); // Dispatch the events DispatchProgressEvent(NS_LITERAL_STRING(ABORT_STR)); DispatchProgressEvent(NS_LITERAL_STRING(LOADEND_STR)); }
nsresult FileReader::OnLoadEnd(nsresult aStatus) { // Cancel the progress event timer ClearProgressEventTimer(); // FileReader must be in DONE stage after an operation mReadyState = DONE; // Quick return, if failed. if (NS_FAILED(aStatus)) { FreeDataAndDispatchError(aStatus); return NS_OK; } // In case we read a different number of bytes, we can assume that the // underlying storage has changed. We should not continue. if (mDataLen != mTotal) { FreeDataAndDispatchError(NS_ERROR_FAILURE); return NS_OK; } // ArrayBuffer needs a custom handling. if (mDataFormat == FILE_AS_ARRAYBUFFER) { OnLoadEndArrayBuffer(); return NS_OK; } nsresult rv = NS_OK; // We don't do anything special for Binary format. if (mDataFormat == FILE_AS_DATAURL) { rv = GetAsDataURL(mBlob, mFileData, mDataLen, mResult); } else if (mDataFormat == FILE_AS_TEXT) { if (!mFileData && mDataLen) { rv = NS_ERROR_OUT_OF_MEMORY; } else if (!mFileData) { rv = GetAsText(mBlob, mCharset, "", mDataLen, mResult); } else { rv = GetAsText(mBlob, mCharset, mFileData, mDataLen, mResult); } } if (NS_WARN_IF(NS_FAILED(rv))) { FreeDataAndDispatchError(rv); return NS_OK; } FreeDataAndDispatchSuccess(); return NS_OK; }
void FileIOObject::Abort(ErrorResult& aRv) { if (mReadyState != 1) { // XXX The spec doesn't say this aRv.Throw(NS_ERROR_DOM_FILE_ABORT_ERR); return; } ClearProgressEventTimer(); mReadyState = 2; // There are DONE constants on multiple interfaces, // but they all have value 2. // XXX The spec doesn't say this mError = new DOMError(GetOwner(), NS_LITERAL_STRING("AbortError")); nsString finalEvent; DoAbort(finalEvent); // Dispatch the events DispatchProgressEvent(NS_LITERAL_STRING(ABORT_STR)); DispatchProgressEvent(finalEvent); }
NS_IMETHODIMP FileIOObject::Abort() { if (mReadyState != 1) { // XXX The spec doesn't say this return NS_ERROR_DOM_FILE_ABORT_ERR; } ClearProgressEventTimer(); mReadyState = 2; // There are DONE constants on multiple interfaces, // but they all have value 2. // XXX The spec doesn't say this mError = DOMError::CreateWithName(NS_LITERAL_STRING("AbortError")); nsString finalEvent; nsresult rv = DoAbort(finalEvent); // Dispatch the events DispatchProgressEvent(NS_LITERAL_STRING(ABORT_STR)); DispatchProgressEvent(finalEvent); return rv; }