OLD | NEW |
1 // Copyright (c) 2010 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/browser/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/message_box_flags.h" | 9 #include "app/message_box_flags.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 #include "webkit/glue/plugins/plugin_list.h" | 106 #include "webkit/glue/plugins/plugin_list.h" |
107 | 107 |
108 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
109 #include "chrome/browser/external_tab_container_win.h" | 109 #include "chrome/browser/external_tab_container_win.h" |
110 #endif // defined(OS_WIN) | 110 #endif // defined(OS_WIN) |
111 | 111 |
112 using base::Time; | 112 using base::Time; |
113 | 113 |
114 AutomationProvider::AutomationProvider(Profile* profile) | 114 AutomationProvider::AutomationProvider(Profile* profile) |
115 : profile_(profile), | 115 : profile_(profile), |
116 reply_message_(NULL) { | 116 reply_message_(NULL), |
| 117 is_connected_(false), |
| 118 initial_loads_complete_(false) { |
117 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); | 119 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); |
118 | 120 |
119 browser_tracker_.reset(new AutomationBrowserTracker(this)); | 121 browser_tracker_.reset(new AutomationBrowserTracker(this)); |
120 extension_tracker_.reset(new AutomationExtensionTracker(this)); | 122 extension_tracker_.reset(new AutomationExtensionTracker(this)); |
121 tab_tracker_.reset(new AutomationTabTracker(this)); | 123 tab_tracker_.reset(new AutomationTabTracker(this)); |
122 window_tracker_.reset(new AutomationWindowTracker(this)); | 124 window_tracker_.reset(new AutomationWindowTracker(this)); |
123 autocomplete_edit_tracker_.reset( | 125 autocomplete_edit_tracker_.reset( |
124 new AutomationAutocompleteEditTracker(this)); | 126 new AutomationAutocompleteEditTracker(this)); |
125 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); | 127 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); |
126 dom_operation_observer_.reset(new DomOperationMessageSender(this)); | 128 dom_operation_observer_.reset(new DomOperationMessageSender(this)); |
(...skipping 15 matching lines...) Expand all Loading... |
142 NotificationObserver* observer; | 144 NotificationObserver* observer; |
143 while ((observer = it.GetNext()) != NULL) | 145 while ((observer = it.GetNext()) != NULL) |
144 delete observer; | 146 delete observer; |
145 | 147 |
146 if (channel_.get()) { | 148 if (channel_.get()) { |
147 channel_->Close(); | 149 channel_->Close(); |
148 } | 150 } |
149 g_browser_process->ReleaseModule(); | 151 g_browser_process->ReleaseModule(); |
150 } | 152 } |
151 | 153 |
152 void AutomationProvider::ConnectToChannel(const std::string& channel_id) { | 154 bool AutomationProvider::InitializeChannel(const std::string& channel_id) { |
153 TRACE_EVENT_BEGIN("AutomationProvider::ConnectToChannel", 0, ""); | 155 TRACE_EVENT_BEGIN("AutomationProvider::InitializeChannel", 0, ""); |
| 156 |
| 157 std::string effective_channel_id = channel_id; |
| 158 |
| 159 // If the channel_id starts with kNamedInterfacePrefix, create a named IPC |
| 160 // server and listen on it, else connect as client to an existing IPC server |
| 161 bool use_named_interface = |
| 162 channel_id.find(automation::kNamedInterfacePrefix) == 0; |
| 163 if (use_named_interface) { |
| 164 effective_channel_id = channel_id.substr( |
| 165 strlen(automation::kNamedInterfacePrefix)); |
| 166 if (effective_channel_id.length() <= 0) |
| 167 return false; |
| 168 } |
154 | 169 |
155 if (!automation_resource_message_filter_.get()) { | 170 if (!automation_resource_message_filter_.get()) { |
156 automation_resource_message_filter_ = new AutomationResourceMessageFilter; | 171 automation_resource_message_filter_ = new AutomationResourceMessageFilter; |
157 } | 172 } |
158 | 173 |
159 channel_.reset( | 174 channel_.reset(new IPC::SyncChannel( |
160 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, | 175 effective_channel_id, |
161 automation_resource_message_filter_, | 176 use_named_interface ? IPC::Channel::MODE_NAMED_SERVER |
162 g_browser_process->io_thread()->message_loop(), | 177 : IPC::Channel::MODE_CLIENT, |
163 true, g_browser_process->shutdown_event())); | 178 this, |
| 179 automation_resource_message_filter_, |
| 180 g_browser_process->io_thread()->message_loop(), |
| 181 true, g_browser_process->shutdown_event())); |
164 | 182 |
165 // Send a hello message with our current automation protocol version. | 183 TRACE_EVENT_END("AutomationProvider::InitializeChannel", 0, ""); |
166 channel_->Send(new AutomationMsg_Hello(0, GetProtocolVersion().c_str())); | |
167 | 184 |
168 TRACE_EVENT_END("AutomationProvider::ConnectToChannel", 0, ""); | 185 return true; |
169 } | 186 } |
170 | 187 |
171 std::string AutomationProvider::GetProtocolVersion() { | 188 std::string AutomationProvider::GetProtocolVersion() { |
172 chrome::VersionInfo version_info; | 189 chrome::VersionInfo version_info; |
173 return version_info.Version().c_str(); | 190 return version_info.Version().c_str(); |
174 } | 191 } |
175 | 192 |
176 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { | 193 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { |
177 if (expected_tabs == 0) { | 194 if (expected_tabs == 0) |
| 195 OnInitialLoadsComplete(); |
| 196 else |
| 197 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); |
| 198 } |
| 199 |
| 200 void AutomationProvider::OnInitialLoadsComplete() { |
| 201 initial_loads_complete_ = true; |
| 202 if (is_connected_) |
178 Send(new AutomationMsg_InitialLoadsComplete(0)); | 203 Send(new AutomationMsg_InitialLoadsComplete(0)); |
179 } else { | |
180 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); | |
181 } | |
182 } | 204 } |
183 | 205 |
184 NotificationObserver* AutomationProvider::AddNavigationStatusListener( | 206 NotificationObserver* AutomationProvider::AddNavigationStatusListener( |
185 NavigationController* tab, IPC::Message* reply_message, | 207 NavigationController* tab, IPC::Message* reply_message, |
186 int number_of_navigations, bool include_current_navigation) { | 208 int number_of_navigations, bool include_current_navigation) { |
187 NotificationObserver* observer = | 209 NotificationObserver* observer = |
188 new NavigationNotificationObserver(tab, this, reply_message, | 210 new NavigationNotificationObserver(tab, this, reply_message, |
189 number_of_navigations, | 211 number_of_navigations, |
190 include_current_navigation); | 212 include_current_navigation); |
191 | 213 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 const Extension* extension = | 342 const Extension* extension = |
321 extension_tracker_->GetResource(extension_handle); | 343 extension_tracker_->GetResource(extension_handle); |
322 ExtensionsService* service = profile_->GetExtensionsService(); | 344 ExtensionsService* service = profile_->GetExtensionsService(); |
323 if (extension && service && | 345 if (extension && service && |
324 service->GetExtensionById(extension->id(), true) && | 346 service->GetExtensionById(extension->id(), true) && |
325 !service->GetExtensionById(extension->id(), false)) | 347 !service->GetExtensionById(extension->id(), false)) |
326 return extension; | 348 return extension; |
327 return NULL; | 349 return NULL; |
328 } | 350 } |
329 | 351 |
| 352 void AutomationProvider::OnChannelConnected(int pid) { |
| 353 is_connected_ = true; |
| 354 LOG(INFO) << "Testing channel connected, sending hello message"; |
| 355 |
| 356 // Send a hello message with our current automation protocol version. |
| 357 chrome::VersionInfo version_info; |
| 358 channel_->Send(new AutomationMsg_Hello(0, version_info.Version())); |
| 359 if (initial_loads_complete_) |
| 360 Send(new AutomationMsg_InitialLoadsComplete(0)); |
| 361 } |
| 362 |
330 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { | 363 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
331 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) | 364 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) |
332 #if !defined(OS_MACOSX) | 365 #if !defined(OS_MACOSX) |
333 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, | 366 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
334 WindowSimulateDrag) | 367 WindowSimulateDrag) |
335 #endif // !defined(OS_MACOSX) | 368 #endif // !defined(OS_MACOSX) |
336 #if defined(OS_WIN) | 369 #if defined(OS_WIN) |
337 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) | 370 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) |
338 #endif // defined(OS_WIN) | 371 #endif // defined(OS_WIN) |
339 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) | 372 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 } | 1025 } |
993 } | 1026 } |
994 } | 1027 } |
995 | 1028 |
996 void AutomationProvider::SaveAsAsync(int tab_handle) { | 1029 void AutomationProvider::SaveAsAsync(int tab_handle) { |
997 NavigationController* tab = NULL; | 1030 NavigationController* tab = NULL; |
998 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); | 1031 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
999 if (tab_contents) | 1032 if (tab_contents) |
1000 tab_contents->OnSavePage(); | 1033 tab_contents->OnSavePage(); |
1001 } | 1034 } |
OLD | NEW |