Chromium Code Reviews| 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..ef6459e7155abfa1257d8d4f934e4059344ae9fa 100644 |
| --- a/chrome/browser/shell_integration_win.cc |
| +++ b/chrome/browser/shell_integration_win.cc |
| @@ -31,6 +31,7 @@ |
| #include "chrome/installer/util/util_constants.h" |
| #include "chrome/installer/util/work_item.h" |
| #include "chrome/installer/util/work_item_list.h" |
| +#include "chrome/installer/setup/setup_util.h" |
|
grt (UTC plus 2)
2011/05/25 14:35:45
this goes above the installer/util includes
benwells
2011/05/26 00:23:04
Done.
|
| #include "content/browser/browser_thread.h" |
| namespace { |
| @@ -287,13 +288,36 @@ bool ShellIntegration::SetAsDefaultBrowser() { |
| return true; |
| } |
| -ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { |
| +bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
| + if (protocol.empty()) |
| + return false; |
| + |
| + 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::DefaultWebClientState 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_WEB_CLIENT; |
| } |
| // 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, |
| @@ -307,12 +331,12 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { |
| const std::wstring kChromeProtocols[] = {L"http", L"https"}; |
| if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| - IApplicationAssociationRegistration* pAAR; |
| + base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
|
grt (UTC plus 2)
2011/05/25 14:35:45
pAAR.CreateInstance(CLSID_ApplicationAssociationRe
benwells
2011/05/26 00:23:04
Done.
|
| NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), |
| (void**)&pAAR); |
| if (!SUCCEEDED(hr)) |
| - return NOT_DEFAULT_BROWSER; |
| + return NOT_DEFAULT_WEB_CLIENT; |
| BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| std::wstring app_name = dist->GetApplicationName(); |
| @@ -328,11 +352,9 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { |
| hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, |
| AL_EFFECTIVE, app_name.c_str(), &result); |
| if (!SUCCEEDED(hr) || result == FALSE) { |
| - pAAR->Release(); |
| - return NOT_DEFAULT_BROWSER; |
| + return NOT_DEFAULT_WEB_CLIENT; |
| } |
| } |
| - pAAR->Release(); |
| } else { |
| std::wstring short_app_path; |
| GetShortPathName(app_path.value().c_str(), |
| @@ -349,17 +371,82 @@ 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_WEB_CLIENT; |
| // 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_WEB_CLIENT; |
| } |
| } |
| - return IS_DEFAULT_BROWSER; |
| + return IS_DEFAULT_WEB_CLIENT; |
| +} |
| + |
| +ShellIntegration::DefaultWebClientState |
| + ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
| + if (protocol.empty()) |
| + return UNKNOWN_DEFAULT_WEB_CLIENT; |
| + |
| + // 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_WEB_CLIENT; |
| + } |
| + |
| + std::wstring wprotocol = UTF8ToWide(protocol); |
| + |
| + if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| + base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| + HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
|
grt (UTC plus 2)
2011/05/25 14:35:45
pAAR.CreateInstance(CLSID_ApplicationAssociationRe
benwells
2011/05/26 00:23:04
Done.
|
| + NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), |
| + (void**)&pAAR); |
| + if (!SUCCEEDED(hr)) |
| + return NOT_DEFAULT_WEB_CLIENT; |
| + |
| + 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) { |
| + return NOT_DEFAULT_WEB_CLIENT; |
| + } |
| + } 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_WEB_CLIENT; |
| + // 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_WEB_CLIENT; |
| + } |
| + return IS_DEFAULT_WEB_CLIENT; |
| } |
| // There is no reliable way to say which browser is default on a machine (each |