Bug 530901. Fix a warning and align an error code with the spec. r=jst a=jst
authorJonas Sicking <jonas@sicking.cc>
Tue, 24 Nov 2009 17:53:17 -0800
changeset 35227 3ca32b7c0d214aba5b1aab38f854b5a4206a647f
parent 35226 47477a31989f6d3d2d2109b627ea1068769ffe0f
child 35228 0573fb2293c016149ca31e5995c1124fa28e5be8
push idunknown
push userunknown
push dateunknown
reviewersjst, jst
bugs530901
milestone1.9.3a1pre
Bug 530901. Fix a warning and align an error code with the spec. r=jst a=jst
content/base/public/nsIDOMFileError.idl
content/base/src/nsDOMFileReader.cpp
content/base/src/nsDOMFileReader.h
--- a/content/base/public/nsIDOMFileError.idl
+++ b/content/base/public/nsIDOMFileError.idl
@@ -39,14 +39,14 @@
 
 [scriptable, uuid(4BDAFB64-15E2-49C1-A090-4315A7884A56)]
 interface nsIDOMFileError : nsISupports
 {
   //File error codes
   const unsigned short NOT_FOUND_ERR = 8;
   const unsigned short NOT_READABLE_ERR = 24;
   const unsigned short SECURITY_ERR = 18;
-  const unsigned short ABORT_ERR = 25;
+  const unsigned short ABORT_ERR = 20;
   const unsigned short ENCODING_ERR = 26;
 
   readonly attribute unsigned short code;
 };
 
--- a/content/base/src/nsDOMFileReader.cpp
+++ b/content/base/src/nsDOMFileReader.cpp
@@ -118,20 +118,16 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
   NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
   NS_INTERFACE_MAP_ENTRY(nsICharsetDetectionObserver)
   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(FileReader)
 NS_INTERFACE_MAP_END_INHERITING(nsXHREventTarget)
 
 NS_IMPL_ADDREF_INHERITED(nsDOMFileReader, nsXHREventTarget)
 NS_IMPL_RELEASE_INHERITED(nsDOMFileReader, nsXHREventTarget)
 
-static const PRUint32 FILE_AS_BINARY   = 1;
-static const PRUint32 FILE_AS_TEXT     = 2;
-static const PRUint32 FILE_AS_DATAURL  = 3;
-
 NS_IMETHODIMP
 nsDOMFileReader::GetOnloadend(nsIDOMEventListener** aOnloadend)
 {
   return GetInnerEventListener(mOnLoadEndListener, aOnloadend);
 }
 
 NS_IMETHODIMP
 nsDOMFileReader::SetOnloadend(nsIDOMEventListener* aOnloadend)
@@ -148,17 +144,17 @@ nsDOMFileReader::Notify(const char *aCha
   CopyASCIItoUTF16(aCharset, mCharset);
   return NS_OK;
 }
 
 //nsDOMFileReader constructors/initializers
 
 nsDOMFileReader::nsDOMFileReader()
   : mFileData(nsnull),
-    mDataLen(0), mDataFormat(0),
+    mDataLen(0), mDataFormat(FILE_AS_BINARY),
     mReadyState(nsIDOMFileReader::EMPTY),
     mProgressEventWasDelayed(PR_FALSE),
     mTimerIsActive(PR_FALSE),
     mReadTotal(0), mReadTransferred(0)
 {
   nsLayoutStatics::AddRef();
 }
 
@@ -449,46 +445,49 @@ nsDOMFileReader::OnStopRequest(nsIReques
 
   //Set the status field as appropriate
   if (NS_FAILED(aStatus)) {
     FreeFileData();
     DispatchError(aStatus);
     return NS_OK;
   }
 
-  nsresult rv;
+  nsresult rv = NS_OK;
   switch (mDataFormat) {
     case FILE_AS_BINARY:
       break; //Already accumulated mResult
     case FILE_AS_TEXT:
       rv = GetAsText(mCharset, mFileData, mDataLen, mResult);
       break;
     case FILE_AS_DATAURL:
       rv = GetAsDataURL(mFile, mFileData, mDataLen, mResult);
       break;
-    default:
-     return NS_ERROR_FAILURE;
   }
 
   FreeFileData();
 
+  if (NS_FAILED(rv)) {
+    DispatchError(rv);
+    return NS_OK;
+  }
+
   //Dispatch load event to signify end of a successful load
   DispatchProgressEvent(NS_LITERAL_STRING(LOAD_STR));
   DispatchProgressEvent(NS_LITERAL_STRING(LOADEND_STR));
 
-  return rv;
+  return NS_OK;
 }
 
 // Helper methods
 
 nsresult
 nsDOMFileReader::ReadFileContent(nsIDOMFile* aFile,
                                  const nsAString &aCharset,
-                                 PRUint32 aDataFormat)
-{ 
+                                 eDataFormat aDataFormat)
+{
   NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
 
   //Implicit abort to clear any other activity going on
   Abort();
   mError = nsnull;
   SetDOMStringToNull(mResult);
   mReadTransferred = 0;
   mReadTotal = 0;
--- a/content/base/src/nsDOMFileReader.h
+++ b/content/base/src/nsDOMFileReader.h
@@ -106,17 +106,23 @@ public:
   // nsICharsetDetectionObserver
   NS_IMETHOD Notify(const char *aCharset, nsDetectionConfident aConf);
 
   void DispatchProgressEvent(const nsAString& aType);
 
   nsresult Init();
 
 protected:
-  nsresult ReadFileContent(nsIDOMFile *aFile, const nsAString &aCharset, PRUint32 aDataFormat); 
+  enum eDataFormat {
+    FILE_AS_BINARY,
+    FILE_AS_TEXT,
+    FILE_AS_DATAURL
+  };
+
+  nsresult ReadFileContent(nsIDOMFile *aFile, const nsAString &aCharset, eDataFormat aDataFormat); 
   nsresult GetAsText(const nsAString &aCharset,
                      const char *aFileData, PRUint32 aDataLen, nsAString &aResult);
   nsresult GetAsDataURL(nsIFile *aFile, const char *aFileData, PRUint32 aDataLen, nsAString &aResult); 
   nsresult GuessCharset(const char *aFileData, PRUint32 aDataLen, nsACString &aCharset); 
   nsresult ConvertStream(const char *aFileData, PRUint32 aDataLen, const char *aCharset, nsAString &aResult); 
   void DispatchError(nsresult rv);
   void StartProgressEventTimer();
 
@@ -125,17 +131,18 @@ protected:
     mFileData = nsnull;
     mDataLen = 0;
   }
 
   char *mFileData;
   nsCOMPtr<nsIFile> mFile;
   nsString mCharset;
   PRUint32 mDataLen;
-  PRUint32 mDataFormat;
+
+  eDataFormat mDataFormat;
 
   nsString mResult;
   PRUint16 mReadyState;
 
   PRBool mProgressEventWasDelayed;
   PRBool mTimerIsActive;
   nsCOMPtr<nsIDOMFileError> mError;