| Index: chrome/browser/shell_integration_win.cc
|
| diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc
|
| index 72f9ad1546a9c941ffea96b5e8ad58b90ecec7c7..b689ab611f195ccb6df3e5c71cc48ece560e0474 100644
|
| --- a/chrome/browser/shell_integration_win.cc
|
| +++ b/chrome/browser/shell_integration_win.cc
|
| @@ -287,13 +287,33 @@ bool ShellIntegration::SetAsDefaultBrowser() {
|
| return true;
|
| }
|
|
|
| -ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
|
| +bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) {
|
| + FilePath chrome_exe;
|
| + if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
|
| + LOG(ERROR) << "Error getting app exe path";
|
| + return false;
|
| + }
|
| +
|
| + std::wstring wprotocol = UTF8ToWide(protocol);
|
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution();
|
| + if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(),
|
| + wprotocol)) {
|
| + LOG(ERROR) << "Chrome could not be set as default handler for "
|
| + << protocol << ".";
|
| + return false;
|
| + }
|
| +
|
| + VLOG(1) << "Chrome registered as default handler for " << protocol << ".";
|
| + return true;
|
| +}
|
| +
|
| +ShellIntegration::DefaultClientAppState ShellIntegration::IsDefaultBrowser() {
|
| // First determine the app path. If we can't determine what that is, we have
|
| // bigger fish to fry...
|
| FilePath app_path;
|
| if (!PathService::Get(base::FILE_EXE, &app_path)) {
|
| LOG(ERROR) << "Error getting app exe path";
|
| - return UNKNOWN_DEFAULT_BROWSER;
|
| + return UNKNOWN_DEFAULT_CLIENT_APP;
|
| }
|
| // When we check for default browser we don't necessarily want to count file
|
| // type handlers and icons as having changed the default browser status,
|
| @@ -312,7 +332,7 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
|
| NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration),
|
| (void**)&pAAR);
|
| if (!SUCCEEDED(hr))
|
| - return NOT_DEFAULT_BROWSER;
|
| + return NOT_DEFAULT_CLIENT_APP;
|
|
|
| BrowserDistribution* dist = BrowserDistribution::GetDistribution();
|
| std::wstring app_name = dist->GetApplicationName();
|
| @@ -329,7 +349,7 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
|
| AL_EFFECTIVE, app_name.c_str(), &result);
|
| if (!SUCCEEDED(hr) || result == FALSE) {
|
| pAAR->Release();
|
| - return NOT_DEFAULT_BROWSER;
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| }
|
| }
|
| pAAR->Release();
|
| @@ -349,17 +369,81 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
|
| base::win::RegKey key(root_key, key_path.c_str(), KEY_READ);
|
| std::wstring value;
|
| if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS))
|
| - return NOT_DEFAULT_BROWSER;
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| // Need to normalize path in case it's been munged.
|
| CommandLine command_line = CommandLine::FromString(value);
|
| std::wstring short_path;
|
| GetShortPathName(command_line.GetProgram().value().c_str(),
|
| WriteInto(&short_path, MAX_PATH), MAX_PATH);
|
| if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path))
|
| - return NOT_DEFAULT_BROWSER;
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| }
|
| }
|
| - return IS_DEFAULT_BROWSER;
|
| + return IS_DEFAULT_CLIENT_APP;
|
| +}
|
| +
|
| +ShellIntegration::DefaultClientAppState
|
| + ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) {
|
| + // First determine the app path. If we can't determine what that is, we have
|
| + // bigger fish to fry...
|
| + FilePath app_path;
|
| + if (!PathService::Get(base::FILE_EXE, &app_path)) {
|
| + LOG(ERROR) << "Error getting app exe path";
|
| + return UNKNOWN_DEFAULT_CLIENT_APP;
|
| + }
|
| +
|
| + std::wstring wprotocol = UTF8ToWide(protocol);
|
| +
|
| + if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
|
| + IApplicationAssociationRegistration* pAAR;
|
| + HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
|
| + NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration),
|
| + (void**)&pAAR);
|
| + if (!SUCCEEDED(hr))
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| +
|
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution();
|
| + std::wstring app_name = dist->GetApplicationName();
|
| + // If a user specific default browser entry exists, we check for that
|
| + // app name being default. If not, then default browser is just called
|
| + // Google Chrome or Chromium so we do not append suffix to app name.
|
| + std::wstring suffix;
|
| + if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix))
|
| + app_name += suffix;
|
| +
|
| + BOOL result = TRUE;
|
| + hr = pAAR->QueryAppIsDefault(wprotocol.c_str(), AT_URLPROTOCOL,
|
| + AL_EFFECTIVE, app_name.c_str(), &result);
|
| + if (!SUCCEEDED(hr) || result == FALSE) {
|
| + pAAR->Release();
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| + }
|
| + pAAR->Release();
|
| + } else {
|
| + std::wstring short_app_path;
|
| + GetShortPathName(app_path.value().c_str(),
|
| + WriteInto(&short_app_path, MAX_PATH),
|
| + MAX_PATH);
|
| +
|
| + // open command for protocol associations
|
| + // Check in HKEY_CLASSES_ROOT that is the result of merge between
|
| + // HKLM and HKCU
|
| + HKEY root_key = HKEY_CLASSES_ROOT;
|
| + // Check <protocol>\shell\open\command
|
| + std::wstring key_path(wprotocol + ShellUtil::kRegShellOpen);
|
| + base::win::RegKey key(root_key, key_path.c_str(), KEY_READ);
|
| + std::wstring value;
|
| + if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS))
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| + // Need to normalize path in case it's been munged.
|
| + CommandLine command_line = CommandLine::FromString(value);
|
| + std::wstring short_path;
|
| + GetShortPathName(command_line.GetProgram().value().c_str(),
|
| + WriteInto(&short_path, MAX_PATH), MAX_PATH);
|
| + if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path))
|
| + return NOT_DEFAULT_CLIENT_APP;
|
| + }
|
| + return IS_DEFAULT_CLIENT_APP;
|
| }
|
|
|
| // There is no reliable way to say which browser is default on a machine (each
|
|
|