blob: 79e384e83d83ddb24f36adb44d87b5abfeb37b1e [file] [log] [blame]
[email protected]4801ecc2009-04-05 04:52:581// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/automation/automation_provider.h"
6
[email protected]c6cb1992009-04-13 16:45:297#include "base/file_version_info.h"
[email protected]5fac9622009-02-04 21:49:388#include "base/message_loop.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/path_service.h"
[email protected]4c4d8d22009-03-04 05:29:2710#include "base/string_util.h"
[email protected]5fac9622009-02-04 21:49:3811#include "base/thread.h"
[email protected]4f3dc372009-02-24 00:10:2912#include "chrome/app/chrome_dll_resource.h"
[email protected]0bfa713f2009-04-07 20:18:2813#include "chrome/browser/app_modal_dialog.h"
[email protected]464146e2009-04-09 18:17:0914#include "chrome/browser/app_modal_dialog_queue.h"
initial.commit09911bf2008-07-26 23:55:2915#include "chrome/browser/automation/automation_provider_list.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/browser/automation/url_request_failed_dns_job.h"
17#include "chrome/browser/automation/url_request_mock_http_job.h"
18#include "chrome/browser/automation/url_request_slow_download_job.h"
[email protected]f3e99e32008-07-30 04:48:3919#include "chrome/browser/browser_window.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/dom_operation_notification_details.h"
[email protected]cdaa8652008-09-13 02:48:5921#include "chrome/browser/download/download_manager.h"
[email protected]4801ecc2009-04-05 04:52:5822#include "chrome/browser/find_bar.h"
23#include "chrome/browser/find_bar_controller.h"
initial.commit09911bf2008-07-26 23:55:2924#include "chrome/browser/find_notification_details.h"
[email protected]6524b5f92009-01-22 17:48:2525#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]3b073b22009-01-16 03:29:0326#include "chrome/browser/ssl/ssl_manager.h"
27#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]57c6a652009-05-04 07:58:3428#include "chrome/browser/tab_contents/tab_contents.h"
[email protected]81af9392009-04-21 02:37:4529#include "chrome/browser/tab_contents/tab_contents_view.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/chrome_paths.h"
[email protected]478ff2ed2009-04-21 23:49:1831#include "chrome/common/message_box_flags.h"
[email protected]6a02963e2009-01-06 16:58:0332#include "chrome/common/notification_registrar.h"
[email protected]3753f522009-04-14 23:15:4733#include "chrome/common/platform_util.h"
[email protected]8a3422c92008-09-24 17:42:4234#include "chrome/common/pref_service.h"
[email protected]71f65dd2009-02-11 19:14:5635#include "chrome/test/automation/automation_messages.h"
initial.commit09911bf2008-07-26 23:55:2936#include "net/base/cookie_monster.h"
[email protected]319d9e6f2009-02-18 19:47:2137#include "net/url_request/url_request_context.h"
initial.commit09911bf2008-07-26 23:55:2938#include "net/url_request/url_request_filter.h"
39
[email protected]de246f52009-02-25 18:25:4540#if defined(OS_WIN)
41// TODO(port): Port these headers.
[email protected]de246f52009-02-25 18:25:4542#include "chrome/browser/automation/ui_controls.h"
43#include "chrome/browser/character_encoding.h"
44#include "chrome/browser/download/save_package.h"
45#include "chrome/browser/external_tab_container.h"
46#include "chrome/browser/login_prompt.h"
47#include "chrome/browser/printing/print_job.h"
48#include "chrome/browser/views/bookmark_bar_view.h"
49#include "chrome/browser/views/location_bar_view.h"
[email protected]0e8588c12009-03-17 01:44:3650#include "chrome/views/window/window.h"
[email protected]de246f52009-02-25 18:25:4551#endif // defined(OS_WIN)
52
[email protected]e1acf6f2008-10-27 20:43:3353using base::Time;
54
initial.commit09911bf2008-07-26 23:55:2955class InitialLoadObserver : public NotificationObserver {
56 public:
57 InitialLoadObserver(size_t tab_count, AutomationProvider* automation)
[email protected]66791d22009-02-24 20:11:3358 : automation_(automation),
59 outstanding_tab_count_(tab_count) {
initial.commit09911bf2008-07-26 23:55:2960 if (outstanding_tab_count_ > 0) {
[email protected]bfd04a62009-02-01 18:16:5661 registrar_.Add(this, NotificationType::LOAD_START,
[email protected]6a02963e2009-01-06 16:58:0362 NotificationService::AllSources());
[email protected]bfd04a62009-02-01 18:16:5663 registrar_.Add(this, NotificationType::LOAD_STOP,
[email protected]6a02963e2009-01-06 16:58:0364 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:2965 }
66 }
67
68 ~InitialLoadObserver() {
initial.commit09911bf2008-07-26 23:55:2969 }
70
71 void ConditionMet() {
[email protected]6a02963e2009-01-06 16:58:0372 registrar_.RemoveAll();
initial.commit09911bf2008-07-26 23:55:2973 automation_->Send(new AutomationMsg_InitialLoadsComplete(0));
74 }
75
initial.commit09911bf2008-07-26 23:55:2976 virtual void Observe(NotificationType type,
77 const NotificationSource& source,
78 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:5679 if (type == NotificationType::LOAD_START) {
initial.commit09911bf2008-07-26 23:55:2980 if (outstanding_tab_count_ > loading_tabs_.size())
81 loading_tabs_.insert(source.map_key());
[email protected]bfd04a62009-02-01 18:16:5682 } else if (type == NotificationType::LOAD_STOP) {
initial.commit09911bf2008-07-26 23:55:2983 if (outstanding_tab_count_ > finished_tabs_.size()) {
84 if (loading_tabs_.find(source.map_key()) != loading_tabs_.end())
85 finished_tabs_.insert(source.map_key());
86 if (outstanding_tab_count_ == finished_tabs_.size())
87 ConditionMet();
88 }
89 } else {
90 NOTREACHED();
91 }
92 }
93
94 private:
95 typedef std::set<uintptr_t> TabSet;
96
[email protected]6a02963e2009-01-06 16:58:0397 NotificationRegistrar registrar_;
98
initial.commit09911bf2008-07-26 23:55:2999 AutomationProvider* automation_;
100 size_t outstanding_tab_count_;
101 TabSet loading_tabs_;
102 TabSet finished_tabs_;
103};
104
105// Watches for NewTabUI page loads for performance timing purposes.
106class NewTabUILoadObserver : public NotificationObserver {
107 public:
108 explicit NewTabUILoadObserver(AutomationProvider* automation)
109 : automation_(automation) {
[email protected]bfd04a62009-02-01 18:16:56110 NotificationService::current()->AddObserver(
111 this, NotificationType::INITIAL_NEW_TAB_UI_LOAD,
112 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29113 }
114
115 ~NewTabUILoadObserver() {
116 Unregister();
117 }
118
119 void Unregister() {
[email protected]bfd04a62009-02-01 18:16:56120 NotificationService::current()->RemoveObserver(
121 this, NotificationType::INITIAL_NEW_TAB_UI_LOAD,
122 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29123 }
124
125 virtual void Observe(NotificationType type,
126 const NotificationSource& source,
127 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56128 if (type == NotificationType::INITIAL_NEW_TAB_UI_LOAD) {
initial.commit09911bf2008-07-26 23:55:29129 Details<int> load_time(details);
130 automation_->Send(
131 new AutomationMsg_InitialNewTabUILoadComplete(0, *load_time.ptr()));
132 } else {
133 NOTREACHED();
134 }
135 }
136
137 private:
138 AutomationProvider* automation_;
139};
140
141class NavigationControllerRestoredObserver : public NotificationObserver {
142 public:
143 NavigationControllerRestoredObserver(AutomationProvider* automation,
144 NavigationController* controller,
[email protected]71f65dd2009-02-11 19:14:56145 int32 routing_id,
146 IPC::Message* reply_message)
initial.commit09911bf2008-07-26 23:55:29147 : automation_(automation),
148 controller_(controller),
[email protected]71f65dd2009-02-11 19:14:56149 routing_id_(routing_id),
150 reply_message_(reply_message) {
initial.commit09911bf2008-07-26 23:55:29151 if (FinishedRestoring()) {
152 registered_ = false;
153 SendDone();
154 } else {
155 registered_ = true;
156 NotificationService* service = NotificationService::current();
[email protected]bfd04a62009-02-01 18:16:56157 service->AddObserver(this, NotificationType::LOAD_STOP,
initial.commit09911bf2008-07-26 23:55:29158 NotificationService::AllSources());
159 }
160 }
161
162 ~NavigationControllerRestoredObserver() {
163 if (registered_)
164 Unregister();
165 }
166
167 virtual void Observe(NotificationType type,
168 const NotificationSource& source,
169 const NotificationDetails& details) {
170 if (FinishedRestoring()) {
171 SendDone();
172 Unregister();
173 }
174 }
175
176 private:
177 void Unregister() {
178 NotificationService* service = NotificationService::current();
[email protected]bfd04a62009-02-01 18:16:56179 service->RemoveObserver(this, NotificationType::LOAD_STOP,
initial.commit09911bf2008-07-26 23:55:29180 NotificationService::AllSources());
181 registered_ = false;
182 }
183
184 bool FinishedRestoring() {
[email protected]7f0005a2009-04-15 03:25:11185 return (!controller_->needs_reload() && !controller_->pending_entry() &&
186 !controller_->tab_contents()->is_loading());
initial.commit09911bf2008-07-26 23:55:29187 }
188
189 void SendDone() {
[email protected]71f65dd2009-02-11 19:14:56190 DCHECK(reply_message_ != NULL);
191 automation_->Send(reply_message_);
initial.commit09911bf2008-07-26 23:55:29192 }
193
194 bool registered_;
195 AutomationProvider* automation_;
196 NavigationController* controller_;
197 const int routing_id_;
[email protected]71f65dd2009-02-11 19:14:56198 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29199
[email protected]5a52f162008-08-27 04:15:31200 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver);
initial.commit09911bf2008-07-26 23:55:29201};
202
[email protected]71f65dd2009-02-11 19:14:56203template<class NavigationCodeType>
initial.commit09911bf2008-07-26 23:55:29204class NavigationNotificationObserver : public NotificationObserver {
205 public:
206 NavigationNotificationObserver(NavigationController* controller,
207 AutomationProvider* automation,
[email protected]71f65dd2009-02-11 19:14:56208 IPC::Message* reply_message,
209 NavigationCodeType success_code,
210 NavigationCodeType auth_needed_code,
211 NavigationCodeType failed_code)
initial.commit09911bf2008-07-26 23:55:29212 : automation_(automation),
[email protected]71f65dd2009-02-11 19:14:56213 reply_message_(reply_message),
initial.commit09911bf2008-07-26 23:55:29214 controller_(controller),
[email protected]71f65dd2009-02-11 19:14:56215 navigation_started_(false),
216 success_code_(success_code),
217 auth_needed_code_(auth_needed_code),
218 failed_code_(failed_code) {
initial.commit09911bf2008-07-26 23:55:29219 NotificationService* service = NotificationService::current();
[email protected]bfd04a62009-02-01 18:16:56220 service->AddObserver(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]8a3422c92008-09-24 17:42:42221 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56222 service->AddObserver(this, NotificationType::LOAD_START,
initial.commit09911bf2008-07-26 23:55:29223 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56224 service->AddObserver(this, NotificationType::LOAD_STOP,
initial.commit09911bf2008-07-26 23:55:29225 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56226 service->AddObserver(this, NotificationType::AUTH_NEEDED,
initial.commit09911bf2008-07-26 23:55:29227 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56228 service->AddObserver(this, NotificationType::AUTH_SUPPLIED,
initial.commit09911bf2008-07-26 23:55:29229 Source<NavigationController>(controller_));
230 }
231
232 ~NavigationNotificationObserver() {
initial.commit09911bf2008-07-26 23:55:29233 Unregister();
234 }
235
[email protected]71f65dd2009-02-11 19:14:56236 void ConditionMet(NavigationCodeType navigation_result) {
237 DCHECK(reply_message_ != NULL);
238
239 IPC::ParamTraits<NavigationCodeType>::Write(reply_message_,
240 navigation_result);
241 automation_->Send(reply_message_);
242 reply_message_ = NULL;
243
[email protected]d5798082008-09-29 21:02:03244 automation_->RemoveNavigationStatusListener(this);
initial.commit09911bf2008-07-26 23:55:29245 delete this;
246 }
247
248 void Unregister() {
[email protected]71f65dd2009-02-11 19:14:56249 // This means we did not receive a notification for this navigation.
250 // Send over a failed navigation status back to the caller to ensure that
251 // the caller does not hang waiting for the response.
252 if (reply_message_) {
253 IPC::ParamTraits<NavigationCodeType>::Write(reply_message_,
254 failed_code_);
255 automation_->Send(reply_message_);
256 reply_message_ = NULL;
257 }
258
initial.commit09911bf2008-07-26 23:55:29259 NotificationService* service = NotificationService::current();
[email protected]bfd04a62009-02-01 18:16:56260 service->RemoveObserver(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]8a3422c92008-09-24 17:42:42261 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56262 service->RemoveObserver(this, NotificationType::LOAD_START,
initial.commit09911bf2008-07-26 23:55:29263 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56264 service->RemoveObserver(this, NotificationType::LOAD_STOP,
initial.commit09911bf2008-07-26 23:55:29265 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56266 service->RemoveObserver(this, NotificationType::AUTH_NEEDED,
initial.commit09911bf2008-07-26 23:55:29267 Source<NavigationController>(controller_));
[email protected]bfd04a62009-02-01 18:16:56268 service->RemoveObserver(this, NotificationType::AUTH_SUPPLIED,
initial.commit09911bf2008-07-26 23:55:29269 Source<NavigationController>(controller_));
270 }
271
272 virtual void Observe(NotificationType type,
273 const NotificationSource& source,
274 const NotificationDetails& details) {
[email protected]8a3422c92008-09-24 17:42:42275 // We listen for 2 events to determine when the navigation started because:
276 // - when this is used by the WaitForNavigation method, we might be invoked
277 // afer the load has started (but not after the entry was committed, as
278 // WaitForNavigation compares times of the last navigation).
279 // - when this is used with a page requiring authentication, we will not get
[email protected]4f3dc372009-02-24 00:10:29280 // a NotificationType::NAV_ENTRY_COMMITTED until after we authenticate, so
281 // we need the NotificationType::LOAD_START.
[email protected]bfd04a62009-02-01 18:16:56282 if (type == NotificationType::NAV_ENTRY_COMMITTED ||
283 type == NotificationType::LOAD_START) {
initial.commit09911bf2008-07-26 23:55:29284 navigation_started_ = true;
[email protected]bfd04a62009-02-01 18:16:56285 } else if (type == NotificationType::LOAD_STOP) {
initial.commit09911bf2008-07-26 23:55:29286 if (navigation_started_) {
287 navigation_started_ = false;
[email protected]71f65dd2009-02-11 19:14:56288 ConditionMet(success_code_);
initial.commit09911bf2008-07-26 23:55:29289 }
[email protected]bfd04a62009-02-01 18:16:56290 } else if (type == NotificationType::AUTH_SUPPLIED) {
initial.commit09911bf2008-07-26 23:55:29291 // The LoginHandler for this tab is no longer valid.
292 automation_->RemoveLoginHandler(controller_);
293
294 // Treat this as if navigation started again, since load start/stop don't
295 // occur while authentication is ongoing.
296 navigation_started_ = true;
[email protected]bfd04a62009-02-01 18:16:56297 } else if (type == NotificationType::AUTH_NEEDED) {
[email protected]de246f52009-02-25 18:25:45298#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29299 if (navigation_started_) {
300 // Remember the login handler that wants authentication.
301 LoginHandler* handler =
302 Details<LoginNotificationDetails>(details)->handler();
303 automation_->AddLoginHandler(controller_, handler);
304
305 // Respond that authentication is needed.
306 navigation_started_ = false;
[email protected]71f65dd2009-02-11 19:14:56307 ConditionMet(auth_needed_code_);
initial.commit09911bf2008-07-26 23:55:29308 } else {
309 NOTREACHED();
310 }
[email protected]de246f52009-02-25 18:25:45311#else
312 // TODO(port): Enable when we have LoginNotificationDetails etc.
313 NOTIMPLEMENTED();
314#endif
initial.commit09911bf2008-07-26 23:55:29315 } else {
316 NOTREACHED();
317 }
318 }
319
320 private:
321 AutomationProvider* automation_;
[email protected]71f65dd2009-02-11 19:14:56322 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29323 NavigationController* controller_;
324 bool navigation_started_;
[email protected]71f65dd2009-02-11 19:14:56325 NavigationCodeType success_code_;
326 NavigationCodeType auth_needed_code_;
327 NavigationCodeType failed_code_;
initial.commit09911bf2008-07-26 23:55:29328};
329
330class TabStripNotificationObserver : public NotificationObserver {
331 public:
332 TabStripNotificationObserver(Browser* parent, NotificationType notification,
333 AutomationProvider* automation, int32 routing_id)
334 : automation_(automation),
initial.commit09911bf2008-07-26 23:55:29335 parent_(parent),
[email protected]66791d22009-02-24 20:11:33336 notification_(notification),
initial.commit09911bf2008-07-26 23:55:29337 routing_id_(routing_id) {
338 NotificationService::current()->
339 AddObserver(this, notification_, NotificationService::AllSources());
340 }
341
342 virtual ~TabStripNotificationObserver() {
343 Unregister();
344 }
345
346 void Unregister() {
347 NotificationService::current()->
348 RemoveObserver(this, notification_, NotificationService::AllSources());
349 }
350
351 virtual void Observe(NotificationType type,
352 const NotificationSource& source,
353 const NotificationDetails& details) {
354 if (type == notification_) {
355 ObserveTab(Source<NavigationController>(source).ptr());
356
357 // If verified, no need to observe anymore
358 automation_->RemoveTabStripObserver(this);
359 delete this;
360 } else {
361 NOTREACHED();
362 }
363 }
364
365 virtual void ObserveTab(NavigationController* controller) = 0;
366
367 protected:
368 AutomationProvider* automation_;
369 Browser* parent_;
370 NotificationType notification_;
371 int32 routing_id_;
372};
373
374class TabAppendedNotificationObserver : public TabStripNotificationObserver {
375 public:
376 TabAppendedNotificationObserver(Browser* parent,
[email protected]4f3dc372009-02-24 00:10:29377 AutomationProvider* automation, int32 routing_id,
[email protected]71f65dd2009-02-11 19:14:56378 IPC::Message* reply_message)
[email protected]bfd04a62009-02-01 18:16:56379 : TabStripNotificationObserver(parent, NotificationType::TAB_PARENTED,
[email protected]71f65dd2009-02-11 19:14:56380 automation, routing_id),
381 reply_message_(reply_message) {
initial.commit09911bf2008-07-26 23:55:29382 }
383
384 virtual void ObserveTab(NavigationController* controller) {
385 int tab_index =
386 automation_->GetIndexForNavigationController(controller, parent_);
387 if (tab_index == TabStripModel::kNoTab) {
388 // This tab notification doesn't belong to the parent_
389 return;
390 }
391
392 // Give the same response even if auth is needed, since it doesn't matter.
[email protected]71f65dd2009-02-11 19:14:56393 automation_->AddNavigationStatusListener<int>(
394 controller, reply_message_, AUTOMATION_MSG_NAVIGATION_SUCCESS,
395 AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, AUTOMATION_MSG_NAVIGATION_ERROR);
initial.commit09911bf2008-07-26 23:55:29396 }
[email protected]71f65dd2009-02-11 19:14:56397
398 protected:
399 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29400};
401
402class TabClosedNotificationObserver : public TabStripNotificationObserver {
403 public:
404 TabClosedNotificationObserver(Browser* parent,
405 AutomationProvider* automation,
406 int32 routing_id,
[email protected]71f65dd2009-02-11 19:14:56407 bool wait_until_closed,
408 IPC::Message* reply_message)
initial.commit09911bf2008-07-26 23:55:29409 : TabStripNotificationObserver(parent,
[email protected]bfd04a62009-02-01 18:16:56410 wait_until_closed ? NotificationType::TAB_CLOSED :
411 NotificationType::TAB_CLOSING,
412 automation,
[email protected]71f65dd2009-02-11 19:14:56413 routing_id),
414 reply_message_(reply_message) {
initial.commit09911bf2008-07-26 23:55:29415 }
416
417 virtual void ObserveTab(NavigationController* controller) {
[email protected]71f65dd2009-02-11 19:14:56418 AutomationMsg_CloseTab::WriteReplyParams(reply_message_, true);
419 automation_->Send(reply_message_);
initial.commit09911bf2008-07-26 23:55:29420 }
[email protected]71f65dd2009-02-11 19:14:56421
422 protected:
423 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29424};
425
[email protected]14c0a032009-04-13 18:15:14426class BrowserOpenedNotificationObserver : public NotificationObserver {
427 public:
428 BrowserOpenedNotificationObserver(AutomationProvider* automation,
429 IPC::Message* reply_message)
430 : automation_(automation),
431 reply_message_(reply_message) {
432 registrar_.Add(this, NotificationType::BROWSER_OPENED,
433 NotificationService::AllSources());
434 }
435
436 ~BrowserOpenedNotificationObserver() {
437 }
438
439 virtual void Observe(NotificationType type,
440 const NotificationSource& source,
441 const NotificationDetails& details) {
442 if (type == NotificationType::BROWSER_OPENED) {
443 automation_->Send(reply_message_);
444 delete this;
445 } else {
446 NOTREACHED();
447 }
448 }
449
450 private:
451 AutomationProvider* automation_;
452 IPC::Message* reply_message_;
453 NotificationRegistrar registrar_;
454};
455
initial.commit09911bf2008-07-26 23:55:29456class BrowserClosedNotificationObserver : public NotificationObserver {
457 public:
458 BrowserClosedNotificationObserver(Browser* browser,
459 AutomationProvider* automation,
[email protected]71f65dd2009-02-11 19:14:56460 int32 routing_id,
461 IPC::Message* reply_message)
initial.commit09911bf2008-07-26 23:55:29462 : automation_(automation),
[email protected]71f65dd2009-02-11 19:14:56463 routing_id_(routing_id),
464 reply_message_(reply_message) {
[email protected]bfd04a62009-02-01 18:16:56465 NotificationService::current()->AddObserver(this,
466 NotificationType::BROWSER_CLOSED, Source<Browser>(browser));
initial.commit09911bf2008-07-26 23:55:29467 }
468
469 virtual void Observe(NotificationType type,
470 const NotificationSource& source,
471 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56472 DCHECK(type == NotificationType::BROWSER_CLOSED);
initial.commit09911bf2008-07-26 23:55:29473 Details<bool> close_app(details);
[email protected]71f65dd2009-02-11 19:14:56474 DCHECK(reply_message_ != NULL);
475 AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_, true,
476 *(close_app.ptr()));
477 automation_->Send(reply_message_);
478 reply_message_ = NULL;
initial.commit09911bf2008-07-26 23:55:29479 delete this;
480 }
481
482 private:
483 AutomationProvider* automation_;
484 int32 routing_id_;
[email protected]71f65dd2009-02-11 19:14:56485 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29486};
487
[email protected]4e41709d2009-04-08 00:04:27488namespace {
489
490// Define mapping from command to notification
491struct CommandNotification {
492 int command;
493 NotificationType::Type notification_type;
494};
495
496const struct CommandNotification command_notifications[] = {
[email protected]14c0a032009-04-13 18:15:14497 {IDC_DUPLICATE_TAB, NotificationType::TAB_PARENTED},
[email protected]4e41709d2009-04-08 00:04:27498 {IDC_NEW_TAB, NotificationType::TAB_PARENTED}
499};
500
501} // namespace
502
[email protected]56e71b7c2009-03-27 03:05:56503class ExecuteBrowserCommandObserver : public NotificationObserver {
504 public:
[email protected]4e41709d2009-04-08 00:04:27505 ExecuteBrowserCommandObserver(AutomationProvider* automation,
506 IPC::Message* reply_message)
[email protected]56e71b7c2009-03-27 03:05:56507 : automation_(automation),
[email protected]56e71b7c2009-03-27 03:05:56508 reply_message_(reply_message) {
[email protected]56e71b7c2009-03-27 03:05:56509 }
510
511 ~ExecuteBrowserCommandObserver() {
512 }
513
[email protected]4e41709d2009-04-08 00:04:27514 bool Register(int command) {
515 if (!GetNotificationType(command, &notification_type_))
516 return false;
517 registrar_.Add(this, notification_type_,
518 NotificationService::AllSources());
519 return true;
520 }
521
[email protected]56e71b7c2009-03-27 03:05:56522 virtual void Observe(NotificationType type,
523 const NotificationSource& source,
524 const NotificationDetails& details) {
525 if (type == notification_type_) {
[email protected]49a14a82009-03-31 04:16:44526 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_,
527 true);
[email protected]56e71b7c2009-03-27 03:05:56528 automation_->Send(reply_message_);
529 delete this;
530 } else {
531 NOTREACHED();
532 }
533 }
534
535 private:
[email protected]4e41709d2009-04-08 00:04:27536 bool GetNotificationType(int command, NotificationType::Type* type) {
537 if (!type)
538 return false;
539 bool found = false;
540 for (unsigned int i = 0; i < arraysize(command_notifications); i++) {
541 if (command_notifications[i].command == command) {
542 *type = command_notifications[i].notification_type;
543 found = true;
544 break;
545 }
546 }
547 return found;
548 }
549
[email protected]56e71b7c2009-03-27 03:05:56550 AutomationProvider* automation_;
551 NotificationType::Type notification_type_;
552 IPC::Message* reply_message_;
553 NotificationRegistrar registrar_;
554};
555
initial.commit09911bf2008-07-26 23:55:29556class FindInPageNotificationObserver : public NotificationObserver {
557 public:
558 FindInPageNotificationObserver(AutomationProvider* automation,
559 TabContents* parent_tab,
[email protected]71f65dd2009-02-11 19:14:56560 int32 routing_id,
561 IPC::Message* reply_message)
initial.commit09911bf2008-07-26 23:55:29562 : automation_(automation),
563 parent_tab_(parent_tab),
[email protected]aedd85a2008-12-04 19:32:49564 routing_id_(routing_id),
[email protected]71f65dd2009-02-11 19:14:56565 active_match_ordinal_(-1),
566 reply_message_(reply_message) {
[email protected]bfd04a62009-02-01 18:16:56567 NotificationService::current()->AddObserver(
568 this,
569 NotificationType::FIND_RESULT_AVAILABLE,
570 Source<TabContents>(parent_tab_));
initial.commit09911bf2008-07-26 23:55:29571 }
572
573 ~FindInPageNotificationObserver() {
574 Unregister();
575 }
576
577 void Unregister() {
[email protected]71f65dd2009-02-11 19:14:56578 DCHECK(reply_message_ == NULL);
initial.commit09911bf2008-07-26 23:55:29579 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56580 RemoveObserver(this, NotificationType::FIND_RESULT_AVAILABLE,
initial.commit09911bf2008-07-26 23:55:29581 Source<TabContents>(parent_tab_));
582 }
583
584 virtual void Observe(NotificationType type, const NotificationSource& source,
585 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56586 if (type == NotificationType::FIND_RESULT_AVAILABLE) {
initial.commit09911bf2008-07-26 23:55:29587 Details<FindNotificationDetails> find_details(details);
588 if (find_details->request_id() == kFindInPageRequestId) {
[email protected]aedd85a2008-12-04 19:32:49589 // We get multiple responses and one of those will contain the ordinal.
590 // This message comes to us before the final update is sent.
591 if (find_details->active_match_ordinal() > -1)
592 active_match_ordinal_ = find_details->active_match_ordinal();
initial.commit09911bf2008-07-26 23:55:29593 if (find_details->final_update()) {
[email protected]71f65dd2009-02-11 19:14:56594 DCHECK(reply_message_ != NULL);
595
596 AutomationMsg_FindInPage::WriteReplyParams(
597 reply_message_, active_match_ordinal_,
598 find_details->number_of_matches());
599
600 automation_->Send(reply_message_);
601 reply_message_ = NULL;
initial.commit09911bf2008-07-26 23:55:29602 } else {
603 DLOG(INFO) << "Ignoring, since we only care about the final message";
604 }
605 }
606 } else {
607 NOTREACHED();
608 }
609 }
610
611 // The Find mechanism is over asynchronous IPC, so a search is kicked off and
612 // we wait for notification to find out what the results are. As the user is
613 // typing, new search requests can be issued and the Request ID helps us make
614 // sense of whether this is the current request or an old one. The unit tests,
615 // however, which uses this constant issues only one search at a time, so we
616 // don't need a rolling id to identify each search. But, we still need to
617 // specify one, so we just use a fixed one - its value does not matter.
618 static const int kFindInPageRequestId;
619 private:
620 AutomationProvider* automation_;
621 TabContents* parent_tab_;
622 int32 routing_id_;
[email protected]aedd85a2008-12-04 19:32:49623 // We will at some point (before final update) be notified of the ordinal and
624 // we need to preserve it so we can send it later.
625 int active_match_ordinal_;
[email protected]71f65dd2009-02-11 19:14:56626 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29627};
628
629const int FindInPageNotificationObserver::kFindInPageRequestId = -1;
630
631class DomOperationNotificationObserver : public NotificationObserver {
632 public:
633 explicit DomOperationNotificationObserver(AutomationProvider* automation)
634 : automation_(automation) {
635 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56636 AddObserver(this, NotificationType::DOM_OPERATION_RESPONSE,
initial.commit09911bf2008-07-26 23:55:29637 NotificationService::AllSources());
638 }
639
640 ~DomOperationNotificationObserver() {
641 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56642 RemoveObserver(this, NotificationType::DOM_OPERATION_RESPONSE,
initial.commit09911bf2008-07-26 23:55:29643 NotificationService::AllSources());
644 }
645
646 virtual void Observe(NotificationType type, const NotificationSource& source,
647 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56648 if (NotificationType::DOM_OPERATION_RESPONSE == type) {
initial.commit09911bf2008-07-26 23:55:29649 Details<DomOperationNotificationDetails> dom_op_details(details);
[email protected]71f65dd2009-02-11 19:14:56650
651 IPC::Message* reply_message = automation_->reply_message_release();
652 DCHECK(reply_message != NULL);
653
654 AutomationMsg_DomOperation::WriteReplyParams(
655 reply_message, dom_op_details->json());
656 automation_->Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29657 }
658 }
659 private:
660 AutomationProvider* automation_;
661};
662
663class DomInspectorNotificationObserver : public NotificationObserver {
664 public:
665 explicit DomInspectorNotificationObserver(AutomationProvider* automation)
666 : automation_(automation) {
[email protected]bfd04a62009-02-01 18:16:56667 NotificationService::current()->AddObserver(
668 this,
669 NotificationType::DOM_INSPECT_ELEMENT_RESPONSE,
670 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29671 }
672
673 ~DomInspectorNotificationObserver() {
[email protected]bfd04a62009-02-01 18:16:56674 NotificationService::current()->RemoveObserver(
675 this,
676 NotificationType::DOM_INSPECT_ELEMENT_RESPONSE,
677 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29678 }
679
680 virtual void Observe(NotificationType type, const NotificationSource& source,
681 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56682 if (NotificationType::DOM_INSPECT_ELEMENT_RESPONSE == type) {
initial.commit09911bf2008-07-26 23:55:29683 Details<int> dom_inspect_details(details);
684 automation_->ReceivedInspectElementResponse(*(dom_inspect_details.ptr()));
685 }
686 }
687
688 private:
689 AutomationProvider* automation_;
690};
691
[email protected]de246f52009-02-25 18:25:45692#if defined(OS_WIN)
693// TODO(port): Enable when printing is ported.
initial.commit09911bf2008-07-26 23:55:29694class DocumentPrintedNotificationObserver : public NotificationObserver {
695 public:
696 DocumentPrintedNotificationObserver(AutomationProvider* automation,
[email protected]71f65dd2009-02-11 19:14:56697 int32 routing_id,
698 IPC::Message* reply_message)
initial.commit09911bf2008-07-26 23:55:29699 : automation_(automation),
700 routing_id_(routing_id),
[email protected]71f65dd2009-02-11 19:14:56701 success_(false),
702 reply_message_(reply_message) {
[email protected]bfd04a62009-02-01 18:16:56703 NotificationService::current()->AddObserver(
704 this,
705 NotificationType::PRINT_JOB_EVENT,
706 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29707 }
708
709 ~DocumentPrintedNotificationObserver() {
[email protected]71f65dd2009-02-11 19:14:56710 DCHECK(reply_message_ != NULL);
711 AutomationMsg_PrintNow::WriteReplyParams(reply_message_, success_);
712 automation_->Send(reply_message_);
initial.commit09911bf2008-07-26 23:55:29713 automation_->RemoveNavigationStatusListener(this);
[email protected]bfd04a62009-02-01 18:16:56714 NotificationService::current()->RemoveObserver(
715 this,
716 NotificationType::PRINT_JOB_EVENT,
717 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29718 }
719
720 virtual void Observe(NotificationType type, const NotificationSource& source,
721 const NotificationDetails& details) {
722 using namespace printing;
[email protected]bfd04a62009-02-01 18:16:56723 DCHECK(type == NotificationType::PRINT_JOB_EVENT);
initial.commit09911bf2008-07-26 23:55:29724 switch (Details<JobEventDetails>(details)->type()) {
725 case JobEventDetails::JOB_DONE: {
726 // Succeeded.
727 success_ = true;
728 delete this;
729 break;
730 }
731 case JobEventDetails::USER_INIT_CANCELED:
732 case JobEventDetails::FAILED: {
733 // Failed.
734 delete this;
735 break;
736 }
737 case JobEventDetails::NEW_DOC:
738 case JobEventDetails::USER_INIT_DONE:
739 case JobEventDetails::DEFAULT_INIT_DONE:
740 case JobEventDetails::NEW_PAGE:
741 case JobEventDetails::PAGE_DONE:
742 case JobEventDetails::DOC_DONE:
743 case JobEventDetails::ALL_PAGES_REQUESTED: {
744 // Don't care.
745 break;
746 }
747 default: {
748 NOTREACHED();
749 break;
750 }
751 }
752 }
753
754 private:
755 scoped_refptr<AutomationProvider> automation_;
756 int32 routing_id_;
757 bool success_;
[email protected]71f65dd2009-02-11 19:14:56758 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:29759};
[email protected]de246f52009-02-25 18:25:45760#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29761
[email protected]cbab76d2008-10-13 22:42:47762class AutomationInterstitialPage : public InterstitialPage {
763 public:
[email protected]57c6a652009-05-04 07:58:34764 AutomationInterstitialPage(TabContents* tab,
[email protected]cbab76d2008-10-13 22:42:47765 const GURL& url,
766 const std::string& contents)
767 : InterstitialPage(tab, true, url),
768 contents_(contents) {
769 }
770
771 virtual std::string GetHTMLContents() { return contents_; }
772
773 private:
774 std::string contents_;
[email protected]4f3dc372009-02-24 00:10:29775
[email protected]cbab76d2008-10-13 22:42:47776 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage);
777};
778
initial.commit09911bf2008-07-26 23:55:29779AutomationProvider::AutomationProvider(Profile* profile)
[email protected]295039bd2008-08-15 04:32:57780 : redirect_query_(0),
[email protected]71f65dd2009-02-11 19:14:56781 profile_(profile),
782 reply_message_(NULL) {
initial.commit09911bf2008-07-26 23:55:29783 browser_tracker_.reset(new AutomationBrowserTracker(this));
initial.commit09911bf2008-07-26 23:55:29784 tab_tracker_.reset(new AutomationTabTracker(this));
[email protected]0e9f4ee2009-04-08 01:44:20785 window_tracker_.reset(new AutomationWindowTracker(this));
[email protected]de246f52009-02-25 18:25:45786#if defined(OS_WIN)
787 // TODO(port): Enable as the trackers get ported.
initial.commit09911bf2008-07-26 23:55:29788 autocomplete_edit_tracker_.reset(
789 new AutomationAutocompleteEditTracker(this));
790 cwindow_tracker_.reset(new AutomationConstrainedWindowTracker(this));
791 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this));
[email protected]de246f52009-02-25 18:25:45792#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29793 dom_operation_observer_.reset(new DomOperationNotificationObserver(this));
794 dom_inspector_observer_.reset(new DomInspectorNotificationObserver(this));
795}
796
797AutomationProvider::~AutomationProvider() {
[email protected]0da050b92008-08-19 19:29:47798 // Make sure that any outstanding NotificationObservers also get destroyed.
799 ObserverList<NotificationObserver>::Iterator it(notification_observer_list_);
[email protected]5a52f162008-08-27 04:15:31800 NotificationObserver* observer;
[email protected]0da050b92008-08-19 19:29:47801 while ((observer = it.GetNext()) != NULL)
802 delete observer;
initial.commit09911bf2008-07-26 23:55:29803}
804
805void AutomationProvider::ConnectToChannel(const std::wstring& channel_id) {
[email protected]295039bd2008-08-15 04:32:57806 channel_.reset(
[email protected]71f65dd2009-02-11 19:14:56807 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, NULL,
808 g_browser_process->io_thread()->message_loop(),
809 true, g_browser_process->shutdown_event()));
[email protected]79e966832009-04-21 14:23:05810 scoped_ptr<FileVersionInfo> file_version_info(
811 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
[email protected]cf620752009-04-24 17:05:40812 std::string version_string;
813 if (file_version_info != NULL) {
814 version_string = WideToASCII(file_version_info->file_version());
815 }
[email protected]c6cb1992009-04-13 16:45:29816
817 // Send a hello message with our current automation protocol version.
818 channel_->Send(new AutomationMsg_Hello(0, version_string.c_str()));
initial.commit09911bf2008-07-26 23:55:29819}
820
821void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) {
822 if (expected_tabs == 0) {
823 Send(new AutomationMsg_InitialLoadsComplete(0));
824 } else {
825 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this));
826 }
827}
828
[email protected]71f65dd2009-02-11 19:14:56829template<class NavigationCodeType>
initial.commit09911bf2008-07-26 23:55:29830NotificationObserver* AutomationProvider::AddNavigationStatusListener(
[email protected]71f65dd2009-02-11 19:14:56831 NavigationController* tab, IPC::Message* reply_message,
832 NavigationCodeType success_code,
833 NavigationCodeType auth_needed_code,
834 NavigationCodeType failed_code) {
initial.commit09911bf2008-07-26 23:55:29835 NotificationObserver* observer =
[email protected]71f65dd2009-02-11 19:14:56836 new NavigationNotificationObserver<NavigationCodeType>(
837 tab, this, reply_message, success_code, auth_needed_code,
838 failed_code);
initial.commit09911bf2008-07-26 23:55:29839
[email protected]71f65dd2009-02-11 19:14:56840 notification_observer_list_.AddObserver(observer);
initial.commit09911bf2008-07-26 23:55:29841 return observer;
842}
843
844void AutomationProvider::RemoveNavigationStatusListener(
845 NotificationObserver* obs) {
846 notification_observer_list_.RemoveObserver(obs);
847}
848
849NotificationObserver* AutomationProvider::AddTabStripObserver(
[email protected]71f65dd2009-02-11 19:14:56850 Browser* parent, int32 routing_id, IPC::Message* reply_message) {
851 NotificationObserver* observer =
852 new TabAppendedNotificationObserver(parent, this, routing_id,
853 reply_message);
initial.commit09911bf2008-07-26 23:55:29854 notification_observer_list_.AddObserver(observer);
855
856 return observer;
857}
858
859void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) {
860 notification_observer_list_.RemoveObserver(obs);
861}
862
863void AutomationProvider::AddLoginHandler(NavigationController* tab,
864 LoginHandler* handler) {
865 login_handler_map_[tab] = handler;
866}
867
868void AutomationProvider::RemoveLoginHandler(NavigationController* tab) {
869 DCHECK(login_handler_map_[tab]);
870 login_handler_map_.erase(tab);
871}
872
873int AutomationProvider::GetIndexForNavigationController(
874 const NavigationController* controller, const Browser* parent) const {
875 DCHECK(parent);
876 return parent->GetIndexOfController(controller);
877}
878
879void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
880 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message)
[email protected]71f65dd2009-02-11 19:14:56881 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser,
882 CloseBrowser)
883 IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync,
884 CloseBrowserAsync)
885 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
886 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex)
887 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab)
888 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
889 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
890 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
891 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL,
892 NavigateToURL)
893 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
894 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack)
895 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward)
896 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload)
897 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth)
898 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth,
899 CancelAuth)
900 IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth)
901 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom,
902 GetRedirectsFrom)
903 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount,
initial.commit09911bf2008-07-26 23:55:29904 GetBrowserWindowCount)
[email protected]24497032009-05-01 17:00:29905 IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount,
906 GetNormalBrowserWindowCount)
[email protected]71f65dd2009-02-11 19:14:56907 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow)
908 IPC_MESSAGE_HANDLER(AutomationMsg_LastActiveBrowserWindow,
initial.commit09911bf2008-07-26 23:55:29909 GetLastActiveBrowserWindow)
[email protected]71f65dd2009-02-11 19:14:56910 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveWindow, GetActiveWindow)
[email protected]24497032009-05-01 17:00:29911 IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow,
912 FindNormalBrowserWindow)
[email protected]71f65dd2009-02-11 19:14:56913 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive)
initial.commit09911bf2008-07-26 23:55:29914 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow);
[email protected]de246f52009-02-25 18:25:45915#if defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56916 IPC_MESSAGE_HANDLER(AutomationMsg_WindowHWND, GetWindowHWND)
[email protected]de246f52009-02-25 18:25:45917#endif // defined(OS_WIN)
[email protected]49a14a82009-03-31 04:16:44918 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync,
[email protected]4f6381ee2009-04-16 02:46:33919 ExecuteBrowserCommandAsync)
[email protected]49a14a82009-03-31 04:16:44920 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand,
[email protected]4f6381ee2009-04-16 02:46:33921 ExecuteBrowserCommand)
[email protected]71f65dd2009-02-11 19:14:56922 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds,
initial.commit09911bf2008-07-26 23:55:29923 WindowGetViewBounds)
[email protected]71f65dd2009-02-11 19:14:56924 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible,
925 SetWindowVisible)
[email protected]de246f52009-02-25 18:25:45926#if defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56927 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
928 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress,
initial.commit09911bf2008-07-26 23:55:29929 WindowSimulateKeyPress)
[email protected]71f65dd2009-02-11 19:14:56930 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag,
931 WindowSimulateDrag)
[email protected]d7fa7552009-03-20 21:06:37932#endif // defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56933 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount)
934 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab)
[email protected]d7fa7552009-03-20 21:06:37935#if defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56936 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND)
[email protected]de246f52009-02-25 18:25:45937#endif // defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56938 IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID)
939 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
[email protected]77bc6732009-04-20 22:01:03940 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex)
[email protected]71f65dd2009-02-11 19:14:56941 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL)
942 IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility,
initial.commit09911bf2008-07-26 23:55:29943 GetShelfVisibility)
944 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused)
[email protected]71f65dd2009-02-11 19:14:56945 IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator,
946 ApplyAccelerator)
947 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
948 ExecuteJavascript)
949 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount,
initial.commit09911bf2008-07-26 23:55:29950 GetConstrainedWindowCount)
[email protected]71f65dd2009-02-11 19:14:56951 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindow,
initial.commit09911bf2008-07-26 23:55:29952 GetConstrainedWindow)
[email protected]71f65dd2009-02-11 19:14:56953 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedTitle,
initial.commit09911bf2008-07-26 23:55:29954 GetConstrainedTitle)
[email protected]71f65dd2009-02-11 19:14:56955 IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage,
initial.commit09911bf2008-07-26 23:55:29956 HandleFindInPageRequest)
[email protected]71f65dd2009-02-11 19:14:56957 IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID,
958 GetFocusedViewID)
959 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement,
960 HandleInspectElementRequest)
initial.commit09911bf2008-07-26 23:55:29961 IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet,
962 SetFilteredInet);
[email protected]71f65dd2009-02-11 19:14:56963 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory,
initial.commit09911bf2008-07-26 23:55:29964 GetDownloadDirectory);
[email protected]14c0a032009-04-13 18:15:14965 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow,
966 OpenNewBrowserWindow);
[email protected]71f65dd2009-02-11 19:14:56967 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser,
initial.commit09911bf2008-07-26 23:55:29968 GetWindowForBrowser);
[email protected]71f65dd2009-02-11 19:14:56969 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser,
initial.commit09911bf2008-07-26 23:55:29970 GetAutocompleteEditForBrowser);
[email protected]71f65dd2009-02-11 19:14:56971 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow,
initial.commit09911bf2008-07-26 23:55:29972 GetBrowserForWindow);
[email protected]de246f52009-02-25 18:25:45973#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29974 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab)
[email protected]d2cc6ed2009-04-24 00:26:17975#endif
[email protected]71f65dd2009-02-11 19:14:56976 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab,
initial.commit09911bf2008-07-26 23:55:29977 NavigateInExternalTab)
[email protected]71f65dd2009-02-11 19:14:56978 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage,
979 ShowInterstitialPage);
980 IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage,
initial.commit09911bf2008-07-26 23:55:29981 HideInterstitialPage);
[email protected]d2cc6ed2009-04-24 00:26:17982#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29983 IPC_MESSAGE_HANDLER(AutomationMsg_SetAcceleratorsForTab,
984 SetAcceleratorsForTab)
985 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator,
986 ProcessUnhandledAccelerator)
[email protected]d2cc6ed2009-04-24 00:26:17987#endif
[email protected]71f65dd2009-02-11 19:14:56988 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored,
989 WaitForTabToBeRestored)
[email protected]b9d227492009-02-10 15:20:27990 IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus,
991 SetInitialFocus)
[email protected]d2cc6ed2009-04-24 00:26:17992#if defined(OS_WIN)
[email protected]87eab222009-03-13 00:47:45993 IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition)
[email protected]d2cc6ed2009-04-24 00:26:17994#endif
initial.commit09911bf2008-07-26 23:55:29995 IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState,
996 GetSecurityState)
997 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType,
998 GetPageType)
[email protected]71f65dd2009-02-11 19:14:56999 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage,
1000 ActionOnSSLBlockingPage)
initial.commit09911bf2008-07-26 23:55:291001 IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront)
1002 IPC_MESSAGE_HANDLER(AutomationMsg_IsPageMenuCommandEnabled,
1003 IsPageMenuCommandEnabled)
[email protected]71f65dd2009-02-11 19:14:561004 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow)
1005 IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage)
1006 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText,
initial.commit09911bf2008-07-26 23:55:291007 GetAutocompleteEditText)
[email protected]71f65dd2009-02-11 19:14:561008 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText,
initial.commit09911bf2008-07-26 23:55:291009 SetAutocompleteEditText)
[email protected]71f65dd2009-02-11 19:14:561010 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress,
initial.commit09911bf2008-07-26 23:55:291011 AutocompleteEditIsQueryInProgress)
[email protected]71f65dd2009-02-11 19:14:561012 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches,
initial.commit09911bf2008-07-26 23:55:291013 AutocompleteEditGetMatches)
[email protected]71f65dd2009-02-11 19:14:561014 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowBounds,
initial.commit09911bf2008-07-26 23:55:291015 GetConstrainedWindowBounds)
[email protected]71f65dd2009-02-11 19:14:561016 IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage,
[email protected]5f8af2a2008-08-06 22:49:451017 HandleOpenFindInPageRequest)
[email protected]18cb2572008-08-21 20:34:451018 IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost,
1019 OnMessageFromExternalHost)
[email protected]71f65dd2009-02-11 19:14:561020 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find,
1021 HandleFindRequest)
1022 IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility,
[email protected]20e93d12008-08-28 16:31:571023 GetFindWindowVisibility)
[email protected]71f65dd2009-02-11 19:14:561024 IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation,
[email protected]20e93d12008-08-28 16:31:571025 HandleFindWindowLocationRequest)
[email protected]71f65dd2009-02-11 19:14:561026 IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility,
1027 GetBookmarkBarVisibility)
1028 IPC_MESSAGE_HANDLER(AutomationMsg_GetSSLInfoBarCount,
[email protected]8a3422c92008-09-24 17:42:421029 GetSSLInfoBarCount)
[email protected]71f65dd2009-02-11 19:14:561030 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickSSLInfoBarLink,
1031 ClickSSLInfoBarLink)
1032 IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime,
[email protected]8a3422c92008-09-24 17:42:421033 GetLastNavigationTime)
[email protected]71f65dd2009-02-11 19:14:561034 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation,
1035 WaitForNavigation)
1036 IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference,
[email protected]8a3422c92008-09-24 17:42:421037 SetIntPreference)
[email protected]71f65dd2009-02-11 19:14:561038 IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog,
[email protected]c274acc2008-11-11 20:13:441039 GetShowingAppModalDialog)
[email protected]71f65dd2009-02-11 19:14:561040 IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton,
[email protected]fad84eab2008-12-05 00:37:201041 ClickAppModalDialogButton)
[email protected]71f65dd2009-02-11 19:14:561042 IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference,
[email protected]97fa6ce32008-12-19 01:48:161043 SetStringPreference)
[email protected]71f65dd2009-02-11 19:14:561044 IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference,
[email protected]97fa6ce32008-12-19 01:48:161045 GetBooleanPreference)
[email protected]71f65dd2009-02-11 19:14:561046 IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference,
[email protected]97fa6ce32008-12-19 01:48:161047 SetBooleanPreference)
[email protected]71f65dd2009-02-11 19:14:561048 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding,
[email protected]97fa6ce32008-12-19 01:48:161049 GetPageCurrentEncoding)
[email protected]71f65dd2009-02-11 19:14:561050 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding,
[email protected]97fa6ce32008-12-19 01:48:161051 OverrideEncoding)
[email protected]5bcdb312009-01-07 21:43:201052 IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser,
1053 SavePackageShouldPromptUser)
[email protected]3753f522009-04-14 23:15:471054 IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle,
1055 GetWindowTitle)
initial.commit09911bf2008-07-26 23:55:291056 IPC_END_MESSAGE_MAP()
1057}
1058
[email protected]71f65dd2009-02-11 19:14:561059void AutomationProvider::ActivateTab(int handle, int at_index, int* status) {
1060 *status = -1;
initial.commit09911bf2008-07-26 23:55:291061 if (browser_tracker_->ContainsHandle(handle) && at_index > -1) {
1062 Browser* browser = browser_tracker_->GetResource(handle);
1063 if (at_index >= 0 && at_index < browser->tab_count()) {
1064 browser->SelectTabContentsAt(at_index, true);
[email protected]71f65dd2009-02-11 19:14:561065 *status = 0;
initial.commit09911bf2008-07-26 23:55:291066 }
1067 }
initial.commit09911bf2008-07-26 23:55:291068}
1069
[email protected]71f65dd2009-02-11 19:14:561070void AutomationProvider::AppendTab(int handle, const GURL& url,
1071 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291072 int append_tab_response = -1; // -1 is the error code
1073 NotificationObserver* observer = NULL;
1074
1075 if (browser_tracker_->ContainsHandle(handle)) {
1076 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:561077 observer = AddTabStripObserver(browser, reply_message->routing_id(),
1078 reply_message);
[email protected]22735af62009-04-07 21:09:581079 TabContents* tab_contents = browser->AddTabWithURL(url, GURL(),
1080 PageTransition::TYPED,
1081 true, -1, NULL);
initial.commit09911bf2008-07-26 23:55:291082 if (tab_contents) {
1083 append_tab_response =
[email protected]ce3fa3c2009-04-20 19:55:571084 GetIndexForNavigationController(&tab_contents->controller(), browser);
initial.commit09911bf2008-07-26 23:55:291085 }
1086 }
1087
1088 if (append_tab_response < 0) {
1089 // The append tab failed. Remove the TabStripObserver
1090 if (observer) {
1091 RemoveTabStripObserver(observer);
1092 delete observer;
1093 }
1094
[email protected]71f65dd2009-02-11 19:14:561095 AutomationMsg_AppendTab::WriteReplyParams(reply_message,
1096 append_tab_response);
1097 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291098 }
1099}
1100
[email protected]71f65dd2009-02-11 19:14:561101void AutomationProvider::NavigateToURL(int handle, const GURL& url,
1102 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291103 if (tab_tracker_->ContainsHandle(handle)) {
1104 NavigationController* tab = tab_tracker_->GetResource(handle);
1105
1106 // Simulate what a user would do. Activate the tab and then navigate.
1107 // We could allow navigating in a background tab in future.
1108 Browser* browser = FindAndActivateTab(tab);
1109
1110 if (browser) {
[email protected]71f65dd2009-02-11 19:14:561111 AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>(
1112 tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS,
1113 AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
1114 AUTOMATION_MSG_NAVIGATION_ERROR);
1115
initial.commit09911bf2008-07-26 23:55:291116 // TODO(darin): avoid conversion to GURL
[email protected]c0588052008-10-27 23:01:501117 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
initial.commit09911bf2008-07-26 23:55:291118 return;
1119 }
1120 }
[email protected]71f65dd2009-02-11 19:14:561121
1122 AutomationMsg_NavigateToURL::WriteReplyParams(
1123 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1124 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291125}
1126
[email protected]71f65dd2009-02-11 19:14:561127void AutomationProvider::NavigationAsync(int handle, const GURL& url,
1128 bool* status) {
1129 *status = false;
initial.commit09911bf2008-07-26 23:55:291130
1131 if (tab_tracker_->ContainsHandle(handle)) {
1132 NavigationController* tab = tab_tracker_->GetResource(handle);
1133
1134 // Simulate what a user would do. Activate the tab and then navigate.
1135 // We could allow navigating in a background tab in future.
1136 Browser* browser = FindAndActivateTab(tab);
1137
1138 if (browser) {
1139 // Don't add any listener unless a callback mechanism is desired.
1140 // TODO(vibhor): Do this if such a requirement arises in future.
[email protected]c0588052008-10-27 23:01:501141 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
[email protected]71f65dd2009-02-11 19:14:561142 *status = true;
initial.commit09911bf2008-07-26 23:55:291143 }
1144 }
initial.commit09911bf2008-07-26 23:55:291145}
1146
[email protected]71f65dd2009-02-11 19:14:561147void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291148 if (tab_tracker_->ContainsHandle(handle)) {
1149 NavigationController* tab = tab_tracker_->GetResource(handle);
1150 Browser* browser = FindAndActivateTab(tab);
[email protected]1fc025202009-01-20 23:03:141151 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) {
[email protected]71f65dd2009-02-11 19:14:561152 AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>(
1153 tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS,
1154 AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
1155 AUTOMATION_MSG_NAVIGATION_ERROR);
[email protected]485fba42009-03-24 23:27:291156 browser->GoBack(CURRENT_TAB);
initial.commit09911bf2008-07-26 23:55:291157 return;
1158 }
1159 }
[email protected]71f65dd2009-02-11 19:14:561160
1161 AutomationMsg_GoBack::WriteReplyParams(
1162 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1163 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291164}
1165
[email protected]71f65dd2009-02-11 19:14:561166void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291167 if (tab_tracker_->ContainsHandle(handle)) {
1168 NavigationController* tab = tab_tracker_->GetResource(handle);
1169 Browser* browser = FindAndActivateTab(tab);
[email protected]1fc025202009-01-20 23:03:141170 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) {
[email protected]71f65dd2009-02-11 19:14:561171 AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>(
1172 tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS,
1173 AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
1174 AUTOMATION_MSG_NAVIGATION_ERROR);
[email protected]485fba42009-03-24 23:27:291175 browser->GoForward(CURRENT_TAB);
initial.commit09911bf2008-07-26 23:55:291176 return;
1177 }
1178 }
[email protected]71f65dd2009-02-11 19:14:561179
1180 AutomationMsg_GoForward::WriteReplyParams(
1181 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1182 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291183}
1184
[email protected]71f65dd2009-02-11 19:14:561185void AutomationProvider::Reload(int handle, IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291186 if (tab_tracker_->ContainsHandle(handle)) {
1187 NavigationController* tab = tab_tracker_->GetResource(handle);
1188 Browser* browser = FindAndActivateTab(tab);
[email protected]1fc025202009-01-20 23:03:141189 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) {
[email protected]71f65dd2009-02-11 19:14:561190 AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>(
1191 tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS,
1192 AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
1193 AUTOMATION_MSG_NAVIGATION_ERROR);
initial.commit09911bf2008-07-26 23:55:291194 browser->Reload();
1195 return;
1196 }
1197 }
[email protected]71f65dd2009-02-11 19:14:561198
1199 AutomationMsg_Reload::WriteReplyParams(
1200 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1201 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291202}
1203
[email protected]71f65dd2009-02-11 19:14:561204void AutomationProvider::SetAuth(int tab_handle,
initial.commit09911bf2008-07-26 23:55:291205 const std::wstring& username,
[email protected]71f65dd2009-02-11 19:14:561206 const std::wstring& password,
1207 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291208 int status = -1;
1209
1210 if (tab_tracker_->ContainsHandle(tab_handle)) {
1211 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1212 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
1213
1214 if (iter != login_handler_map_.end()) {
1215 // If auth is needed again after this, assume login has failed. This is
1216 // not strictly correct, because a navigation can require both proxy and
1217 // server auth, but it should be OK for now.
1218 LoginHandler* handler = iter->second;
[email protected]71f65dd2009-02-11 19:14:561219 AddNavigationStatusListener<int>(tab, reply_message, 0, -1, -1);
initial.commit09911bf2008-07-26 23:55:291220 handler->SetAuth(username, password);
1221 status = 0;
1222 }
1223 }
[email protected]de246f52009-02-25 18:25:451224
initial.commit09911bf2008-07-26 23:55:291225 if (status < 0) {
[email protected]71f65dd2009-02-11 19:14:561226 AutomationMsg_SetAuth::WriteReplyParams(reply_message, status);
1227 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291228 }
1229}
1230
[email protected]71f65dd2009-02-11 19:14:561231void AutomationProvider::CancelAuth(int tab_handle,
1232 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291233 int status = -1;
1234
1235 if (tab_tracker_->ContainsHandle(tab_handle)) {
1236 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1237 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
1238
1239 if (iter != login_handler_map_.end()) {
1240 // If auth is needed again after this, something is screwy.
1241 LoginHandler* handler = iter->second;
[email protected]71f65dd2009-02-11 19:14:561242 AddNavigationStatusListener<int>(tab, reply_message, 0, -1, -1);
initial.commit09911bf2008-07-26 23:55:291243 handler->CancelAuth();
1244 status = 0;
1245 }
1246 }
[email protected]de246f52009-02-25 18:25:451247
initial.commit09911bf2008-07-26 23:55:291248 if (status < 0) {
[email protected]71f65dd2009-02-11 19:14:561249 AutomationMsg_CancelAuth::WriteReplyParams(reply_message, status);
1250 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291251 }
1252}
1253
[email protected]71f65dd2009-02-11 19:14:561254void AutomationProvider::NeedsAuth(int tab_handle, bool* needs_auth) {
1255 *needs_auth = false;
initial.commit09911bf2008-07-26 23:55:291256
1257 if (tab_tracker_->ContainsHandle(tab_handle)) {
1258 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1259 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
1260
1261 if (iter != login_handler_map_.end()) {
1262 // The LoginHandler will be in our map IFF the tab needs auth.
[email protected]71f65dd2009-02-11 19:14:561263 *needs_auth = true;
initial.commit09911bf2008-07-26 23:55:291264 }
1265 }
initial.commit09911bf2008-07-26 23:55:291266}
1267
[email protected]71f65dd2009-02-11 19:14:561268void AutomationProvider::GetRedirectsFrom(int tab_handle,
1269 const GURL& source_url,
1270 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291271 DCHECK(!redirect_query_) << "Can only handle one redirect query at once.";
1272 if (tab_tracker_->ContainsHandle(tab_handle)) {
1273 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1274 HistoryService* history_service =
1275 tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
1276
1277 DCHECK(history_service) << "Tab " << tab_handle << "'s profile " <<
1278 "has no history service";
1279 if (history_service) {
[email protected]71f65dd2009-02-11 19:14:561280 DCHECK(reply_message_ == NULL);
1281 reply_message_ = reply_message;
initial.commit09911bf2008-07-26 23:55:291282 // Schedule a history query for redirects. The response will be sent
1283 // asynchronously from the callback the history system uses to notify us
1284 // that it's done: OnRedirectQueryComplete.
[email protected]71f65dd2009-02-11 19:14:561285 redirect_query_routing_id_ = reply_message->routing_id();
initial.commit09911bf2008-07-26 23:55:291286 redirect_query_ = history_service->QueryRedirectsFrom(
1287 source_url, &consumer_,
1288 NewCallback(this, &AutomationProvider::OnRedirectQueryComplete));
1289 return; // Response will be sent when query completes.
1290 }
1291 }
1292
1293 // Send failure response.
[email protected]deb57402009-02-06 01:35:301294 std::vector<GURL> empty;
[email protected]71f65dd2009-02-11 19:14:561295 AutomationMsg_RedirectsFrom::WriteReplyParams(reply_message, false, empty);
1296 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291297}
1298
[email protected]71f65dd2009-02-11 19:14:561299void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) {
1300 *active_tab_index = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291301 if (browser_tracker_->ContainsHandle(handle)) {
1302 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:561303 *active_tab_index = browser->selected_index();
initial.commit09911bf2008-07-26 23:55:291304 }
initial.commit09911bf2008-07-26 23:55:291305}
1306
[email protected]71f65dd2009-02-11 19:14:561307void AutomationProvider::GetBrowserWindowCount(int* window_count) {
1308 *window_count = static_cast<int>(BrowserList::size());
initial.commit09911bf2008-07-26 23:55:291309}
1310
[email protected]24497032009-05-01 17:00:291311void AutomationProvider::GetNormalBrowserWindowCount(int* window_count) {
1312 *window_count = static_cast<int>(
1313 BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL));
1314}
1315
[email protected]71f65dd2009-02-11 19:14:561316void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog,
1317 int* dialog_button) {
[email protected]0bfa713f2009-04-07 20:18:281318 AppModalDialog* dialog_delegate = AppModalDialogQueue::active_dialog();
[email protected]b3a70332009-02-25 02:40:501319 *showing_dialog = (dialog_delegate != NULL);
1320 if (*showing_dialog)
1321 *dialog_button = dialog_delegate->GetDialogButtons();
1322 else
[email protected]478ff2ed2009-04-21 23:49:181323 *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE;
[email protected]fad84eab2008-12-05 00:37:201324}
1325
[email protected]71f65dd2009-02-11 19:14:561326void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) {
1327 *success = false;
[email protected]fad84eab2008-12-05 00:37:201328
[email protected]0bfa713f2009-04-07 20:18:281329 AppModalDialog* dialog_delegate = AppModalDialogQueue::active_dialog();
[email protected]b3a70332009-02-25 02:40:501330 if (dialog_delegate &&
1331 (dialog_delegate->GetDialogButtons() & button) == button) {
[email protected]478ff2ed2009-04-21 23:49:181332 if ((button & MessageBoxFlags::DIALOGBUTTON_OK) ==
1333 MessageBoxFlags::DIALOGBUTTON_OK) {
[email protected]0bfa713f2009-04-07 20:18:281334 dialog_delegate->AcceptWindow();
[email protected]71f65dd2009-02-11 19:14:561335 *success = true;
[email protected]fad84eab2008-12-05 00:37:201336 }
[email protected]478ff2ed2009-04-21 23:49:181337 if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) ==
1338 MessageBoxFlags::DIALOGBUTTON_CANCEL) {
[email protected]71f65dd2009-02-11 19:14:561339 DCHECK(!*success) << "invalid param, OK and CANCEL specified";
[email protected]0bfa713f2009-04-07 20:18:281340 dialog_delegate->CancelWindow();
[email protected]71f65dd2009-02-11 19:14:561341 *success = true;
[email protected]fad84eab2008-12-05 00:37:201342 }
1343 }
[email protected]c274acc2008-11-11 20:13:441344}
[email protected]c274acc2008-11-11 20:13:441345
[email protected]71f65dd2009-02-11 19:14:561346void AutomationProvider::GetBrowserWindow(int index, int* handle) {
1347 *handle = 0;
initial.commit09911bf2008-07-26 23:55:291348 if (index >= 0) {
1349 BrowserList::const_iterator iter = BrowserList::begin();
[email protected]24497032009-05-01 17:00:291350 for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index);
initial.commit09911bf2008-07-26 23:55:291351 if (iter != BrowserList::end()) {
[email protected]71f65dd2009-02-11 19:14:561352 *handle = browser_tracker_->Add(*iter);
initial.commit09911bf2008-07-26 23:55:291353 }
1354 }
initial.commit09911bf2008-07-26 23:55:291355}
1356
[email protected]24497032009-05-01 17:00:291357void AutomationProvider::FindNormalBrowserWindow(int* handle) {
1358 *handle = 0;
1359 Browser* browser = BrowserList::FindBrowserWithType(profile_,
1360 Browser::TYPE_NORMAL);
1361 if (browser)
1362 *handle = browser_tracker_->Add(browser);
1363}
1364
[email protected]71f65dd2009-02-11 19:14:561365void AutomationProvider::GetLastActiveBrowserWindow(int* handle) {
1366 *handle = 0;
initial.commit09911bf2008-07-26 23:55:291367 Browser* browser = BrowserList::GetLastActive();
1368 if (browser)
[email protected]71f65dd2009-02-11 19:14:561369 *handle = browser_tracker_->Add(browser);
initial.commit09911bf2008-07-26 23:55:291370}
1371
[email protected]de246f52009-02-25 18:25:451372#if defined(OS_WIN)
1373// TODO(port): Remove windowsisms.
initial.commit09911bf2008-07-26 23:55:291374BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM l_param) {
1375 if (hwnd == reinterpret_cast<HWND>(l_param)) {
1376 return FALSE;
1377 }
1378 return TRUE;
1379}
1380
[email protected]71f65dd2009-02-11 19:14:561381void AutomationProvider::GetActiveWindow(int* handle) {
initial.commit09911bf2008-07-26 23:55:291382 HWND window = GetForegroundWindow();
1383
1384 // Let's make sure this window belongs to our process.
1385 if (EnumThreadWindows(::GetCurrentThreadId(),
1386 EnumThreadWndProc,
1387 reinterpret_cast<LPARAM>(window))) {
1388 // We enumerated all the windows and did not find the foreground window,
1389 // it is not our window, ignore it.
[email protected]71f65dd2009-02-11 19:14:561390 *handle = 0;
initial.commit09911bf2008-07-26 23:55:291391 return;
1392 }
1393
[email protected]71f65dd2009-02-11 19:14:561394 *handle = window_tracker_->Add(window);
initial.commit09911bf2008-07-26 23:55:291395}
1396
[email protected]71f65dd2009-02-11 19:14:561397void AutomationProvider::GetWindowHWND(int handle, HWND* win32_handle) {
1398 *win32_handle = window_tracker_->GetResource(handle);
initial.commit09911bf2008-07-26 23:55:291399}
[email protected]de246f52009-02-25 18:25:451400#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291401
[email protected]4f6381ee2009-04-16 02:46:331402void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command,
1403 bool* success) {
[email protected]71f65dd2009-02-11 19:14:561404 *success = false;
[email protected]4ae62752008-08-04 23:28:471405 if (browser_tracker_->ContainsHandle(handle)) {
1406 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]1fc025202009-01-20 23:03:141407 if (browser->command_updater()->SupportsCommand(command) &&
1408 browser->command_updater()->IsCommandEnabled(command)) {
[email protected]4ae62752008-08-04 23:28:471409 browser->ExecuteCommand(command);
[email protected]71f65dd2009-02-11 19:14:561410 *success = true;
[email protected]4ae62752008-08-04 23:28:471411 }
1412 }
[email protected]4ae62752008-08-04 23:28:471413}
1414
[email protected]4f6381ee2009-04-16 02:46:331415void AutomationProvider::ExecuteBrowserCommand(
[email protected]56e71b7c2009-03-27 03:05:561416 int handle, int command, IPC::Message* reply_message) {
1417 if (browser_tracker_->ContainsHandle(handle)) {
1418 Browser* browser = browser_tracker_->GetResource(handle);
1419 if (browser->command_updater()->SupportsCommand(command) &&
1420 browser->command_updater()->IsCommandEnabled(command)) {
[email protected]4e41709d2009-04-08 00:04:271421 ExecuteBrowserCommandObserver* observer =
1422 new ExecuteBrowserCommandObserver(this, reply_message);
1423 if (observer->Register(command))
1424 browser->ExecuteCommand(command);
1425 else
1426 delete observer;
[email protected]56e71b7c2009-03-27 03:05:561427 return;
1428 }
1429 }
[email protected]49a14a82009-03-31 04:16:441430 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false);
[email protected]56e71b7c2009-03-27 03:05:561431 Send(reply_message);
1432}
1433
[email protected]71f65dd2009-02-11 19:14:561434void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
1435 bool screen_coordinates,
1436 bool* success,
1437 gfx::Rect* bounds) {
1438 *success = false;
initial.commit09911bf2008-07-26 23:55:291439
[email protected]de246f52009-02-25 18:25:451440#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291441 void* iter = NULL;
1442 if (window_tracker_->ContainsHandle(handle)) {
1443 HWND hwnd = window_tracker_->GetResource(handle);
[email protected]a0dde122008-11-21 20:51:201444 views::RootView* root_view = views::WidgetWin::FindRootView(hwnd);
initial.commit09911bf2008-07-26 23:55:291445 if (root_view) {
[email protected]c2dacc92008-10-16 23:51:381446 views::View* view = root_view->GetViewByID(view_id);
initial.commit09911bf2008-07-26 23:55:291447 if (view) {
[email protected]71f65dd2009-02-11 19:14:561448 *success = true;
[email protected]96b667d2008-10-14 20:58:441449 gfx::Point point;
initial.commit09911bf2008-07-26 23:55:291450 if (screen_coordinates)
[email protected]c2dacc92008-10-16 23:51:381451 views::View::ConvertPointToScreen(view, &point);
initial.commit09911bf2008-07-26 23:55:291452 else
[email protected]c2dacc92008-10-16 23:51:381453 views::View::ConvertPointToView(view, root_view, &point);
[email protected]71f65dd2009-02-11 19:14:561454 *bounds = view->GetLocalBounds(false);
1455 bounds->set_origin(point);
initial.commit09911bf2008-07-26 23:55:291456 }
1457 }
1458 }
[email protected]de246f52009-02-25 18:25:451459#else
1460 // TODO(port): Enable when window_tracker is ported.
1461 NOTIMPLEMENTED();
1462#endif
initial.commit09911bf2008-07-26 23:55:291463}
1464
[email protected]de246f52009-02-25 18:25:451465#if defined(OS_WIN)
1466// TODO(port): Use portable replacement for POINT.
1467
initial.commit09911bf2008-07-26 23:55:291468// This task enqueues a mouse event on the event loop, so that the view
1469// that it's being sent to can do the requisite post-processing.
1470class MouseEventTask : public Task {
1471 public:
[email protected]c2dacc92008-10-16 23:51:381472 MouseEventTask(views::View* view,
1473 views::Event::EventType type,
initial.commit09911bf2008-07-26 23:55:291474 POINT point,
1475 int flags)
1476 : view_(view), type_(type), point_(point), flags_(flags) {}
1477 virtual ~MouseEventTask() {}
1478
1479 virtual void Run() {
[email protected]c2dacc92008-10-16 23:51:381480 views::MouseEvent event(type_, point_.x, point_.y, flags_);
initial.commit09911bf2008-07-26 23:55:291481 // We need to set the cursor position before we process the event because
1482 // some code (tab dragging, for instance) queries the actual cursor location
1483 // rather than the location of the mouse event. Note that the reason why
1484 // the drag code moved away from using mouse event locations was because
1485 // our conversion to screen location doesn't work well with multiple
1486 // monitors, so this only works reliably in a single monitor setup.
[email protected]96b667d2008-10-14 20:58:441487 gfx::Point screen_location(point_.x, point_.y);
initial.commit09911bf2008-07-26 23:55:291488 view_->ConvertPointToScreen(view_, &screen_location);
[email protected]96b667d2008-10-14 20:58:441489 ::SetCursorPos(screen_location.x(), screen_location.y());
initial.commit09911bf2008-07-26 23:55:291490 switch (type_) {
[email protected]c2dacc92008-10-16 23:51:381491 case views::Event::ET_MOUSE_PRESSED:
initial.commit09911bf2008-07-26 23:55:291492 view_->OnMousePressed(event);
1493 break;
1494
[email protected]c2dacc92008-10-16 23:51:381495 case views::Event::ET_MOUSE_DRAGGED:
initial.commit09911bf2008-07-26 23:55:291496 view_->OnMouseDragged(event);
1497 break;
1498
[email protected]c2dacc92008-10-16 23:51:381499 case views::Event::ET_MOUSE_RELEASED:
initial.commit09911bf2008-07-26 23:55:291500 view_->OnMouseReleased(event, false);
1501 break;
1502
1503 default:
1504 NOTREACHED();
1505 }
1506 }
1507
1508 private:
[email protected]c2dacc92008-10-16 23:51:381509 views::View* view_;
1510 views::Event::EventType type_;
initial.commit09911bf2008-07-26 23:55:291511 POINT point_;
1512 int flags_;
1513
[email protected]5a52f162008-08-27 04:15:311514 DISALLOW_COPY_AND_ASSIGN(MouseEventTask);
initial.commit09911bf2008-07-26 23:55:291515};
1516
[email protected]c2dacc92008-10-16 23:51:381517void AutomationProvider::ScheduleMouseEvent(views::View* view,
1518 views::Event::EventType type,
initial.commit09911bf2008-07-26 23:55:291519 POINT point,
1520 int flags) {
1521 MessageLoop::current()->PostTask(FROM_HERE,
1522 new MouseEventTask(view, type, point, flags));
1523}
[email protected]de246f52009-02-25 18:25:451524#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291525
1526// This task just adds another task to the event queue. This is useful if
1527// you want to ensure that any tasks added to the event queue after this one
1528// have already been processed by the time |task| is run.
1529class InvokeTaskLaterTask : public Task {
1530 public:
1531 explicit InvokeTaskLaterTask(Task* task) : task_(task) {}
1532 virtual ~InvokeTaskLaterTask() {}
1533
1534 virtual void Run() {
1535 MessageLoop::current()->PostTask(FROM_HERE, task_);
1536 }
1537
1538 private:
1539 Task* task_;
1540
[email protected]5a52f162008-08-27 04:15:311541 DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask);
initial.commit09911bf2008-07-26 23:55:291542};
1543
[email protected]de246f52009-02-25 18:25:451544#if defined(OS_WIN)
1545// TODO(port): Replace POINT and other windowsisms.
1546
initial.commit09911bf2008-07-26 23:55:291547// This task sends a WindowDragResponse message with the appropriate
1548// routing ID to the automation proxy. This is implemented as a task so that
1549// we know that the mouse events (and any tasks that they spawn on the message
1550// loop) have been processed by the time this is sent.
1551class WindowDragResponseTask : public Task {
1552 public:
[email protected]71f65dd2009-02-11 19:14:561553 WindowDragResponseTask(AutomationProvider* provider, int routing_id,
1554 IPC::Message* reply_message)
1555 : provider_(provider), routing_id_(routing_id),
1556 reply_message_(reply_message) {}
initial.commit09911bf2008-07-26 23:55:291557 virtual ~WindowDragResponseTask() {}
1558
1559 virtual void Run() {
[email protected]71f65dd2009-02-11 19:14:561560 DCHECK(reply_message_ != NULL);
1561 AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true);
1562 provider_->Send(reply_message_);
initial.commit09911bf2008-07-26 23:55:291563 }
1564
1565 private:
1566 AutomationProvider* provider_;
1567 int routing_id_;
[email protected]71f65dd2009-02-11 19:14:561568 IPC::Message* reply_message_;
initial.commit09911bf2008-07-26 23:55:291569
[email protected]5a52f162008-08-27 04:15:311570 DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
initial.commit09911bf2008-07-26 23:55:291571};
1572
1573void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
1574 int handle,
1575 POINT click,
1576 int flags) {
1577 HWND hwnd = 0;
1578
1579 if (window_tracker_->ContainsHandle(handle)) {
1580 hwnd = window_tracker_->GetResource(handle);
1581
initial.commit09911bf2008-07-26 23:55:291582 ui_controls::SendMouseMove(click.x, click.y);
1583
1584 ui_controls::MouseButton button = ui_controls::LEFT;
[email protected]c2dacc92008-10-16 23:51:381585 if ((flags & views::Event::EF_LEFT_BUTTON_DOWN) ==
1586 views::Event::EF_LEFT_BUTTON_DOWN) {
initial.commit09911bf2008-07-26 23:55:291587 button = ui_controls::LEFT;
[email protected]c2dacc92008-10-16 23:51:381588 } else if ((flags & views::Event::EF_RIGHT_BUTTON_DOWN) ==
1589 views::Event::EF_RIGHT_BUTTON_DOWN) {
initial.commit09911bf2008-07-26 23:55:291590 button = ui_controls::RIGHT;
[email protected]c2dacc92008-10-16 23:51:381591 } else if ((flags & views::Event::EF_MIDDLE_BUTTON_DOWN) ==
1592 views::Event::EF_MIDDLE_BUTTON_DOWN) {
initial.commit09911bf2008-07-26 23:55:291593 button = ui_controls::MIDDLE;
1594 } else {
1595 NOTREACHED();
1596 }
1597 ui_controls::SendMouseClick(button);
1598 }
1599}
1600
[email protected]71f65dd2009-02-11 19:14:561601void AutomationProvider::WindowSimulateDrag(int handle,
[email protected]fe92e4e2008-11-18 21:31:321602 std::vector<POINT> drag_path,
[email protected]5e0f30c2008-08-14 22:52:441603 int flags,
[email protected]71f65dd2009-02-11 19:14:561604 bool press_escape_en_route,
1605 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291606 bool succeeded = false;
[email protected]fe92e4e2008-11-18 21:31:321607 if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) {
1608 succeeded = true;
1609
1610 UINT down_message = 0;
1611 UINT up_message = 0;
1612 WPARAM wparam_flags = 0;
1613 if (flags & views::Event::EF_SHIFT_DOWN)
1614 wparam_flags |= MK_SHIFT;
1615 if (flags & views::Event::EF_CONTROL_DOWN)
1616 wparam_flags |= MK_CONTROL;
1617 if (flags & views::Event::EF_LEFT_BUTTON_DOWN) {
1618 wparam_flags |= MK_LBUTTON;
1619 down_message = WM_LBUTTONDOWN;
1620 up_message = WM_LBUTTONUP;
1621 }
1622 if (flags & views::Event::EF_MIDDLE_BUTTON_DOWN) {
1623 wparam_flags |= MK_MBUTTON;
1624 down_message = WM_MBUTTONDOWN;
1625 up_message = WM_MBUTTONUP;
1626 }
1627 if (flags & views::Event::EF_RIGHT_BUTTON_DOWN) {
1628 wparam_flags |= MK_RBUTTON;
1629 down_message = WM_LBUTTONDOWN;
1630 up_message = WM_LBUTTONUP;
1631 }
1632
initial.commit09911bf2008-07-26 23:55:291633 Browser* browser = browser_tracker_->GetResource(handle);
1634 DCHECK(browser);
[email protected]0a6fb3f2008-11-18 21:39:551635 HWND top_level_hwnd =
1636 reinterpret_cast<HWND>(browser->window()->GetNativeHandle());
[email protected]fe92e4e2008-11-18 21:31:321637 POINT temp = drag_path[0];
1638 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1);
1639 SetCursorPos(temp.x, temp.y);
1640 SendMessage(top_level_hwnd, down_message, wparam_flags,
1641 MAKELPARAM(drag_path[0].x, drag_path[0].y));
1642 for (int i = 1; i < static_cast<int>(drag_path.size()); ++i) {
1643 temp = drag_path[i];
1644 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1);
1645 SetCursorPos(temp.x, temp.y);
1646 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags,
1647 MAKELPARAM(drag_path[i].x, drag_path[i].y));
[email protected]f7a391a12008-11-10 21:29:341648 }
[email protected]fe92e4e2008-11-18 21:31:321649 POINT end = drag_path[drag_path.size() - 1];
1650 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1);
1651 SetCursorPos(end.x, end.y);
1652
1653 if (press_escape_en_route) {
1654 // Press Escape.
1655 ui_controls::SendKeyPress(VK_ESCAPE,
1656 ((flags & views::Event::EF_CONTROL_DOWN)
1657 == views::Event::EF_CONTROL_DOWN),
1658 ((flags & views::Event::EF_SHIFT_DOWN) ==
1659 views::Event::EF_SHIFT_DOWN),
1660 ((flags & views::Event::EF_ALT_DOWN) ==
1661 views::Event::EF_ALT_DOWN));
1662 }
1663 SendMessage(top_level_hwnd, up_message, wparam_flags,
1664 MAKELPARAM(end.x, end.y));
1665
initial.commit09911bf2008-07-26 23:55:291666 MessageLoop::current()->PostTask(FROM_HERE,
1667 new InvokeTaskLaterTask(
[email protected]71f65dd2009-02-11 19:14:561668 new WindowDragResponseTask(this, reply_message->routing_id(),
1669 reply_message)));
initial.commit09911bf2008-07-26 23:55:291670 } else {
[email protected]71f65dd2009-02-11 19:14:561671 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true);
1672 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291673 }
1674}
1675
1676void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message,
1677 int handle,
1678 wchar_t key,
1679 int flags) {
1680 if (!window_tracker_->ContainsHandle(handle))
1681 return;
1682
1683 // The key event is sent to whatever window is active.
1684 ui_controls::SendKeyPress(key,
[email protected]c2dacc92008-10-16 23:51:381685 ((flags & views::Event::EF_CONTROL_DOWN) ==
1686 views::Event::EF_CONTROL_DOWN),
1687 ((flags & views::Event::EF_SHIFT_DOWN) ==
1688 views::Event::EF_SHIFT_DOWN),
1689 ((flags & views::Event::EF_ALT_DOWN) ==
1690 views::Event::EF_ALT_DOWN));
initial.commit09911bf2008-07-26 23:55:291691}
1692
[email protected]71f65dd2009-02-11 19:14:561693void AutomationProvider::GetFocusedViewID(int handle, int* view_id) {
1694 *view_id = -1;
initial.commit09911bf2008-07-26 23:55:291695 if (window_tracker_->ContainsHandle(handle)) {
1696 HWND hwnd = window_tracker_->GetResource(handle);
[email protected]c2dacc92008-10-16 23:51:381697 views::FocusManager* focus_manager =
1698 views::FocusManager::GetFocusManager(hwnd);
initial.commit09911bf2008-07-26 23:55:291699 DCHECK(focus_manager);
[email protected]c2dacc92008-10-16 23:51:381700 views::View* focused_view = focus_manager->GetFocusedView();
initial.commit09911bf2008-07-26 23:55:291701 if (focused_view)
[email protected]71f65dd2009-02-11 19:14:561702 *view_id = focused_view->GetID();
initial.commit09911bf2008-07-26 23:55:291703 }
initial.commit09911bf2008-07-26 23:55:291704}
1705
[email protected]71f65dd2009-02-11 19:14:561706void AutomationProvider::SetWindowVisible(int handle, bool visible,
1707 bool* result) {
initial.commit09911bf2008-07-26 23:55:291708 if (window_tracker_->ContainsHandle(handle)) {
1709 HWND hwnd = window_tracker_->GetResource(handle);
1710 ::ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE);
[email protected]71f65dd2009-02-11 19:14:561711 *result = true;
initial.commit09911bf2008-07-26 23:55:291712 } else {
[email protected]71f65dd2009-02-11 19:14:561713 *result = false;
initial.commit09911bf2008-07-26 23:55:291714 }
1715}
[email protected]d2cc6ed2009-04-24 00:26:171716#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291717
[email protected]71f65dd2009-02-11 19:14:561718void AutomationProvider::IsWindowActive(int handle, bool* success,
1719 bool* is_active) {
initial.commit09911bf2008-07-26 23:55:291720 if (window_tracker_->ContainsHandle(handle)) {
[email protected]d2cc6ed2009-04-24 00:26:171721 *is_active =
1722 platform_util::IsWindowActive(window_tracker_->GetResource(handle));
[email protected]71f65dd2009-02-11 19:14:561723 *success = true;
initial.commit09911bf2008-07-26 23:55:291724 } else {
[email protected]71f65dd2009-02-11 19:14:561725 *success = false;
1726 *is_active = false;
initial.commit09911bf2008-07-26 23:55:291727 }
1728}
1729
[email protected]d2cc6ed2009-04-24 00:26:171730// TODO(port): port this.
1731#if defined(OS_WIN)
[email protected]659d0e82009-02-13 22:43:281732void AutomationProvider::ActivateWindow(int handle) {
initial.commit09911bf2008-07-26 23:55:291733 if (window_tracker_->ContainsHandle(handle)) {
1734 ::SetActiveWindow(window_tracker_->GetResource(handle));
1735 }
1736}
[email protected]d2cc6ed2009-04-24 00:26:171737#endif
initial.commit09911bf2008-07-26 23:55:291738
[email protected]71f65dd2009-02-11 19:14:561739void AutomationProvider::GetTabCount(int handle, int* tab_count) {
1740 *tab_count = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291741
1742 if (browser_tracker_->ContainsHandle(handle)) {
1743 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:561744 *tab_count = browser->tab_count();
initial.commit09911bf2008-07-26 23:55:291745 }
initial.commit09911bf2008-07-26 23:55:291746}
1747
[email protected]71f65dd2009-02-11 19:14:561748void AutomationProvider::GetTab(int win_handle, int tab_index,
1749 int* tab_handle) {
[email protected]71f65dd2009-02-11 19:14:561750 *tab_handle = 0;
initial.commit09911bf2008-07-26 23:55:291751 if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) {
1752 Browser* browser = browser_tracker_->GetResource(win_handle);
1753 if (tab_index < browser->tab_count()) {
1754 TabContents* tab_contents =
1755 browser->GetTabContentsAt(tab_index);
[email protected]ce3fa3c2009-04-20 19:55:571756 *tab_handle = tab_tracker_->Add(&tab_contents->controller());
initial.commit09911bf2008-07-26 23:55:291757 }
1758 }
initial.commit09911bf2008-07-26 23:55:291759}
1760
[email protected]71f65dd2009-02-11 19:14:561761void AutomationProvider::GetTabTitle(int handle, int* title_string_size,
1762 std::wstring* title) {
1763 *title_string_size = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291764 if (tab_tracker_->ContainsHandle(handle)) {
1765 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]c100dbd2009-04-29 23:44:361766 NavigationEntry* entry = tab->GetActiveEntry();
1767 if (entry != NULL) {
1768 *title = UTF16ToWideHack(entry->title());
1769 } else {
1770 *title = std::wstring();
1771 }
[email protected]71f65dd2009-02-11 19:14:561772 *title_string_size = static_cast<int>(title->size());
initial.commit09911bf2008-07-26 23:55:291773 }
initial.commit09911bf2008-07-26 23:55:291774}
1775
[email protected]77bc6732009-04-20 22:01:031776void AutomationProvider::GetTabIndex(int handle, int* tabstrip_index) {
1777 *tabstrip_index = -1; // -1 is the error code
1778
1779 if (tab_tracker_->ContainsHandle(handle)) {
1780 NavigationController* tab = tab_tracker_->GetResource(handle);
1781 Browser* browser = Browser::GetBrowserForController(tab, NULL);
1782 *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab);
1783 }
1784}
1785
initial.commit09911bf2008-07-26 23:55:291786void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) {
1787 if (window_tracker_->ContainsHandle(handle)) {
1788 window_tracker_->Remove(window_tracker_->GetResource(handle));
1789 }
1790}
1791
1792void AutomationProvider::OnChannelError() {
1793 LOG(ERROR) << "AutomationProxy went away, shutting down app.";
[email protected]295039bd2008-08-15 04:32:571794 AutomationProviderList::GetInstance()->RemoveProvider(this);
initial.commit09911bf2008-07-26 23:55:291795}
1796
1797// TODO(brettw) change this to accept GURLs when history supports it
1798void AutomationProvider::OnRedirectQueryComplete(
1799 HistoryService::Handle request_handle,
1800 GURL from_url,
1801 bool success,
1802 HistoryService::RedirectList* redirects) {
1803 DCHECK(request_handle == redirect_query_);
[email protected]71f65dd2009-02-11 19:14:561804 DCHECK(reply_message_ != NULL);
initial.commit09911bf2008-07-26 23:55:291805
[email protected]deb57402009-02-06 01:35:301806 std::vector<GURL> redirects_gurl;
initial.commit09911bf2008-07-26 23:55:291807 if (success) {
[email protected]71f65dd2009-02-11 19:14:561808 reply_message_->WriteBool(true);
initial.commit09911bf2008-07-26 23:55:291809 for (size_t i = 0; i < redirects->size(); i++)
[email protected]deb57402009-02-06 01:35:301810 redirects_gurl.push_back(redirects->at(i));
initial.commit09911bf2008-07-26 23:55:291811 } else {
[email protected]71f65dd2009-02-11 19:14:561812 reply_message_->WriteInt(-1); // Negative count indicates failure.
initial.commit09911bf2008-07-26 23:55:291813 }
1814
[email protected]4f3dc372009-02-24 00:10:291815 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl);
[email protected]deb57402009-02-06 01:35:301816
[email protected]71f65dd2009-02-11 19:14:561817 Send(reply_message_);
initial.commit09911bf2008-07-26 23:55:291818 redirect_query_ = NULL;
[email protected]71f65dd2009-02-11 19:14:561819 reply_message_ = NULL;
initial.commit09911bf2008-07-26 23:55:291820}
1821
1822bool AutomationProvider::Send(IPC::Message* msg) {
[email protected]295039bd2008-08-15 04:32:571823 DCHECK(channel_.get());
1824 return channel_->Send(msg);
initial.commit09911bf2008-07-26 23:55:291825}
1826
1827Browser* AutomationProvider::FindAndActivateTab(
1828 NavigationController* controller) {
1829 int tab_index;
1830 Browser* browser = Browser::GetBrowserForController(controller, &tab_index);
1831 if (browser)
1832 browser->SelectTabContentsAt(tab_index, true);
1833
1834 return browser;
1835}
1836
[email protected]71f65dd2009-02-11 19:14:561837void AutomationProvider::GetCookies(const GURL& url, int handle,
1838 int* value_size,
1839 std::string* value) {
1840 *value_size = -1;
initial.commit09911bf2008-07-26 23:55:291841 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1842 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:561843 *value =
initial.commit09911bf2008-07-26 23:55:291844 tab->profile()->GetRequestContext()->cookie_store()->GetCookies(url);
[email protected]71f65dd2009-02-11 19:14:561845 *value_size = static_cast<int>(value->size());
initial.commit09911bf2008-07-26 23:55:291846 }
initial.commit09911bf2008-07-26 23:55:291847}
1848
[email protected]71f65dd2009-02-11 19:14:561849void AutomationProvider::SetCookie(const GURL& url,
initial.commit09911bf2008-07-26 23:55:291850 const std::string value,
[email protected]71f65dd2009-02-11 19:14:561851 int handle,
1852 int* response_value) {
1853 *response_value = -1;
initial.commit09911bf2008-07-26 23:55:291854
1855 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1856 NavigationController* tab = tab_tracker_->GetResource(handle);
1857 URLRequestContext* context = tab->profile()->GetRequestContext();
1858 if (context->cookie_store()->SetCookie(url, value))
[email protected]71f65dd2009-02-11 19:14:561859 *response_value = 1;
initial.commit09911bf2008-07-26 23:55:291860 }
initial.commit09911bf2008-07-26 23:55:291861}
1862
[email protected]71f65dd2009-02-11 19:14:561863void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) {
1864 *success = false;
initial.commit09911bf2008-07-26 23:55:291865 if (tab_tracker_->ContainsHandle(handle)) {
1866 NavigationController* tab = tab_tracker_->GetResource(handle);
1867 // Return what the user would see in the location bar.
[email protected]71f65dd2009-02-11 19:14:561868 *url = tab->GetActiveEntry()->display_url();
1869 *success = true;
initial.commit09911bf2008-07-26 23:55:291870 }
initial.commit09911bf2008-07-26 23:55:291871}
1872
[email protected]de246f52009-02-25 18:25:451873#if defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:561874void AutomationProvider::GetTabHWND(int handle, HWND* tab_hwnd) {
1875 *tab_hwnd = NULL;
initial.commit09911bf2008-07-26 23:55:291876
1877 if (tab_tracker_->ContainsHandle(handle)) {
1878 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:111879 *tab_hwnd = tab->tab_contents()->GetNativeView();
initial.commit09911bf2008-07-26 23:55:291880 }
initial.commit09911bf2008-07-26 23:55:291881}
[email protected]de246f52009-02-25 18:25:451882#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291883
[email protected]71f65dd2009-02-11 19:14:561884void AutomationProvider::GetTabProcessID(int handle, int* process_id) {
1885 *process_id = -1;
initial.commit09911bf2008-07-26 23:55:291886
1887 if (tab_tracker_->ContainsHandle(handle)) {
[email protected]71f65dd2009-02-11 19:14:561888 *process_id = 0;
[email protected]57c6a652009-05-04 07:58:341889 TabContents* tab_contents =
1890 tab_tracker_->GetResource(handle)->tab_contents();
1891 if (tab_contents->process())
1892 *process_id = tab_contents->process()->process().pid();
initial.commit09911bf2008-07-26 23:55:291893 }
initial.commit09911bf2008-07-26 23:55:291894}
1895
1896void AutomationProvider::ApplyAccelerator(int handle, int id) {
[email protected]4f6381ee2009-04-16 02:46:331897 NOTREACHED() << "This function has been deprecated. "
1898 << "Please use ExecuteBrowserCommandAsync instead.";
initial.commit09911bf2008-07-26 23:55:291899}
1900
[email protected]71f65dd2009-02-11 19:14:561901void AutomationProvider::ExecuteJavascript(int handle,
initial.commit09911bf2008-07-26 23:55:291902 const std::wstring& frame_xpath,
[email protected]71f65dd2009-02-11 19:14:561903 const std::wstring& script,
1904 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291905 bool succeeded = false;
[email protected]57c6a652009-05-04 07:58:341906 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
1907 if (tab_contents) {
[email protected]20e93d12008-08-28 16:31:571908 // Set the routing id of this message with the controller.
1909 // This routing id needs to be remembered for the reverse
1910 // communication while sending back the response of
1911 // this javascript execution.
[email protected]f29acf52008-11-03 20:08:331912 std::wstring set_automation_id;
1913 SStringPrintf(&set_automation_id,
1914 L"window.domAutomationController.setAutomationId(%d);",
[email protected]71f65dd2009-02-11 19:14:561915 reply_message->routing_id());
1916
1917 DCHECK(reply_message_ == NULL);
1918 reply_message_ = reply_message;
initial.commit09911bf2008-07-26 23:55:291919
[email protected]57c6a652009-05-04 07:58:341920 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
[email protected]f29acf52008-11-03 20:08:331921 frame_xpath, set_automation_id);
[email protected]57c6a652009-05-04 07:58:341922 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
[email protected]1f5af4442008-09-25 22:11:061923 frame_xpath, script);
[email protected]20e93d12008-08-28 16:31:571924 succeeded = true;
initial.commit09911bf2008-07-26 23:55:291925 }
1926
1927 if (!succeeded) {
[email protected]71f65dd2009-02-11 19:14:561928 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string());
1929 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291930 }
1931}
1932
[email protected]71f65dd2009-02-11 19:14:561933void AutomationProvider::GetShelfVisibility(int handle, bool* visible) {
1934 *visible = false;
[email protected]20e93d12008-08-28 16:31:571935
[email protected]57c6a652009-05-04 07:58:341936 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
1937 if (tab_contents)
1938 *visible = tab_contents->IsDownloadShelfVisible();
initial.commit09911bf2008-07-26 23:55:291939}
1940
[email protected]71f65dd2009-02-11 19:14:561941void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) {
1942 *count = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291943 if (tab_tracker_->ContainsHandle(handle)) {
1944 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:111945 TabContents* tab_contents = nav_controller->tab_contents();
initial.commit09911bf2008-07-26 23:55:291946 if (tab_contents) {
[email protected]71f65dd2009-02-11 19:14:561947 *count = static_cast<int>(tab_contents->child_windows_.size());
initial.commit09911bf2008-07-26 23:55:291948 }
1949 }
initial.commit09911bf2008-07-26 23:55:291950}
1951
[email protected]71f65dd2009-02-11 19:14:561952void AutomationProvider::GetConstrainedWindow(int handle, int index,
1953 int* cwindow_handle) {
1954 *cwindow_handle = 0;
initial.commit09911bf2008-07-26 23:55:291955 if (tab_tracker_->ContainsHandle(handle) && index >= 0) {
1956 NavigationController* nav_controller =
1957 tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:111958 TabContents* tab = nav_controller->tab_contents();
[email protected]d5f942ba2008-09-26 19:30:341959 if (tab && index < static_cast<int>(tab->child_windows_.size())) {
[email protected]de246f52009-02-25 18:25:451960#if defined(OS_WIN)
[email protected]d5f942ba2008-09-26 19:30:341961 ConstrainedWindow* window = tab->child_windows_[index];
[email protected]71f65dd2009-02-11 19:14:561962 *cwindow_handle = cwindow_tracker_->Add(window);
[email protected]de246f52009-02-25 18:25:451963#else
1964 // TODO(port): Enable when cwindow_tracker is ported.
1965 NOTIMPLEMENTED();
1966#endif
initial.commit09911bf2008-07-26 23:55:291967 }
1968 }
initial.commit09911bf2008-07-26 23:55:291969}
1970
[email protected]71f65dd2009-02-11 19:14:561971void AutomationProvider::GetConstrainedTitle(int handle,
1972 int* title_string_size,
1973 std::wstring* title) {
1974 *title_string_size = -1; // -1 is the error code
[email protected]de246f52009-02-25 18:25:451975#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291976 if (cwindow_tracker_->ContainsHandle(handle)) {
1977 ConstrainedWindow* window = cwindow_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:561978 *title = window->GetWindowTitle();
1979 *title_string_size = static_cast<int>(title->size());
initial.commit09911bf2008-07-26 23:55:291980 }
[email protected]de246f52009-02-25 18:25:451981#else
1982 // TODO(port): Enable when cwindow_tracker is ported.
1983 NOTIMPLEMENTED();
1984#endif
initial.commit09911bf2008-07-26 23:55:291985}
1986
[email protected]71f65dd2009-02-11 19:14:561987void AutomationProvider::GetConstrainedWindowBounds(int handle, bool* exists,
1988 gfx::Rect* rect) {
1989 *rect = gfx::Rect(0, 0, 0, 0);
[email protected]de246f52009-02-25 18:25:451990#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291991 if (cwindow_tracker_->ContainsHandle(handle)) {
1992 ConstrainedWindow* window = cwindow_tracker_->GetResource(handle);
1993 if (window) {
[email protected]71f65dd2009-02-11 19:14:561994 *exists = true;
1995 *rect = window->GetCurrentBounds();
initial.commit09911bf2008-07-26 23:55:291996 }
1997 }
[email protected]de246f52009-02-25 18:25:451998#else
1999 // TODO(port): Enable when cwindow_tracker is ported.
2000 NOTIMPLEMENTED();
2001#endif
initial.commit09911bf2008-07-26 23:55:292002}
2003
2004void AutomationProvider::HandleFindInPageRequest(
[email protected]71f65dd2009-02-11 19:14:562005 int handle, const std::wstring& find_request,
2006 int forward, int match_case, int* active_ordinal, int* matches_found) {
[email protected]5a52f162008-08-27 04:15:312007 NOTREACHED() << "This function has been deprecated."
2008 << "Please use HandleFindRequest instead.";
[email protected]71f65dd2009-02-11 19:14:562009 *matches_found = -1;
[email protected]5a52f162008-08-27 04:15:312010 return;
2011}
2012
[email protected]4f999132009-03-31 18:08:402013void AutomationProvider::HandleFindRequest(
2014 int handle,
2015 const AutomationMsg_Find_Params& params,
2016 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:292017 if (!tab_tracker_->ContainsHandle(handle)) {
[email protected]71f65dd2009-02-11 19:14:562018 AutomationMsg_FindInPage::WriteReplyParams(reply_message, -1, -1);
2019 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292020 return;
2021 }
2022
2023 NavigationController* nav = tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:112024 TabContents* tab_contents = nav->tab_contents();
initial.commit09911bf2008-07-26 23:55:292025
2026 find_in_page_observer_.reset(new
[email protected]71f65dd2009-02-11 19:14:562027 FindInPageNotificationObserver(this, tab_contents,
2028 reply_message->routing_id(),
2029 reply_message));
initial.commit09911bf2008-07-26 23:55:292030
[email protected]57c6a652009-05-04 07:58:342031 tab_contents->set_current_find_request_id(
2032 FindInPageNotificationObserver::kFindInPageRequestId);
2033 tab_contents->render_view_host()->StartFinding(
2034 FindInPageNotificationObserver::kFindInPageRequestId,
2035 params.search_string, params.forward, params.match_case,
2036 params.find_next);
initial.commit09911bf2008-07-26 23:55:292037}
2038
[email protected]5f8af2a2008-08-06 22:49:452039void AutomationProvider::HandleOpenFindInPageRequest(
2040 const IPC::Message& message, int handle) {
[email protected]4f3dc372009-02-24 00:10:292041 if (browser_tracker_->ContainsHandle(handle)) {
[email protected]de246f52009-02-25 18:25:452042#if defined(OS_WIN)
[email protected]4f3dc372009-02-24 00:10:292043 Browser* browser = browser_tracker_->GetResource(handle);
2044 browser->FindInPage(false, false);
[email protected]de246f52009-02-25 18:25:452045#else
2046 // TODO(port): Enable when Browser::FindInPage is ported.
2047 NOTIMPLEMENTED();
2048#endif
[email protected]5f8af2a2008-08-06 22:49:452049 }
2050}
2051
[email protected]71f65dd2009-02-11 19:14:562052void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) {
[email protected]9e0534b2008-10-21 15:03:012053 gfx::Point position;
[email protected]71f65dd2009-02-11 19:14:562054 *visible = false;
[email protected]4f3dc372009-02-24 00:10:292055 if (browser_tracker_->ContainsHandle(handle)) {
2056 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]4801ecc2009-04-05 04:52:582057 FindBarTesting* find_bar =
2058 browser->find_bar()->find_bar()->GetFindBarTesting();
2059 find_bar->GetFindBarWindowInfo(&position, visible);
[email protected]4f3dc372009-02-24 00:10:292060 }
[email protected]20e93d12008-08-28 16:31:572061}
2062
[email protected]71f65dd2009-02-11 19:14:562063void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x,
2064 int* y) {
[email protected]9e0534b2008-10-21 15:03:012065 gfx::Point position(0, 0);
2066 bool visible = false;
[email protected]4f3dc372009-02-24 00:10:292067 if (browser_tracker_->ContainsHandle(handle)) {
2068 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]4801ecc2009-04-05 04:52:582069 FindBarTesting* find_bar =
2070 browser->find_bar()->find_bar()->GetFindBarTesting();
2071 find_bar->GetFindBarWindowInfo(&position, &visible);
[email protected]4f3dc372009-02-24 00:10:292072 }
[email protected]20e93d12008-08-28 16:31:572073
[email protected]71f65dd2009-02-11 19:14:562074 *x = position.x();
2075 *y = position.y();
[email protected]20e93d12008-08-28 16:31:572076}
2077
[email protected]71f65dd2009-02-11 19:14:562078void AutomationProvider::GetBookmarkBarVisibility(int handle, bool* visible,
2079 bool* animating) {
2080 *visible = false;
2081 *animating = false;
[email protected]c2cbeb92008-09-05 21:36:572082
[email protected]de246f52009-02-25 18:25:452083#if defined(OS_WIN)
[email protected]c2cbeb92008-09-05 21:36:572084 if (browser_tracker_->ContainsHandle(handle)) {
2085 Browser* browser = browser_tracker_->GetResource(handle);
2086 if (browser) {
[email protected]0ba1f5302009-01-22 01:34:522087 BrowserWindowTesting* testing =
2088 browser->window()->GetBrowserWindowTesting();
2089 BookmarkBarView* bookmark_bar = testing->GetBookmarkBarView();
[email protected]c2cbeb92008-09-05 21:36:572090 if (bookmark_bar) {
[email protected]71f65dd2009-02-11 19:14:562091 *animating = bookmark_bar->IsAnimating();
2092 *visible = browser->window()->IsBookmarkBarVisible();
[email protected]c2cbeb92008-09-05 21:36:572093 }
2094 }
2095 }
[email protected]de246f52009-02-25 18:25:452096#else
2097 // TODO(port): Enable when bookmarks ui is ported.
2098 NOTIMPLEMENTED();
2099#endif
[email protected]c2cbeb92008-09-05 21:36:572100}
2101
initial.commit09911bf2008-07-26 23:55:292102void AutomationProvider::HandleInspectElementRequest(
[email protected]71f65dd2009-02-11 19:14:562103 int handle, int x, int y, IPC::Message* reply_message) {
[email protected]57c6a652009-05-04 07:58:342104 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
2105 if (tab_contents) {
[email protected]71f65dd2009-02-11 19:14:562106 DCHECK(reply_message_ == NULL);
2107 reply_message_ = reply_message;
2108
[email protected]57c6a652009-05-04 07:58:342109 tab_contents->render_view_host()->InspectElementAt(x, y);
[email protected]71f65dd2009-02-11 19:14:562110 inspect_element_routing_id_ = reply_message->routing_id();
initial.commit09911bf2008-07-26 23:55:292111 } else {
[email protected]71f65dd2009-02-11 19:14:562112 AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1);
2113 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292114 }
2115}
2116
2117void AutomationProvider::ReceivedInspectElementResponse(int num_resources) {
[email protected]396c3b32009-03-12 22:26:092118 if (reply_message_) {
2119 AutomationMsg_InspectElement::WriteReplyParams(reply_message_,
2120 num_resources);
2121 Send(reply_message_);
2122 reply_message_ = NULL;
2123 }
initial.commit09911bf2008-07-26 23:55:292124}
2125
2126// Helper class for making changes to the URLRequest ProtocolFactory on the
2127// IO thread.
2128class SetFilteredInetTask : public Task {
2129 public:
2130 explicit SetFilteredInetTask(bool enabled) : enabled_(enabled) { }
2131 virtual void Run() {
2132 if (enabled_) {
2133 URLRequestFilter::GetInstance()->ClearHandlers();
2134
2135 URLRequestFailedDnsJob::AddUITestUrls();
2136 URLRequestSlowDownloadJob::AddUITestUrls();
2137
2138 std::wstring root_http;
2139 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
2140 URLRequestMockHTTPJob::AddUITestUrls(root_http);
2141 } else {
2142 // Revert to the default handlers.
2143 URLRequestFilter::GetInstance()->ClearHandlers();
2144 }
2145 }
2146 private:
2147 bool enabled_;
2148};
2149
2150void AutomationProvider::SetFilteredInet(const IPC::Message& message,
2151 bool enabled) {
2152 // Since this involves changing the URLRequest ProtocolFactory, we want to
2153 // run on the main thread.
2154 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
2155 new SetFilteredInetTask(enabled));
2156}
2157
[email protected]4f3dc372009-02-24 00:10:292158void AutomationProvider::GetDownloadDirectory(
2159 int handle, std::wstring* download_directory) {
initial.commit09911bf2008-07-26 23:55:292160 DLOG(INFO) << "Handling download directory request";
initial.commit09911bf2008-07-26 23:55:292161 if (tab_tracker_->ContainsHandle(handle)) {
2162 NavigationController* tab = tab_tracker_->GetResource(handle);
2163 DownloadManager* dlm = tab->profile()->GetDownloadManager();
2164 DCHECK(dlm);
[email protected]71f65dd2009-02-11 19:14:562165 *download_directory = dlm->download_path().ToWStringHack();
initial.commit09911bf2008-07-26 23:55:292166 }
initial.commit09911bf2008-07-26 23:55:292167}
2168
[email protected]14c0a032009-04-13 18:15:142169void AutomationProvider::OpenNewBrowserWindow(bool show,
2170 IPC::Message* reply_message) {
2171 new BrowserOpenedNotificationObserver(this, reply_message);
initial.commit09911bf2008-07-26 23:55:292172 // We may have no current browser windows open so don't rely on
2173 // asking an existing browser to execute the IDC_NEWWINDOW command
[email protected]15952e462008-11-14 00:29:052174 Browser* browser = Browser::Create(profile_);
2175 browser->AddBlankTab(true);
[email protected]3683cbb2009-04-09 21:46:152176 if (show)
[email protected]15952e462008-11-14 00:29:052177 browser->window()->Show();
initial.commit09911bf2008-07-26 23:55:292178}
2179
[email protected]71f65dd2009-02-11 19:14:562180void AutomationProvider::GetWindowForBrowser(int browser_handle,
2181 bool* success,
2182 int* handle) {
2183 *success = false;
2184 *handle = 0;
initial.commit09911bf2008-07-26 23:55:292185
2186 if (browser_tracker_->ContainsHandle(browser_handle)) {
2187 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]0e9f4ee2009-04-08 01:44:202188 gfx::NativeWindow win = browser->window()->GetNativeHandle();
initial.commit09911bf2008-07-26 23:55:292189 // Add() returns the existing handle for the resource if any.
[email protected]0e9f4ee2009-04-08 01:44:202190 *handle = window_tracker_->Add(win);
[email protected]71f65dd2009-02-11 19:14:562191 *success = true;
initial.commit09911bf2008-07-26 23:55:292192 }
initial.commit09911bf2008-07-26 23:55:292193}
2194
[email protected]0e9f4ee2009-04-08 01:44:202195#if defined(OS_WIN)
2196// TODO(port): Remove windowsisms.
initial.commit09911bf2008-07-26 23:55:292197void AutomationProvider::GetAutocompleteEditForBrowser(
[email protected]71f65dd2009-02-11 19:14:562198 int browser_handle,
2199 bool* success,
2200 int* autocomplete_edit_handle) {
2201 *success = false;
2202 *autocomplete_edit_handle = 0;
initial.commit09911bf2008-07-26 23:55:292203
2204 if (browser_tracker_->ContainsHandle(browser_handle)) {
2205 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]7745b822009-01-27 20:15:352206 BrowserWindowTesting* testing_interface =
2207 browser->window()->GetBrowserWindowTesting();
2208 LocationBarView* loc_bar_view = testing_interface->GetLocationBarView();
[email protected]81c21222008-09-10 19:35:522209 AutocompleteEditView* edit_view = loc_bar_view->location_entry();
initial.commit09911bf2008-07-26 23:55:292210 // Add() returns the existing handle for the resource if any.
[email protected]71f65dd2009-02-11 19:14:562211 *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view);
2212 *success = true;
initial.commit09911bf2008-07-26 23:55:292213 }
initial.commit09911bf2008-07-26 23:55:292214}
2215
[email protected]71f65dd2009-02-11 19:14:562216void AutomationProvider::GetBrowserForWindow(int window_handle,
2217 bool* success,
2218 int* browser_handle) {
2219 *success = false;
2220 *browser_handle = 0;
initial.commit09911bf2008-07-26 23:55:292221
2222 if (window_tracker_->ContainsHandle(window_handle)) {
2223 HWND window = window_tracker_->GetResource(window_handle);
2224 BrowserList::const_iterator iter = BrowserList::begin();
2225 Browser* browser = NULL;
2226 for (;iter != BrowserList::end(); ++iter) {
[email protected]2d46c842008-11-14 19:24:312227 HWND hwnd = reinterpret_cast<HWND>((*iter)->window()->GetNativeHandle());
2228 if (window == hwnd) {
initial.commit09911bf2008-07-26 23:55:292229 browser = *iter;
2230 break;
2231 }
2232 }
2233 if (browser) {
2234 // Add() returns the existing handle for the resource if any.
[email protected]71f65dd2009-02-11 19:14:562235 *browser_handle = browser_tracker_->Add(browser);
2236 *success = true;
initial.commit09911bf2008-07-26 23:55:292237 }
2238 }
initial.commit09911bf2008-07-26 23:55:292239}
[email protected]de246f52009-02-25 18:25:452240#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292241
[email protected]71f65dd2009-02-11 19:14:562242void AutomationProvider::ShowInterstitialPage(int tab_handle,
2243 const std::string& html_text,
2244 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:292245 if (tab_tracker_->ContainsHandle(tab_handle)) {
2246 NavigationController* controller = tab_tracker_->GetResource(tab_handle);
[email protected]7f0005a2009-04-15 03:25:112247 TabContents* tab_contents = controller->tab_contents();
[email protected]965524b2009-04-04 21:32:402248
2249 AddNavigationStatusListener<bool>(controller, reply_message, true,
2250 false, false);
[email protected]965524b2009-04-04 21:32:402251 AutomationInterstitialPage* interstitial =
[email protected]57c6a652009-05-04 07:58:342252 new AutomationInterstitialPage(tab_contents,
[email protected]965524b2009-04-04 21:32:402253 GURL("about:interstitial"),
2254 html_text);
2255 interstitial->Show();
2256 return;
initial.commit09911bf2008-07-26 23:55:292257 }
[email protected]71f65dd2009-02-11 19:14:562258
2259 AutomationMsg_ShowInterstitialPage::WriteReplyParams(reply_message, false);
2260 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292261}
2262
[email protected]71f65dd2009-02-11 19:14:562263void AutomationProvider::HideInterstitialPage(int tab_handle,
2264 bool* success) {
2265 *success = false;
[email protected]57c6a652009-05-04 07:58:342266 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL);
2267 if (tab_contents && tab_contents->interstitial_page()) {
2268 tab_contents->interstitial_page()->DontProceed();
[email protected]71f65dd2009-02-11 19:14:562269 *success = true;
initial.commit09911bf2008-07-26 23:55:292270 }
initial.commit09911bf2008-07-26 23:55:292271}
2272
[email protected]71f65dd2009-02-11 19:14:562273void AutomationProvider::CloseTab(int tab_handle,
2274 bool wait_until_closed,
2275 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:292276 if (tab_tracker_->ContainsHandle(tab_handle)) {
2277 NavigationController* controller = tab_tracker_->GetResource(tab_handle);
2278 int index;
2279 Browser* browser = Browser::GetBrowserForController(controller, &index);
2280 DCHECK(browser);
[email protected]de246f52009-02-25 18:25:452281 new TabClosedNotificationObserver(browser, this,
2282 reply_message->routing_id(),
2283 wait_until_closed, reply_message);
[email protected]7f0005a2009-04-15 03:25:112284 browser->CloseContents(controller->tab_contents());
[email protected]de246f52009-02-25 18:25:452285 return;
initial.commit09911bf2008-07-26 23:55:292286 }
[email protected]de246f52009-02-25 18:25:452287
2288 AutomationMsg_CloseTab::WriteReplyParams(reply_message, false);
initial.commit09911bf2008-07-26 23:55:292289}
2290
[email protected]71f65dd2009-02-11 19:14:562291void AutomationProvider::CloseBrowser(int browser_handle,
2292 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:292293 if (browser_tracker_->ContainsHandle(browser_handle)) {
2294 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]71f65dd2009-02-11 19:14:562295 new BrowserClosedNotificationObserver(browser, this,
2296 reply_message->routing_id(),
2297 reply_message);
[email protected]f3e99e32008-07-30 04:48:392298 browser->window()->Close();
initial.commit09911bf2008-07-26 23:55:292299 } else {
2300 NOTREACHED();
2301 }
2302}
2303
[email protected]71f65dd2009-02-11 19:14:562304void AutomationProvider::CloseBrowserAsync(int browser_handle) {
2305 if (browser_tracker_->ContainsHandle(browser_handle)) {
2306 Browser* browser = browser_tracker_->GetResource(browser_handle);
2307 browser->window()->Close();
2308 } else {
2309 NOTREACHED();
2310 }
2311}
2312
[email protected]de246f52009-02-25 18:25:452313#if defined(OS_WIN)
2314// TODO(port): Remove windowsisms.
[email protected]71f65dd2009-02-11 19:14:562315void AutomationProvider::CreateExternalTab(HWND parent,
[email protected]31fb110522009-01-28 21:50:392316 const gfx::Rect& dimensions,
[email protected]71f65dd2009-02-11 19:14:562317 unsigned int style,
[email protected]dd07d60b2009-04-23 18:24:322318 bool incognito,
[email protected]71f65dd2009-02-11 19:14:562319 HWND* tab_container_window,
2320 int* tab_handle) {
2321 *tab_handle = 0;
2322 *tab_container_window = NULL;
initial.commit09911bf2008-07-26 23:55:292323 ExternalTabContainer *external_tab_container =
2324 new ExternalTabContainer(this);
[email protected]dd07d60b2009-04-23 18:24:322325 Profile* profile = incognito? profile_->GetOffTheRecordProfile() : profile_;
2326 external_tab_container->Init(profile, parent, dimensions, style);
initial.commit09911bf2008-07-26 23:55:292327 TabContents* tab_contents = external_tab_container->tab_contents();
2328 if (tab_contents) {
[email protected]ce3fa3c2009-04-20 19:55:572329 *tab_handle = tab_tracker_->Add(&tab_contents->controller());
[email protected]71f65dd2009-02-11 19:14:562330 *tab_container_window = *external_tab_container;
[email protected]31fb110522009-01-28 21:50:392331 } else {
2332 delete external_tab_container;
initial.commit09911bf2008-07-26 23:55:292333 }
initial.commit09911bf2008-07-26 23:55:292334}
[email protected]d2cc6ed2009-04-24 00:26:172335#endif
initial.commit09911bf2008-07-26 23:55:292336
[email protected]71f65dd2009-02-11 19:14:562337void AutomationProvider::NavigateInExternalTab(
2338 int handle, const GURL& url,
2339 AutomationMsg_NavigationResponseValues* status) {
2340 *status = AUTOMATION_MSG_NAVIGATION_ERROR;
initial.commit09911bf2008-07-26 23:55:292341
2342 if (tab_tracker_->ContainsHandle(handle)) {
2343 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]c0588052008-10-27 23:01:502344 tab->LoadURL(url, GURL(), PageTransition::TYPED);
[email protected]71f65dd2009-02-11 19:14:562345 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS;
initial.commit09911bf2008-07-26 23:55:292346 }
initial.commit09911bf2008-07-26 23:55:292347}
2348
[email protected]d2cc6ed2009-04-24 00:26:172349#if defined(OS_WIN)
2350// TODO(port): remove windowisms.
[email protected]71f65dd2009-02-11 19:14:562351void AutomationProvider::SetAcceleratorsForTab(int handle,
initial.commit09911bf2008-07-26 23:55:292352 HACCEL accel_table,
[email protected]71f65dd2009-02-11 19:14:562353 int accel_entry_count,
2354 bool* status) {
2355 *status = false;
2356
[email protected]b9d227492009-02-10 15:20:272357 ExternalTabContainer* external_tab = GetExternalTabForHandle(handle);
2358 if (external_tab) {
2359 external_tab->SetAccelerators(accel_table, accel_entry_count);
[email protected]71f65dd2009-02-11 19:14:562360 *status = true;
initial.commit09911bf2008-07-26 23:55:292361 }
initial.commit09911bf2008-07-26 23:55:292362}
2363
2364void AutomationProvider::ProcessUnhandledAccelerator(
2365 const IPC::Message& message, int handle, const MSG& msg) {
[email protected]b9d227492009-02-10 15:20:272366 ExternalTabContainer* external_tab = GetExternalTabForHandle(handle);
2367 if (external_tab) {
2368 external_tab->ProcessUnhandledAccelerator(msg);
2369 }
2370 // This message expects no response.
2371}
[email protected]d2cc6ed2009-04-24 00:26:172372#endif
[email protected]b9d227492009-02-10 15:20:272373
[email protected]71f65dd2009-02-11 19:14:562374void AutomationProvider::WaitForTabToBeRestored(int tab_handle,
2375 IPC::Message* reply_message) {
2376 if (tab_tracker_->ContainsHandle(tab_handle)) {
2377 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
2378 restore_tracker_.reset(
2379 new NavigationControllerRestoredObserver(this, tab,
2380 reply_message->routing_id(),
2381 reply_message));
2382 }
2383}
2384
[email protected]b9d227492009-02-10 15:20:272385void AutomationProvider::SetInitialFocus(const IPC::Message& message,
2386 int handle, bool reverse) {
[email protected]d2cc6ed2009-04-24 00:26:172387#if defined(OS_WIN)
[email protected]b9d227492009-02-10 15:20:272388 ExternalTabContainer* external_tab = GetExternalTabForHandle(handle);
2389 if (external_tab) {
2390 external_tab->SetInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:292391 }
2392 // This message expects no response.
[email protected]d2cc6ed2009-04-24 00:26:172393#elif defined(OS_POSIX)
2394 // TODO(port) enable this function.
2395 NOTIMPLEMENTED();
2396#endif
initial.commit09911bf2008-07-26 23:55:292397}
2398
[email protected]d2cc6ed2009-04-24 00:26:172399// TODO(port): enable these functions.
2400#if defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:562401void AutomationProvider::GetSecurityState(int handle, bool* success,
2402 SecurityStyle* security_style,
2403 int* ssl_cert_status,
2404 int* mixed_content_status) {
initial.commit09911bf2008-07-26 23:55:292405 if (tab_tracker_->ContainsHandle(handle)) {
2406 NavigationController* tab = tab_tracker_->GetResource(handle);
2407 NavigationEntry* entry = tab->GetActiveEntry();
[email protected]71f65dd2009-02-11 19:14:562408 *success = true;
2409 *security_style = entry->ssl().security_style();
2410 *ssl_cert_status = entry->ssl().cert_status();
2411 *mixed_content_status = entry->ssl().content_status();
initial.commit09911bf2008-07-26 23:55:292412 } else {
[email protected]71f65dd2009-02-11 19:14:562413 *success = false;
2414 *security_style = SECURITY_STYLE_UNKNOWN;
2415 *ssl_cert_status = 0;
2416 *mixed_content_status = 0;
initial.commit09911bf2008-07-26 23:55:292417 }
2418}
2419
[email protected]71f65dd2009-02-11 19:14:562420void AutomationProvider::GetPageType(int handle, bool* success,
2421 NavigationEntry::PageType* page_type) {
initial.commit09911bf2008-07-26 23:55:292422 if (tab_tracker_->ContainsHandle(handle)) {
2423 NavigationController* tab = tab_tracker_->GetResource(handle);
2424 NavigationEntry* entry = tab->GetActiveEntry();
[email protected]71f65dd2009-02-11 19:14:562425 *page_type = entry->page_type();
2426 *success = true;
initial.commit09911bf2008-07-26 23:55:292427 // In order to return the proper result when an interstitial is shown and
[email protected]57c6a652009-05-04 07:58:342428 // no navigation entry were created for it we need to ask the TabContents.
[email protected]71f65dd2009-02-11 19:14:562429 if (*page_type == NavigationEntry::NORMAL_PAGE &&
[email protected]57c6a652009-05-04 07:58:342430 tab->tab_contents()->showing_interstitial_page())
[email protected]71f65dd2009-02-11 19:14:562431 *page_type = NavigationEntry::INTERSTITIAL_PAGE;
initial.commit09911bf2008-07-26 23:55:292432 } else {
[email protected]71f65dd2009-02-11 19:14:562433 *success = false;
2434 *page_type = NavigationEntry::NORMAL_PAGE;
initial.commit09911bf2008-07-26 23:55:292435 }
2436}
2437
[email protected]71f65dd2009-02-11 19:14:562438void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed,
2439 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:292440 if (tab_tracker_->ContainsHandle(handle)) {
2441 NavigationController* tab = tab_tracker_->GetResource(handle);
2442 NavigationEntry* entry = tab->GetActiveEntry();
[email protected]1e5645ff2008-08-27 18:09:072443 if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) {
[email protected]965524b2009-04-04 21:32:402444 TabContents* tab_contents = tab->tab_contents();
[email protected]cbab76d2008-10-13 22:42:472445 InterstitialPage* ssl_blocking_page =
[email protected]57c6a652009-05-04 07:58:342446 InterstitialPage::GetInterstitialPage(tab_contents);
initial.commit09911bf2008-07-26 23:55:292447 if (ssl_blocking_page) {
2448 if (proceed) {
[email protected]71f65dd2009-02-11 19:14:562449 AddNavigationStatusListener<bool>(tab, reply_message, true, true,
2450 false);
2451 ssl_blocking_page->Proceed();
initial.commit09911bf2008-07-26 23:55:292452 return;
2453 }
2454 ssl_blocking_page->DontProceed();
[email protected]71f65dd2009-02-11 19:14:562455 AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(reply_message,
2456 true);
2457 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292458 return;
2459 }
2460 }
2461 }
2462 // We failed.
[email protected]71f65dd2009-02-11 19:14:562463 AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(reply_message,
2464 false);
2465 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292466}
[email protected]de246f52009-02-25 18:25:452467#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292468
[email protected]71f65dd2009-02-11 19:14:562469void AutomationProvider::BringBrowserToFront(int browser_handle,
2470 bool* success) {
initial.commit09911bf2008-07-26 23:55:292471 if (browser_tracker_->ContainsHandle(browser_handle)) {
2472 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]cd7ffc22008-11-12 00:26:062473 browser->window()->Activate();
[email protected]71f65dd2009-02-11 19:14:562474 *success = true;
initial.commit09911bf2008-07-26 23:55:292475 } else {
[email protected]71f65dd2009-02-11 19:14:562476 *success = false;
initial.commit09911bf2008-07-26 23:55:292477 }
2478}
2479
[email protected]71f65dd2009-02-11 19:14:562480void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle,
2481 int message_num,
2482 bool* menu_item_enabled) {
initial.commit09911bf2008-07-26 23:55:292483 if (browser_tracker_->ContainsHandle(browser_handle)) {
2484 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]71f65dd2009-02-11 19:14:562485 *menu_item_enabled =
[email protected]1fc025202009-01-20 23:03:142486 browser->command_updater()->IsCommandEnabled(message_num);
initial.commit09911bf2008-07-26 23:55:292487 } else {
[email protected]71f65dd2009-02-11 19:14:562488 *menu_item_enabled = false;
initial.commit09911bf2008-07-26 23:55:292489 }
2490}
2491
[email protected]de246f52009-02-25 18:25:452492#if defined(OS_WIN)
[email protected]3753f522009-04-14 23:15:472493// TODO(port): Enable this.
[email protected]71f65dd2009-02-11 19:14:562494void AutomationProvider::PrintNow(int tab_handle,
2495 IPC::Message* reply_message) {
[email protected]20e93d12008-08-28 16:31:572496 NavigationController* tab = NULL;
[email protected]57c6a652009-05-04 07:58:342497 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab);
2498 if (tab_contents) {
initial.commit09911bf2008-07-26 23:55:292499 FindAndActivateTab(tab);
[email protected]20e93d12008-08-28 16:31:572500 notification_observer_list_.AddObserver(
[email protected]71f65dd2009-02-11 19:14:562501 new DocumentPrintedNotificationObserver(this,
2502 reply_message->routing_id(),
2503 reply_message));
[email protected]57c6a652009-05-04 07:58:342504 if (tab_contents->PrintNow())
[email protected]20e93d12008-08-28 16:31:572505 return;
initial.commit09911bf2008-07-26 23:55:292506 }
[email protected]71f65dd2009-02-11 19:14:562507 AutomationMsg_PrintNow::WriteReplyParams(reply_message, false);
2508 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292509}
[email protected]3753f522009-04-14 23:15:472510#endif
initial.commit09911bf2008-07-26 23:55:292511
[email protected]71f65dd2009-02-11 19:14:562512void AutomationProvider::SavePage(int tab_handle,
initial.commit09911bf2008-07-26 23:55:292513 const std::wstring& file_name,
2514 const std::wstring& dir_path,
[email protected]71f65dd2009-02-11 19:14:562515 int type,
2516 bool* success) {
initial.commit09911bf2008-07-26 23:55:292517 if (!tab_tracker_->ContainsHandle(tab_handle)) {
[email protected]71f65dd2009-02-11 19:14:562518 *success = false;
initial.commit09911bf2008-07-26 23:55:292519 return;
2520 }
2521
2522 NavigationController* nav = tab_tracker_->GetResource(tab_handle);
2523 Browser* browser = FindAndActivateTab(nav);
2524 DCHECK(browser);
[email protected]1fc025202009-01-20 23:03:142525 if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) {
[email protected]71f65dd2009-02-11 19:14:562526 *success = false;
initial.commit09911bf2008-07-26 23:55:292527 return;
2528 }
2529
initial.commit09911bf2008-07-26 23:55:292530 SavePackage::SavePackageType save_type =
2531 static_cast<SavePackage::SavePackageType>(type);
2532 DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML &&
2533 save_type <= SavePackage::SAVE_AS_COMPLETE_HTML);
[email protected]57c6a652009-05-04 07:58:342534 nav->tab_contents()->SavePage(file_name, dir_path, save_type);
initial.commit09911bf2008-07-26 23:55:292535
[email protected]71f65dd2009-02-11 19:14:562536 *success = true;
initial.commit09911bf2008-07-26 23:55:292537}
2538
[email protected]3753f522009-04-14 23:15:472539#if defined(OS_WIN)
2540// TODO(port): Enable these.
[email protected]71f65dd2009-02-11 19:14:562541void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle,
2542 bool* success,
2543 std::wstring* text) {
2544 *success = false;
initial.commit09911bf2008-07-26 23:55:292545 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]71f65dd2009-02-11 19:14:562546 *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)->
[email protected]81c21222008-09-10 19:35:522547 GetText();
[email protected]71f65dd2009-02-11 19:14:562548 *success = true;
initial.commit09911bf2008-07-26 23:55:292549 }
initial.commit09911bf2008-07-26 23:55:292550}
2551
[email protected]71f65dd2009-02-11 19:14:562552void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle,
2553 const std::wstring& text,
2554 bool* success) {
2555 *success = false;
initial.commit09911bf2008-07-26 23:55:292556 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]81c21222008-09-10 19:35:522557 autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)->
2558 SetUserText(text);
[email protected]71f65dd2009-02-11 19:14:562559 *success = true;
initial.commit09911bf2008-07-26 23:55:292560 }
initial.commit09911bf2008-07-26 23:55:292561}
2562
2563void AutomationProvider::AutocompleteEditGetMatches(
[email protected]71f65dd2009-02-11 19:14:562564 int autocomplete_edit_handle,
2565 bool* success,
2566 std::vector<AutocompleteMatchData>* matches) {
2567 *success = false;
initial.commit09911bf2008-07-26 23:55:292568 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]8deeb952008-10-09 18:21:272569 const AutocompleteResult& result = autocomplete_edit_tracker_->
2570 GetResource(autocomplete_edit_handle)->model()->result();
2571 for (AutocompleteResult::const_iterator i = result.begin();
2572 i != result.end(); ++i)
[email protected]71f65dd2009-02-11 19:14:562573 matches->push_back(AutocompleteMatchData(*i));
2574 *success = true;
initial.commit09911bf2008-07-26 23:55:292575 }
initial.commit09911bf2008-07-26 23:55:292576}
2577
2578void AutomationProvider::AutocompleteEditIsQueryInProgress(
[email protected]71f65dd2009-02-11 19:14:562579 int autocomplete_edit_handle,
2580 bool* success,
2581 bool* query_in_progress) {
2582 *success = false;
2583 *query_in_progress = false;
initial.commit09911bf2008-07-26 23:55:292584 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]71f65dd2009-02-11 19:14:562585 *query_in_progress = autocomplete_edit_tracker_->
[email protected]81c21222008-09-10 19:35:522586 GetResource(autocomplete_edit_handle)->model()->query_in_progress();
[email protected]71f65dd2009-02-11 19:14:562587 *success = true;
initial.commit09911bf2008-07-26 23:55:292588 }
initial.commit09911bf2008-07-26 23:55:292589}
2590
[email protected]28790922009-03-09 19:48:372591void AutomationProvider::OnMessageFromExternalHost(int handle,
2592 const std::string& message,
2593 const std::string& origin,
2594 const std::string& target) {
[email protected]fa83e762008-08-15 21:41:392595 if (tab_tracker_->ContainsHandle(handle)) {
2596 NavigationController* tab = tab_tracker_->GetResource(handle);
2597 if (!tab) {
2598 NOTREACHED();
2599 return;
2600 }
[email protected]965524b2009-04-04 21:32:402601 TabContents* tab_contents = tab->tab_contents();
[email protected]fa83e762008-08-15 21:41:392602 if (!tab_contents) {
2603 NOTREACHED();
2604 return;
2605 }
2606
[email protected]57c6a652009-05-04 07:58:342607 RenderViewHost* view_host = tab_contents->render_view_host();
[email protected]fa83e762008-08-15 21:41:392608 if (!view_host) {
2609 return;
2610 }
2611
[email protected]28790922009-03-09 19:48:372612 view_host->ForwardMessageFromExternalHost(message, origin, target);
[email protected]fa83e762008-08-15 21:41:392613 }
2614}
[email protected]5cc063692009-04-07 23:21:312615#endif // defined(OS_WIN)
[email protected]fa83e762008-08-15 21:41:392616
[email protected]57c6a652009-05-04 07:58:342617TabContents* AutomationProvider::GetTabContentsForHandle(
[email protected]20e93d12008-08-28 16:31:572618 int handle, NavigationController** tab) {
[email protected]20e93d12008-08-28 16:31:572619 if (tab_tracker_->ContainsHandle(handle)) {
2620 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:112621 TabContents* tab_contents = nav_controller->tab_contents();
[email protected]57c6a652009-05-04 07:58:342622 if (tab)
2623 *tab = nav_controller;
2624 return nav_controller->tab_contents();
[email protected]20e93d12008-08-28 16:31:572625 }
[email protected]57c6a652009-05-04 07:58:342626 return NULL;
[email protected]20e93d12008-08-28 16:31:572627}
2628
[email protected]5cc063692009-04-07 23:21:312629#if defined(OS_WIN)
[email protected]b9d227492009-02-10 15:20:272630ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) {
2631 if (tab_tracker_->ContainsHandle(handle)) {
2632 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]965524b2009-04-04 21:32:402633 return ExternalTabContainer::GetContainerForTab(
2634 tab->tab_contents()->GetNativeView());
[email protected]b9d227492009-02-10 15:20:272635 }
2636
2637 return NULL;
2638}
[email protected]de246f52009-02-25 18:25:452639#endif // defined(OS_WIN)
[email protected]b9d227492009-02-10 15:20:272640
initial.commit09911bf2008-07-26 23:55:292641TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
2642 : AutomationProvider(profile) {
2643 BrowserList::AddObserver(this);
[email protected]bfd04a62009-02-01 18:16:562644 NotificationService::current()->AddObserver(
2645 this,
2646 NotificationType::SESSION_END,
initial.commit09911bf2008-07-26 23:55:292647 NotificationService::AllSources());
2648}
2649
2650TestingAutomationProvider::~TestingAutomationProvider() {
[email protected]bfd04a62009-02-01 18:16:562651 NotificationService::current()->RemoveObserver(
2652 this,
2653 NotificationType::SESSION_END,
initial.commit09911bf2008-07-26 23:55:292654 NotificationService::AllSources());
2655 BrowserList::RemoveObserver(this);
2656}
2657
2658void TestingAutomationProvider::OnChannelError() {
2659 BrowserList::CloseAllBrowsers(true);
2660 AutomationProvider::OnChannelError();
2661}
2662
2663void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) {
2664 // For backwards compatibility with the testing automation interface, we
2665 // want the automation provider (and hence the process) to go away when the
2666 // last browser goes away.
2667 if (BrowserList::size() == 1) {
[email protected]4f3dc372009-02-24 00:10:292668 // If you change this, update Observer for NotificationType::SESSION_END
2669 // below.
[email protected]295039bd2008-08-15 04:32:572670 MessageLoop::current()->PostTask(FROM_HERE,
2671 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
initial.commit09911bf2008-07-26 23:55:292672 }
2673}
2674
2675void TestingAutomationProvider::Observe(NotificationType type,
2676 const NotificationSource& source,
2677 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:562678 DCHECK(type == NotificationType::SESSION_END);
initial.commit09911bf2008-07-26 23:55:292679 // OnBrowserRemoving does a ReleaseLater. When session end is received we exit
2680 // before the task runs resulting in this object not being deleted. This
2681 // Release balance out the Release scheduled by OnBrowserRemoving.
2682 Release();
2683}
[email protected]295039bd2008-08-15 04:32:572684
2685void TestingAutomationProvider::OnRemoveProvider() {
2686 AutomationProviderList::GetInstance()->RemoveProvider(this);
2687}
[email protected]8a3422c92008-09-24 17:42:422688
[email protected]71f65dd2009-02-11 19:14:562689void AutomationProvider::GetSSLInfoBarCount(int handle, int* count) {
2690 *count = -1; // -1 means error.
[email protected]de246f52009-02-25 18:25:452691#if defined(OS_WIN)
[email protected]8a3422c92008-09-24 17:42:422692 if (tab_tracker_->ContainsHandle(handle)) {
2693 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
[email protected]eb9ba192008-12-02 02:41:342694 if (nav_controller)
[email protected]7f0005a2009-04-15 03:25:112695 *count = nav_controller->tab_contents()->infobar_delegate_count();
[email protected]8a3422c92008-09-24 17:42:422696 }
[email protected]de246f52009-02-25 18:25:452697#else
2698 // TODO(port): Enable when TabContents infobar related stuff is ported.
2699 NOTIMPLEMENTED();
2700#endif
[email protected]8a3422c92008-09-24 17:42:422701}
2702
[email protected]71f65dd2009-02-11 19:14:562703void AutomationProvider::ClickSSLInfoBarLink(int handle,
[email protected]8a3422c92008-09-24 17:42:422704 int info_bar_index,
[email protected]71f65dd2009-02-11 19:14:562705 bool wait_for_navigation,
2706 IPC::Message* reply_message) {
[email protected]8a3422c92008-09-24 17:42:422707 bool success = false;
[email protected]de246f52009-02-25 18:25:452708#if defined(OS_WIN)
[email protected]8a3422c92008-09-24 17:42:422709 if (tab_tracker_->ContainsHandle(handle)) {
2710 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
2711 if (nav_controller) {
[email protected]7f0005a2009-04-15 03:25:112712 int count = nav_controller->tab_contents()->infobar_delegate_count();
[email protected]8a3422c92008-09-24 17:42:422713 if (info_bar_index >= 0 && info_bar_index < count) {
2714 if (wait_for_navigation) {
[email protected]71f65dd2009-02-11 19:14:562715 AddNavigationStatusListener<bool>(nav_controller, reply_message,
2716 true, true, false);
[email protected]8a3422c92008-09-24 17:42:422717 }
[email protected]eb9ba192008-12-02 02:41:342718 InfoBarDelegate* delegate =
[email protected]7f0005a2009-04-15 03:25:112719 nav_controller->tab_contents()->GetInfoBarDelegateAt(
[email protected]eb9ba192008-12-02 02:41:342720 info_bar_index);
2721 if (delegate->AsConfirmInfoBarDelegate())
2722 delegate->AsConfirmInfoBarDelegate()->Accept();
[email protected]8a3422c92008-09-24 17:42:422723 success = true;
2724 }
2725 }
[email protected]4f3dc372009-02-24 00:10:292726 }
[email protected]de246f52009-02-25 18:25:452727#else
2728 // TODO(port): Enable when TabContents infobar related stuff is ported.
2729 NOTIMPLEMENTED();
2730#endif
[email protected]8a3422c92008-09-24 17:42:422731 if (!wait_for_navigation || !success)
[email protected]71f65dd2009-02-11 19:14:562732 AutomationMsg_ClickSSLInfoBarLink::WriteReplyParams(reply_message,
2733 success);
[email protected]8a3422c92008-09-24 17:42:422734}
2735
[email protected]71f65dd2009-02-11 19:14:562736void AutomationProvider::GetLastNavigationTime(int handle,
2737 int64* last_navigation_time) {
[email protected]8a3422c92008-09-24 17:42:422738 Time time = tab_tracker_->GetLastNavigationTime(handle);
[email protected]71f65dd2009-02-11 19:14:562739 *last_navigation_time = time.ToInternalValue();
[email protected]8a3422c92008-09-24 17:42:422740}
2741
[email protected]71f65dd2009-02-11 19:14:562742void AutomationProvider::WaitForNavigation(int handle,
2743 int64 last_navigation_time,
2744 IPC::Message* reply_message) {
[email protected]8a3422c92008-09-24 17:42:422745 NavigationController* controller = NULL;
2746 if (tab_tracker_->ContainsHandle(handle))
2747 controller = tab_tracker_->GetResource(handle);
2748
2749 Time time = tab_tracker_->GetLastNavigationTime(handle);
2750 if (time.ToInternalValue() > last_navigation_time || !controller) {
[email protected]71f65dd2009-02-11 19:14:562751 AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message,
2752 controller != NULL);
[email protected]4f3dc372009-02-24 00:10:292753 return;
[email protected]8a3422c92008-09-24 17:42:422754 }
2755
[email protected]71f65dd2009-02-11 19:14:562756 AddNavigationStatusListener<bool>(controller, reply_message, true, true,
2757 false);
[email protected]8a3422c92008-09-24 17:42:422758}
2759
[email protected]71f65dd2009-02-11 19:14:562760void AutomationProvider::SetIntPreference(int handle,
[email protected]97fa6ce32008-12-19 01:48:162761 const std::wstring& name,
[email protected]71f65dd2009-02-11 19:14:562762 int value,
2763 bool* success) {
2764 *success = false;
[email protected]8a3422c92008-09-24 17:42:422765 if (browser_tracker_->ContainsHandle(handle)) {
2766 Browser* browser = browser_tracker_->GetResource(handle);
2767 browser->profile()->GetPrefs()->SetInteger(name.c_str(), value);
[email protected]71f65dd2009-02-11 19:14:562768 *success = true;
[email protected]8a3422c92008-09-24 17:42:422769 }
[email protected]8a3422c92008-09-24 17:42:422770}
[email protected]97fa6ce32008-12-19 01:48:162771
[email protected]71f65dd2009-02-11 19:14:562772void AutomationProvider::SetStringPreference(int handle,
[email protected]97fa6ce32008-12-19 01:48:162773 const std::wstring& name,
[email protected]71f65dd2009-02-11 19:14:562774 const std::wstring& value,
2775 bool* success) {
2776 *success = false;
[email protected]97fa6ce32008-12-19 01:48:162777 if (browser_tracker_->ContainsHandle(handle)) {
2778 Browser* browser = browser_tracker_->GetResource(handle);
2779 browser->profile()->GetPrefs()->SetString(name.c_str(), value);
[email protected]71f65dd2009-02-11 19:14:562780 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162781 }
[email protected]97fa6ce32008-12-19 01:48:162782}
2783
[email protected]71f65dd2009-02-11 19:14:562784void AutomationProvider::GetBooleanPreference(int handle,
2785 const std::wstring& name,
2786 bool* success,
2787 bool* value) {
2788 *success = false;
2789 *value = false;
[email protected]97fa6ce32008-12-19 01:48:162790 if (browser_tracker_->ContainsHandle(handle)) {
2791 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:562792 *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str());
2793 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162794 }
[email protected]97fa6ce32008-12-19 01:48:162795}
2796
[email protected]71f65dd2009-02-11 19:14:562797void AutomationProvider::SetBooleanPreference(int handle,
[email protected]97fa6ce32008-12-19 01:48:162798 const std::wstring& name,
[email protected]71f65dd2009-02-11 19:14:562799 bool value,
2800 bool* success) {
2801 *success = false;
[email protected]97fa6ce32008-12-19 01:48:162802 if (browser_tracker_->ContainsHandle(handle)) {
2803 Browser* browser = browser_tracker_->GetResource(handle);
2804 browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value);
[email protected]71f65dd2009-02-11 19:14:562805 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162806 }
[email protected]97fa6ce32008-12-19 01:48:162807}
2808
2809// Gets the current used encoding name of the page in the specified tab.
[email protected]71f65dd2009-02-11 19:14:562810void AutomationProvider::GetPageCurrentEncoding(
2811 int tab_handle, std::wstring* current_encoding) {
[email protected]97fa6ce32008-12-19 01:48:162812 if (tab_tracker_->ContainsHandle(tab_handle)) {
2813 NavigationController* nav = tab_tracker_->GetResource(tab_handle);
2814 Browser* browser = FindAndActivateTab(nav);
2815 DCHECK(browser);
2816
[email protected]57c6a652009-05-04 07:58:342817 if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU))
2818 *current_encoding = nav->tab_contents()->encoding();
[email protected]97fa6ce32008-12-19 01:48:162819 }
[email protected]97fa6ce32008-12-19 01:48:162820}
2821
2822// Gets the current used encoding name of the page in the specified tab.
[email protected]71f65dd2009-02-11 19:14:562823void AutomationProvider::OverrideEncoding(int tab_handle,
2824 const std::wstring& encoding_name,
2825 bool* success) {
2826 *success = false;
[email protected]de246f52009-02-25 18:25:452827#if defined(OS_WIN)
[email protected]97fa6ce32008-12-19 01:48:162828 if (tab_tracker_->ContainsHandle(tab_handle)) {
2829 NavigationController* nav = tab_tracker_->GetResource(tab_handle);
2830 Browser* browser = FindAndActivateTab(nav);
2831 DCHECK(browser);
2832
[email protected]1fc025202009-01-20 23:03:142833 if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) {
[email protected]7f0005a2009-04-15 03:25:112834 TabContents* tab_contents = nav->tab_contents();
[email protected]97fa6ce32008-12-19 01:48:162835 int selected_encoding_id =
2836 CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name);
2837 if (selected_encoding_id) {
2838 browser->OverrideEncoding(selected_encoding_id);
[email protected]71f65dd2009-02-11 19:14:562839 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162840 }
2841 }
2842 }
[email protected]de246f52009-02-25 18:25:452843#else
2844 // TODO(port): Enable when encoding-related parts of Browser are ported.
2845 NOTIMPLEMENTED();
2846#endif
[email protected]97fa6ce32008-12-19 01:48:162847}
[email protected]5bcdb312009-01-07 21:43:202848
[email protected]4d434a1a2009-02-11 21:06:572849void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) {
[email protected]5bcdb312009-01-07 21:43:202850 SavePackage::SetShouldPromptUser(should_prompt);
2851}
[email protected]87eab222009-03-13 00:47:452852
[email protected]d2cc6ed2009-04-24 00:26:172853#if defined(OS_WIN)
2854// TODO(port): Reposition_Params is win-specific. We'll need to port it.
[email protected]87eab222009-03-13 00:47:452855void AutomationProvider::OnTabReposition(
2856 int tab_handle, const IPC::Reposition_Params& params) {
2857 if (!tab_tracker_->ContainsHandle(tab_handle))
2858 return;
2859
2860 if (!IsWindow(params.window))
2861 return;
2862
2863 unsigned long process_id = 0;
2864 unsigned long thread_id = 0;
2865
2866 thread_id = GetWindowThreadProcessId(params.window, &process_id);
2867
2868 if (thread_id != GetCurrentThreadId()) {
2869 NOTREACHED();
2870 return;
2871 }
2872
[email protected]a9233d0f2009-04-20 05:39:332873 SetWindowPos(params.window, params.window_insert_after, params.left,
2874 params.top, params.width, params.height, params.flags);
2875
[email protected]a2c5a9892009-04-07 16:13:452876 if (params.set_parent) {
2877 if (IsWindow(params.parent_window)) {
2878 if (!SetParent(params.window, params.parent_window))
2879 DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError();
2880 }
2881 }
[email protected]87eab222009-03-13 00:47:452882}
[email protected]d2cc6ed2009-04-24 00:26:172883#endif
[email protected]3753f522009-04-14 23:15:472884
2885void AutomationProvider::GetWindowTitle(int handle, string16* text) {
2886 gfx::NativeWindow window = window_tracker_->GetResource(handle);
2887 text->assign(platform_util::GetWindowTitle(window));
2888}