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

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 6012006: Revert 68944 - Revert "Add named testing interface." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 #include "webkit/glue/password_form.h" 104 #include "webkit/glue/password_form.h"
105 105
106 #if defined(OS_WIN) 106 #if defined(OS_WIN)
107 #include "chrome/browser/external_tab_container_win.h" 107 #include "chrome/browser/external_tab_container_win.h"
108 #endif // defined(OS_WIN) 108 #endif // defined(OS_WIN)
109 109
110 using base::Time; 110 using base::Time;
111 111
112 AutomationProvider::AutomationProvider(Profile* profile) 112 AutomationProvider::AutomationProvider(Profile* profile)
113 : profile_(profile), 113 : profile_(profile),
114 reply_message_(NULL) { 114 reply_message_(NULL),
115 is_connected_(false),
116 initial_loads_complete_(false) {
115 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); 117 TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, "");
116 118
117 browser_tracker_.reset(new AutomationBrowserTracker(this)); 119 browser_tracker_.reset(new AutomationBrowserTracker(this));
118 extension_tracker_.reset(new AutomationExtensionTracker(this)); 120 extension_tracker_.reset(new AutomationExtensionTracker(this));
119 tab_tracker_.reset(new AutomationTabTracker(this)); 121 tab_tracker_.reset(new AutomationTabTracker(this));
120 window_tracker_.reset(new AutomationWindowTracker(this)); 122 window_tracker_.reset(new AutomationWindowTracker(this));
121 autocomplete_edit_tracker_.reset( 123 autocomplete_edit_tracker_.reset(
122 new AutomationAutocompleteEditTracker(this)); 124 new AutomationAutocompleteEditTracker(this));
123 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); 125 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this));
124 dom_operation_observer_.reset(new DomOperationMessageSender(this)); 126 dom_operation_observer_.reset(new DomOperationMessageSender(this));
(...skipping 15 matching lines...) Expand all
140 NotificationObserver* observer; 142 NotificationObserver* observer;
141 while ((observer = it.GetNext()) != NULL) 143 while ((observer = it.GetNext()) != NULL)
142 delete observer; 144 delete observer;
143 145
144 if (channel_.get()) { 146 if (channel_.get()) {
145 channel_->Close(); 147 channel_->Close();
146 } 148 }
147 g_browser_process->ReleaseModule(); 149 g_browser_process->ReleaseModule();
148 } 150 }
149 151
150 void AutomationProvider::ConnectToChannel(const std::string& channel_id) { 152 bool AutomationProvider::InitializeChannel(const std::string& channel_id) {
151 TRACE_EVENT_BEGIN("AutomationProvider::ConnectToChannel", 0, ""); 153 TRACE_EVENT_BEGIN("AutomationProvider::InitializeChannel", 0, "");
154
155 std::string effective_channel_id = channel_id;
156
157 // If the channel_id starts with kNamedInterfacePrefix, create a named IPC
158 // server and listen on it, else connect as client to an existing IPC server
159 bool use_named_interface =
160 channel_id.find(automation::kNamedInterfacePrefix) == 0;
161 if (use_named_interface) {
162 effective_channel_id = channel_id.substr(
163 strlen(automation::kNamedInterfacePrefix));
164 if (effective_channel_id.length() <= 0)
165 return false;
166 }
152 167
153 if (!automation_resource_message_filter_.get()) { 168 if (!automation_resource_message_filter_.get()) {
154 automation_resource_message_filter_ = new AutomationResourceMessageFilter; 169 automation_resource_message_filter_ = new AutomationResourceMessageFilter;
155 } 170 }
156 171
157 channel_.reset( 172 channel_.reset(new IPC::SyncChannel(
158 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, 173 effective_channel_id,
159 g_browser_process->io_thread()->message_loop(), 174 use_named_interface ? IPC::Channel::MODE_NAMED_SERVER
160 true, g_browser_process->shutdown_event())); 175 : IPC::Channel::MODE_CLIENT,
176 this,
177 g_browser_process->io_thread()->message_loop(),
178 true, g_browser_process->shutdown_event()));
161 channel_->AddFilter(automation_resource_message_filter_); 179 channel_->AddFilter(automation_resource_message_filter_);
162 180
163 // Send a hello message with our current automation protocol version. 181 TRACE_EVENT_END("AutomationProvider::InitializeChannel", 0, "");
164 channel_->Send(new AutomationMsg_Hello(0, GetProtocolVersion().c_str()));
165 182
166 TRACE_EVENT_END("AutomationProvider::ConnectToChannel", 0, ""); 183 return true;
167 } 184 }
168 185
169 std::string AutomationProvider::GetProtocolVersion() { 186 std::string AutomationProvider::GetProtocolVersion() {
170 chrome::VersionInfo version_info; 187 chrome::VersionInfo version_info;
171 return version_info.Version().c_str(); 188 return version_info.Version().c_str();
172 } 189 }
173 190
174 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { 191 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) {
175 if (expected_tabs == 0) { 192 if (expected_tabs == 0)
193 OnInitialLoadsComplete();
194 else
195 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this));
196 }
197
198 void AutomationProvider::OnInitialLoadsComplete() {
199 initial_loads_complete_ = true;
200 if (is_connected_)
176 Send(new AutomationMsg_InitialLoadsComplete(0)); 201 Send(new AutomationMsg_InitialLoadsComplete(0));
177 } else {
178 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this));
179 }
180 } 202 }
181 203
182 NotificationObserver* AutomationProvider::AddNavigationStatusListener( 204 NotificationObserver* AutomationProvider::AddNavigationStatusListener(
183 NavigationController* tab, IPC::Message* reply_message, 205 NavigationController* tab, IPC::Message* reply_message,
184 int number_of_navigations, bool include_current_navigation) { 206 int number_of_navigations, bool include_current_navigation) {
185 NotificationObserver* observer = 207 NotificationObserver* observer =
186 new NavigationNotificationObserver(tab, this, reply_message, 208 new NavigationNotificationObserver(tab, this, reply_message,
187 number_of_navigations, 209 number_of_navigations,
188 include_current_navigation); 210 include_current_navigation);
189 211
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 const Extension* extension = 340 const Extension* extension =
319 extension_tracker_->GetResource(extension_handle); 341 extension_tracker_->GetResource(extension_handle);
320 ExtensionService* service = profile_->GetExtensionService(); 342 ExtensionService* service = profile_->GetExtensionService();
321 if (extension && service && 343 if (extension && service &&
322 service->GetExtensionById(extension->id(), true) && 344 service->GetExtensionById(extension->id(), true) &&
323 !service->GetExtensionById(extension->id(), false)) 345 !service->GetExtensionById(extension->id(), false))
324 return extension; 346 return extension;
325 return NULL; 347 return NULL;
326 } 348 }
327 349
350 void AutomationProvider::OnChannelConnected(int pid) {
351 is_connected_ = true;
352 LOG(INFO) << "Testing channel connected, sending hello message";
353
354 // Send a hello message with our current automation protocol version.
355 chrome::VersionInfo version_info;
356 channel_->Send(new AutomationMsg_Hello(0, version_info.Version()));
357 if (initial_loads_complete_)
358 Send(new AutomationMsg_InitialLoadsComplete(0));
359 }
360
328 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { 361 void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
329 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) 362 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message)
330 #if !defined(OS_MACOSX) 363 #if !defined(OS_MACOSX)
331 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, 364 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag,
332 WindowSimulateDrag) 365 WindowSimulateDrag)
333 #endif // !defined(OS_MACOSX) 366 #endif // !defined(OS_MACOSX)
334 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) 367 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused)
335 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); 368 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig);
336 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) 369 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync)
337 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) 370 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest)
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 } 1014 }
982 } 1015 }
983 } 1016 }
984 1017
985 void AutomationProvider::SaveAsAsync(int tab_handle) { 1018 void AutomationProvider::SaveAsAsync(int tab_handle) {
986 NavigationController* tab = NULL; 1019 NavigationController* tab = NULL;
987 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); 1020 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab);
988 if (tab_contents) 1021 if (tab_contents)
989 tab_contents->OnSavePage(); 1022 tab_contents->OnSavePage();
990 } 1023 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.h ('k') | chrome/browser/automation/automation_provider_observers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698