OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_frame/chrome_frame_automation.h" | 5 #include "chrome_frame/chrome_frame_automation.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
12 #include "base/lock.h" | 12 #include "base/lock.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/singleton.h" | 16 #include "base/singleton.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
19 #include "base/waitable_event.h" | 19 #include "base/waitable_event.h" |
20 #include "chrome/app/client_util.h" | 20 #include "chrome/app/client_util.h" |
21 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_paths.h" | |
23 #include "chrome/common/chrome_paths_internal.h" | |
24 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/test/automation/tab_proxy.h" | 23 #include "chrome/test/automation/tab_proxy.h" |
26 #include "chrome_frame/chrome_launcher.h" | 24 #include "chrome_frame/chrome_launcher.h" |
27 #include "chrome_frame/utils.h" | 25 #include "chrome_frame/utils.h" |
28 #include "chrome_frame/sync_msg_reply_dispatcher.h" | 26 #include "chrome_frame/sync_msg_reply_dispatcher.h" |
29 | 27 |
30 #ifdef NDEBUG | 28 #ifdef NDEBUG |
31 int64 kAutomationServerReasonableLaunchDelay = 1000; // in milliseconds | 29 int64 kAutomationServerReasonableLaunchDelay = 1000; // in milliseconds |
32 #else | 30 #else |
33 int64 kAutomationServerReasonableLaunchDelay = 1000 * 10; | 31 int64 kAutomationServerReasonableLaunchDelay = 1000 * 10; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 command_line->AppendSwitch(switches::kDisablePopupBlocking); | 257 command_line->AppendSwitch(switches::kDisablePopupBlocking); |
260 | 258 |
261 // Disable the "Whoa! Chrome has crashed." dialog, because that isn't very | 259 // Disable the "Whoa! Chrome has crashed." dialog, because that isn't very |
262 // useful for Chrome Frame users. | 260 // useful for Chrome Frame users. |
263 #ifndef NDEBUG | 261 #ifndef NDEBUG |
264 command_line->AppendSwitch(switches::kNoErrorDialogs); | 262 command_line->AppendSwitch(switches::kNoErrorDialogs); |
265 #endif | 263 #endif |
266 | 264 |
267 command_line->AppendSwitch(switches::kEnableRendererAccessibility); | 265 command_line->AppendSwitch(switches::kEnableRendererAccessibility); |
268 | 266 |
269 // Place the profile directory in | 267 DLOG(INFO) << "Profile path: " << params.profile_path.value(); |
270 // "<chrome_exe_path>\..\User Data\<profile-name>" | 268 command_line->AppendSwitchWithValue(switches::kUserDataDir, |
271 if (!entry->profile_name.empty()) { | 269 params.profile_path.value()); |
272 FilePath profile_path; | |
273 if (chrome::GetChromeFrameUserDataDirectory(&profile_path)) { | |
274 profile_path = profile_path.Append(entry->profile_name); | |
275 command_line->AppendSwitchWithValue(switches::kUserDataDir, | |
276 profile_path.value()); | |
277 } else { | |
278 // Can't get the profile dir :-( We need one to work, so fail. | |
279 // We have no code for launch failure. | |
280 entry->launch_result = AutomationLaunchResult(-1); | |
281 } | |
282 } | |
283 | 270 |
284 std::wstring command_line_string(command_line->command_line_string()); | 271 std::wstring command_line_string(command_line->command_line_string()); |
285 // If there are any extra arguments, append them to the command line. | 272 // If there are any extra arguments, append them to the command line. |
286 if (!params.extra_chrome_arguments.empty()) { | 273 if (!params.extra_chrome_arguments.empty()) { |
287 command_line_string += L' ' + params.extra_chrome_arguments; | 274 command_line_string += L' ' + params.extra_chrome_arguments; |
288 } | 275 } |
289 | 276 |
290 automation_server_launch_start_time_ = base::TimeTicks::Now(); | 277 automation_server_launch_start_time_ = base::TimeTicks::Now(); |
291 | 278 |
292 if (!base::LaunchApp(command_line_string, false, false, NULL)) { | 279 if (!base::LaunchApp(command_line_string, false, false, NULL)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 AUTOMATION_CREATE_TAB_FAILED, | 314 AUTOMATION_CREATE_TAB_FAILED, |
328 AUTOMATION_CREATE_TAB_FAILED + 1); | 315 AUTOMATION_CREATE_TAB_FAILED + 1); |
329 } | 316 } |
330 | 317 |
331 // Finally set the proxy. | 318 // Finally set the proxy. |
332 entry->proxy = proxy; | 319 entry->proxy = proxy; |
333 delegate->LaunchComplete(proxy, entry->launch_result); | 320 delegate->LaunchComplete(proxy, entry->launch_result); |
334 } | 321 } |
335 | 322 |
336 bool ProxyFactory::ReleaseAutomationServer(void* server_id) { | 323 bool ProxyFactory::ReleaseAutomationServer(void* server_id) { |
337 DLOG(INFO) << __FUNCTION__; | |
338 | |
339 if (!server_id) { | 324 if (!server_id) { |
340 NOTREACHED(); | 325 NOTREACHED(); |
341 return false; | 326 return false; |
342 } | 327 } |
343 | 328 |
344 ProxyCacheEntry* entry = reinterpret_cast<ProxyCacheEntry*>(server_id); | 329 ProxyCacheEntry* entry = reinterpret_cast<ProxyCacheEntry*>(server_id); |
345 | 330 |
346 #ifndef NDEBUG | 331 #ifndef NDEBUG |
347 lock_.Acquire(); | 332 lock_.Acquire(); |
348 Vector::ContainerType::iterator it = std::find(proxies_.container().begin(), | 333 Vector::ContainerType::iterator it = std::find(proxies_.container().begin(), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 430 |
446 ChromeFrameAutomationClient::~ChromeFrameAutomationClient() { | 431 ChromeFrameAutomationClient::~ChromeFrameAutomationClient() { |
447 // Uninitialize must be called prior to the destructor | 432 // Uninitialize must be called prior to the destructor |
448 DCHECK(automation_server_ == NULL); | 433 DCHECK(automation_server_ == NULL); |
449 } | 434 } |
450 | 435 |
451 bool ChromeFrameAutomationClient::Initialize( | 436 bool ChromeFrameAutomationClient::Initialize( |
452 ChromeFrameDelegate* chrome_frame_delegate, | 437 ChromeFrameDelegate* chrome_frame_delegate, |
453 int automation_server_launch_timeout, | 438 int automation_server_launch_timeout, |
454 bool perform_version_check, | 439 bool perform_version_check, |
455 const std::wstring& profile_name, | 440 const FilePath& profile_path, |
456 const std::wstring& extra_chrome_arguments, | 441 const std::wstring& extra_chrome_arguments, |
457 bool incognito) { | 442 bool incognito) { |
458 DCHECK(!IsWindow()); | 443 DCHECK(!IsWindow()); |
459 chrome_frame_delegate_ = chrome_frame_delegate; | 444 chrome_frame_delegate_ = chrome_frame_delegate; |
460 ui_thread_id_ = PlatformThread::CurrentId(); | 445 ui_thread_id_ = PlatformThread::CurrentId(); |
461 #ifndef NDEBUG | 446 #ifndef NDEBUG |
462 // In debug mode give more time to work with a debugger. | 447 // In debug mode give more time to work with a debugger. |
463 if (IsDebuggerPresent()) { | 448 if (IsDebuggerPresent()) { |
464 // Don't use INFINITE (which is -1) or even MAXINT since we will convert | 449 // Don't use INFINITE (which is -1) or even MAXINT since we will convert |
465 // from milliseconds to microseconds when stored in a base::TimeDelta, | 450 // from milliseconds to microseconds when stored in a base::TimeDelta, |
(...skipping 19 matching lines...) Expand all Loading... |
485 // Keep object in memory, while the window is alive. | 470 // Keep object in memory, while the window is alive. |
486 // Corresponsing Release is in OnFinalMessage(); | 471 // Corresponsing Release is in OnFinalMessage(); |
487 AddRef(); | 472 AddRef(); |
488 | 473 |
489 // Mark our state as initializing. We'll reach initialized once | 474 // Mark our state as initializing. We'll reach initialized once |
490 // InitializeComplete is called successfully. | 475 // InitializeComplete is called successfully. |
491 init_state_ = INITIALIZING; | 476 init_state_ = INITIALIZING; |
492 | 477 |
493 chrome_launch_params_.automation_server_launch_timeout = | 478 chrome_launch_params_.automation_server_launch_timeout = |
494 automation_server_launch_timeout; | 479 automation_server_launch_timeout; |
495 chrome_launch_params_.profile_name = profile_name; | 480 chrome_launch_params_.profile_path = profile_path; |
| 481 chrome_launch_params_.profile_name = profile_path.BaseName().value(); |
496 chrome_launch_params_.extra_chrome_arguments = extra_chrome_arguments; | 482 chrome_launch_params_.extra_chrome_arguments = extra_chrome_arguments; |
497 chrome_launch_params_.perform_version_check = perform_version_check; | 483 chrome_launch_params_.perform_version_check = perform_version_check; |
498 chrome_launch_params_.url = navigate_after_initialization_ ? GURL() : url_; | 484 chrome_launch_params_.url = navigate_after_initialization_ ? GURL() : url_; |
499 chrome_launch_params_.incognito_mode = incognito; | 485 chrome_launch_params_.incognito_mode = incognito; |
500 | 486 |
501 proxy_factory_->GetAutomationServer( | 487 proxy_factory_->GetAutomationServer( |
502 static_cast<ProxyFactory::LaunchDelegate*>(this), | 488 static_cast<ProxyFactory::LaunchDelegate*>(this), |
503 chrome_launch_params_, &automation_server_id_); | 489 chrome_launch_params_, &automation_server_id_); |
504 | 490 |
505 return true; | 491 return true; |
506 } | 492 } |
507 | 493 |
508 void ChromeFrameAutomationClient::Uninitialize() { | 494 void ChromeFrameAutomationClient::Uninitialize() { |
509 DLOG(INFO) << __FUNCTION__; | |
510 | |
511 if (init_state_ == UNINITIALIZED) { | 495 if (init_state_ == UNINITIALIZED) { |
512 DLOG(WARNING) << __FUNCTION__ << ": Automation client not initialized"; | 496 DLOG(WARNING) << __FUNCTION__ << ": Automation client not initialized"; |
513 return; | 497 return; |
514 } | 498 } |
515 | 499 |
516 init_state_ = UNINITIALIZING; | 500 init_state_ = UNINITIALIZING; |
517 | 501 |
518 // Called from client's FinalRelease() / destructor | 502 // Called from client's FinalRelease() / destructor |
519 // ChromeFrameAutomationClient may wait for the initialization (launch) | 503 // ChromeFrameAutomationClient may wait for the initialization (launch) |
520 // to complete while Uninitialize is called. | 504 // to complete while Uninitialize is called. |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 // Continue with Initialization - Create external tab | 902 // Continue with Initialization - Create external tab |
919 CreateExternalTab(); | 903 CreateExternalTab(); |
920 } else { | 904 } else { |
921 // Send a notification to Chrome that we are ready to connect to the | 905 // Send a notification to Chrome that we are ready to connect to the |
922 // ExternalTab. | 906 // ExternalTab. |
923 IPC::SyncMessage* message = | 907 IPC::SyncMessage* message = |
924 new AutomationMsg_ConnectExternalTab(0, external_tab_cookie_, true, | 908 new AutomationMsg_ConnectExternalTab(0, external_tab_cookie_, true, |
925 NULL, NULL, NULL); | 909 NULL, NULL, NULL); |
926 automation_server_->SendAsAsync(message, NewCallback(this, | 910 automation_server_->SendAsAsync(message, NewCallback(this, |
927 &ChromeFrameAutomationClient::CreateExternalTabComplete), this); | 911 &ChromeFrameAutomationClient::CreateExternalTabComplete), this); |
| 912 DLOG(INFO) << __FUNCTION__ << ": sending CreateExternalTabComplete"; |
928 } | 913 } |
929 } | 914 } |
930 } else { | 915 } else { |
931 // Launch failed. Note, we cannot delete proxy here. | 916 // Launch failed. Note, we cannot delete proxy here. |
932 PostTask(FROM_HERE, NewRunnableMethod(this, | 917 PostTask(FROM_HERE, NewRunnableMethod(this, |
933 &ChromeFrameAutomationClient::InitializeComplete, result)); | 918 &ChromeFrameAutomationClient::InitializeComplete, result)); |
934 } | 919 } |
935 } | 920 } |
936 | 921 |
937 void ChromeFrameAutomationClient::InitializeComplete( | 922 void ChromeFrameAutomationClient::InitializeComplete( |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 ::GetClientRect(parent_window, &parent_client_rect); | 1072 ::GetClientRect(parent_window, &parent_client_rect); |
1088 int width = parent_client_rect.right - parent_client_rect.left; | 1073 int width = parent_client_rect.right - parent_client_rect.left; |
1089 int height = parent_client_rect.bottom - parent_client_rect.top; | 1074 int height = parent_client_rect.bottom - parent_client_rect.top; |
1090 | 1075 |
1091 Resize(width, height, SWP_SHOWWINDOW | SWP_NOZORDER); | 1076 Resize(width, height, SWP_SHOWWINDOW | SWP_NOZORDER); |
1092 } | 1077 } |
1093 } | 1078 } |
1094 } | 1079 } |
1095 | 1080 |
1096 void ChromeFrameAutomationClient::ReleaseAutomationServer() { | 1081 void ChromeFrameAutomationClient::ReleaseAutomationServer() { |
1097 DLOG(INFO) << __FUNCTION__; | |
1098 if (automation_server_id_) { | 1082 if (automation_server_id_) { |
1099 // Cache the server id and clear the automation_server_id_ before | 1083 // Cache the server id and clear the automation_server_id_ before |
1100 // calling ReleaseAutomationServer. The reason we do this is that | 1084 // calling ReleaseAutomationServer. The reason we do this is that |
1101 // we must cancel pending messages before we release the automation server. | 1085 // we must cancel pending messages before we release the automation server. |
1102 // Furthermore, while ReleaseAutomationServer is running, we could get | 1086 // Furthermore, while ReleaseAutomationServer is running, we could get |
1103 // a callback to LaunchComplete which is where we normally get our pointer | 1087 // a callback to LaunchComplete which is where we normally get our pointer |
1104 // to the automation server and there we check the server id for NULLness | 1088 // to the automation server and there we check the server id for NULLness |
1105 // and do nothing if it is NULL. | 1089 // and do nothing if it is NULL. |
1106 void* server_id = automation_server_id_; | 1090 void* server_id = automation_server_id_; |
1107 automation_server_id_ = NULL; | 1091 automation_server_id_ = NULL; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 font_size > LARGEST_FONT) { | 1189 font_size > LARGEST_FONT) { |
1206 NOTREACHED() << "Invalid font size specified : " | 1190 NOTREACHED() << "Invalid font size specified : " |
1207 << font_size; | 1191 << font_size; |
1208 return; | 1192 return; |
1209 } | 1193 } |
1210 | 1194 |
1211 automation_server_->Send( | 1195 automation_server_->Send( |
1212 new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); | 1196 new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); |
1213 } | 1197 } |
1214 | 1198 |
| 1199 void ChromeFrameAutomationClient::RemoveBrowsingData(int remove_mask) { |
| 1200 automation_server_->Send( |
| 1201 new AutomationMsg_RemoveBrowsingData(0, remove_mask)); |
| 1202 } |
1215 | 1203 |
1216 ////////////////////////////////////////////////////////////////////////// | 1204 ////////////////////////////////////////////////////////////////////////// |
1217 // PluginUrlRequestDelegate implementation. | 1205 // PluginUrlRequestDelegate implementation. |
1218 // Forward network related responses to Chrome. | 1206 // Forward network related responses to Chrome. |
1219 | 1207 |
1220 void ChromeFrameAutomationClient::OnResponseStarted(int request_id, | 1208 void ChromeFrameAutomationClient::OnResponseStarted(int request_id, |
1221 const char* mime_type, const char* headers, int size, | 1209 const char* mime_type, const char* headers, int size, |
1222 base::Time last_modified, const std::string& redirect_url, | 1210 base::Time last_modified, const std::string& redirect_url, |
1223 int redirect_status) { | 1211 int redirect_status) { |
1224 const IPC::AutomationURLResponse response = { | 1212 const IPC::AutomationURLResponse response = { |
(...skipping 15 matching lines...) Expand all Loading... |
1240 automation_server_->Send(new AutomationMsg_RequestData(0, tab_->handle(), | 1228 automation_server_->Send(new AutomationMsg_RequestData(0, tab_->handle(), |
1241 request_id, data)); | 1229 request_id, data)); |
1242 } | 1230 } |
1243 | 1231 |
1244 void ChromeFrameAutomationClient::OnResponseEnd(int request_id, | 1232 void ChromeFrameAutomationClient::OnResponseEnd(int request_id, |
1245 const URLRequestStatus& status) { | 1233 const URLRequestStatus& status) { |
1246 automation_server_->Send(new AutomationMsg_RequestEnd(0, tab_->handle(), | 1234 automation_server_->Send(new AutomationMsg_RequestEnd(0, tab_->handle(), |
1247 request_id, status)); | 1235 request_id, status)); |
1248 } | 1236 } |
1249 | 1237 |
OLD | NEW |