Bug 669433 Part 2: Clean up File implementations. Move functions around such that they are grouped with their respective class. No other changes. r=khuey
authorJonas Sicking <jonas@sicking.cc>
Mon, 11 Jul 2011 19:41:44 -0700
changeset 73058 3265ea092f0ffaec0913add8a14f30f4aa07806e
parent 73057 df4de9835c7880aadc0fb1ec3e127efecd03bcf0
child 73059 ab1f4bc0b70a5cf10a45033085c989691c75dd4e
push idunknown
push userunknown
push dateunknown
reviewerskhuey
bugs669433
milestone8.0a1
Bug 669433 Part 2: Clean up File implementations. Move functions around such that they are grouped with their respective class. No other changes. r=khuey
content/base/src/nsDOMFile.cpp
--- a/content/base/src/nsDOMFile.cpp
+++ b/content/base/src/nsDOMFile.cpp
@@ -159,24 +159,16 @@ DOMFileResult(nsresult rv)
 
   if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_FILES) {
     return NS_ERROR_DOM_FILE_NOT_READABLE_ERR;
   }
 
   return rv;
 }
 
-/* static */ nsresult
-nsDOMFileFile::NewFile(nsISupports* *aNewObject)
-{
-  nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMFileFile());
-  file.forget(aNewObject);
-  return NS_OK;
-}
-
 NS_IMETHODIMP
 nsDOMFileBase::GetName(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
   aFileName = mName;
   return NS_OK;
 }
 
@@ -195,93 +187,29 @@ NS_IMETHODIMP
 nsDOMFileBase::GetMozFullPathInternal(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
   aFileName.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMFileFile::GetSize(PRUint64 *aFileSize)
-{
-  if (IsSizeUnknown()) {
-    NS_ASSERTION(mWholeFile,
-                 "Should only use lazy size when using the whole file");
-    PRInt64 fileSize;
-    nsresult rv = mFile->GetFileSize(&fileSize);
-    NS_ENSURE_SUCCESS(rv, rv);
-  
-    if (fileSize < 0) {
-      return NS_ERROR_FAILURE;
-    }
-  
-    mLength = fileSize;
-  }
-
-  *aFileSize = mLength;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMFileFile::GetType(nsAString &aType)
-{
-  if (mContentType.IsVoid()) {
-    NS_ASSERTION(mWholeFile,
-                 "Should only use lazy ContentType when using the whole file");
-    nsresult rv;
-    nsCOMPtr<nsIMIMEService> mimeService =
-      do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCAutoString mimeType;
-    rv = mimeService->GetTypeFromFile(mFile, mimeType);
-    if (NS_FAILED(rv)) {
-      mimeType.Truncate();
-    }
-
-    AppendUTF8toUTF16(mimeType, mContentType);
-    mContentType.SetIsVoid(PR_FALSE);
-  }
-
-  aType = mContentType;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDOMFileBase::GetSize(PRUint64 *aSize)
 {
   *aSize = mLength;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMFileBase::GetType(nsAString &aType)
 {
   aType = mContentType;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDOMFileBase::GetInternalStream(nsIInputStream **aStream)
-{
-  // Must be overridden
-  NS_NOTREACHED("Must override GetInternalStream");
-  
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsDOMFileFile::GetMozFullPathInternal(nsAString &aFilename)
-{
-  NS_ASSERTION(mIsFile, "Should only be called on files");
-  return mFile->GetPath(aFilename);
-}
-
 // Makes sure that aStart and aEnd is less then or equal to aSize and greater
 // than 0
 static void
 ParseSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd)
 {
   CheckedInt64 newStartOffset = aStart;
   if (aStart < -aSize) {
     newStartOffset = 0;
@@ -334,28 +262,23 @@ nsDOMFileBase::MozSlice(PRInt64 aStart, 
   
   // Create the new file
   *aBlob = CreateSlice((PRUint64)aStart, (PRUint64)(aEnd - aStart),
                        aContentType).get();
 
   return *aBlob ? NS_OK : NS_ERROR_UNEXPECTED;
 }
 
-const PRUint32 sFileStreamFlags =
-  nsIFileInputStream::CLOSE_ON_EOF |
-  nsIFileInputStream::REOPEN_ON_REWIND |
-  nsIFileInputStream::DEFER_OPEN;
-
 NS_IMETHODIMP
-nsDOMFileFile::GetInternalStream(nsIInputStream **aStream)
+nsDOMFileBase::GetInternalStream(nsIInputStream **aStream)
 {
-  return mWholeFile ?
-    NS_NewLocalFileInputStream(aStream, mFile, -1, -1, sFileStreamFlags) :
-    NS_NewPartialLocalFileInputStream(aStream, mFile, mStart, mLength,
-                                      -1, -1, sFileStreamFlags);
+  // Must be overridden
+  NS_NOTREACHED("Must override GetInternalStream");
+  
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsDOMFileBase::GetInternalUrl(nsIPrincipal* aPrincipal, nsAString& aURL)
 {
   NS_ENSURE_STATE(aPrincipal);
 
   nsresult rv;
@@ -413,16 +336,93 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsDOMFileFi
 already_AddRefed<nsIDOMBlob>
 nsDOMFileFile::CreateSlice(PRUint64 aStart, PRUint64 aLength,
                            const nsAString& aContentType)
 {
   nsCOMPtr<nsIDOMBlob> t = new nsDOMFileFile(this, aStart, aLength, aContentType);
   return t.forget();
 }
 
+/* static */ nsresult
+nsDOMFileFile::NewFile(nsISupports* *aNewObject)
+{
+  nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMFileFile());
+  file.forget(aNewObject);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDOMFileFile::GetMozFullPathInternal(nsAString &aFilename)
+{
+  NS_ASSERTION(mIsFile, "Should only be called on files");
+  return mFile->GetPath(aFilename);
+}
+
+NS_IMETHODIMP
+nsDOMFileFile::GetSize(PRUint64 *aFileSize)
+{
+  if (IsSizeUnknown()) {
+    NS_ASSERTION(mWholeFile,
+                 "Should only use lazy size when using the whole file");
+    PRInt64 fileSize;
+    nsresult rv = mFile->GetFileSize(&fileSize);
+    NS_ENSURE_SUCCESS(rv, rv);
+  
+    if (fileSize < 0) {
+      return NS_ERROR_FAILURE;
+    }
+  
+    mLength = fileSize;
+  }
+
+  *aFileSize = mLength;
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDOMFileFile::GetType(nsAString &aType)
+{
+  if (mContentType.IsVoid()) {
+    NS_ASSERTION(mWholeFile,
+                 "Should only use lazy ContentType when using the whole file");
+    nsresult rv;
+    nsCOMPtr<nsIMIMEService> mimeService =
+      do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCAutoString mimeType;
+    rv = mimeService->GetTypeFromFile(mFile, mimeType);
+    if (NS_FAILED(rv)) {
+      mimeType.Truncate();
+    }
+
+    AppendUTF8toUTF16(mimeType, mContentType);
+    mContentType.SetIsVoid(PR_FALSE);
+  }
+
+  aType = mContentType;
+
+  return NS_OK;
+}
+
+const PRUint32 sFileStreamFlags =
+  nsIFileInputStream::CLOSE_ON_EOF |
+  nsIFileInputStream::REOPEN_ON_REWIND |
+  nsIFileInputStream::DEFER_OPEN;
+
+NS_IMETHODIMP
+nsDOMFileFile::GetInternalStream(nsIInputStream **aStream)
+{
+  return mWholeFile ?
+    NS_NewLocalFileInputStream(aStream, mFile, -1, -1, sFileStreamFlags) :
+    NS_NewPartialLocalFileInputStream(aStream, mFile, mStart, mLength,
+                                      -1, -1, sFileStreamFlags);
+}
+
 NS_IMETHODIMP
 nsDOMFileFile::Initialize(nsISupports* aOwner,
                           JSContext* aCx,
                           JSObject* aObj,
                           PRUint32 aArgc,
                           jsval* aArgv)
 {
   nsresult rv;