Bug 1260483 - Use AssocQueryString to get friendly protocol handler names. r=jimm FUNNELCAKE86_BRANCH
authorChris H-C <chutten@mozilla.com>
Mon, 04 Apr 2016 12:54:41 -0400
branchFUNNELCAKE86_BRANCH
changeset 326423 d71f2fa0771913a9bd47265869332a154070673a
parent 326422 b27e04aa4f5421b1baf796cabbe64af62fbd09ca
child 326424 22b54748738957f9db2ca8d8b8e02bb7e495dc9b
push id1143
push usernthomas@mozilla.com
push dateTue, 05 Jul 2016 23:40:05 +0000
treeherdermozilla-release@0cc1138c8b72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1260483
milestone47.0.1
Bug 1260483 - Use AssocQueryString to get friendly protocol handler names. r=jimm In Win8+, AssocQueryString supports ASSOCF_IS_PROTOCOL which simplifies fetching the friendly application name for a given protocol/scheme. For "Universal" apps, this simplified mechanism is required to get something other than TWINUI. MozReview-Commit-ID: pTruoBeTgK
uriloader/exthandler/win/nsOSHelperAppService.cpp
--- a/uriloader/exthandler/win/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/win/nsOSHelperAppService.cpp
@@ -15,19 +15,21 @@
 #include "nsMimeTypes.h"
 #include "nsILocalFileWin.h"
 #include "nsIProcess.h"
 #include "plstr.h"
 #include "nsAutoPtr.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsIWindowsRegKey.h"
 #include "mozilla/UniquePtrExtensions.h"
+#include "mozilla/WindowsVersion.h"
 
 // shellapi.h is needed to build with WIN32_LEAN_AND_MEAN
 #include <shellapi.h>
+#include <shlwapi.h>
 
 #define LOG(args) MOZ_LOG(mLog, mozilla::LogLevel::Debug, args)
 
 // helper methods: forward declarations...
 static nsresult GetExtensionFrom4xRegistryInfo(const nsACString& aMimeType, 
                                                nsString& aFileExtension);
 static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
                                                     nsString& aFileExtension);
@@ -158,18 +160,33 @@ NS_IMETHODIMP nsOSHelperAppService::GetA
 {
   nsCOMPtr<nsIWindowsRegKey> regKey = 
     do_CreateInstance("@mozilla.org/windows-registry-key;1");
   if (!regKey) 
     return NS_ERROR_NOT_AVAILABLE;
 
   NS_ConvertASCIItoUTF16 buf(aScheme);
 
-  // Vista: use new application association interface
+  if (mozilla::IsWin8OrLater()) {
+    wchar_t result[1024];
+    DWORD resultSize = 1024;
+    HRESULT hr = AssocQueryString(0x1000 /* ASSOCF_IS_PROTOCOL */,
+                                  ASSOCSTR_FRIENDLYAPPNAME,
+                                  buf.get(),
+                                  NULL,
+                                  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);