Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Side by Side Diff: chrome_frame/chrome_frame_automation.cc

Issue 1343004: 3rd try. *sigh*... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/chrome_frame_automation.h ('k') | chrome_frame/chrome_frame_plugin.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // In headless mode runs like reliability test runs we want full crash dumps 267 // In headless mode runs like reliability test runs we want full crash dumps
270 // from chrome. 268 // from chrome.
271 if (IsHeadlessMode()) 269 if (IsHeadlessMode())
272 command_line->AppendSwitch(switches::kFullMemoryCrashReport); 270 command_line->AppendSwitch(switches::kFullMemoryCrashReport);
273 271
274 // Place the profile directory in 272 DLOG(INFO) << "Profile path: " << params.profile_path.value();
275 // "<chrome_exe_path>\..\User Data\<profile-name>" 273 command_line->AppendSwitchWithValue(switches::kUserDataDir,
276 if (!entry->profile_name.empty()) { 274 params.profile_path.value());
277 FilePath profile_path;
278 if (chrome::GetChromeFrameUserDataDirectory(&profile_path)) {
279 profile_path = profile_path.Append(entry->profile_name);
280 command_line->AppendSwitchWithValue(switches::kUserDataDir,
281 profile_path.value());
282 } else {
283 // Can't get the profile dir :-( We need one to work, so fail.
284 // We have no code for launch failure.
285 entry->launch_result = AutomationLaunchResult(-1);
286 }
287 }
288 275
289 std::wstring command_line_string(command_line->command_line_string()); 276 std::wstring command_line_string(command_line->command_line_string());
290 // If there are any extra arguments, append them to the command line. 277 // If there are any extra arguments, append them to the command line.
291 if (!params.extra_chrome_arguments.empty()) { 278 if (!params.extra_chrome_arguments.empty()) {
292 command_line_string += L' ' + params.extra_chrome_arguments; 279 command_line_string += L' ' + params.extra_chrome_arguments;
293 } 280 }
294 281
295 automation_server_launch_start_time_ = base::TimeTicks::Now(); 282 automation_server_launch_start_time_ = base::TimeTicks::Now();
296 283
297 if (!base::LaunchApp(command_line_string, false, false, NULL)) { 284 if (!base::LaunchApp(command_line_string, false, false, NULL)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 AUTOMATION_CREATE_TAB_FAILED, 319 AUTOMATION_CREATE_TAB_FAILED,
333 AUTOMATION_CREATE_TAB_FAILED + 1); 320 AUTOMATION_CREATE_TAB_FAILED + 1);
334 } 321 }
335 322
336 // Finally set the proxy. 323 // Finally set the proxy.
337 entry->proxy = proxy; 324 entry->proxy = proxy;
338 delegate->LaunchComplete(proxy, entry->launch_result); 325 delegate->LaunchComplete(proxy, entry->launch_result);
339 } 326 }
340 327
341 bool ProxyFactory::ReleaseAutomationServer(void* server_id) { 328 bool ProxyFactory::ReleaseAutomationServer(void* server_id) {
342 DLOG(INFO) << __FUNCTION__;
343
344 if (!server_id) { 329 if (!server_id) {
345 NOTREACHED(); 330 NOTREACHED();
346 return false; 331 return false;
347 } 332 }
348 333
349 ProxyCacheEntry* entry = reinterpret_cast<ProxyCacheEntry*>(server_id); 334 ProxyCacheEntry* entry = reinterpret_cast<ProxyCacheEntry*>(server_id);
350 335
351 #ifndef NDEBUG 336 #ifndef NDEBUG
352 lock_.Acquire(); 337 lock_.Acquire();
353 Vector::ContainerType::iterator it = std::find(proxies_.container().begin(), 338 Vector::ContainerType::iterator it = std::find(proxies_.container().begin(),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 435
451 ChromeFrameAutomationClient::~ChromeFrameAutomationClient() { 436 ChromeFrameAutomationClient::~ChromeFrameAutomationClient() {
452 // Uninitialize must be called prior to the destructor 437 // Uninitialize must be called prior to the destructor
453 DCHECK(automation_server_ == NULL); 438 DCHECK(automation_server_ == NULL);
454 } 439 }
455 440
456 bool ChromeFrameAutomationClient::Initialize( 441 bool ChromeFrameAutomationClient::Initialize(
457 ChromeFrameDelegate* chrome_frame_delegate, 442 ChromeFrameDelegate* chrome_frame_delegate,
458 int automation_server_launch_timeout, 443 int automation_server_launch_timeout,
459 bool perform_version_check, 444 bool perform_version_check,
460 const std::wstring& profile_name, 445 const FilePath& profile_path,
461 const std::wstring& extra_chrome_arguments, 446 const std::wstring& extra_chrome_arguments,
462 bool incognito) { 447 bool incognito) {
463 DCHECK(!IsWindow()); 448 DCHECK(!IsWindow());
464 chrome_frame_delegate_ = chrome_frame_delegate; 449 chrome_frame_delegate_ = chrome_frame_delegate;
465 ui_thread_id_ = PlatformThread::CurrentId(); 450 ui_thread_id_ = PlatformThread::CurrentId();
466 #ifndef NDEBUG 451 #ifndef NDEBUG
467 // In debug mode give more time to work with a debugger. 452 // In debug mode give more time to work with a debugger.
468 if (IsDebuggerPresent()) { 453 if (IsDebuggerPresent()) {
469 // Don't use INFINITE (which is -1) or even MAXINT since we will convert 454 // Don't use INFINITE (which is -1) or even MAXINT since we will convert
470 // from milliseconds to microseconds when stored in a base::TimeDelta, 455 // from milliseconds to microseconds when stored in a base::TimeDelta,
(...skipping 19 matching lines...) Expand all
490 // Keep object in memory, while the window is alive. 475 // Keep object in memory, while the window is alive.
491 // Corresponsing Release is in OnFinalMessage(); 476 // Corresponsing Release is in OnFinalMessage();
492 AddRef(); 477 AddRef();
493 478
494 // Mark our state as initializing. We'll reach initialized once 479 // Mark our state as initializing. We'll reach initialized once
495 // InitializeComplete is called successfully. 480 // InitializeComplete is called successfully.
496 init_state_ = INITIALIZING; 481 init_state_ = INITIALIZING;
497 482
498 chrome_launch_params_.automation_server_launch_timeout = 483 chrome_launch_params_.automation_server_launch_timeout =
499 automation_server_launch_timeout; 484 automation_server_launch_timeout;
500 chrome_launch_params_.profile_name = profile_name; 485 chrome_launch_params_.profile_path = profile_path;
486 chrome_launch_params_.profile_name = profile_path.BaseName().value();
501 chrome_launch_params_.extra_chrome_arguments = extra_chrome_arguments; 487 chrome_launch_params_.extra_chrome_arguments = extra_chrome_arguments;
502 chrome_launch_params_.perform_version_check = perform_version_check; 488 chrome_launch_params_.perform_version_check = perform_version_check;
503 chrome_launch_params_.url = navigate_after_initialization_ ? GURL() : url_; 489 chrome_launch_params_.url = navigate_after_initialization_ ? GURL() : url_;
504 chrome_launch_params_.incognito_mode = incognito; 490 chrome_launch_params_.incognito_mode = incognito;
505 491
506 proxy_factory_->GetAutomationServer( 492 proxy_factory_->GetAutomationServer(
507 static_cast<ProxyFactory::LaunchDelegate*>(this), 493 static_cast<ProxyFactory::LaunchDelegate*>(this),
508 chrome_launch_params_, &automation_server_id_); 494 chrome_launch_params_, &automation_server_id_);
509 495
510 return true; 496 return true;
511 } 497 }
512 498
513 void ChromeFrameAutomationClient::Uninitialize() { 499 void ChromeFrameAutomationClient::Uninitialize() {
514 DLOG(INFO) << __FUNCTION__;
515
516 if (init_state_ == UNINITIALIZED) { 500 if (init_state_ == UNINITIALIZED) {
517 DLOG(WARNING) << __FUNCTION__ << ": Automation client not initialized"; 501 DLOG(WARNING) << __FUNCTION__ << ": Automation client not initialized";
518 return; 502 return;
519 } 503 }
520 504
521 init_state_ = UNINITIALIZING; 505 init_state_ = UNINITIALIZING;
522 506
523 // Called from client's FinalRelease() / destructor 507 // Called from client's FinalRelease() / destructor
524 // ChromeFrameAutomationClient may wait for the initialization (launch) 508 // ChromeFrameAutomationClient may wait for the initialization (launch)
525 // to complete while Uninitialize is called. 509 // to complete while Uninitialize is called.
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 // Continue with Initialization - Create external tab 907 // Continue with Initialization - Create external tab
924 CreateExternalTab(); 908 CreateExternalTab();
925 } else { 909 } else {
926 // Send a notification to Chrome that we are ready to connect to the 910 // Send a notification to Chrome that we are ready to connect to the
927 // ExternalTab. 911 // ExternalTab.
928 IPC::SyncMessage* message = 912 IPC::SyncMessage* message =
929 new AutomationMsg_ConnectExternalTab(0, external_tab_cookie_, true, 913 new AutomationMsg_ConnectExternalTab(0, external_tab_cookie_, true,
930 NULL, NULL, NULL); 914 NULL, NULL, NULL);
931 automation_server_->SendAsAsync(message, NewCallback(this, 915 automation_server_->SendAsAsync(message, NewCallback(this,
932 &ChromeFrameAutomationClient::CreateExternalTabComplete), this); 916 &ChromeFrameAutomationClient::CreateExternalTabComplete), this);
917 DLOG(INFO) << __FUNCTION__ << ": sending CreateExternalTabComplete";
933 } 918 }
934 } 919 }
935 } else { 920 } else {
936 // Launch failed. Note, we cannot delete proxy here. 921 // Launch failed. Note, we cannot delete proxy here.
937 PostTask(FROM_HERE, NewRunnableMethod(this, 922 PostTask(FROM_HERE, NewRunnableMethod(this,
938 &ChromeFrameAutomationClient::InitializeComplete, result)); 923 &ChromeFrameAutomationClient::InitializeComplete, result));
939 } 924 }
940 } 925 }
941 926
942 void ChromeFrameAutomationClient::InitializeComplete( 927 void ChromeFrameAutomationClient::InitializeComplete(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 ::GetClientRect(parent_window, &parent_client_rect); 1077 ::GetClientRect(parent_window, &parent_client_rect);
1093 int width = parent_client_rect.right - parent_client_rect.left; 1078 int width = parent_client_rect.right - parent_client_rect.left;
1094 int height = parent_client_rect.bottom - parent_client_rect.top; 1079 int height = parent_client_rect.bottom - parent_client_rect.top;
1095 1080
1096 Resize(width, height, SWP_SHOWWINDOW | SWP_NOZORDER); 1081 Resize(width, height, SWP_SHOWWINDOW | SWP_NOZORDER);
1097 } 1082 }
1098 } 1083 }
1099 } 1084 }
1100 1085
1101 void ChromeFrameAutomationClient::ReleaseAutomationServer() { 1086 void ChromeFrameAutomationClient::ReleaseAutomationServer() {
1102 DLOG(INFO) << __FUNCTION__;
1103 if (automation_server_id_) { 1087 if (automation_server_id_) {
1104 // Cache the server id and clear the automation_server_id_ before 1088 // Cache the server id and clear the automation_server_id_ before
1105 // calling ReleaseAutomationServer. The reason we do this is that 1089 // calling ReleaseAutomationServer. The reason we do this is that
1106 // we must cancel pending messages before we release the automation server. 1090 // we must cancel pending messages before we release the automation server.
1107 // Furthermore, while ReleaseAutomationServer is running, we could get 1091 // Furthermore, while ReleaseAutomationServer is running, we could get
1108 // a callback to LaunchComplete which is where we normally get our pointer 1092 // a callback to LaunchComplete which is where we normally get our pointer
1109 // to the automation server and there we check the server id for NULLness 1093 // to the automation server and there we check the server id for NULLness
1110 // and do nothing if it is NULL. 1094 // and do nothing if it is NULL.
1111 void* server_id = automation_server_id_; 1095 void* server_id = automation_server_id_;
1112 automation_server_id_ = NULL; 1096 automation_server_id_ = NULL;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 font_size > LARGEST_FONT) { 1194 font_size > LARGEST_FONT) {
1211 NOTREACHED() << "Invalid font size specified : " 1195 NOTREACHED() << "Invalid font size specified : "
1212 << font_size; 1196 << font_size;
1213 return; 1197 return;
1214 } 1198 }
1215 1199
1216 automation_server_->Send( 1200 automation_server_->Send(
1217 new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); 1201 new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size));
1218 } 1202 }
1219 1203
1204 void ChromeFrameAutomationClient::RemoveBrowsingData(int remove_mask) {
1205 automation_server_->Send(
1206 new AutomationMsg_RemoveBrowsingData(0, remove_mask));
1207 }
1220 1208
1221 ////////////////////////////////////////////////////////////////////////// 1209 //////////////////////////////////////////////////////////////////////////
1222 // PluginUrlRequestDelegate implementation. 1210 // PluginUrlRequestDelegate implementation.
1223 // Forward network related responses to Chrome. 1211 // Forward network related responses to Chrome.
1224 1212
1225 void ChromeFrameAutomationClient::OnResponseStarted(int request_id, 1213 void ChromeFrameAutomationClient::OnResponseStarted(int request_id,
1226 const char* mime_type, const char* headers, int size, 1214 const char* mime_type, const char* headers, int size,
1227 base::Time last_modified, const std::string& redirect_url, 1215 base::Time last_modified, const std::string& redirect_url,
1228 int redirect_status) { 1216 int redirect_status) {
1229 const IPC::AutomationURLResponse response = { 1217 const IPC::AutomationURLResponse response = {
(...skipping 15 matching lines...) Expand all
1245 automation_server_->Send(new AutomationMsg_RequestData(0, tab_->handle(), 1233 automation_server_->Send(new AutomationMsg_RequestData(0, tab_->handle(),
1246 request_id, data)); 1234 request_id, data));
1247 } 1235 }
1248 1236
1249 void ChromeFrameAutomationClient::OnResponseEnd(int request_id, 1237 void ChromeFrameAutomationClient::OnResponseEnd(int request_id,
1250 const URLRequestStatus& status) { 1238 const URLRequestStatus& status) {
1251 automation_server_->Send(new AutomationMsg_RequestEnd(0, tab_->handle(), 1239 automation_server_->Send(new AutomationMsg_RequestEnd(0, tab_->handle(),
1252 request_id, status)); 1240 request_id, status));
1253 } 1241 }
1254 1242
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_automation.h ('k') | chrome_frame/chrome_frame_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698