Bug 791501 - Default Programs UI should select Firefox by default. r=jimm
authorBrian R. Bondy <netzen@gmail.com>
Sat, 27 Jun 2015 12:27:26 +0900
changeset 268583 28e6664ad1a16463932d397aaac7f3fbc6bde73b
parent 268582 ac30d7919319b83cdcd42308baf911222b2c95a8
child 268584 10ac7b53802a130d1c225d4c43033dca152edaab
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs791501
milestone41.0a1
Bug 791501 - Default Programs UI should select Firefox by default. r=jimm
browser/components/shell/nsWindowsShellService.cpp
browser/components/shell/nsWindowsShellService.h
--- a/browser/components/shell/nsWindowsShellService.cpp
+++ b/browser/components/shell/nsWindowsShellService.cpp
@@ -631,44 +631,29 @@ DynSHOpenWithDialog(HWND hwndParent, con
   } else {
     rv = NS_ERROR_FAILURE;
   }
   FreeLibrary(shellDLL);
   return rv;
 }
 
 nsresult
-nsWindowsShellService::LaunchControlPanelDefaultPrograms()
+nsWindowsShellService::LaunchControlPanelDefaultsSelectionUI()
 {
-  // Build the path control.exe path safely
-  WCHAR controlEXEPath[MAX_PATH + 1] = { '\0' };
-  if (!GetSystemDirectoryW(controlEXEPath, MAX_PATH)) {
-    return NS_ERROR_FAILURE;
-  }
-  LPCWSTR controlEXE = L"control.exe";
-  if (wcslen(controlEXEPath) + wcslen(controlEXE) >= MAX_PATH) {
-    return NS_ERROR_FAILURE;
-  }
-  if (!PathAppendW(controlEXEPath, controlEXE)) {
-    return NS_ERROR_FAILURE;
+  IApplicationAssociationRegistrationUI* pAARUI;
+  HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
+                                NULL,
+                                CLSCTX_INPROC,
+                                IID_IApplicationAssociationRegistrationUI,
+                                (void**)&pAARUI);
+  if (SUCCEEDED(hr)) {
+    hr = pAARUI->LaunchAdvancedAssociationUI(APP_REG_NAME);
+    pAARUI->Release();
   }
-
-  WCHAR params[] = L"control.exe /name Microsoft.DefaultPrograms /page pageDefaultProgram";
-  STARTUPINFOW si = {sizeof(si), 0};
-  si.dwFlags = STARTF_USESHOWWINDOW;
-  si.wShowWindow = SW_SHOWDEFAULT;
-  PROCESS_INFORMATION pi = {0};
-  if (!CreateProcessW(controlEXEPath, params, nullptr, nullptr, FALSE,
-                      0, nullptr, nullptr, &si, &pi)) {
-    return NS_ERROR_FAILURE;
-  }
-  CloseHandle(pi.hProcess);
-  CloseHandle(pi.hThread);
-
-  return NS_OK;
+  return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult
 nsWindowsShellService::LaunchModernSettingsDialogDefaultApps()
 {
   IApplicationActivationManager* pActivator;
   HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager,
                                 nullptr,
@@ -745,17 +730,17 @@ nsWindowsShellService::SetDefaultBrowser
 
   nsresult rv = LaunchHelper(appHelperPath);
   nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
   if (NS_SUCCEEDED(rv) && IsWin8OrLater()) {
     if (aClaimAllTypes) {
       if (IsWin10OrLater()) {
         rv = LaunchModernSettingsDialogDefaultApps();
       } else {
-        rv = LaunchControlPanelDefaultPrograms();
+        rv = LaunchControlPanelDefaultsSelectionUI();
       }
       // The above call should never really fail, but just in case
       // fall back to showing the HTTP association screen only.
       if (NS_FAILED(rv)) {
         if (IsWin10OrLater()) {
           rv = InvokeHTTPOpenAsVerb();
         } else {
           rv = LaunchHTTPHandlerPane();
@@ -779,17 +764,17 @@ nsWindowsShellService::SetDefaultBrowser
       }
 
       // The above call should never really fail, but just in case
       // fall back to showing control panel for all defaults
       if (NS_FAILED(rv)) {
         if (IsWin10OrLater()) {
           rv = LaunchModernSettingsDialogDefaultApps();
         } else {
-          rv = LaunchControlPanelDefaultPrograms();
+          rv = LaunchControlPanelDefaultsSelectionUI();
         }
       }
     }
   }
 
   if (prefs) {
     (void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
   }
--- a/browser/components/shell/nsWindowsShellService.h
+++ b/browser/components/shell/nsWindowsShellService.h
@@ -22,17 +22,17 @@ public:
   nsWindowsShellService();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSISHELLSERVICE
   NS_DECL_NSIWINDOWSSHELLSERVICE
 
 protected:
   bool IsDefaultBrowserVista(bool aCheckAllTypes, bool* aIsDefaultBrowser);
-  nsresult LaunchControlPanelDefaultPrograms();
+  nsresult LaunchControlPanelDefaultsSelectionUI();
   nsresult LaunchModernSettingsDialogDefaultApps();
   nsresult InvokeHTTPOpenAsVerb();
   nsresult LaunchHTTPHandlerPane();
 
 private:
   bool      mCheckedThisSession;
 };