Bug 801579 - Don't mix nsresult with HRESULT (widget/windows part) r=jmathies
authorJacek Caban <jacek@codeweavers.com>
Wed, 24 Oct 2012 10:57:08 +0200
changeset 111362 496d1304440c37e3fbd25b8969354de742b009d2
parent 111361 75cdeb27891cbd2dc8cbe45e0778dac18367ef74
child 111363 dff2047ef68ef7d24b456e37d0217003adef01ae
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjmathies
bugs801579
milestone19.0a1
Bug 801579 - Don't mix nsresult with HRESULT (widget/windows part) r=jmathies
widget/windows/nsDataObj.cpp
widget/windows/nsDataObj.h
--- a/widget/windows/nsDataObj.cpp
+++ b/widget/windows/nsDataObj.cpp
@@ -304,20 +304,22 @@ STDMETHODIMP nsDataObj::CStream::Write(c
 //-----------------------------------------------------------------------------
 HRESULT nsDataObj::CreateStream(IStream **outStream)
 {
   NS_ENSURE_TRUE(outStream, E_INVALIDARG);
 
   nsresult rv = NS_ERROR_FAILURE;
   nsAutoString wideFileName;
   nsCOMPtr<nsIURI> sourceURI;
+  HRESULT res;
 
-  rv = GetDownloadDetails(getter_AddRefs(sourceURI),
-                          wideFileName);
-  NS_ENSURE_SUCCESS(rv, E_FAIL);
+  res = GetDownloadDetails(getter_AddRefs(sourceURI),
+                           wideFileName);
+  if(FAILED(res))
+    return res;
 
   nsDataObj::CStream *pStream = new nsDataObj::CStream();
   NS_ENSURE_TRUE(pStream, E_OUTOFMEMORY);
 
   pStream->AddRef();
 
   rv = pStream->Init(sourceURI);
   if (NS_FAILED(rv))
@@ -1111,19 +1113,19 @@ nsDataObj :: GetFileContentsInternetShor
   mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
 
   nsresult rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
   NS_ENSURE_SUCCESS(rv, E_FAIL);
   nsCString path;
   rv = icoFile->GetNativePath(path);
   NS_ENSURE_SUCCESS(rv, E_FAIL);
 
-  static char* shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n" 
-                                   "IDList=\r\nHotKey=0\r\nIconFile=%s\r\n" 
-                                   "IconIndex=0\r\n";
+  static const char* shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n"
+                                         "IDList=\r\nHotKey=0\r\nIconFile=%s\r\n"
+                                         "IconIndex=0\r\n";
   static const int formatLen = strlen(shortcutFormatStr) - 2*2; // don't include %s (2 times) in the len
   const int totalLen = formatLen + asciiUrl.Length() 
                        + path.Length(); // we don't want a null character on the end
 
   // create a global memory area and build up the file contents w/in it
   HGLOBAL hGlobalMemory = ::GlobalAlloc(GMEM_SHARE, totalLen);
   if ( !hGlobalMemory )
     return E_OUTOFMEMORY;
@@ -1533,20 +1535,21 @@ HRESULT nsDataObj::DropTempFile(FORMATET
     rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(dropFile));
     if (!dropFile)
       return E_FAIL;
 
     // Filename must be random
     nsCString filename;
     nsAutoString wideFileName;
     nsCOMPtr<nsIURI> sourceURI;
-    rv = GetDownloadDetails(getter_AddRefs(sourceURI),
+    HRESULT res;
+    res = GetDownloadDetails(getter_AddRefs(sourceURI),
       wideFileName);
-    if (NS_FAILED(rv))
-      return E_FAIL;
+    if (FAILED(res))
+      return res;
     NS_UTF16ToCString(wideFileName, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, filename);
 
     dropFile->AppendNative(filename);
     rv = dropFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660);
     if (NS_FAILED(rv))
       return E_FAIL;
 
     // Cache the temp file so we can delete it later and so
@@ -1955,84 +1958,83 @@ nsDataObj::ExtractUniformResourceLocator
   aSTG.hGlobal = hGlobalMemory;
   aSTG.tymed = TYMED_HGLOBAL;
 
   return result;
 }
 
 
 // Gets the filename from the kFilePromiseURLMime flavour
-nsresult nsDataObj::GetDownloadDetails(nsIURI **aSourceURI,
-                                       nsAString &aFilename)
+HRESULT nsDataObj::GetDownloadDetails(nsIURI **aSourceURI,
+                                      nsAString &aFilename)
 {
   *aSourceURI = nullptr;
 
-  NS_ENSURE_TRUE(mTransferable, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(mTransferable, E_FAIL);
 
   // get the URI from the kFilePromiseURLMime flavor
   nsCOMPtr<nsISupports> urlPrimitive;
   uint32_t dataSize = 0;
   mTransferable->GetTransferData(kFilePromiseURLMime, getter_AddRefs(urlPrimitive), &dataSize);
   nsCOMPtr<nsISupportsString> srcUrlPrimitive = do_QueryInterface(urlPrimitive);
-  NS_ENSURE_TRUE(srcUrlPrimitive, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(srcUrlPrimitive, E_FAIL);
   
   nsAutoString srcUri;
   srcUrlPrimitive->GetData(srcUri);
   if (srcUri.IsEmpty())
-    return NS_ERROR_FAILURE;
+    return E_FAIL;
   nsCOMPtr<nsIURI> sourceURI;
   NS_NewURI(getter_AddRefs(sourceURI), srcUri);
 
   nsAutoString srcFileName;
   nsCOMPtr<nsISupports> fileNamePrimitive;
   mTransferable->GetTransferData(kFilePromiseDestFilename, getter_AddRefs(fileNamePrimitive), &dataSize);
   nsCOMPtr<nsISupportsString> srcFileNamePrimitive = do_QueryInterface(fileNamePrimitive);
   if (srcFileNamePrimitive) {
     srcFileNamePrimitive->GetData(srcFileName);
   } else {
     nsCOMPtr<nsIURL> sourceURL = do_QueryInterface(sourceURI);
     if (!sourceURL)
-      return NS_ERROR_FAILURE;
+      return E_FAIL;
     
     nsAutoCString urlFileName;
     sourceURL->GetFileName(urlFileName);
     NS_UnescapeURL(urlFileName);
     CopyUTF8toUTF16(urlFileName, srcFileName);
   }
   if (srcFileName.IsEmpty())
-    return NS_ERROR_FAILURE;
+    return E_FAIL;
 
   // make the name safe for the filesystem
   MangleTextToValidFilename(srcFileName);
 
   sourceURI.swap(*aSourceURI);
   aFilename = srcFileName;
-  return NS_OK;
+  return S_OK;
 }
 
 HRESULT nsDataObj::GetFileDescriptor_IStreamA(FORMATETC& aFE, STGMEDIUM& aSTG)
 {
   HGLOBAL fileGroupDescHandle = ::GlobalAlloc(GMEM_ZEROINIT|GMEM_SHARE,sizeof(FILEGROUPDESCRIPTORW));
   NS_ENSURE_TRUE(fileGroupDescHandle, E_OUTOFMEMORY);
 
   LPFILEGROUPDESCRIPTORA fileGroupDescA = reinterpret_cast<LPFILEGROUPDESCRIPTORA>(GlobalLock(fileGroupDescHandle));
   if (!fileGroupDescA) {
     ::GlobalFree(fileGroupDescHandle);
     return E_OUTOFMEMORY;
   }
 
   nsAutoString wideFileName;
-  nsresult rv;
+  HRESULT res;
   nsCOMPtr<nsIURI> sourceURI;
-  rv = GetDownloadDetails(getter_AddRefs(sourceURI),
-                          wideFileName);
-  if (NS_FAILED(rv))
+  res = GetDownloadDetails(getter_AddRefs(sourceURI), wideFileName);
+  if (FAILED(res))
   {
     ::GlobalFree(fileGroupDescHandle);
-    return E_FAIL;
+    return res;
   }
 
   nsAutoCString nativeFileName;
   NS_UTF16ToCString(wideFileName, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, nativeFileName);
   
   strncpy(fileGroupDescA->fgd[0].cFileName, nativeFileName.get(), NS_MAX_FILEDESCRIPTOR - 1);
   fileGroupDescA->fgd[0].cFileName[NS_MAX_FILEDESCRIPTOR - 1] = '\0';
 
@@ -2054,24 +2056,24 @@ HRESULT nsDataObj::GetFileDescriptor_ISt
 
   LPFILEGROUPDESCRIPTORW fileGroupDescW = reinterpret_cast<LPFILEGROUPDESCRIPTORW>(GlobalLock(fileGroupDescHandle));
   if (!fileGroupDescW) {
     ::GlobalFree(fileGroupDescHandle);
     return E_OUTOFMEMORY;
   }
 
   nsAutoString wideFileName;
-  nsresult rv;
+  HRESULT res;
   nsCOMPtr<nsIURI> sourceURI;
-  rv = GetDownloadDetails(getter_AddRefs(sourceURI),
-                          wideFileName);
-  if (NS_FAILED(rv))
+  res = GetDownloadDetails(getter_AddRefs(sourceURI),
+                           wideFileName);
+  if (FAILED(res))
   {
     ::GlobalFree(fileGroupDescHandle);
-    return E_FAIL;
+    return res;
   }
 
   wcsncpy(fileGroupDescW->fgd[0].cFileName, wideFileName.get(), NS_MAX_FILEDESCRIPTOR - 1);
   fileGroupDescW->fgd[0].cFileName[NS_MAX_FILEDESCRIPTOR - 1] = '\0';
   // one file in the file block
   fileGroupDescW->cItems = 1;
   fileGroupDescW->fgd[0].dwFlags = FD_PROGRESSUI;
 
--- a/widget/windows/nsDataObj.h
+++ b/widget/windows/nsDataObj.h
@@ -159,18 +159,18 @@ protected:
     STDMETHOD(GetAsyncMode)(BOOL *pfIsOpAsync);
     STDMETHOD(InOperation)(BOOL *pfInAsyncOp);
     STDMETHOD(SetAsyncMode)(BOOL fDoOpAsync);
     STDMETHOD(StartOperation)(IBindCtx *pbcReserved);
 
 	public: // other methods
 
     // Gets the filename from the kFilePromiseURLMime flavour
-    nsresult GetDownloadDetails(nsIURI **aSourceURI,
-                                nsAString &aFilename);
+    HRESULT GetDownloadDetails(nsIURI **aSourceURI,
+                               nsAString &aFilename);
 
 	protected:
     // help determine the kind of drag
     bool IsFlavourPresent(const char *inFlavour);
 
     virtual HRESULT AddSetFormat(FORMATETC&  FE);
     virtual HRESULT AddGetFormat(FORMATETC&  FE);