bug 1260483 - Use AssocQueryString to get friendly protocol handler names r?jimm draft
authorChris H-C <chutten@mozilla.com>
Mon, 04 Apr 2016 12:54:41 -0400
changeset 347335 f4f4965dd58aba91d7e92d1cc8e2dfdf7987c5f3
parent 345496 d5d53a3b4e50b94cdf85d20690526e5a00d5b63e
child 517606 0933c51d989cf1efe3b673e7378228d121615033
push id14556
push userbmo:chutten@mozilla.com
push dateMon, 04 Apr 2016 17:16:39 +0000
reviewersjimm
bugs1260483
milestone48.0a1
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);