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..9a93f21c4c87cc50e44fc6e7e591ccc66369df4c 100644 |
| --- a/chrome/browser/shell_integration_win.cc |
| +++ b/chrome/browser/shell_integration_win.cc |
| @@ -287,13 +287,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, |
| @@ -312,7 +335,7 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { |
| 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(); |
| @@ -329,7 +352,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_WEB_CLIENT; |
| } |
| } |
| pAAR->Release(); |
| @@ -349,17 +372,84 @@ 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) { |
| + IApplicationAssociationRegistration* pAAR; |
|
xiyuan
2011/05/24 17:55:20
suggest to use base::win::ScopedComPtr<...> so tha
benwells
2011/05/25 08:07:19
Done (also for IsDefaultBrowser earlier).
|
| + HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
| + 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) { |
| + pAAR->Release(); |
| + return NOT_DEFAULT_WEB_CLIENT; |
| + } |
| + pAAR->Release(); |
| + } else { |
| + std::wstring short_app_path; |
| + GetShortPathName(app_path.value().c_str(), |
|
grt (UTC plus 2)
2011/05/24 20:27:53
This has a variety of failure modes. Check the re
benwells
2011/05/25 08:07:19
See later...
|
| + 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(), |
|
grt (UTC plus 2)
2011/05/24 20:27:53
Same comment as above.
benwells
2011/05/25 08:07:19
See later ...
|
| + WriteInto(&short_path, MAX_PATH), MAX_PATH); |
| + if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) |
|
grt (UTC plus 2)
2011/05/24 20:27:53
Ah, I see now that this code is using string compa
benwells
2011/05/25 08:07:19
The ProgramCompare looks very useful here but when
grt (UTC plus 2)
2011/05/25 14:35:45
If you choose to defer using the same mechanism as
benwells
2011/05/26 00:23:04
Done (and same change was made in IsDefaultBrowser
|
| + 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 |