Bug 1240282 - Don't use NS_LossyConvertUTF16toASCII for URI. r?jimm draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 17 Feb 2016 20:44:41 +0900
changeset 331718 e4719fdc63cfc1c2d9324576d51542aa39b516f3
parent 331663 0629918a09ae87808efdda432d7852371ba37db6
child 514449 07a3f1f5a1aaa3a713138e8e5ff8f3a7d0afeabd
push id11059
push userm_kato@ga2.so-net.ne.jp
push dateThu, 18 Feb 2016 01:58:47 +0000
reviewersjimm
bugs1240282
milestone47.0a1
Bug 1240282 - Don't use NS_LossyConvertUTF16toASCII for URI. r?jimm We should use GetAsciiSpec for idn and non-ASCII path MozReview-Commit-ID: EjldSMJYUDg
widget/windows/nsDataObj.cpp
--- a/widget/windows/nsDataObj.cpp
+++ b/widget/windows/nsDataObj.cpp
@@ -1124,42 +1124,42 @@ nsDataObj :: GetFileDescriptorInternetSh
 HRESULT
 nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
 {
   static const char * kShellIconPref = "browser.shell.shortcutFavicons";
   nsAutoString url;
   if ( NS_FAILED(ExtractShortcutURL(url)) )
     return E_OUTOFMEMORY;
 
-  // will need to change if we ever support iDNS
-  nsAutoCString asciiUrl;
-  LossyCopyUTF16toASCII(url, asciiUrl);
-
-  nsCOMPtr<nsIFile> icoFile;
   nsCOMPtr<nsIURI> aUri;
   NS_NewURI(getter_AddRefs(aUri), url);
 
+  nsresult rv;
+  nsAutoCString asciiUrl;
+  rv = aUri->GetAsciiSpec(asciiUrl);
+  if (NS_FAILED(rv)) {
+    return E_FAIL;
+  }
+
   const char *shortcutFormatStr;
   int totalLen;
   nsCString path;
   if (!Preferences::GetBool(kShellIconPref, true) ||
       !IsVistaOrLater()) {
     shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n";
     const int formatLen = strlen(shortcutFormatStr) - 2;  // don't include %s
     totalLen = formatLen + asciiUrl.Length();  // don't include null character
   } else {
     nsCOMPtr<nsIFile> icoFile;
-    nsCOMPtr<nsIURI> aUri;
-    NS_NewURI(getter_AddRefs(aUri), url);
 
     nsAutoString aUriHash;
 
     mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
 
-    nsresult rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
+    rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
     NS_ENSURE_SUCCESS(rv, E_FAIL);
     rv = icoFile->GetNativePath(path);
     NS_ENSURE_SUCCESS(rv, E_FAIL);
 
     shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n"
                         "IDList=\r\nHotKey=0\r\nIconFile=%s\r\n"
                         "IconIndex=0\r\n";
     const int formatLen = strlen(shortcutFormatStr) - 2 * 2; // no %s twice