Bug 791501 - Default Programs UI should select Firefox by default. r=jimm, a=lmandel
authorBrian R. Bondy <netzen@gmail.com>
Sat, 27 Jun 2015 12:27:26 +0900
changeset 275427 54302ec0f509a730a03a4883a2e40de0d5eb8007
parent 275426 7f005a3c9f9d57217be6541948eb194a5f2914d8
child 275428 9468920c54b3732e4f0025b6087c3a450d42b32e
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, lmandel
bugs791501
milestone40.0
Bug 791501 - Default Programs UI should select Firefox by default. r=jimm, a=lmandel
browser/components/shell/nsWindowsShellService.cpp
browser/components/shell/nsWindowsShellService.h
--- a/browser/components/shell/nsWindowsShellService.cpp
+++ b/browser/components/shell/nsWindowsShellService.cpp
@@ -630,44 +630,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,
@@ -710,17 +695,17 @@ nsWindowsShellService::SetDefaultBrowser
     appHelperPath.AppendLiteral(" /SetAsDefaultAppGlobal");
   } else {
     appHelperPath.AppendLiteral(" /SetAsDefaultAppUser");
   }
 
   nsresult rv = LaunchHelper(appHelperPath);
   if (NS_SUCCEEDED(rv) && IsWin8OrLater()) {
     if (aClaimAllTypes) {
-      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)) {
         rv = LaunchHTTPHandlerPane();
       }
     } else {
       // Windows 10 blocks attempts to load the HTTP Handler
       // association dialog, so the modern Settings dialog
@@ -729,17 +714,17 @@ nsWindowsShellService::SetDefaultBrowser
         rv = LaunchModernSettingsDialogDefaultApps();
       } else {
         rv = LaunchHTTPHandlerPane();
       }
 
       // The above call should never really fail, but just in case
       // fall back to showing control panel for all defaults
       if (NS_FAILED(rv)) {
-        rv = LaunchControlPanelDefaultPrograms();
+        rv = LaunchControlPanelDefaultsSelectionUI();
       }
     }
   }
 
   nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
   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 LaunchHTTPHandlerPane();
 
 private:
   bool      mCheckedThisSession;
 };
 
 #endif // nswindowsshellservice_h____