Bug 1172724 - Use the "openas" verb to select the default HTTP handler on Windows 10. r=jaws, jimm

This commit is contained in:
Masatoshi Kimura 2015-06-19 08:16:52 +09:00
Родитель 7a583fc688
Коммит 734970163c
3 изменённых файлов: 63 добавлений и 4 удалений

Просмотреть файл

@ -622,6 +622,21 @@ nsBrowserContentHandler.prototype = {
var urlParam = cmdLine.getArgument(urlFlagIdx + 1);
if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/.test(urlParam))
throw NS_ERROR_ABORT;
var isDefault = false;
try {
var url = Services.urlFormatter.formatURLPref("app.support.baseURL") +
"win10-default-browser";
if (urlParam == url) {
var shellSvc = Components.classes["@mozilla.org/browser/shell-service;1"]
.getService(Components.interfaces.nsIShellService);
isDefault = shellSvc.isDefaultBrowser(false, false);
}
} catch (ex) {}
if (isDefault) {
// Firefox is already the default HTTP handler.
// We don't have to show the instruction page.
throw NS_ERROR_ABORT;
}
cmdLine.handleFlag("osint", false)
}
},

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsUnicharUtils.h"
#include "nsIWinTaskbar.h"
#include "nsISupportsPrimitives.h"
#include "nsIURLFormatter.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
#include "mozilla/WindowsVersion.h"
@ -687,6 +688,36 @@ nsWindowsShellService::LaunchModernSettingsDialogDefaultApps()
return NS_OK;
}
nsresult
nsWindowsShellService::InvokeHTTPOpenAsVerb()
{
nsCOMPtr<nsIURLFormatter> formatter(
do_GetService("@mozilla.org/toolkit/URLFormatterService;1"));
if (!formatter) {
return NS_ERROR_UNEXPECTED;
}
nsString urlStr;
nsresult rv = formatter->FormatURLPref(
NS_LITERAL_STRING("app.support.baseURL"), urlStr);
if (NS_FAILED(rv)) {
return rv;
}
if (!StringBeginsWith(urlStr, NS_LITERAL_STRING("https://"))) {
return NS_ERROR_FAILURE;
}
urlStr.AppendLiteral("win10-default-browser");
SHELLEXECUTEINFOW seinfo = { sizeof(SHELLEXECUTEINFOW) };
seinfo.lpVerb = L"openas";
seinfo.lpFile = urlStr.get();
seinfo.nShow = SW_SHOWNORMAL;
if (!ShellExecuteExW(&seinfo)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
nsWindowsShellService::LaunchHTTPHandlerPane()
{
@ -715,18 +746,26 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
nsresult rv = LaunchHelper(appHelperPath);
if (NS_SUCCEEDED(rv) && IsWin8OrLater()) {
if (aClaimAllTypes) {
rv = LaunchControlPanelDefaultPrograms();
if (IsWin10OrLater()) {
rv = LaunchModernSettingsDialogDefaultApps();
} else {
rv = LaunchControlPanelDefaultPrograms();
}
// 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();
if (IsWin10OrLater()) {
rv = InvokeHTTPOpenAsVerb();
} else {
rv = LaunchHTTPHandlerPane();
}
}
} else {
// 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();
rv = InvokeHTTPOpenAsVerb();
} else {
rv = LaunchHTTPHandlerPane();
}
@ -734,7 +773,11 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
// 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();
if (IsWin10OrLater()) {
rv = LaunchModernSettingsDialogDefaultApps();
} else {
rv = LaunchControlPanelDefaultPrograms();
}
}
}
}

Просмотреть файл

@ -29,6 +29,7 @@ protected:
bool IsDefaultBrowserVista(bool aCheckAllTypes, bool* aIsDefaultBrowser);
nsresult LaunchControlPanelDefaultPrograms();
nsresult LaunchModernSettingsDialogDefaultApps();
nsresult InvokeHTTPOpenAsVerb();
nsresult LaunchHTTPHandlerPane();
private: