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) { | |
119 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); | 117 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); |
120 | 118 |
121 browser_tracker_.reset(new AutomationBrowserTracker(this)); | 119 browser_tracker_.reset(new AutomationBrowserTracker(this)); |
122 extension_tracker_.reset(new AutomationExtensionTracker(this)); | 120 extension_tracker_.reset(new AutomationExtensionTracker(this)); |
123 tab_tracker_.reset(new AutomationTabTracker(this)); | 121 tab_tracker_.reset(new AutomationTabTracker(this)); |
124 window_tracker_.reset(new AutomationWindowTracker(this)); | 122 window_tracker_.reset(new AutomationWindowTracker(this)); |
125 autocomplete_edit_tracker_.reset( | 123 autocomplete_edit_tracker_.reset( |
126 new AutomationAutocompleteEditTracker(this)); | 124 new AutomationAutocompleteEditTracker(this)); |
127 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); | 125 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); |
128 dom_operation_observer_.reset(new DomOperationMessageSender(this)); | 126 dom_operation_observer_.reset(new DomOperationMessageSender(this)); |
(...skipping 15 matching lines...) Expand all Loading... |
144 NotificationObserver* observer; | 142 NotificationObserver* observer; |
145 while ((observer = it.GetNext()) != NULL) | 143 while ((observer = it.GetNext()) != NULL) |
146 delete observer; | 144 delete observer; |
147 | 145 |
148 if (channel_.get()) { | 146 if (channel_.get()) { |
149 channel_->Close(); | 147 channel_->Close(); |
150 } | 148 } |
151 g_browser_process->ReleaseModule(); | 149 g_browser_process->ReleaseModule(); |
152 } | 150 } |
153 | 151 |
154 bool AutomationProvider::InitializeChannel(const std::string& channel_id) { | 152 void AutomationProvider::ConnectToChannel(const std::string& channel_id) { |
155 TRACE_EVENT_BEGIN("AutomationProvider::InitializeChannel", 0, ""); | 153 TRACE_EVENT_BEGIN("AutomationProvider::ConnectToChannel", 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 } | |
169 | 154 |
170 if (!automation_resource_message_filter_.get()) { | 155 if (!automation_resource_message_filter_.get()) { |
171 automation_resource_message_filter_ = new AutomationResourceMessageFilter; | 156 automation_resource_message_filter_ = new AutomationResourceMessageFilter; |
172 } | 157 } |
173 | 158 |
174 channel_.reset(new IPC::SyncChannel( | 159 channel_.reset( |
175 effective_channel_id, | 160 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, |
176 use_named_interface ? IPC::Channel::MODE_NAMED_SERVER | 161 g_browser_process->io_thread()->message_loop(), |
177 : IPC::Channel::MODE_CLIENT, | 162 true, g_browser_process->shutdown_event())); |
178 this, | |
179 g_browser_process->io_thread()->message_loop(), | |
180 true, g_browser_process->shutdown_event())); | |
181 channel_->AddFilter(automation_resource_message_filter_); | 163 channel_->AddFilter(automation_resource_message_filter_); |
182 | 164 |
183 TRACE_EVENT_END("AutomationProvider::InitializeChannel", 0, ""); | 165 // Send a hello message with our current automation protocol version. |
| 166 channel_->Send(new AutomationMsg_Hello(0, GetProtocolVersion().c_str())); |
184 | 167 |
185 return true; | 168 TRACE_EVENT_END("AutomationProvider::ConnectToChannel", 0, ""); |
186 } | 169 } |
187 | 170 |
188 std::string AutomationProvider::GetProtocolVersion() { | 171 std::string AutomationProvider::GetProtocolVersion() { |
189 chrome::VersionInfo version_info; | 172 chrome::VersionInfo version_info; |
190 return version_info.Version().c_str(); | 173 return version_info.Version().c_str(); |
191 } | 174 } |
192 | 175 |
193 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { | 176 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { |
194 if (expected_tabs == 0) | 177 if (expected_tabs == 0) { |
195 OnInitialLoadsComplete(); | 178 Send(new AutomationMsg_InitialLoadsComplete(0)); |
196 else | 179 } else { |
197 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); | 180 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); |
198 } | 181 } |
199 | |
200 void AutomationProvider::OnInitialLoadsComplete() { | |
201 initial_loads_complete_ = true; | |
202 if (is_connected_) | |
203 Send(new AutomationMsg_InitialLoadsComplete(0)); | |
204 } | 182 } |
205 | 183 |
206 NotificationObserver* AutomationProvider::AddNavigationStatusListener( | 184 NotificationObserver* AutomationProvider::AddNavigationStatusListener( |
207 NavigationController* tab, IPC::Message* reply_message, | 185 NavigationController* tab, IPC::Message* reply_message, |
208 int number_of_navigations, bool include_current_navigation) { | 186 int number_of_navigations, bool include_current_navigation) { |
209 NotificationObserver* observer = | 187 NotificationObserver* observer = |
210 new NavigationNotificationObserver(tab, this, reply_message, | 188 new NavigationNotificationObserver(tab, this, reply_message, |
211 number_of_navigations, | 189 number_of_navigations, |
212 include_current_navigation); | 190 include_current_navigation); |
213 | 191 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 const Extension* extension = | 320 const Extension* extension = |
343 extension_tracker_->GetResource(extension_handle); | 321 extension_tracker_->GetResource(extension_handle); |
344 ExtensionsService* service = profile_->GetExtensionsService(); | 322 ExtensionsService* service = profile_->GetExtensionsService(); |
345 if (extension && service && | 323 if (extension && service && |
346 service->GetExtensionById(extension->id(), true) && | 324 service->GetExtensionById(extension->id(), true) && |
347 !service->GetExtensionById(extension->id(), false)) | 325 !service->GetExtensionById(extension->id(), false)) |
348 return extension; | 326 return extension; |
349 return NULL; | 327 return NULL; |
350 } | 328 } |
351 | 329 |
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 | |
363 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { | 330 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
364 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) | 331 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) |
365 #if !defined(OS_MACOSX) | 332 #if !defined(OS_MACOSX) |
366 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, | 333 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
367 WindowSimulateDrag) | 334 WindowSimulateDrag) |
368 #endif // !defined(OS_MACOSX) | 335 #endif // !defined(OS_MACOSX) |
369 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) | 336 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) |
370 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); | 337 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); |
371 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) | 338 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) |
372 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) | 339 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 } | 981 } |
1015 } | 982 } |
1016 } | 983 } |
1017 | 984 |
1018 void AutomationProvider::SaveAsAsync(int tab_handle) { | 985 void AutomationProvider::SaveAsAsync(int tab_handle) { |
1019 NavigationController* tab = NULL; | 986 NavigationController* tab = NULL; |
1020 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); | 987 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
1021 if (tab_contents) | 988 if (tab_contents) |
1022 tab_contents->OnSavePage(); | 989 tab_contents->OnSavePage(); |
1023 } | 990 } |
OLD | NEW |