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 fe34868bc706c43859f428c264309159668a7a39..92a2274b23a0ea1360ceb01a8676773388a53a79 100644 |
| --- a/chrome/browser/shell_integration_win.cc |
| +++ b/chrome/browser/shell_integration_win.cc |
| @@ -19,7 +19,6 @@ |
| #include "base/stringprintf.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/win/registry.h" |
| -#include "base/win/scoped_co_mem.h" |
| #include "base/win/scoped_comptr.h" |
| #include "base/win/shortcut.h" |
| #include "base/win/windows_version.h" |
| @@ -42,157 +41,6 @@ using content::BrowserThread; |
| namespace { |
| -// Gets the short (8.3) form of |path|, putting the result in |short_path| and |
| -// returning true on success. |short_path| is not modified on failure. |
| -bool ShortNameFromPath(const FilePath& path, string16* short_path) { |
| - DCHECK(short_path); |
| - string16 result(MAX_PATH, L'\0'); |
| - DWORD short_length = GetShortPathName(path.value().c_str(), &result[0], |
| - result.size()); |
| - if (short_length == 0 || short_length > result.size()) { |
| - PLOG(ERROR) << "Error getting short (8.3) path"; |
| - return false; |
| - } |
| - |
| - result.resize(short_length); |
| - short_path->swap(result); |
| - return true; |
| -} |
| - |
| -// Probe using IApplicationAssociationRegistration::QueryCurrentDefault |
| -// (Windows 8); see ProbeProtocolHandlers. This mechanism is not suitable for |
| -// use on previous versions of Windows despite the presence of |
| -// QueryCurrentDefault on them since versions of Windows prior to Windows 8 |
| -// did not perform validation on the ProgID registered as the current default. |
| -// As a result, stale ProgIDs could be returned, leading to false positives. |
| -ShellIntegration::DefaultWebClientState ProbeCurrentDefaultHandlers( |
| - const wchar_t* const* protocols, |
| - size_t num_protocols) { |
| - base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; |
| - HRESULT hr = registration.CreateInstance( |
| - CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); |
| - if (FAILED(hr)) |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - |
| - BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| - FilePath chrome_exe; |
| - if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| - NOTREACHED(); |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - } |
| - string16 prog_id(ShellUtil::kChromeHTMLProgId); |
| - prog_id += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe.value()); |
| - |
| - for (size_t i = 0; i < num_protocols; ++i) { |
| - base::win::ScopedCoMem<wchar_t> current_app; |
| - hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL, |
| - AL_EFFECTIVE, ¤t_app); |
| - if (FAILED(hr) || prog_id.compare(current_app) != 0) |
| - return ShellIntegration::NOT_DEFAULT_WEB_CLIENT; |
| - } |
| - |
| - return ShellIntegration::IS_DEFAULT_WEB_CLIENT; |
| -} |
| - |
| -// Probe using IApplicationAssociationRegistration::QueryAppIsDefault (Vista and |
| -// Windows 7); see ProbeProtocolHandlers. |
| -ShellIntegration::DefaultWebClientState ProbeAppIsDefaultHandlers( |
| - const wchar_t* const* protocols, |
| - size_t num_protocols) { |
| - base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; |
| - HRESULT hr = registration.CreateInstance( |
| - CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); |
| - if (FAILED(hr)) |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - |
| - BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| - FilePath chrome_exe; |
| - if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| - NOTREACHED(); |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - } |
| - string16 app_name(ShellUtil::GetApplicationName(dist, chrome_exe.value())); |
| - |
| - BOOL result; |
| - for (size_t i = 0; i < num_protocols; ++i) { |
| - result = TRUE; |
| - hr = registration->QueryAppIsDefault(protocols[i], AT_URLPROTOCOL, |
| - AL_EFFECTIVE, app_name.c_str(), &result); |
| - if (FAILED(hr) || result == FALSE) |
| - return ShellIntegration::NOT_DEFAULT_WEB_CLIENT; |
| - } |
| - |
| - return ShellIntegration::IS_DEFAULT_WEB_CLIENT; |
| -} |
| - |
| -// Probe the current commands registered to handle the shell "open" verb for |
| -// |protocols| (Windows XP); see ProbeProtocolHandlers. |
| -ShellIntegration::DefaultWebClientState ProbeOpenCommandHandlers( |
| - const wchar_t* const* protocols, |
| - size_t num_protocols) { |
| - // Get the path to the current exe (Chrome). |
| - FilePath app_path; |
| - if (!PathService::Get(base::FILE_EXE, &app_path)) { |
| - LOG(ERROR) << "Error getting app exe path"; |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - } |
| - |
| - // Get its short (8.3) form. |
| - string16 short_app_path; |
| - if (!ShortNameFromPath(app_path, &short_app_path)) |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - |
| - const HKEY root_key = HKEY_CLASSES_ROOT; |
| - string16 key_path; |
| - base::win::RegKey key; |
| - string16 value; |
| - CommandLine command_line(CommandLine::NO_PROGRAM); |
| - string16 short_path; |
| - |
| - for (size_t i = 0; i < num_protocols; ++i) { |
| - // Get the command line from HKCU\<protocol>\shell\open\command. |
| - key_path.assign(protocols[i]).append(ShellUtil::kRegShellOpen); |
| - if ((key.Open(root_key, key_path.c_str(), |
| - KEY_QUERY_VALUE) != ERROR_SUCCESS) || |
| - (key.ReadValue(L"", &value) != ERROR_SUCCESS)) { |
| - return ShellIntegration::NOT_DEFAULT_WEB_CLIENT; |
| - } |
| - |
| - // Need to normalize path in case it's been munged. |
| - command_line = CommandLine::FromString(value); |
| - if (!ShortNameFromPath(command_line.GetProgram(), &short_path)) |
| - return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
| - |
| - if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) |
| - return ShellIntegration::NOT_DEFAULT_WEB_CLIENT; |
| - } |
| - |
| - return ShellIntegration::IS_DEFAULT_WEB_CLIENT; |
| -} |
| - |
| -// A helper function that probes default protocol handler registration (in a |
| -// manner appropriate for the current version of Windows) to determine if |
| -// Chrome is the default handler for |protocols|. Returns IS_DEFAULT_WEB_CLIENT |
| -// only if Chrome is the default for all specified protocols. |
| -ShellIntegration::DefaultWebClientState ProbeProtocolHandlers( |
| - const wchar_t* const* protocols, |
| - size_t num_protocols) { |
| - DCHECK(!num_protocols || protocols); |
| - if (DCHECK_IS_ON()) { |
| - for (size_t i = 0; i < num_protocols; ++i) |
| - DCHECK(protocols[i] && *protocols[i]); |
| - } |
| - |
| - const base::win::Version windows_version = base::win::GetVersion(); |
| - |
| - if (windows_version >= base::win::VERSION_WIN8) |
| - return ProbeCurrentDefaultHandlers(protocols, num_protocols); |
| - else if (windows_version >= base::win::VERSION_VISTA) |
| - return ProbeAppIsDefaultHandlers(protocols, num_protocols); |
| - |
| - return ProbeOpenCommandHandlers(protocols, num_protocols); |
| -} |
| - |
| // Helper function for ShellIntegration::GetAppId to generates profile id |
| // from profile path. "profile_id" is composed of sanitized basenames of |
| // user data dir and profile dir joined by a ".". |
| @@ -389,6 +237,20 @@ void MigrateChromiumShortcutsCallback() { |
| } |
| } |
| +ShellIntegration::DefaultWebClientState |
| + GetDefaultWebClientStateFromShellUtilDefaultState( |
| + ShellUtil::DefaultState default_state) { |
| + switch (default_state) { |
| + case ShellUtil::NOT_DEFAULT: |
| + return ShellIntegration::NOT_DEFAULT_WEB_CLIENT; |
| + case ShellUtil::IS_DEFAULT: |
| + return ShellIntegration::IS_DEFAULT_WEB_CLIENT; |
| + default: |
| + DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state); |
| + return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; |
|
Nico
2012/10/15 17:09:24
nit: I believe it's preferable to list all cases e
gab
2012/10/15 17:45:33
I would have liked that, but this doesn't compile
scottmg
2012/10/15 18:04:23
4062 is off by default even at /W4 (we don't use /
|
| + } |
| +} |
| + |
| } // namespace |
| ShellIntegration::DefaultWebClientSetPermission |
| @@ -482,29 +344,14 @@ bool ShellIntegration::SetAsDefaultProtocolClientInteractive( |
| } |
| ShellIntegration::DefaultWebClientState ShellIntegration::IsDefaultBrowser() { |
| - // 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, |
| - // since the user may have changed their shell settings to cause HTML files |
| - // to open with a text editor for example. We also don't want to aggressively |
| - // claim FTP, since the user may have a separate FTP client. It is an open |
| - // question as to how to "heal" these settings. Perhaps the user should just |
| - // re-run the installer or run with the --set-default-browser command line |
| - // flag. There is doubtless some other key we can hook into to cause "Repair" |
| - // to show up in Add/Remove programs for us. |
| - static const wchar_t* const kChromeProtocols[] = { L"http", L"https" }; |
| - |
| - return ProbeProtocolHandlers(kChromeProtocols, arraysize(kChromeProtocols)); |
| + return GetDefaultWebClientStateFromShellUtilDefaultState( |
| + ShellUtil::IsChromeDefault()); |
| } |
| ShellIntegration::DefaultWebClientState |
| ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
| - if (protocol.empty()) |
| - return UNKNOWN_DEFAULT_WEB_CLIENT; |
| - |
| - string16 wide_protocol(UTF8ToUTF16(protocol)); |
| - const wchar_t* const protocols[] = { wide_protocol.c_str() }; |
| - |
| - return ProbeProtocolHandlers(protocols, arraysize(protocols)); |
| + return GetDefaultWebClientStateFromShellUtilDefaultState( |
| + ShellUtil::IsChromeDefaultProtocolClient(UTF8ToUTF16(protocol))); |
| } |
| // There is no reliable way to say which browser is default on a machine (each |