From f3d985358c46b925c922d5e4d7603b228d07e598 Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Wed, 3 Jun 2015 11:40:40 -0400 Subject: [PATCH] Bug 1167294 - Launch the modern Settings app when setting the default browser on Windows 10. r=jimm,Gijs --HG-- extra : rebase_source : 4739b173a9885404a6393f47416904f6f7604891 --- browser/components/nsBrowserGlue.js | 20 +++++----- .../components/preferences/in-content/main.js | 11 +++++- .../shell/nsWindowsShellService.cpp | 39 +++++++++++++++++-- .../components/shell/nsWindowsShellService.h | 1 + 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 8e477ee6255d..3754ad3dba3e 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -2626,16 +2626,16 @@ let DefaultBrowserCheck = { setAsDefault: function() { let claimAllTypes = true; -#ifdef XP_WIN - try { - // In Windows 8, the UI for selecting default protocol is much - // nicer than the UI for setting file type associations. So we - // only show the protocol association screen on Windows 8. - // Windows 8 is version 6.2. - let version = Services.sysinfo.getProperty("version"); - claimAllTypes = (parseFloat(version) < 6.2); - } catch (ex) { } -#endif + if (AppConstants.platform == "win") { + try { + // In Windows 8+, the UI for selecting default protocol is much + // nicer than the UI for setting file type associations. So we + // only show the protocol association screen on Windows 8+. + // Windows 8 is version 6.2. + let version = Services.sysinfo.getProperty("version"); + claimAllTypes = (parseFloat(version) < 6.2); + } catch (ex) { } + } try { ShellService.setDefaultBrowser(claimAllTypes, false); } catch (ex) { diff --git a/browser/components/preferences/in-content/main.js b/browser/components/preferences/in-content/main.js index 50fbb3771b34..131bfc56e9a1 100644 --- a/browser/components/preferences/in-content/main.js +++ b/browser/components/preferences/in-content/main.js @@ -713,7 +713,16 @@ var gMainPane = { if (!shellSvc) return; try { - shellSvc.setDefaultBrowser(true, false); + let claimAllTypes = true; + if (AppConstants.platform == "win") { + // In Windows 8+, the UI for selecting default protocol is much + // nicer than the UI for setting file type associations. So we + // only show the protocol association screen on Windows 8+. + // Windows 8 is version 6.2. + let version = Services.sysinfo.getProperty("version"); + claimAllTypes = (parseFloat(version) < 6.2); + } + shellSvc.setDefaultBrowser(claimAllTypes, false); } catch (ex) { Cu.reportError(ex); return; diff --git a/browser/components/shell/nsWindowsShellService.cpp b/browser/components/shell/nsWindowsShellService.cpp index 145b152f6403..3808b516e80c 100644 --- a/browser/components/shell/nsWindowsShellService.cpp +++ b/browser/components/shell/nsWindowsShellService.cpp @@ -39,6 +39,9 @@ #endif #define _WIN32_WINNT 0x0600 #define INITGUID +#undef NTDDI_VERSION +#define NTDDI_VERSION NTDDI_WIN8 +// Needed for access to IApplicationActivationManager #include #include @@ -662,6 +665,28 @@ nsWindowsShellService::LaunchControlPanelDefaultPrograms() return NS_OK; } +nsresult +nsWindowsShellService::LaunchModernSettingsDialogDefaultApps() +{ + IApplicationActivationManager* pActivator; + HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager, + nullptr, + CLSCTX_INPROC, + IID_IApplicationActivationManager, + (void**)&pActivator); + + if (SUCCEEDED(hr)) { + DWORD pid; + hr = pActivator->ActivateApplication( + L"windows.immersivecontrolpanel_cw5n1h2txyewy" + L"!microsoft.windows.immersivecontrolpanel", + L"page=SettingsPageAppsDefaults", AO_NONE, &pid); + pActivator->Release(); + return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE; + } + return NS_OK; +} + nsresult nsWindowsShellService::LaunchHTTPHandlerPane() { @@ -697,9 +722,17 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers) rv = LaunchHTTPHandlerPane(); } } else { - rv = LaunchHTTPHandlerPane(); - // The above calls hould never really fail, but just in case - // fallb ack to showing control panel for all defaults + // Windows 10 blocks attempts to load the HTTP Handler + // association dialog, so the modern Settings dialog + // is opened with the Default Apps view loaded. + if (IsWin10OrLater()) { + 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(); } diff --git a/browser/components/shell/nsWindowsShellService.h b/browser/components/shell/nsWindowsShellService.h index d567a2aa2cac..1ba897fa0e25 100644 --- a/browser/components/shell/nsWindowsShellService.h +++ b/browser/components/shell/nsWindowsShellService.h @@ -28,6 +28,7 @@ public: protected: bool IsDefaultBrowserVista(bool aCheckAllTypes, bool* aIsDefaultBrowser); nsresult LaunchControlPanelDefaultPrograms(); + nsresult LaunchModernSettingsDialogDefaultApps(); nsresult LaunchHTTPHandlerPane(); private: