Bug 1357791 - require mAppAssoc (Vista+) API for extension lookup from nsOSHelperAppService.cpp, r=gijs
authorAshish <supersonic12910@gmail.com>
Wed, 31 Jan 2018 17:00:56 +0000
changeset 401752 21fea000a9fadc75f1170337d34065992b7a74fd
parent 401751 23805f660a56ebfb0b1d57eeb9398c0e0ba0fa34
child 401753 a246a99f932b26f44c1c691ba741025a5d38c1d3
push id99429
push usergijskruitbosch@gmail.com
push dateWed, 31 Jan 2018 17:08:32 +0000
treeherdermozilla-inbound@21fea000a9fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs
bugs1357791
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1357791 - require mAppAssoc (Vista+) API for extension lookup from nsOSHelperAppService.cpp, r=gijs
uriloader/exthandler/win/nsOSHelperAppService.cpp
--- a/uriloader/exthandler/win/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/win/nsOSHelperAppService.cpp
@@ -75,44 +75,26 @@ static nsresult GetExtensionFromWindowsM
 }
 
 nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists)
 {
   // look up the protocol scheme in the windows registry....if we find a match then we have a handler for it...
   *aHandlerExists = false;
   if (aProtocolScheme && *aProtocolScheme)
   {
-    // Vista: use new application association interface
-    if (mAppAssoc) {
-      wchar_t * pResult = nullptr;
-      NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
-      // We are responsible for freeing returned strings.
-      HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
-                                                  AT_URLPROTOCOL, AL_EFFECTIVE,
-                                                  &pResult);
-      if (SUCCEEDED(hr)) {
-        CoTaskMemFree(pResult);
-        *aHandlerExists = true;
-      }
-      return NS_OK;
-    }
-
-    HKEY hKey;
-    LONG err = ::RegOpenKeyExW(HKEY_CLASSES_ROOT,
-                               NS_ConvertASCIItoUTF16(aProtocolScheme).get(),
-                               0,
-                               KEY_QUERY_VALUE,
-                               &hKey);
-    if (err == ERROR_SUCCESS)
-    {
-      err = ::RegQueryValueExW(hKey, L"URL Protocol",
-                               nullptr, nullptr, nullptr, nullptr);
-      *aHandlerExists = (err == ERROR_SUCCESS);
-      // close the key
-      ::RegCloseKey(hKey);
+    NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
+    wchar_t * pResult = nullptr;
+    NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
+    // We are responsible for freeing returned strings.
+    HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
+      AT_URLPROTOCOL, AL_EFFECTIVE,
+      &pResult);
+    if (SUCCEEDED(hr)) {
+      CoTaskMemFree(pResult);
+      *aHandlerExists = true;
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
 {
@@ -133,50 +115,30 @@ NS_IMETHODIMP nsOSHelperAppService::GetA
                                   result,
                                   &resultSize);
     if (SUCCEEDED(hr)) {
       _retval = result;
       return NS_OK;
     }
   }
 
-  if (mAppAssoc) {
-    // Vista: use new application association interface
-    wchar_t * pResult = nullptr;
-    // We are responsible for freeing returned strings.
-    HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
-                                                AT_URLPROTOCOL, AL_EFFECTIVE,
-                                                &pResult);
-    if (SUCCEEDED(hr)) {
-      nsCOMPtr<nsIFile> app;
-      nsAutoString appInfo(pResult);
-      CoTaskMemFree(pResult);
-      if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
-        return NS_OK;
-    }
-    return NS_ERROR_NOT_AVAILABLE;
+  NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
+  wchar_t * pResult = nullptr;
+  // We are responsible for freeing returned strings.
+  HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
+                                              AT_URLPROTOCOL, AL_EFFECTIVE,
+                                              &pResult);
+  if (SUCCEEDED(hr)) {
+    nsCOMPtr<nsIFile> app;
+    nsAutoString appInfo(pResult);
+    CoTaskMemFree(pResult);
+    if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
+      return NS_OK;
   }
-
-  nsCOMPtr<nsIFile> app;
-  GetDefaultAppInfo(buf, _retval, getter_AddRefs(app));
-
-  if (!_retval.Equals(buf))
-    return NS_OK;
-
-  // Fall back to full path
-  buf.AppendLiteral("\\shell\\open\\command");
-  nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
-                             buf,
-                             nsIWindowsRegKey::ACCESS_QUERY_VALUE);
-  if (NS_FAILED(rv))
-    return NS_ERROR_NOT_AVAILABLE;   
-   
-  rv = regKey->ReadStringValue(EmptyString(), _retval); 
-
-  return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_NOT_AVAILABLE;
+  return NS_ERROR_NOT_AVAILABLE;
 }
 
 // GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
 // attributes for the mimeType/extension associated with the input registry key.  The default
 // entry for that key is the name of a registry key under HKEY_CLASSES_ROOT.  The default
 // value for *that* key is the descriptive name of the type.  The EditFlags value is a binary
 // value; the low order bit of the third byte of which indicates that the user does not need
 // to be prompted.
@@ -374,46 +336,29 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelp
   // don't append the '.' for our APIs.
   mimeInfo->AppendExtension(NS_ConvertUTF16toUTF8(Substring(fileExtToUse, 1)));
   mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
 
   nsAutoString appInfo;
   bool found;
 
   // Retrieve the default application for this extension
-  if (mAppAssoc) {
-    // Vista: use the new application association COM interfaces
-    // for resolving helpers.
-    nsString assocType(fileExtToUse);
-    wchar_t * pResult = nullptr;
-    HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
-                                                AT_FILEEXTENSION, AL_EFFECTIVE,
-                                                &pResult);
-    if (SUCCEEDED(hr)) {
-      found = true;
-      appInfo.Assign(pResult);
-      CoTaskMemFree(pResult);
-    } 
-    else {
-      found = false;
-    }
+  NS_ENSURE_TRUE(mAppAssoc, nullptr);
+  nsString assocType(fileExtToUse);
+  wchar_t * pResult = nullptr;
+  HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
+                                              AT_FILEEXTENSION, AL_EFFECTIVE,
+                                              &pResult);
+  if (SUCCEEDED(hr)) {
+    found = true;
+    appInfo.Assign(pResult);
+    CoTaskMemFree(pResult);
   } 
-  else
-  {
-    nsCOMPtr<nsIWindowsRegKey> regKey =
-      do_CreateInstance("@mozilla.org/windows-registry-key;1");
-    if (!regKey)
-      return nullptr;
-    nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
-                               fileExtToUse,
-                               nsIWindowsRegKey::ACCESS_QUERY_VALUE);
-    if (NS_SUCCEEDED(rv)) {
-      found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(),
-                                                   appInfo));
-    }
+  else {
+    found = false;
   }
 
   // Bug 358297 - ignore the default handler, force the user to choose app
   if (appInfo.EqualsLiteral("XPSViewer.Document"))
     found = false;
 
   if (!found) {
     return nullptr;