| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // Return empty string if profile_path is empty | 52 // Return empty string if profile_path is empty |
| 53 if (profile_path.empty()) | 53 if (profile_path.empty()) |
| 54 return base::string16(); | 54 return base::string16(); |
| 55 | 55 |
| 56 base::FilePath default_user_data_dir; | 56 base::FilePath default_user_data_dir; |
| 57 // Return empty string if profile_path is in default user data | 57 // Return empty string if profile_path is in default user data |
| 58 // dir and is the default profile. | 58 // dir and is the default profile. |
| 59 if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) && | 59 if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) && |
| 60 profile_path.DirName() == default_user_data_dir && | 60 profile_path.DirName() == default_user_data_dir && |
| 61 profile_path.BaseName().value() == | 61 profile_path.BaseName().value() == |
| 62 ASCIIToUTF16(chrome::kInitialProfile)) { | 62 base::ASCIIToUTF16(chrome::kInitialProfile)) { |
| 63 return base::string16(); | 63 return base::string16(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Get joined basenames of user data dir and profile. | 66 // Get joined basenames of user data dir and profile. |
| 67 base::string16 basenames = profile_path.DirName().BaseName().value() + | 67 base::string16 basenames = profile_path.DirName().BaseName().value() + |
| 68 L"." + profile_path.BaseName().value(); | 68 L"." + profile_path.BaseName().value(); |
| 69 | 69 |
| 70 base::string16 profile_id; | 70 base::string16 profile_id; |
| 71 profile_id.reserve(basenames.size()); | 71 profile_id.reserve(basenames.size()); |
| 72 | 72 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 99 chrome::GetDefaultUserDataDirectory(&user_data_dir); | 99 chrome::GetDefaultUserDataDirectory(&user_data_dir); |
| 100 // Adjust with any policy that overrides any other way to set the path. | 100 // Adjust with any policy that overrides any other way to set the path. |
| 101 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); | 101 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); |
| 102 DCHECK(!user_data_dir.empty()); | 102 DCHECK(!user_data_dir.empty()); |
| 103 | 103 |
| 104 base::FilePath profile_subdir; | 104 base::FilePath profile_subdir; |
| 105 if (command_line.HasSwitch(switches::kProfileDirectory)) { | 105 if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 106 profile_subdir = | 106 profile_subdir = |
| 107 command_line.GetSwitchValuePath(switches::kProfileDirectory); | 107 command_line.GetSwitchValuePath(switches::kProfileDirectory); |
| 108 } else { | 108 } else { |
| 109 profile_subdir = base::FilePath(ASCIIToUTF16(chrome::kInitialProfile)); | 109 profile_subdir = |
| 110 base::FilePath(base::ASCIIToUTF16(chrome::kInitialProfile)); |
| 110 } | 111 } |
| 111 DCHECK(!profile_subdir.empty()); | 112 DCHECK(!profile_subdir.empty()); |
| 112 | 113 |
| 113 base::FilePath profile_path = user_data_dir.Append(profile_subdir); | 114 base::FilePath profile_path = user_data_dir.Append(profile_subdir); |
| 114 base::string16 app_name; | 115 base::string16 app_name; |
| 115 if (command_line.HasSwitch(switches::kApp)) { | 116 if (command_line.HasSwitch(switches::kApp)) { |
| 116 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( | 117 app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( |
| 117 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); | 118 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); |
| 118 } else if (command_line.HasSwitch(switches::kAppId)) { | 119 } else if (command_line.HasSwitch(switches::kAppId)) { |
| 119 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromExtensionId( | 120 app_name = base::UTF8ToUTF16( |
| 120 command_line.GetSwitchValueASCII(switches::kAppId))); | 121 web_app::GenerateApplicationNameFromExtensionId( |
| 122 command_line.GetSwitchValueASCII(switches::kAppId))); |
| 121 } else if (command_line.HasSwitch(switches::kShowAppList)) { | 123 } else if (command_line.HasSwitch(switches::kShowAppList)) { |
| 122 app_name = GetAppListAppName(); | 124 app_name = GetAppListAppName(); |
| 123 } else { | 125 } else { |
| 124 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 126 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 125 app_name = ShellUtil::GetBrowserModelId(dist, is_per_user_install); | 127 app_name = ShellUtil::GetBrowserModelId(dist, is_per_user_install); |
| 126 } | 128 } |
| 127 DCHECK(!app_name.empty()); | 129 DCHECK(!app_name.empty()); |
| 128 | 130 |
| 129 return ShellIntegration::GetAppModelIdForProfile(app_name, profile_path); | 131 return ShellIntegration::GetAppModelIdForProfile(app_name, profile_path); |
| 130 } | 132 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { | 227 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
| 226 if (protocol.empty()) | 228 if (protocol.empty()) |
| 227 return false; | 229 return false; |
| 228 | 230 |
| 229 base::FilePath chrome_exe; | 231 base::FilePath chrome_exe; |
| 230 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 232 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 231 LOG(ERROR) << "Error getting app exe path"; | 233 LOG(ERROR) << "Error getting app exe path"; |
| 232 return false; | 234 return false; |
| 233 } | 235 } |
| 234 | 236 |
| 235 base::string16 wprotocol(UTF8ToUTF16(protocol)); | 237 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| 236 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 238 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 237 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(), | 239 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(), |
| 238 wprotocol)) { | 240 wprotocol)) { |
| 239 LOG(ERROR) << "Chrome could not be set as default handler for " | 241 LOG(ERROR) << "Chrome could not be set as default handler for " |
| 240 << protocol << "."; | 242 << protocol << "."; |
| 241 return false; | 243 return false; |
| 242 } | 244 } |
| 243 | 245 |
| 244 VLOG(1) << "Chrome registered as default handler for " << protocol << "."; | 246 VLOG(1) << "Chrome registered as default handler for " << protocol << "."; |
| 245 return true; | 247 return true; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 264 | 266 |
| 265 bool ShellIntegration::SetAsDefaultProtocolClientInteractive( | 267 bool ShellIntegration::SetAsDefaultProtocolClientInteractive( |
| 266 const std::string& protocol) { | 268 const std::string& protocol) { |
| 267 base::FilePath chrome_exe; | 269 base::FilePath chrome_exe; |
| 268 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 270 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 269 NOTREACHED() << "Error getting app exe path"; | 271 NOTREACHED() << "Error getting app exe path"; |
| 270 return false; | 272 return false; |
| 271 } | 273 } |
| 272 | 274 |
| 273 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 275 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 274 base::string16 wprotocol(UTF8ToUTF16(protocol)); | 276 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| 275 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( | 277 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( |
| 276 dist, chrome_exe.value(), wprotocol)) { | 278 dist, chrome_exe.value(), wprotocol)) { |
| 277 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; | 279 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; |
| 278 return false; | 280 return false; |
| 279 } | 281 } |
| 280 | 282 |
| 281 VLOG(1) << "Set-default-client Windows UI completed."; | 283 VLOG(1) << "Set-default-client Windows UI completed."; |
| 282 return true; | 284 return true; |
| 283 } | 285 } |
| 284 | 286 |
| 285 ShellIntegration::DefaultWebClientState ShellIntegration::GetDefaultBrowser() { | 287 ShellIntegration::DefaultWebClientState ShellIntegration::GetDefaultBrowser() { |
| 286 return GetDefaultWebClientStateFromShellUtilDefaultState( | 288 return GetDefaultWebClientStateFromShellUtilDefaultState( |
| 287 ShellUtil::GetChromeDefaultState()); | 289 ShellUtil::GetChromeDefaultState()); |
| 288 } | 290 } |
| 289 | 291 |
| 290 ShellIntegration::DefaultWebClientState | 292 ShellIntegration::DefaultWebClientState |
| 291 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { | 293 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
| 292 return GetDefaultWebClientStateFromShellUtilDefaultState( | 294 return GetDefaultWebClientStateFromShellUtilDefaultState( |
| 293 ShellUtil::GetChromeDefaultProtocolClientState(UTF8ToUTF16(protocol))); | 295 ShellUtil::GetChromeDefaultProtocolClientState( |
| 296 base::UTF8ToUTF16(protocol))); |
| 294 } | 297 } |
| 295 | 298 |
| 296 std::string ShellIntegration::GetApplicationForProtocol(const GURL& url) { | 299 std::string ShellIntegration::GetApplicationForProtocol(const GURL& url) { |
| 297 // TODO(calamity): this will be implemented when external_protocol_dialog is | 300 // TODO(calamity): this will be implemented when external_protocol_dialog is |
| 298 // refactored on windows. | 301 // refactored on windows. |
| 299 NOTREACHED(); | 302 NOTREACHED(); |
| 300 return std::string(); | 303 return std::string(); |
| 301 } | 304 } |
| 302 | 305 |
| 303 // There is no reliable way to say which browser is default on a machine (each | 306 // There is no reliable way to say which browser is default on a machine (each |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 } | 521 } |
| 519 | 522 |
| 520 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + | 523 shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + |
| 521 installer::kLnkExt); | 524 installer::kLnkExt); |
| 522 if (base::PathExists(shortcut)) | 525 if (base::PathExists(shortcut)) |
| 523 return shortcut; | 526 return shortcut; |
| 524 } | 527 } |
| 525 | 528 |
| 526 return base::FilePath(); | 529 return base::FilePath(); |
| 527 } | 530 } |
| OLD | NEW |