| 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 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 bool result = false; | 1011 bool result = false; |
| 1012 PluginUrlRequest* request = LookupRequest(request_id); | 1012 PluginUrlRequest* request = LookupRequest(request_id); |
| 1013 if (request) | 1013 if (request) |
| 1014 result = request->Read(bytes_to_read); | 1014 result = request->Read(bytes_to_read); |
| 1015 | 1015 |
| 1016 return result; | 1016 return result; |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 void ChromeFrameAutomationClient::RemoveRequest(PluginUrlRequest* request) { | 1019 void ChromeFrameAutomationClient::RemoveRequest(PluginUrlRequest* request) { |
| 1020 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); | 1020 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); |
| 1021 DCHECK(request_map_.end() != request_map_.find(request->id())); | 1021 |
| 1022 request_map_.erase(request->id()); | 1022 // We check if the request pointer passed in is actually present in the map |
| 1023 // before going ahead and deleting it. This avoids the issue where we would |
| 1024 // incorrectly delete a different request with the same request id. |
| 1025 if (IsValidRequest(request)) { |
| 1026 request_map_.erase(request->id()); |
| 1027 } |
| 1023 } | 1028 } |
| 1024 | 1029 |
| 1025 void ChromeFrameAutomationClient::RemoveRequest(int request_id, bool abort) { | 1030 void ChromeFrameAutomationClient::RemoveRequest(int request_id, bool abort) { |
| 1026 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); | 1031 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); |
| 1027 PluginUrlRequest* request = LookupRequest(request_id); | 1032 PluginUrlRequest* request = LookupRequest(request_id); |
| 1028 if (request) { | 1033 if (request) { |
| 1029 if (abort) { | 1034 if (abort) { |
| 1030 // The request object will get removed asynchronously. | 1035 // The request object will get removed asynchronously. |
| 1031 request->Stop(); | 1036 request->Stop(); |
| 1032 } else { | 1037 } else { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 request->Stop(); | 1079 request->Stop(); |
| 1075 } | 1080 } |
| 1076 } | 1081 } |
| 1077 | 1082 |
| 1078 DCHECK(request_map_.empty()); | 1083 DCHECK(request_map_.empty()); |
| 1079 request_map_.clear(); | 1084 request_map_.clear(); |
| 1080 } | 1085 } |
| 1081 | 1086 |
| 1082 void ChromeFrameAutomationClient::CleanupAsyncRequests() { | 1087 void ChromeFrameAutomationClient::CleanupAsyncRequests() { |
| 1083 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); | 1088 DCHECK_EQ(PlatformThread::CurrentId(), ui_thread_id_); |
| 1089 |
| 1090 std::vector<scoped_refptr<PluginUrlRequest> > request_list; |
| 1091 // 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 |
| 1093 // the request map and the iterator could end up being invalid. |
| 1084 RequestMap::iterator index = request_map_.begin(); | 1094 RequestMap::iterator index = request_map_.begin(); |
| 1085 while (index != request_map_.end()) { | 1095 while (index != request_map_.end()) { |
| 1086 PluginUrlRequest* request = (*index).second; | 1096 PluginUrlRequest* request = (*index).second; |
| 1087 if (request) { | 1097 DCHECK(request != NULL); |
| 1088 int request_id = request->id(); | 1098 request_list.push_back(request); |
| 1089 request->Stop(); | |
| 1090 } | |
| 1091 index++; | 1099 index++; |
| 1092 } | 1100 } |
| 1101 request_map_.clear(); |
| 1093 | 1102 |
| 1094 request_map_.clear(); | 1103 for (unsigned int index = 0; index < request_list.size(); ++index) { |
| 1104 request_list[index]->Stop(); |
| 1105 } |
| 1095 } | 1106 } |
| 1096 | 1107 |
| 1097 bool ChromeFrameAutomationClient::Reinitialize( | 1108 bool ChromeFrameAutomationClient::Reinitialize( |
| 1098 ChromeFrameDelegate* delegate) { | 1109 ChromeFrameDelegate* delegate) { |
| 1099 if (!tab_.get() || !::IsWindow(chrome_window_)) { | 1110 if (!tab_.get() || !::IsWindow(chrome_window_)) { |
| 1100 NOTREACHED(); | 1111 NOTREACHED(); |
| 1101 DLOG(WARNING) << "ChromeFrameAutomationClient instance reused " | 1112 DLOG(WARNING) << "ChromeFrameAutomationClient instance reused " |
| 1102 << "with invalid tab"; | 1113 << "with invalid tab"; |
| 1103 return false; | 1114 return false; |
| 1104 } | 1115 } |
| 1105 | 1116 |
| 1106 if (!delegate) { | 1117 if (!delegate) { |
| 1107 NOTREACHED(); | 1118 NOTREACHED(); |
| 1108 return false; | 1119 return false; |
| 1109 } | 1120 } |
| 1110 | 1121 |
| 1122 CleanupAsyncRequests(); |
| 1111 chrome_frame_delegate_ = delegate; | 1123 chrome_frame_delegate_ = delegate; |
| 1112 SetParentWindow(NULL); | 1124 SetParentWindow(NULL); |
| 1113 return true; | 1125 return true; |
| 1114 } | 1126 } |
| 1115 | 1127 |
| 1116 void ChromeFrameAutomationClient::AttachExternalTab( | 1128 void ChromeFrameAutomationClient::AttachExternalTab( |
| 1117 intptr_t external_tab_cookie) { | 1129 intptr_t external_tab_cookie) { |
| 1118 DCHECK_EQ(static_cast<TabProxy*>(NULL), tab_.get()); | 1130 DCHECK_EQ(static_cast<TabProxy*>(NULL), tab_.get()); |
| 1119 DCHECK_EQ(-1, tab_handle_); | 1131 DCHECK_EQ(-1, tab_handle_); |
| 1120 | 1132 |
| 1121 external_tab_cookie_ = external_tab_cookie; | 1133 external_tab_cookie_ = external_tab_cookie; |
| 1122 } | 1134 } |
| 1123 | 1135 |
| 1124 void ChromeFrameAutomationClient::SetPageFontSize( | 1136 void ChromeFrameAutomationClient::SetPageFontSize( |
| 1125 enum AutomationPageFontSize font_size) { | 1137 enum AutomationPageFontSize font_size) { |
| 1126 if (font_size < SMALLEST_FONT || | 1138 if (font_size < SMALLEST_FONT || |
| 1127 font_size > LARGEST_FONT) { | 1139 font_size > LARGEST_FONT) { |
| 1128 NOTREACHED() << "Invalid font size specified : " | 1140 NOTREACHED() << "Invalid font size specified : " |
| 1129 << font_size; | 1141 << font_size; |
| 1130 return; | 1142 return; |
| 1131 } | 1143 } |
| 1132 | 1144 |
| 1133 Send(new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); | 1145 Send(new AutomationMsg_SetPageFontSize(0, tab_handle_, font_size)); |
| 1134 } | 1146 } |
| 1135 | 1147 |
| OLD | NEW |