1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ 6#define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ 7 8#include <deque> 9#include <map> 10#include <set> 11#include <string> 12#include <vector> 13 14#include "base/callback.h" 15#include "base/compiler_specific.h" 16#include "base/memory/scoped_ptr.h" 17#include "base/memory/weak_ptr.h" 18#include "base/sequenced_task_runner_helpers.h" 19#include "base/synchronization/waitable_event.h" 20#include "base/values.h" 21#include "chrome/browser/automation/automation_provider_json.h" 22#include "chrome/browser/bookmarks/bookmark_model_observer.h" 23#include "components/autofill/core/browser/personal_data_manager.h" 24#include "components/autofill/core/browser/personal_data_manager_observer.h" 25#if defined(OS_CHROMEOS) 26#include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" 27#include "chrome/browser/chromeos/login/login_status_consumer.h" 28#include "chrome/browser/chromeos/login/user_manager.h" 29#include "chrome/browser/chromeos/login/wizard_controller.h" 30#endif // defined(OS_CHROMEOS) 31#include "chrome/browser/common/cancelable_request.h" 32#include "chrome/browser/download/all_download_item_notifier.h" 33#include "chrome/browser/history/history_service.h" 34#include "chrome/browser/history/history_types.h" 35#include "chrome/browser/importer/importer_progress_observer.h" 36#include "chrome/browser/memory_details.h" 37#include "chrome/browser/password_manager/password_store_change.h" 38#include "chrome/browser/password_manager/password_store_consumer.h" 39#include "chrome/browser/search_engines/template_url_service_observer.h" 40#include "chrome/browser/ui/tabs/tab_strip_model.h" 41#include "chrome/common/automation_constants.h" 42#include "chrome/common/extensions/extension_constants.h" 43#include "chrome/common/importer/importer_data_types.h" 44#include "content/public/browser/browser_thread.h" 45#include "content/public/browser/download_item.h" 46#include "content/public/browser/download_manager.h" 47#include "content/public/browser/notification_observer.h" 48#include "content/public/browser/notification_registrar.h" 49#include "content/public/browser/notification_types.h" 50#include "ui/gfx/point.h" 51#include "ui/gfx/size.h" 52 53class AutomationProvider; 54class BalloonCollection; 55class Browser; 56class ExtensionService; 57class Notification; 58class Profile; 59class SavePackage; 60 61namespace automation { 62class Error; 63} 64 65#if defined(OS_CHROMEOS) 66namespace chromeos { 67class ExistingUserController; 68class WizardScreen; 69} 70#endif // defined(OS_CHROMEOS) 71 72namespace content { 73class NavigationController; 74class RenderViewHost; 75class WebContents; 76} 77 78namespace extensions { 79class Extension; 80class ProcessManager; 81} 82 83namespace history { 84class TopSites; 85} 86 87namespace IPC { 88class Message; 89} 90 91namespace policy { 92class BrowserPolicyConnector; 93} 94 95class InitialLoadObserver : public content::NotificationObserver { 96 public: 97 InitialLoadObserver(size_t tab_count, AutomationProvider* automation); 98 virtual ~InitialLoadObserver(); 99 100 // Overridden from content::NotificationObserver: 101 virtual void Observe(int type, 102 const content::NotificationSource& source, 103 const content::NotificationDetails& details) OVERRIDE; 104 105 // Caller owns the return value and is responsible for deleting it. 106 // Example return value: 107 // {'tabs': [{'start_time_ms': 1, 'stop_time_ms': 2.5}, 108 // {'start_time_ms': 0.5, 'stop_time_ms': 3}]} 109 // stop_time_ms values may be null if WaitForInitialLoads has not finished. 110 // Only includes entries for the |tab_count| tabs we are monitoring. 111 // There is no defined ordering of the return value. 112 base::DictionaryValue* GetTimingInformation() const; 113 114 private: 115 class TabTime; 116 typedef std::map<uintptr_t, TabTime> TabTimeMap; 117 typedef std::set<uintptr_t> TabSet; 118 119 void ConditionMet(); 120 121 content::NotificationRegistrar registrar_; 122 123 base::WeakPtr<AutomationProvider> automation_; 124 size_t crashed_tab_count_; 125 size_t outstanding_tab_count_; 126 base::TimeTicks init_time_; 127 TabTimeMap loading_tabs_; 128 TabSet finished_tabs_; 129 130 DISALLOW_COPY_AND_ASSIGN(InitialLoadObserver); 131}; 132 133#if defined(OS_CHROMEOS) 134// Observes when the ChromeOS login WebUI becomes ready (by showing the login 135// form, account picker, a network error or the OOBE wizard, depending on Chrome 136// flags and state). 137class OOBEWebuiReadyObserver : public content::NotificationObserver { 138 public: 139 explicit OOBEWebuiReadyObserver(AutomationProvider* automation); 140 141 // Overridden from content::NotificationObserver: 142 virtual void Observe(int type, 143 const content::NotificationSource& source, 144 const content::NotificationDetails& details) OVERRIDE; 145 146 private: 147 void OOBEWebuiReady(); 148 149 content::NotificationRegistrar registrar_; 150 base::WeakPtr<AutomationProvider> automation_; 151 152 DISALLOW_COPY_AND_ASSIGN(OOBEWebuiReadyObserver); 153}; 154#endif // defined(OS_CHROMEOS) 155 156// Watches for NewTabUI page loads for performance timing purposes. 157class NewTabUILoadObserver : public content::NotificationObserver { 158 public: 159 explicit NewTabUILoadObserver(AutomationProvider* automation, 160 Profile* profile); 161 virtual ~NewTabUILoadObserver(); 162 163 // Overridden from content::NotificationObserver: 164 virtual void Observe(int type, 165 const content::NotificationSource& source, 166 const content::NotificationDetails& details) OVERRIDE; 167 168 private: 169 content::NotificationRegistrar registrar_; 170 base::WeakPtr<AutomationProvider> automation_; 171 172 DISALLOW_COPY_AND_ASSIGN(NewTabUILoadObserver); 173}; 174 175class NavigationControllerRestoredObserver 176 : public content::NotificationObserver { 177 public: 178 NavigationControllerRestoredObserver( 179 AutomationProvider* automation, 180 content::NavigationController* controller, 181 IPC::Message* reply_message); 182 virtual ~NavigationControllerRestoredObserver(); 183 184 // Overridden from content::NotificationObserver: 185 virtual void Observe(int type, 186 const content::NotificationSource& source, 187 const content::NotificationDetails& details) OVERRIDE; 188 189 private: 190 bool FinishedRestoring(); 191 void SendDone(); 192 193 content::NotificationRegistrar registrar_; 194 base::WeakPtr<AutomationProvider> automation_; 195 content::NavigationController* controller_; 196 scoped_ptr<IPC::Message> reply_message_; 197 198 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver); 199}; 200 201class NavigationNotificationObserver : public content::NotificationObserver { 202 public: 203 NavigationNotificationObserver(content::NavigationController* controller, 204 AutomationProvider* automation, 205 IPC::Message* reply_message, 206 int number_of_navigations, 207 bool include_current_navigation, 208 bool use_json_interface); 209 virtual ~NavigationNotificationObserver(); 210 211 // Overridden from content::NotificationObserver: 212 virtual void Observe(int type, 213 const content::NotificationSource& source, 214 const content::NotificationDetails& details) OVERRIDE; 215 216 void ConditionMet(AutomationMsg_NavigationResponseValues navigation_result); 217 218 private: 219 content::NotificationRegistrar registrar_; 220 base::WeakPtr<AutomationProvider> automation_; 221 scoped_ptr<IPC::Message> reply_message_; 222 content::NavigationController* controller_; 223 int navigations_remaining_; 224 bool navigation_started_; 225 bool use_json_interface_; 226 227 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); 228}; 229 230class TabStripNotificationObserver : public content::NotificationObserver { 231 public: 232 TabStripNotificationObserver(int notification, 233 AutomationProvider* automation); 234 virtual ~TabStripNotificationObserver(); 235 236 // Overridden from content::NotificationObserver: 237 virtual void Observe(int type, 238 const content::NotificationSource& source, 239 const content::NotificationDetails& details) OVERRIDE; 240 241 virtual void ObserveTab(content::NavigationController* controller) = 0; 242 243 protected: 244 content::NotificationRegistrar registrar_; 245 base::WeakPtr<AutomationProvider> automation_; 246 int notification_; 247}; 248 249class TabAppendedNotificationObserver : public TabStripNotificationObserver { 250 public: 251 TabAppendedNotificationObserver(Browser* parent, 252 AutomationProvider* automation, 253 IPC::Message* reply_message, 254 bool use_json_interface); 255 virtual ~TabAppendedNotificationObserver(); 256 257 virtual void ObserveTab(content::NavigationController* controller); 258 IPC::Message* ReleaseReply(); 259 260 protected: 261 Browser* parent_; 262 scoped_ptr<IPC::Message> reply_message_; 263 bool use_json_interface_; 264 265 private: 266 DISALLOW_COPY_AND_ASSIGN(TabAppendedNotificationObserver); 267}; 268 269class TabClosedNotificationObserver : public TabStripNotificationObserver { 270 public: 271 TabClosedNotificationObserver(AutomationProvider* automation, 272 bool wait_until_closed, 273 IPC::Message* reply_message, 274 bool use_json_interface); 275 virtual ~TabClosedNotificationObserver(); 276 277 virtual void ObserveTab(content::NavigationController* controller); 278 279 void set_for_browser_command(bool for_browser_command); 280 281 protected: 282 scoped_ptr<IPC::Message> reply_message_; 283 bool use_json_interface_; 284 bool for_browser_command_; 285 286 private: 287 DISALLOW_COPY_AND_ASSIGN(TabClosedNotificationObserver); 288}; 289 290// Notifies when the tab count reaches the target number. 291class TabCountChangeObserver : public TabStripModelObserver { 292 public: 293 TabCountChangeObserver(AutomationProvider* automation, 294 Browser* browser, 295 IPC::Message* reply_message, 296 int target_tab_count); 297 // Implementation of TabStripModelObserver. 298 virtual void TabInsertedAt(content::WebContents* contents, 299 int index, 300 bool foreground) OVERRIDE; 301 virtual void TabDetachedAt(content::WebContents* contents, 302 int index) OVERRIDE; 303 virtual void TabStripModelDeleted() OVERRIDE; 304 305 private: 306 virtual ~TabCountChangeObserver(); 307 308 // Checks if the current tab count matches our target, and if so, 309 // sends the reply message and deletes self. 310 void CheckTabCount(); 311 312 base::WeakPtr<AutomationProvider> automation_; 313 scoped_ptr<IPC::Message> reply_message_; 314 315 TabStripModel* tab_strip_model_; 316 317 const int target_tab_count_; 318 319 DISALLOW_COPY_AND_ASSIGN(TabCountChangeObserver); 320}; 321 322// Observes when an extension has been uninstalled. 323class ExtensionUninstallObserver : public content::NotificationObserver { 324 public: 325 ExtensionUninstallObserver(AutomationProvider* automation, 326 IPC::Message* reply_message, 327 const std::string& id); 328 virtual ~ExtensionUninstallObserver(); 329 330 // Overridden from content::NotificationObserver: 331 virtual void Observe(int type, 332 const content::NotificationSource& source, 333 const content::NotificationDetails& details) OVERRIDE; 334 335 private: 336 content::NotificationRegistrar registrar_; 337 base::WeakPtr<AutomationProvider> automation_; 338 scoped_ptr<IPC::Message> reply_message_; 339 std::string id_; 340 341 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallObserver); 342}; 343 344// Observes when an extension has finished loading and is ready for use. Also 345// checks for possible install errors. 346class ExtensionReadyNotificationObserver 347 : public content::NotificationObserver { 348 public: 349 // Creates an observer that replies using the JSON automation interface. 350 ExtensionReadyNotificationObserver(extensions::ProcessManager* manager, 351 ExtensionService* service, 352 AutomationProvider* automation, 353 IPC::Message* reply_message); 354 virtual ~ExtensionReadyNotificationObserver(); 355 356 // Overridden from content::NotificationObserver: 357 virtual void Observe(int type, 358 const content::NotificationSource& source, 359 const content::NotificationDetails& details) OVERRIDE; 360 361 private: 362 void Init(); 363 364 content::NotificationRegistrar registrar_; 365 extensions::ProcessManager* manager_; 366 ExtensionService* service_; 367 base::WeakPtr<AutomationProvider> automation_; 368 scoped_ptr<IPC::Message> reply_message_; 369 const extensions::Extension* extension_; 370 371 DISALLOW_COPY_AND_ASSIGN(ExtensionReadyNotificationObserver); 372}; 373 374class ExtensionUnloadNotificationObserver 375 : public content::NotificationObserver { 376 public: 377 ExtensionUnloadNotificationObserver(); 378 virtual ~ExtensionUnloadNotificationObserver(); 379 380 // Overridden from content::NotificationObserver: 381 virtual void Observe(int type, 382 const content::NotificationSource& source, 383 const content::NotificationDetails& details) OVERRIDE; 384 385 bool did_receive_unload_notification() { 386 return did_receive_unload_notification_; 387 } 388 389 private: 390 content::NotificationRegistrar registrar_; 391 bool did_receive_unload_notification_; 392 393 DISALLOW_COPY_AND_ASSIGN(ExtensionUnloadNotificationObserver); 394}; 395 396// Observes when the extensions have been fully updated. The ExtensionUpdater 397// service provides a notification whem all the updated extensions have been 398// installed, but it does not wait for all of them to be loaded too. This 399// observer waits until all updated extensions have actually been loaded. 400class ExtensionsUpdatedObserver : public content::NotificationObserver { 401 public: 402 ExtensionsUpdatedObserver(extensions::ProcessManager* manager, 403 AutomationProvider* automation, 404 IPC::Message* reply_message); 405 virtual ~ExtensionsUpdatedObserver(); 406 407 // Overridden from content::NotificationObserver: 408 virtual void Observe(int type, 409 const content::NotificationSource& source, 410 const content::NotificationDetails& details) OVERRIDE; 411 412 // Called by ExtensionUpdater when it has finished updating extensions. 413 void UpdateCheckFinished(); 414 415 private: 416 void MaybeReply(); 417 418 content::NotificationRegistrar registrar_; 419 extensions::ProcessManager* manager_; 420 base::WeakPtr<AutomationProvider> automation_; 421 scoped_ptr<IPC::Message> reply_message_; 422 bool updater_finished_; 423 424 DISALLOW_COPY_AND_ASSIGN(ExtensionsUpdatedObserver); 425}; 426 427// Observes when a new browser has been opened and a tab within it has stopped 428// loading. 429class BrowserOpenedNotificationObserver : public content::NotificationObserver { 430 public: 431 BrowserOpenedNotificationObserver(AutomationProvider* automation, 432 IPC::Message* reply_message, 433 bool use_json_interface); 434 virtual ~BrowserOpenedNotificationObserver(); 435 436 // Overridden from content::NotificationObserver: 437 virtual void Observe(int type, 438 const content::NotificationSource& source, 439 const content::NotificationDetails& details) OVERRIDE; 440 441 void set_for_browser_command(bool for_browser_command); 442 443 private: 444 content::NotificationRegistrar registrar_; 445 base::WeakPtr<AutomationProvider> automation_; 446 scoped_ptr<IPC::Message> reply_message_; 447 int new_window_id_; 448 bool use_json_interface_; 449 bool for_browser_command_; 450 451 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver); 452}; 453 454class BrowserClosedNotificationObserver : public content::NotificationObserver { 455 public: 456 BrowserClosedNotificationObserver(Browser* browser, 457 AutomationProvider* automation, 458 IPC::Message* reply_message, 459 bool use_json_interface); 460 virtual ~BrowserClosedNotificationObserver(); 461 462 // Overridden from content::NotificationObserver: 463 virtual void Observe(int type, 464 const content::NotificationSource& source, 465 const content::NotificationDetails& details) OVERRIDE; 466 467 void set_for_browser_command(bool for_browser_command); 468 469 private: 470 content::NotificationRegistrar registrar_; 471 base::WeakPtr<AutomationProvider> automation_; 472 scoped_ptr<IPC::Message> reply_message_; 473 bool use_json_interface_; 474 bool for_browser_command_; 475 476 DISALLOW_COPY_AND_ASSIGN(BrowserClosedNotificationObserver); 477}; 478 479class BrowserCountChangeNotificationObserver 480 : public content::NotificationObserver { 481 public: 482 BrowserCountChangeNotificationObserver(int target_count, 483 AutomationProvider* automation, 484 IPC::Message* reply_message); 485 virtual ~BrowserCountChangeNotificationObserver(); 486 487 // Overridden from content::NotificationObserver: 488 virtual void Observe(int type, 489 const content::NotificationSource& source, 490 const content::NotificationDetails& details) OVERRIDE; 491 492 private: 493 int target_count_; 494 content::NotificationRegistrar registrar_; 495 base::WeakPtr<AutomationProvider> automation_; 496 scoped_ptr<IPC::Message> reply_message_; 497 498 DISALLOW_COPY_AND_ASSIGN(BrowserCountChangeNotificationObserver); 499}; 500 501class ExecuteBrowserCommandObserver : public content::NotificationObserver { 502 public: 503 virtual ~ExecuteBrowserCommandObserver(); 504 505 static bool CreateAndRegisterObserver(AutomationProvider* automation, 506 Browser* browser, 507 int command, 508 IPC::Message* reply_message, 509 bool use_json_interface); 510 511 // Overridden from content::NotificationObserver: 512 virtual void Observe(int type, 513 const content::NotificationSource& source, 514 const content::NotificationDetails& details) OVERRIDE; 515 516 private: 517 ExecuteBrowserCommandObserver(AutomationProvider* automation, 518 IPC::Message* reply_message, 519 bool use_json_interface); 520 521 bool Register(int command); 522 523 bool Getint(int command, int* type); 524 525 IPC::Message* ReleaseReply(); 526 527 content::NotificationRegistrar registrar_; 528 base::WeakPtr<AutomationProvider> automation_; 529 int notification_type_; 530 scoped_ptr<IPC::Message> reply_message_; 531 bool use_json_interface_; 532 533 DISALLOW_COPY_AND_ASSIGN(ExecuteBrowserCommandObserver); 534}; 535 536class FindInPageNotificationObserver : public content::NotificationObserver { 537 public: 538 FindInPageNotificationObserver(AutomationProvider* automation, 539 content::WebContents* parent_tab, 540 bool reply_with_json, 541 IPC::Message* reply_message); 542 virtual ~FindInPageNotificationObserver(); 543 544 // Overridden from content::NotificationObserver: 545 virtual void Observe(int type, 546 const content::NotificationSource& source, 547 const content::NotificationDetails& details) OVERRIDE; 548 549 // The Find mechanism is over asynchronous IPC, so a search is kicked off and 550 // we wait for notification to find out what the results are. As the user is 551 // typing, new search requests can be issued and the Request ID helps us make 552 // sense of whether this is the current request or an old one. The unit tests, 553 // however, which uses this constant issues only one search at a time, so we 554 // don't need a rolling id to identify each search. But, we still need to 555 // specify one, so we just use a fixed one - its value does not matter. 556 static const int kFindInPageRequestId; 557 558 private: 559 content::NotificationRegistrar registrar_; 560 base::WeakPtr<AutomationProvider> automation_; 561 // We will at some point (before final update) be notified of the ordinal and 562 // we need to preserve it so we can send it later. 563 int active_match_ordinal_; 564 // Send reply using json automation interface. 565 bool reply_with_json_; 566 scoped_ptr<IPC::Message> reply_message_; 567 568 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); 569}; 570 571class DomOperationObserver : public content::NotificationObserver { 572 public: 573 explicit DomOperationObserver(int automation_id); 574 virtual ~DomOperationObserver(); 575 576 // Overridden from content::NotificationObserver: 577 virtual void Observe(int type, 578 const content::NotificationSource& source, 579 const content::NotificationDetails& details) OVERRIDE; 580 581 virtual void OnDomOperationCompleted(const std::string& json) = 0; 582 virtual void OnJavascriptBlocked() = 0; 583 584 private: 585 int automation_id_; 586 content::NotificationRegistrar registrar_; 587 588 DISALLOW_COPY_AND_ASSIGN(DomOperationObserver); 589}; 590 591// Sends a message back to the automation client with the results of the DOM 592// operation. 593class DomOperationMessageSender : public DomOperationObserver { 594 public: 595 DomOperationMessageSender(AutomationProvider* automation, 596 IPC::Message* reply_message, 597 bool use_json_interface); 598 virtual ~DomOperationMessageSender(); 599 600 virtual void OnDomOperationCompleted(const std::string& json) OVERRIDE; 601 virtual void OnJavascriptBlocked() OVERRIDE; 602 603 private: 604 base::WeakPtr<AutomationProvider> automation_; 605 scoped_ptr<IPC::Message> reply_message_; 606 bool use_json_interface_; 607 608 DISALLOW_COPY_AND_ASSIGN(DomOperationMessageSender); 609}; 610 611// Collects METRIC_EVENT_DURATION notifications and keep track of the times. 612class MetricEventDurationObserver : public content::NotificationObserver { 613 public: 614 MetricEventDurationObserver(); 615 virtual ~MetricEventDurationObserver(); 616 617 // Get the duration of an event. Returns -1 if we haven't seen the event. 618 int GetEventDurationMs(const std::string& event_name); 619 620 // Overridden from content::NotificationObserver: 621 virtual void Observe(int type, 622 const content::NotificationSource& source, 623 const content::NotificationDetails& details) OVERRIDE; 624 625 private: 626 content::NotificationRegistrar registrar_; 627 628 typedef std::map<std::string, int> EventDurationMap; 629 EventDurationMap durations_; 630 631 DISALLOW_COPY_AND_ASSIGN(MetricEventDurationObserver); 632}; 633 634class InfoBarCountObserver : public content::NotificationObserver { 635 public: 636 InfoBarCountObserver(AutomationProvider* automation, 637 IPC::Message* reply_message, 638 content::WebContents* web_contents, 639 size_t target_count); 640 virtual ~InfoBarCountObserver(); 641 642 // Overridden from content::NotificationObserver: 643 virtual void Observe(int type, 644 const content::NotificationSource& source, 645 const content::NotificationDetails& details) OVERRIDE; 646 647 private: 648 // Checks whether the infobar count matches our target, and if so 649 // sends the reply message and deletes itself. 650 void CheckCount(); 651 652 content::NotificationRegistrar registrar_; 653 base::WeakPtr<AutomationProvider> automation_; 654 scoped_ptr<IPC::Message> reply_message_; 655 content::WebContents* web_contents_; 656 657 const size_t target_count_; 658 659 DISALLOW_COPY_AND_ASSIGN(InfoBarCountObserver); 660}; 661 662#if defined(OS_CHROMEOS) 663class LoginObserver : public chromeos::LoginStatusConsumer { 664 public: 665 LoginObserver(chromeos::ExistingUserController* controller, 666 AutomationProvider* automation, 667 IPC::Message* reply_message); 668 669 virtual ~LoginObserver(); 670 671 virtual void OnLoginFailure(const chromeos::LoginFailure& error); 672 673 virtual void OnLoginSuccess(const chromeos::UserContext& user_context); 674 675 private: 676 chromeos::ExistingUserController* controller_; 677 base::WeakPtr<AutomationProvider> automation_; 678 scoped_ptr<IPC::Message> reply_message_; 679 680 DISALLOW_COPY_AND_ASSIGN(LoginObserver); 681}; 682 683// Waits for a screen change notification from WizardController. 684class WizardControllerObserver : public chromeos::WizardController::Observer, 685 public content::NotificationObserver { 686 public: 687 WizardControllerObserver(chromeos::WizardController* wizard_controller, 688 AutomationProvider* automation, 689 IPC::Message* reply_message); 690 virtual ~WizardControllerObserver(); 691 692 // If non-empty, waits for a specific change to screen with this name. 693 std::string screen_to_wait_for() { return screen_to_wait_for_; } 694 void set_screen_to_wait_for(const std::string& screen_name) { 695 screen_to_wait_for_ = screen_name; 696 } 697 698 protected: 699 // chromeos::WizardController::Observer overrides: 700 virtual void OnScreenChanged(chromeos::WizardScreen* next_screen) OVERRIDE; 701 virtual void OnSessionStart() OVERRIDE; 702 703 // content::NotificationObserver overrides: 704 void Observe(int type, 705 const content::NotificationSource& source, 706 const content::NotificationDetails& details); 707 708 // Sends reply with the given screen name and deletes |this|. 709 void SendReply(const std::string& screen_name); 710 711 content::NotificationRegistrar registrar_; 712 chromeos::WizardController* wizard_controller_; 713 base::WeakPtr<AutomationProvider> automation_; 714 scoped_ptr<IPC::Message> reply_message_; 715 std::string screen_to_wait_for_; 716 717 DISALLOW_COPY_AND_ASSIGN(WizardControllerObserver); 718}; 719 720// Collects SCREEN_LOCK_STATE_CHANGED notifications and returns 721// whether authentication succeeded to the automation provider. 722class ScreenLockUnlockObserver : public content::NotificationObserver { 723 public: 724 // Set lock_screen to true to observe lock screen events, 725 // false for unlock screen events. 726 ScreenLockUnlockObserver(AutomationProvider* automation, 727 IPC::Message* reply_message, 728 bool lock_screen); 729 virtual ~ScreenLockUnlockObserver(); 730 731 // Overridden from content::NotificationObserver: 732 virtual void Observe(int type, 733 const content::NotificationSource& source, 734 const content::NotificationDetails& details) OVERRIDE; 735 736 protected: 737 base::WeakPtr<AutomationProvider> automation_; 738 scoped_ptr<IPC::Message> reply_message_; 739 740 private: 741 content::NotificationRegistrar registrar_; 742 bool lock_screen_; 743 744 DISALLOW_COPY_AND_ASSIGN(ScreenLockUnlockObserver); 745}; 746 747// Watches SCREEN_LOCK_STATE_CHANGED notifications like the 748// ScreenLockUnlockObserver, but additionally adds itself as an observer 749// to a screen locker in order to monitor unlock failure cases. 750class ScreenUnlockObserver : public ScreenLockUnlockObserver, 751 public chromeos::LoginStatusConsumer { 752 public: 753 ScreenUnlockObserver(AutomationProvider* automation, 754 IPC::Message* reply_message); 755 virtual ~ScreenUnlockObserver(); 756 757 virtual void OnLoginFailure(const chromeos::LoginFailure& error); 758 759 virtual void OnLoginSuccess(const chromeos::UserContext& user_context) {} 760 761 private: 762 DISALLOW_COPY_AND_ASSIGN(ScreenUnlockObserver); 763}; 764 765#endif // defined(OS_CHROMEOS) 766 767// Waits for the bookmark model to load. 768class AutomationProviderBookmarkModelObserver : public BookmarkModelObserver { 769 public: 770 AutomationProviderBookmarkModelObserver(AutomationProvider* provider, 771 IPC::Message* reply_message, 772 BookmarkModel* model, 773 bool use_json_interface); 774 virtual ~AutomationProviderBookmarkModelObserver(); 775 776 // BookmarkModelObserver: 777 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; 778 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; 779 virtual void BookmarkNodeMoved(BookmarkModel* model, 780 const BookmarkNode* old_parent, 781 int old_index, 782 const BookmarkNode* new_parent, 783 int new_index) OVERRIDE {} 784 virtual void BookmarkNodeAdded(BookmarkModel* model, 785 const BookmarkNode* parent, 786 int index) OVERRIDE {} 787 virtual void BookmarkNodeRemoved(BookmarkModel* model, 788 const BookmarkNode* parent, 789 int old_index, 790 const BookmarkNode* node) OVERRIDE {} 791 virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE {} 792 virtual void BookmarkNodeChanged(BookmarkModel* model, 793 const BookmarkNode* node) OVERRIDE {} 794 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, 795 const BookmarkNode* node) OVERRIDE {} 796 virtual void BookmarkNodeChildrenReordered( 797 BookmarkModel* model, 798 const BookmarkNode* node) OVERRIDE {} 799 800 IPC::Message* ReleaseReply(); 801 802 private: 803 // Reply to the automation message with the given success value, 804 // then delete myself (which removes myself from the bookmark model 805 // observer list). 806 void ReplyAndDelete(bool success); 807 808 base::WeakPtr<AutomationProvider> automation_provider_; 809 scoped_ptr<IPC::Message> reply_message_; 810 BookmarkModel* model_; 811 bool use_json_interface_; 812 813 DISALLOW_COPY_AND_ASSIGN(AutomationProviderBookmarkModelObserver); 814}; 815 816// Allows the automation provider to wait until the download has been updated 817// or opened. 818class AutomationProviderDownloadUpdatedObserver 819 : public content::DownloadItem::Observer { 820 public: 821 AutomationProviderDownloadUpdatedObserver( 822 AutomationProvider* provider, 823 IPC::Message* reply_message, 824 bool wait_for_open, 825 bool incognito); 826 virtual ~AutomationProviderDownloadUpdatedObserver(); 827 828 virtual void OnDownloadUpdated(content::DownloadItem* download); 829 virtual void OnDownloadOpened(content::DownloadItem* download); 830 831 private: 832 base::WeakPtr<AutomationProvider> provider_; 833 scoped_ptr<IPC::Message> reply_message_; 834 bool wait_for_open_; 835 bool incognito_; 836 837 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadUpdatedObserver); 838}; 839 840// Allows the automation provider to wait until the download model has changed 841// (because a new download has been added or removed). 842class AutomationProviderDownloadModelChangedObserver 843 : public AllDownloadItemNotifier::Observer { 844 public: 845 AutomationProviderDownloadModelChangedObserver( 846 AutomationProvider* provider, 847 IPC::Message* reply_message, 848 content::DownloadManager* download_manager); 849 virtual ~AutomationProviderDownloadModelChangedObserver(); 850 851 virtual void OnDownloadCreated( 852 content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE; 853 virtual void OnDownloadRemoved( 854 content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE; 855 856 private: 857 void ModelChanged(); 858 859 base::WeakPtr<AutomationProvider> provider_; 860 scoped_ptr<IPC::Message> reply_message_; 861 AllDownloadItemNotifier notifier_; 862 863 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadModelChangedObserver); 864}; 865 866// Observes when all pending downloads have completed. 867class AllDownloadsCompleteObserver 868 : public content::DownloadManager::Observer, 869 public content::DownloadItem::Observer { 870 public: 871 AllDownloadsCompleteObserver( 872 AutomationProvider* provider, 873 IPC::Message* reply_message, 874 content::DownloadManager* download_manager, 875 ListValue* pre_download_ids); 876 virtual ~AllDownloadsCompleteObserver(); 877 878 // content::DownloadManager::Observer. 879 virtual void OnDownloadCreated( 880 content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE; 881 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; 882 883 // content::DownloadItem::Observer. 884 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; 885 886 private: 887 void ReplyIfNecessary(); 888 889 base::WeakPtr<AutomationProvider> provider_; 890 scoped_ptr<IPC::Message> reply_message_; 891 content::DownloadManager* download_manager_; 892 std::set<int> pre_download_ids_; 893 std::set<content::DownloadItem*> pending_downloads_; 894 895 DISALLOW_COPY_AND_ASSIGN(AllDownloadsCompleteObserver); 896}; 897 898// Allows automation provider to wait until TemplateURLService has loaded 899// before looking up/returning search engine info. 900class AutomationProviderSearchEngineObserver 901 : public TemplateURLServiceObserver { 902 public: 903 AutomationProviderSearchEngineObserver( 904 AutomationProvider* provider, 905 Profile* profile, 906 IPC::Message* reply_message); 907 virtual ~AutomationProviderSearchEngineObserver(); 908 909 virtual void OnTemplateURLServiceChanged(); 910 911 private: 912 base::WeakPtr<AutomationProvider> provider_; 913 Profile* profile_; 914 scoped_ptr<IPC::Message> reply_message_; 915 916 DISALLOW_COPY_AND_ASSIGN(AutomationProviderSearchEngineObserver); 917}; 918 919// Allows the automation provider to wait for history queries to finish. 920class AutomationProviderHistoryObserver { 921 public: 922 AutomationProviderHistoryObserver( 923 AutomationProvider* provider, 924 IPC::Message* reply_message); 925 virtual ~AutomationProviderHistoryObserver(); 926 927 void HistoryQueryComplete(HistoryService::Handle request_handle, 928 history::QueryResults* results); 929 930 private: 931 base::WeakPtr<AutomationProvider> provider_; 932 scoped_ptr<IPC::Message> reply_message_; 933}; 934 935// Allows the automation provider to wait for import queries to finish. 936class AutomationProviderImportSettingsObserver 937 : public importer::ImporterProgressObserver { 938 public: 939 AutomationProviderImportSettingsObserver( 940 AutomationProvider* provider, 941 IPC::Message* reply_message); 942 virtual ~AutomationProviderImportSettingsObserver(); 943 944 // importer::ImporterProgressObserver: 945 virtual void ImportStarted() OVERRIDE; 946 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE; 947 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE; 948 virtual void ImportEnded() OVERRIDE; 949 950 private: 951 base::WeakPtr<AutomationProvider> provider_; 952 scoped_ptr<IPC::Message> reply_message_; 953}; 954 955// Allows automation provider to wait for getting passwords to finish. 956class AutomationProviderGetPasswordsObserver : public PasswordStoreConsumer { 957 public: 958 AutomationProviderGetPasswordsObserver( 959 AutomationProvider* provider, 960 IPC::Message* reply_message); 961 virtual ~AutomationProviderGetPasswordsObserver(); 962 963 // PasswordStoreConsumer implementation. 964 virtual void OnPasswordStoreRequestDone( 965 CancelableRequestProvider::Handle handle, 966 const std::vector<autofill::PasswordForm*>& result) OVERRIDE; 967 virtual void OnGetPasswordStoreResults( 968 const std::vector<autofill::PasswordForm*>& results) OVERRIDE; 969 970 private: 971 base::WeakPtr<AutomationProvider> provider_; 972 scoped_ptr<IPC::Message> reply_message_; 973}; 974 975// Observes when login entries stored in the password store are changed. The 976// notifications are sent on the DB thread, the thread that interacts with the 977// web database. 978class PasswordStoreLoginsChangedObserver 979 : public base::RefCountedThreadSafe< 980 PasswordStoreLoginsChangedObserver, 981 content::BrowserThread::DeleteOnUIThread>, 982 public content::NotificationObserver { 983 public: 984 PasswordStoreLoginsChangedObserver(AutomationProvider* automation, 985 IPC::Message* reply_message, 986 PasswordStoreChange::Type expected_type, 987 const std::string& result_key); 988 989 // Schedules a task on the DB thread to register the appropriate observers. 990 virtual void Init(); 991 992 // Overridden from content::NotificationObserver: 993 virtual void Observe(int type, 994 const content::NotificationSource& source, 995 const content::NotificationDetails& details) OVERRIDE; 996 997 private: 998 friend struct content::BrowserThread::DeleteOnThread< 999 content::BrowserThread::UI>; 1000 ~PasswordStoreLoginsChangedObserver(); 1001 friend class base::DeleteHelper<PasswordStoreLoginsChangedObserver>; 1002 1003 // Registers the appropriate observers. Called on the DB thread. 1004 void RegisterObserversTask(); 1005 1006 // Sends the |reply_message_| to |automation_| indicating we're done. Called 1007 // on the UI thread. 1008 void IndicateDone(); 1009 1010 // Sends an error reply to |automation_|. Called on the UI thread. 1011 void IndicateError(const std::string& error); 1012 1013 base::WeakPtr<AutomationProvider> automation_; 1014 scoped_ptr<IPC::Message> reply_message_; 1015 scoped_ptr<content::NotificationRegistrar> registrar_; 1016 PasswordStoreChange::Type expected_type_; 1017 std::string result_key_; 1018 1019 // Used to ensure that the UI thread waits for the DB thread to finish 1020 // registering observers before proceeding. 1021 base::WaitableEvent done_event_; 1022 1023 DISALLOW_COPY_AND_ASSIGN(PasswordStoreLoginsChangedObserver); 1024}; 1025 1026// Allows automation provider to wait until page load after selecting an item 1027// in the omnibox popup. 1028class OmniboxAcceptNotificationObserver : public content::NotificationObserver { 1029 public: 1030 OmniboxAcceptNotificationObserver(content::NavigationController* controller, 1031 AutomationProvider* automation, 1032 IPC::Message* reply_message); 1033 virtual ~OmniboxAcceptNotificationObserver(); 1034 1035 // Overridden from content::NotificationObserver: 1036 virtual void Observe(int type, 1037 const content::NotificationSource& source, 1038 const content::NotificationDetails& details) OVERRIDE; 1039 1040 private: 1041 content::NotificationRegistrar registrar_; 1042 base::WeakPtr<AutomationProvider> automation_; 1043 scoped_ptr<IPC::Message> reply_message_; 1044 content::NavigationController* controller_; 1045 1046 DISALLOW_COPY_AND_ASSIGN(OmniboxAcceptNotificationObserver); 1047}; 1048 1049// Allows the automation provider to wait for a save package notification. 1050class SavePackageNotificationObserver 1051: public content::DownloadManager::Observer { 1052 public: 1053 SavePackageNotificationObserver(content::DownloadManager* download_manager, 1054 AutomationProvider* automation, 1055 IPC::Message* reply_message); 1056 virtual ~SavePackageNotificationObserver(); 1057 1058 // Overridden from content::DownloadManager::Observer: 1059 virtual void OnSavePackageSuccessfullyFinished( 1060 content::DownloadManager* manager, content::DownloadItem* item) OVERRIDE; 1061 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; 1062 1063 private: 1064 content::DownloadManager* download_manager_; 1065 base::WeakPtr<AutomationProvider> automation_; 1066 scoped_ptr<IPC::Message> reply_message_; 1067 1068 DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver); 1069}; 1070 1071class NTPInfoObserver : public content::NotificationObserver { 1072 public: 1073 NTPInfoObserver(AutomationProvider* automation, IPC::Message* reply_message); 1074 virtual ~NTPInfoObserver(); 1075 1076 // Overridden from content::NotificationObserver: 1077 virtual void Observe(int type, 1078 const content::NotificationSource& source, 1079 const content::NotificationDetails& details) OVERRIDE; 1080 1081 private: 1082 void OnTopSitesLoaded(); 1083 void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); 1084 1085 base::WeakPtr<AutomationProvider> automation_; 1086 scoped_ptr<IPC::Message> reply_message_; 1087 CancelableRequestProvider::Handle request_; 1088 scoped_ptr<base::DictionaryValue> ntp_info_; 1089 history::TopSites* top_sites_; 1090 content::NotificationRegistrar registrar_; 1091 1092 DISALLOW_COPY_AND_ASSIGN(NTPInfoObserver); 1093}; 1094 1095// Observes when an app has been launched, as indicated by a notification that 1096// a content load in some tab has stopped. 1097class AppLaunchObserver : public content::NotificationObserver { 1098 public: 1099 AppLaunchObserver(content::NavigationController* controller, 1100 AutomationProvider* automation, 1101 IPC::Message* reply_message, 1102 extensions::LaunchContainer launch_container); 1103 virtual ~AppLaunchObserver(); 1104 1105 // Overridden from content::NotificationObserver: 1106 virtual void Observe(int type, 1107 const content::NotificationSource& source, 1108 const content::NotificationDetails& details) OVERRIDE; 1109 1110 private: 1111 content::NavigationController* controller_; 1112 base::WeakPtr<AutomationProvider> automation_; 1113 scoped_ptr<IPC::Message> reply_message_; 1114 content::NotificationRegistrar registrar_; 1115 extensions::LaunchContainer launch_container_; 1116 int new_window_id_; 1117 1118 DISALLOW_COPY_AND_ASSIGN(AppLaunchObserver); 1119}; 1120 1121// Allows the automation provider to wait until all the notification 1122// processes are ready. 1123class GetAllNotificationsObserver : public content::NotificationObserver { 1124 public: 1125 GetAllNotificationsObserver(AutomationProvider* automation, 1126 IPC::Message* reply_message); 1127 virtual ~GetAllNotificationsObserver(); 1128 1129 // Overridden from content::NotificationObserver: 1130 virtual void Observe(int type, 1131 const content::NotificationSource& source, 1132 const content::NotificationDetails& details) OVERRIDE; 1133 1134 private: 1135 // Sends a message via the |AutomationProvider|. |automation_| must be valid. 1136 // Deletes itself after the message is sent. 1137 void SendMessage(); 1138 // Returns a new dictionary describing the given notification. 1139 base::DictionaryValue* NotificationToJson(const Notification* note); 1140 1141 content::NotificationRegistrar registrar_; 1142 base::WeakPtr<AutomationProvider> automation_; 1143 scoped_ptr<IPC::Message> reply_message_; 1144 1145 DISALLOW_COPY_AND_ASSIGN(GetAllNotificationsObserver); 1146}; 1147 1148// Allows the automation provider to wait for a new notification balloon 1149// to appear and be ready. 1150class NewNotificationBalloonObserver : public content::NotificationObserver { 1151 public: 1152 NewNotificationBalloonObserver(AutomationProvider* provider, 1153 IPC::Message* reply_message); 1154 virtual ~NewNotificationBalloonObserver(); 1155 1156 // Overridden from content::NotificationObserver: 1157 virtual void Observe(int type, 1158 const content::NotificationSource& source, 1159 const content::NotificationDetails& details) OVERRIDE; 1160 1161 private: 1162 content::NotificationRegistrar registrar_; 1163 base::WeakPtr<AutomationProvider> automation_; 1164 scoped_ptr<IPC::Message> reply_message_; 1165 1166 DISALLOW_COPY_AND_ASSIGN(NewNotificationBalloonObserver); 1167}; 1168 1169// Allows the automation provider to wait for a given number of 1170// notification balloons. 1171class OnNotificationBalloonCountObserver 1172 : public content::NotificationObserver { 1173 public: 1174 OnNotificationBalloonCountObserver(AutomationProvider* provider, 1175 IPC::Message* reply_message, 1176 int count); 1177 virtual ~OnNotificationBalloonCountObserver(); 1178 1179 // Sends an automation reply message if |automation_| is still valid and the 1180 // number of ready balloons matches the desired count. Deletes itself if the 1181 // message is sent or if |automation_| is invalid. 1182 void CheckBalloonCount(); 1183 1184 // Overridden from content::NotificationObserver: 1185 virtual void Observe(int type, 1186 const content::NotificationSource& source, 1187 const content::NotificationDetails& details) OVERRIDE; 1188 1189 private: 1190 content::NotificationRegistrar registrar_; 1191 base::WeakPtr<AutomationProvider> automation_; 1192 scoped_ptr<IPC::Message> reply_message_; 1193 1194 BalloonCollection* collection_; 1195 int count_; 1196 1197 DISALLOW_COPY_AND_ASSIGN(OnNotificationBalloonCountObserver); 1198}; 1199 1200// Allows the automation provider to wait for a RENDERER_PROCESS_CLOSED 1201// notification. 1202class RendererProcessClosedObserver : public content::NotificationObserver { 1203 public: 1204 RendererProcessClosedObserver(AutomationProvider* automation, 1205 IPC::Message* reply_message); 1206 virtual ~RendererProcessClosedObserver(); 1207 1208 // Overridden from content::NotificationObserver: 1209 virtual void Observe(int type, 1210 const content::NotificationSource& source, 1211 const content::NotificationDetails& details) OVERRIDE; 1212 1213 private: 1214 content::NotificationRegistrar registrar_; 1215 base::WeakPtr<AutomationProvider> automation_; 1216 scoped_ptr<IPC::Message> reply_message_; 1217 1218 DISALLOW_COPY_AND_ASSIGN(RendererProcessClosedObserver); 1219}; 1220 1221// Allows the automation provider to wait for acknowledgement that a certain 1222// type and number of input events has been processed by the renderer. 1223class InputEventAckNotificationObserver : public content::NotificationObserver { 1224 public: 1225 InputEventAckNotificationObserver(AutomationProvider* automation, 1226 IPC::Message* reply_message, 1227 int event_type, int count); 1228 virtual ~InputEventAckNotificationObserver(); 1229 1230 // Overridden from content::NotificationObserver: 1231 virtual void Observe(int type, 1232 const content::NotificationSource& source, 1233 const content::NotificationDetails& details) OVERRIDE; 1234 1235 private: 1236 content::NotificationRegistrar registrar_; 1237 base::WeakPtr<AutomationProvider> automation_; 1238 scoped_ptr<IPC::Message> reply_message_; 1239 int event_type_; 1240 int count_; 1241 1242 DISALLOW_COPY_AND_ASSIGN(InputEventAckNotificationObserver); 1243}; 1244 1245// Observer used to listen for new tab creation to complete. 1246class NewTabObserver : public content::NotificationObserver { 1247 public: 1248 NewTabObserver(AutomationProvider* automation, 1249 IPC::Message* reply_message, 1250 bool use_json_interface); 1251 1252 // Overridden from content::NotificationObserver: 1253 virtual void Observe(int type, 1254 const content::NotificationSource& source, 1255 const content::NotificationDetails& details) OVERRIDE; 1256 1257 private: 1258 virtual ~NewTabObserver(); 1259 1260 content::NotificationRegistrar registrar_; 1261 base::WeakPtr<AutomationProvider> automation_; 1262 scoped_ptr<IPC::Message> reply_message_; 1263 bool use_json_interface_; 1264 1265 DISALLOW_COPY_AND_ASSIGN(NewTabObserver); 1266}; 1267 1268// Posts a task to the PROCESS_LAUNCHER thread, once processed posts a task 1269// back to the UI thread that notifies the provider we're done. 1270class WaitForProcessLauncherThreadToGoIdleObserver 1271 : public base::RefCountedThreadSafe< 1272 WaitForProcessLauncherThreadToGoIdleObserver, 1273 content::BrowserThread::DeleteOnUIThread> { 1274 public: 1275 WaitForProcessLauncherThreadToGoIdleObserver( 1276 AutomationProvider* automation, IPC::Message* reply_message); 1277 1278 private: 1279 friend struct content::BrowserThread::DeleteOnThread< 1280 content::BrowserThread::UI>; 1281 friend class base::DeleteHelper<WaitForProcessLauncherThreadToGoIdleObserver>; 1282 1283 virtual ~WaitForProcessLauncherThreadToGoIdleObserver(); 1284 1285 // Schedules a task on the PROCESS_LAUNCHER thread to execute 1286 // |RunOnProcessLauncherThread2|. By the time the task is executed the 1287 // PROCESS_LAUNCHER thread should be some what idle. 1288 void RunOnProcessLauncherThread(); 1289 1290 // When executed the PROCESS_LAUNCHER thread should have processed any pending 1291 // tasks. Schedules a task on the UI thread that sends the message saying 1292 // we're done. 1293 void RunOnProcessLauncherThread2(); 1294 1295 // Sends the |reply_message_| to |automation_| indicating we're done. 1296 void RunOnUIThread(); 1297 1298 base::WeakPtr<AutomationProvider> automation_; 1299 scoped_ptr<IPC::Message> reply_message_; 1300 1301 DISALLOW_COPY_AND_ASSIGN(WaitForProcessLauncherThreadToGoIdleObserver); 1302}; 1303 1304// Allows the automation provider to wait for acknowledgement that a drop 1305// operation has been processed by the renderer. 1306class DragTargetDropAckNotificationObserver 1307 : public content::NotificationObserver { 1308 public: 1309 DragTargetDropAckNotificationObserver(AutomationProvider* automation, 1310 IPC::Message* reply_message); 1311 virtual ~DragTargetDropAckNotificationObserver(); 1312 1313 // Overridden from content::NotificationObserver: 1314 virtual void Observe(int type, 1315 const content::NotificationSource& source, 1316 const content::NotificationDetails& details) OVERRIDE; 1317 1318 private: 1319 content::NotificationRegistrar registrar_; 1320 base::WeakPtr<AutomationProvider> automation_; 1321 scoped_ptr<IPC::Message> reply_message_; 1322 1323 DISALLOW_COPY_AND_ASSIGN(DragTargetDropAckNotificationObserver); 1324}; 1325 1326// Allows the automation provider to wait for process memory details to be 1327// available before sending this information to the client. 1328class ProcessInfoObserver : public MemoryDetails { 1329 public: 1330 ProcessInfoObserver(AutomationProvider* automation, 1331 IPC::Message* reply_message); 1332 1333 virtual void OnDetailsAvailable() OVERRIDE; 1334 1335 private: 1336 virtual ~ProcessInfoObserver(); 1337 base::WeakPtr<AutomationProvider> automation_; 1338 scoped_ptr<IPC::Message> reply_message_; 1339 1340 DISALLOW_COPY_AND_ASSIGN(ProcessInfoObserver); 1341}; 1342 1343// Observes when new v8 heap statistics are computed for a renderer process. 1344class V8HeapStatsObserver : public content::NotificationObserver { 1345 public: 1346 V8HeapStatsObserver(AutomationProvider* automation, 1347 IPC::Message* reply_message, 1348 base::ProcessId renderer_id); 1349 virtual ~V8HeapStatsObserver(); 1350 1351 // Overridden from content::NotificationObserver: 1352 virtual void Observe(int type, 1353 const content::NotificationSource& source, 1354 const content::NotificationDetails& details) OVERRIDE; 1355 1356 private: 1357 content::NotificationRegistrar registrar_; 1358 base::WeakPtr<AutomationProvider> automation_; 1359 scoped_ptr<IPC::Message> reply_message_; 1360 base::ProcessId renderer_id_; 1361 1362 DISALLOW_COPY_AND_ASSIGN(V8HeapStatsObserver); 1363}; 1364 1365// Observes when a new FPS value is computed for a renderer process. 1366class FPSObserver : public content::NotificationObserver { 1367 public: 1368 FPSObserver(AutomationProvider* automation, 1369 IPC::Message* reply_message, 1370 base::ProcessId renderer_id, 1371 int routing_id); 1372 virtual ~FPSObserver(); 1373 1374 // Overridden from content::NotificationObserver: 1375 virtual void Observe(int type, 1376 const content::NotificationSource& source, 1377 const content::NotificationDetails& details) OVERRIDE; 1378 1379 private: 1380 content::NotificationRegistrar registrar_; 1381 base::WeakPtr<AutomationProvider> automation_; 1382 scoped_ptr<IPC::Message> reply_message_; 1383 base::ProcessId renderer_id_; 1384 int routing_id_; 1385 1386 DISALLOW_COPY_AND_ASSIGN(FPSObserver); 1387}; 1388 1389// Manages the process of creating a new Profile and opening a new browser with 1390// that profile. This observer should be created, and then a new Profile 1391// should be created through the ProfileManager using 1392// profile_manager->CreateMultiProfileAsync(). The Observer watches for profile 1393// creation, upon which it creates a new browser window; after observing 1394// window creation, it creates a new tab and then finally observes it finish 1395// loading. 1396class BrowserOpenedWithNewProfileNotificationObserver 1397 : public content::NotificationObserver { 1398 public: 1399 BrowserOpenedWithNewProfileNotificationObserver( 1400 AutomationProvider* automation, 1401 IPC::Message* reply_message); 1402 virtual ~BrowserOpenedWithNewProfileNotificationObserver(); 1403 1404 // Overridden from content::NotificationObserver: 1405 virtual void Observe(int type, 1406 const content::NotificationSource& source, 1407 const content::NotificationDetails& details) OVERRIDE; 1408 1409 private: 1410 content::NotificationRegistrar registrar_; 1411 base::WeakPtr<AutomationProvider> automation_; 1412 scoped_ptr<IPC::Message> reply_message_; 1413 int new_window_id_; 1414 1415 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedWithNewProfileNotificationObserver); 1416}; 1417 1418// Waits for an extension popup to appear and load. 1419class ExtensionPopupObserver : public content::NotificationObserver { 1420 public: 1421 ExtensionPopupObserver( 1422 AutomationProvider* automation, 1423 IPC::Message* reply_message, 1424 const std::string& extension_id); 1425 ~ExtensionPopupObserver(); 1426 1427 // Overridden from content::NotificationObserver: 1428 virtual void Observe(int type, 1429 const content::NotificationSource& source, 1430 const content::NotificationDetails& details) OVERRIDE; 1431 1432 private: 1433 base::WeakPtr<AutomationProvider> automation_; 1434 scoped_ptr<IPC::Message> reply_message_; 1435 std::string extension_id_; 1436 content::NotificationRegistrar registrar_; 1437 1438 DISALLOW_COPY_AND_ASSIGN(ExtensionPopupObserver); 1439}; 1440 1441#if defined(OS_LINUX) 1442// Allows the automation provider to wait for a WINDOW_MAXIMIZED notification. 1443class WindowMaximizedObserver : public content::NotificationObserver { 1444 public: 1445 WindowMaximizedObserver(AutomationProvider* automation, 1446 IPC::Message* reply_message); 1447 virtual ~WindowMaximizedObserver(); 1448 1449 // Overridden from content::NotificationObserver: 1450 virtual void Observe(int type, 1451 const content::NotificationSource& source, 1452 const content::NotificationDetails& details) OVERRIDE; 1453 1454 private: 1455 content::NotificationRegistrar registrar_; 1456 base::WeakPtr<AutomationProvider> automation_; 1457 scoped_ptr<IPC::Message> reply_message_; 1458 1459 DISALLOW_COPY_AND_ASSIGN(WindowMaximizedObserver); 1460}; 1461#endif // defined(OS_LINUX) 1462 1463// Wait for a new browser window to get created (for an existing profile). 1464// Useful when reopening a multi-profile window. 1465class BrowserOpenedWithExistingProfileNotificationObserver 1466 : public content::NotificationObserver { 1467 public: 1468 BrowserOpenedWithExistingProfileNotificationObserver( 1469 AutomationProvider* automation, 1470 IPC::Message* reply_message, 1471 int num_loads); 1472 virtual ~BrowserOpenedWithExistingProfileNotificationObserver(); 1473 1474 virtual void Observe(int type, 1475 const content::NotificationSource& source, 1476 const content::NotificationDetails& details); 1477 private: 1478 content::NotificationRegistrar registrar_; 1479 base::WeakPtr<AutomationProvider> automation_; 1480 scoped_ptr<IPC::Message> reply_message_; 1481 int new_window_id_; 1482 int num_loads_; 1483 1484 DISALLOW_COPY_AND_ASSIGN( 1485 BrowserOpenedWithExistingProfileNotificationObserver); 1486}; 1487 1488#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ 1489