| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 ChromeFrameDelegate* chrome_frame_delegate, | 429 ChromeFrameDelegate* chrome_frame_delegate, |
| 430 int automation_server_launch_timeout, | 430 int automation_server_launch_timeout, |
| 431 bool perform_version_check, | 431 bool perform_version_check, |
| 432 const std::wstring& profile_name, | 432 const std::wstring& profile_name, |
| 433 const std::wstring& extra_chrome_arguments, | 433 const std::wstring& extra_chrome_arguments, |
| 434 bool incognito) { | 434 bool incognito) { |
| 435 DCHECK(!IsWindow()); | 435 DCHECK(!IsWindow()); |
| 436 chrome_frame_delegate_ = chrome_frame_delegate; | 436 chrome_frame_delegate_ = chrome_frame_delegate; |
| 437 incognito_ = incognito; | 437 incognito_ = incognito; |
| 438 ui_thread_id_ = PlatformThread::CurrentId(); | 438 ui_thread_id_ = PlatformThread::CurrentId(); |
| 439 | |
| 440 #ifndef NDEBUG | 439 #ifndef NDEBUG |
| 441 // In debug mode give more time to work with a debugger. | 440 // In debug mode give more time to work with a debugger. |
| 442 if (IsDebuggerPresent()) { | 441 if (IsDebuggerPresent()) { |
| 443 // Don't use INFINITE (which is -1) or even MAXINT since we will convert | 442 // Don't use INFINITE (which is -1) or even MAXINT since we will convert |
| 444 // from milliseconds to microseconds when stored in a base::TimeDelta, | 443 // from milliseconds to microseconds when stored in a base::TimeDelta, |
| 445 // thus * 1000. An hour should be enough. | 444 // thus * 1000. An hour should be enough. |
| 446 automation_server_launch_timeout = 60 * 60 * 1000; | 445 automation_server_launch_timeout = 60 * 60 * 1000; |
| 447 } else { | 446 } else { |
| 448 DCHECK_LT(automation_server_launch_timeout, MAXINT / 2000); | 447 DCHECK_LT(automation_server_launch_timeout, MAXINT / 2000); |
| 449 automation_server_launch_timeout *= 2; | 448 automation_server_launch_timeout *= 2; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 469 automation_server_launch_timeout, | 468 automation_server_launch_timeout, |
| 470 profile_name, extra_chrome_arguments, perform_version_check, | 469 profile_name, extra_chrome_arguments, perform_version_check, |
| 471 static_cast<ProxyFactory::LaunchDelegate*>(this)); | 470 static_cast<ProxyFactory::LaunchDelegate*>(this)); |
| 472 | 471 |
| 473 return true; | 472 return true; |
| 474 } | 473 } |
| 475 | 474 |
| 476 void ChromeFrameAutomationClient::Uninitialize() { | 475 void ChromeFrameAutomationClient::Uninitialize() { |
| 477 DLOG(INFO) << __FUNCTION__; | 476 DLOG(INFO) << __FUNCTION__; |
| 478 | 477 |
| 478 if (init_state_ == UNINITIALIZED) { |
| 479 DLOG(WARNING) << __FUNCTION__ << ": Automation client not initialized"; |
| 480 return; |
| 481 } |
| 482 |
| 479 init_state_ = UNINITIALIZING; | 483 init_state_ = UNINITIALIZING; |
| 480 | 484 |
| 481 // Called from client's FinalRelease() / destructor | 485 // Called from client's FinalRelease() / destructor |
| 482 // ChromeFrameAutomationClient may wait for the initialization (launch) | 486 // ChromeFrameAutomationClient may wait for the initialization (launch) |
| 483 // to complete while Uninitialize is called. | 487 // to complete while Uninitialize is called. |
| 484 // We either have to: | 488 // We either have to: |
| 485 // 1) Make ReleaseAutomationServer blocking call (wait until thread exits) | 489 // 1) Make ReleaseAutomationServer blocking call (wait until thread exits) |
| 486 // 2) Behave like a COM object i.e. increase module lock count. | 490 // 2) Behave like a COM object i.e. increase module lock count. |
| 487 // Otherwise the DLL may get unloaded while we have running threads. | 491 // Otherwise the DLL may get unloaded while we have running threads. |
| 488 // Unfortunately in NPAPI case we cannot increase module lock count, hence | 492 // Unfortunately in NPAPI case we cannot increase module lock count, hence |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 public: | 630 public: |
| 627 InstallExtensionContext(ChromeFrameAutomationClient* client, | 631 InstallExtensionContext(ChromeFrameAutomationClient* client, |
| 628 const FilePath& crx_path, void* user_data) : client_(client), | 632 const FilePath& crx_path, void* user_data) : client_(client), |
| 629 crx_path_(crx_path), user_data_(user_data) { | 633 crx_path_(crx_path), user_data_(user_data) { |
| 630 } | 634 } |
| 631 | 635 |
| 632 ~InstallExtensionContext() { | 636 ~InstallExtensionContext() { |
| 633 } | 637 } |
| 634 | 638 |
| 635 void InstallExtensionComplete(AutomationMsg_ExtensionResponseValues res) { | 639 void InstallExtensionComplete(AutomationMsg_ExtensionResponseValues res) { |
| 636 client_->PostTask(FROM_HERE, NewRunnableMethod(client_, | 640 client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(), |
| 637 &ChromeFrameAutomationClient::InstallExtensionComplete, crx_path_, | 641 &ChromeFrameAutomationClient::InstallExtensionComplete, crx_path_, |
| 638 user_data_, res)); | 642 user_data_, res)); |
| 639 delete this; | 643 delete this; |
| 640 } | 644 } |
| 641 | 645 |
| 642 private: | 646 private: |
| 643 ChromeFrameAutomationClient* client_; | 647 scoped_refptr<ChromeFrameAutomationClient> client_; |
| 644 FilePath crx_path_; | 648 FilePath crx_path_; |
| 645 void* user_data_; | 649 void* user_data_; |
| 646 }; | 650 }; |
| 647 | 651 |
| 648 void ChromeFrameAutomationClient::InstallExtension( | 652 void ChromeFrameAutomationClient::InstallExtension( |
| 649 const FilePath& crx_path, | 653 const FilePath& crx_path, |
| 650 void* user_data) { | 654 void* user_data) { |
| 651 if (automation_server_ == NULL) { | 655 if (automation_server_ == NULL) { |
| 652 InstallExtensionComplete(crx_path, | 656 InstallExtensionComplete(crx_path, |
| 653 user_data, | 657 user_data, |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 break; | 1069 break; |
| 1066 } | 1070 } |
| 1067 } | 1071 } |
| 1068 } | 1072 } |
| 1069 | 1073 |
| 1070 return is_valid; | 1074 return is_valid; |
| 1071 } | 1075 } |
| 1072 | 1076 |
| 1073 void ChromeFrameAutomationClient::CleanupRequests() { | 1077 void ChromeFrameAutomationClient::CleanupRequests() { |
| 1074 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); | 1078 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); |
| 1075 while (request_map_.size()) { | |
| 1076 PluginUrlRequest* request = request_map_.begin()->second; | |
| 1077 if (request) { | |
| 1078 int request_id = request->id(); | |
| 1079 request->Stop(); | |
| 1080 } | |
| 1081 } | |
| 1082 | |
| 1083 DCHECK(request_map_.empty()); | |
| 1084 request_map_.clear(); | |
| 1085 } | |
| 1086 | |
| 1087 void ChromeFrameAutomationClient::CleanupAsyncRequests() { | |
| 1088 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); | |
| 1089 | 1079 |
| 1090 std::vector<scoped_refptr<PluginUrlRequest> > request_list; | 1080 std::vector<scoped_refptr<PluginUrlRequest> > request_list; |
| 1091 // We copy the pending requests into a temporary vector as the Stop | 1081 // We copy the pending requests into a temporary vector as the Stop |
| 1092 // function in the request could also try to delete the request from | 1082 // function in the request could also try to delete the request from |
| 1093 // the request map and the iterator could end up being invalid. | 1083 // the request map and the iterator could end up being invalid. |
| 1094 RequestMap::iterator index = request_map_.begin(); | 1084 RequestMap::iterator index = request_map_.begin(); |
| 1095 while (index != request_map_.end()) { | 1085 while (index != request_map_.end()) { |
| 1096 PluginUrlRequest* request = (*index).second; | 1086 PluginUrlRequest* request = (*index).second; |
| 1097 DCHECK(request != NULL); | 1087 DCHECK(request != NULL); |
| 1098 request_list.push_back(request); | 1088 request_list.push_back(request); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1112 DLOG(WARNING) << "ChromeFrameAutomationClient instance reused " | 1102 DLOG(WARNING) << "ChromeFrameAutomationClient instance reused " |
| 1113 << "with invalid tab"; | 1103 << "with invalid tab"; |
| 1114 return false; | 1104 return false; |
| 1115 } | 1105 } |
| 1116 | 1106 |
| 1117 if (!delegate) { | 1107 if (!delegate) { |
| 1118 NOTREACHED(); | 1108 NOTREACHED(); |
| 1119 return false; | 1109 return false; |
| 1120 } | 1110 } |
| 1121 | 1111 |
| 1122 CleanupAsyncRequests(); | 1112 CleanupRequests(); |
| 1123 chrome_frame_delegate_ = delegate; | 1113 chrome_frame_delegate_ = delegate; |
| 1124 SetParentWindow(NULL); | 1114 SetParentWindow(NULL); |
| 1125 return true; | 1115 return true; |
| 1126 } | 1116 } |
| 1127 | 1117 |
| 1128 void ChromeFrameAutomationClient::AttachExternalTab( | 1118 void ChromeFrameAutomationClient::AttachExternalTab( |
| 1129 intptr_t external_tab_cookie) { | 1119 intptr_t external_tab_cookie) { |
| 1130 DCHECK_EQ(static_cast<TabProxy*>(NULL), tab_.get()); | 1120 DCHECK_EQ(static_cast<TabProxy*>(NULL), tab_.get()); |
| 1131 DCHECK_EQ(-1, tab_handle_); | 1121 DCHECK_EQ(-1, tab_handle_); |
| 1132 | 1122 |
| 1133 external_tab_cookie_ = external_tab_cookie; | 1123 external_tab_cookie_ = external_tab_cookie; |
| 1134 } | 1124 } |
| 1135 | 1125 |
| 1136 void ChromeFrameAutomationClient::SetPageFontSize( | 1126 void ChromeFrameAutomationClient::SetPageFontSize( |
| 1137 enum AutomationPageFontSize font_size) { | 1127 enum AutomationPageFontSize font_size) { |
| 1138 if (font_size < SMALLEST_FONT || | 1128 if (font_size < SMALLEST_FONT || |
| 1139 font_size > LARGEST_FONT) { | 1129 font_size > LARGEST_FONT) { |
| 1140 NOTREACHED() << "Invalid font size specified : " | 1130 NOTREACHED() << "Invalid font size specified : " |
| 1141 << font_size; | 1131 << font_size; |
| 1142 return; | 1132 return; |
| 1143 } | 1133 } |
| 1144 | 1134 |
| 1145 Send(new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); | 1135 Send(new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); |
| 1146 } | 1136 } |
| 1147 | 1137 |
| OLD | NEW |