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
--- 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);