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.
5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_
6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_
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.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"
53 class AutomationProvider
;
59 namespace automation
{
63 #if defined(OS_CHROMEOS)
65 class ExistingUserController
;
68 #endif // defined(OS_CHROMEOS)
71 class NavigationController
;
76 namespace extensions
{
78 class ExtensionSystem
;
91 class BrowserPolicyConnector
;
94 class InitialLoadObserver
: public content::NotificationObserver
{
96 InitialLoadObserver(size_t tab_count
, AutomationProvider
* automation
);
97 virtual ~InitialLoadObserver();
99 // Overridden from content::NotificationObserver:
100 virtual void Observe(int type
,
101 const content::NotificationSource
& source
,
102 const content::NotificationDetails
& details
) OVERRIDE
;
104 // Caller owns the return value and is responsible for deleting it.
105 // Example return value:
106 // {'tabs': [{'start_time_ms': 1, 'stop_time_ms': 2.5},
107 // {'start_time_ms': 0.5, 'stop_time_ms': 3}]}
108 // stop_time_ms values may be null if WaitForInitialLoads has not finished.
109 // Only includes entries for the |tab_count| tabs we are monitoring.
110 // There is no defined ordering of the return value.
111 base::DictionaryValue
* GetTimingInformation() const;
115 typedef std::map
<uintptr_t, TabTime
> TabTimeMap
;
116 typedef std::set
<uintptr_t> TabSet
;
120 content::NotificationRegistrar registrar_
;
122 base::WeakPtr
<AutomationProvider
> automation_
;
123 size_t crashed_tab_count_
;
124 size_t outstanding_tab_count_
;
125 base::TimeTicks init_time_
;
126 TabTimeMap loading_tabs_
;
127 TabSet finished_tabs_
;
129 DISALLOW_COPY_AND_ASSIGN(InitialLoadObserver
);
132 #if defined(OS_CHROMEOS)
133 // Observes when the ChromeOS login WebUI becomes ready (by showing the login
134 // form, account picker, a network error or the OOBE wizard, depending on Chrome
136 class OOBEWebuiReadyObserver
: public content::NotificationObserver
{
138 explicit OOBEWebuiReadyObserver(AutomationProvider
* automation
);
140 // Overridden from content::NotificationObserver:
141 virtual void Observe(int type
,
142 const content::NotificationSource
& source
,
143 const content::NotificationDetails
& details
) OVERRIDE
;
146 void OOBEWebuiReady();
148 content::NotificationRegistrar registrar_
;
149 base::WeakPtr
<AutomationProvider
> automation_
;
151 DISALLOW_COPY_AND_ASSIGN(OOBEWebuiReadyObserver
);
153 #endif // defined(OS_CHROMEOS)
155 class NavigationControllerRestoredObserver
156 : public content::NotificationObserver
{
158 NavigationControllerRestoredObserver(
159 AutomationProvider
* automation
,
160 content::NavigationController
* controller
,
161 IPC::Message
* reply_message
);
162 virtual ~NavigationControllerRestoredObserver();
164 // Overridden from content::NotificationObserver:
165 virtual void Observe(int type
,
166 const content::NotificationSource
& source
,
167 const content::NotificationDetails
& details
) OVERRIDE
;
170 bool FinishedRestoring();
173 content::NotificationRegistrar registrar_
;
174 base::WeakPtr
<AutomationProvider
> automation_
;
175 content::NavigationController
* controller_
;
176 scoped_ptr
<IPC::Message
> reply_message_
;
178 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver
);
181 class NavigationNotificationObserver
: public content::NotificationObserver
{
183 NavigationNotificationObserver(content::NavigationController
* controller
,
184 AutomationProvider
* automation
,
185 IPC::Message
* reply_message
,
186 int number_of_navigations
,
187 bool include_current_navigation
,
188 bool use_json_interface
);
189 virtual ~NavigationNotificationObserver();
191 // Overridden from content::NotificationObserver:
192 virtual void Observe(int type
,
193 const content::NotificationSource
& source
,
194 const content::NotificationDetails
& details
) OVERRIDE
;
196 void ConditionMet(AutomationMsg_NavigationResponseValues navigation_result
);
199 content::NotificationRegistrar registrar_
;
200 base::WeakPtr
<AutomationProvider
> automation_
;
201 scoped_ptr
<IPC::Message
> reply_message_
;
202 content::NavigationController
* controller_
;
203 int navigations_remaining_
;
204 bool navigation_started_
;
205 bool use_json_interface_
;
207 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver
);
210 class TabStripNotificationObserver
: public content::NotificationObserver
{
212 TabStripNotificationObserver(int notification
,
213 AutomationProvider
* automation
);
214 virtual ~TabStripNotificationObserver();
216 // Overridden from content::NotificationObserver:
217 virtual void Observe(int type
,
218 const content::NotificationSource
& source
,
219 const content::NotificationDetails
& details
) OVERRIDE
;
221 virtual void ObserveTab(content::NavigationController
* controller
) = 0;
224 content::NotificationRegistrar registrar_
;
225 base::WeakPtr
<AutomationProvider
> automation_
;
229 class TabAppendedNotificationObserver
: public TabStripNotificationObserver
{
231 TabAppendedNotificationObserver(Browser
* parent
,
232 AutomationProvider
* automation
,
233 IPC::Message
* reply_message
,
234 bool use_json_interface
);
235 virtual ~TabAppendedNotificationObserver();
237 virtual void ObserveTab(content::NavigationController
* controller
);
238 IPC::Message
* ReleaseReply();
242 scoped_ptr
<IPC::Message
> reply_message_
;
243 bool use_json_interface_
;
246 DISALLOW_COPY_AND_ASSIGN(TabAppendedNotificationObserver
);
249 class TabClosedNotificationObserver
: public TabStripNotificationObserver
{
251 TabClosedNotificationObserver(AutomationProvider
* automation
,
252 bool wait_until_closed
,
253 IPC::Message
* reply_message
,
254 bool use_json_interface
);
255 virtual ~TabClosedNotificationObserver();
257 virtual void ObserveTab(content::NavigationController
* controller
);
259 void set_for_browser_command(bool for_browser_command
);
262 scoped_ptr
<IPC::Message
> reply_message_
;
263 bool use_json_interface_
;
264 bool for_browser_command_
;
267 DISALLOW_COPY_AND_ASSIGN(TabClosedNotificationObserver
);
270 // Notifies when the tab count reaches the target number.
271 class TabCountChangeObserver
: public TabStripModelObserver
{
273 TabCountChangeObserver(AutomationProvider
* automation
,
275 IPC::Message
* reply_message
,
276 int target_tab_count
);
277 // Implementation of TabStripModelObserver.
278 virtual void TabInsertedAt(content::WebContents
* contents
,
280 bool foreground
) OVERRIDE
;
281 virtual void TabDetachedAt(content::WebContents
* contents
,
283 virtual void TabStripModelDeleted() OVERRIDE
;
286 virtual ~TabCountChangeObserver();
288 // Checks if the current tab count matches our target, and if so,
289 // sends the reply message and deletes self.
290 void CheckTabCount();
292 base::WeakPtr
<AutomationProvider
> automation_
;
293 scoped_ptr
<IPC::Message
> reply_message_
;
295 TabStripModel
* tab_strip_model_
;
297 const int target_tab_count_
;
299 DISALLOW_COPY_AND_ASSIGN(TabCountChangeObserver
);
302 // Observes when an extension has been uninstalled.
303 class ExtensionUninstallObserver
: public content::NotificationObserver
{
305 ExtensionUninstallObserver(AutomationProvider
* automation
,
306 IPC::Message
* reply_message
,
307 const std::string
& id
);
308 virtual ~ExtensionUninstallObserver();
310 // Overridden from content::NotificationObserver:
311 virtual void Observe(int type
,
312 const content::NotificationSource
& source
,
313 const content::NotificationDetails
& details
) OVERRIDE
;
316 content::NotificationRegistrar registrar_
;
317 base::WeakPtr
<AutomationProvider
> automation_
;
318 scoped_ptr
<IPC::Message
> reply_message_
;
321 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallObserver
);
324 // Observes when an extension has finished loading and is ready for use. Also
325 // checks for possible install errors.
326 class ExtensionReadyNotificationObserver
327 : public content::NotificationObserver
{
329 // Creates an observer that replies using the JSON automation interface.
330 ExtensionReadyNotificationObserver(
331 extensions::ExtensionSystem
* extension_system
,
332 AutomationProvider
* automation
,
333 IPC::Message
* reply_message
);
334 virtual ~ExtensionReadyNotificationObserver();
336 // Overridden from content::NotificationObserver:
337 virtual void Observe(int type
,
338 const content::NotificationSource
& source
,
339 const content::NotificationDetails
& details
) OVERRIDE
;
344 content::NotificationRegistrar registrar_
;
345 extensions::ExtensionSystem
* extension_system_
;
346 base::WeakPtr
<AutomationProvider
> automation_
;
347 scoped_ptr
<IPC::Message
> reply_message_
;
348 const extensions::Extension
* extension_
;
350 DISALLOW_COPY_AND_ASSIGN(ExtensionReadyNotificationObserver
);
353 class ExtensionUnloadNotificationObserver
354 : public content::NotificationObserver
{
356 ExtensionUnloadNotificationObserver();
357 virtual ~ExtensionUnloadNotificationObserver();
359 // Overridden from content::NotificationObserver:
360 virtual void Observe(int type
,
361 const content::NotificationSource
& source
,
362 const content::NotificationDetails
& details
) OVERRIDE
;
364 bool did_receive_unload_notification() {
365 return did_receive_unload_notification_
;
369 content::NotificationRegistrar registrar_
;
370 bool did_receive_unload_notification_
;
372 DISALLOW_COPY_AND_ASSIGN(ExtensionUnloadNotificationObserver
);
375 // Observes when the extensions have been fully updated. The ExtensionUpdater
376 // service provides a notification whem all the updated extensions have been
377 // installed, but it does not wait for all of them to be loaded too. This
378 // observer waits until all updated extensions have actually been loaded.
379 class ExtensionsUpdatedObserver
: public content::NotificationObserver
{
381 ExtensionsUpdatedObserver(extensions::ProcessManager
* manager
,
382 AutomationProvider
* automation
,
383 IPC::Message
* reply_message
);
384 virtual ~ExtensionsUpdatedObserver();
386 // Overridden from content::NotificationObserver:
387 virtual void Observe(int type
,
388 const content::NotificationSource
& source
,
389 const content::NotificationDetails
& details
) OVERRIDE
;
391 // Called by ExtensionUpdater when it has finished updating extensions.
392 void UpdateCheckFinished();
397 content::NotificationRegistrar registrar_
;
398 extensions::ProcessManager
* manager_
;
399 base::WeakPtr
<AutomationProvider
> automation_
;
400 scoped_ptr
<IPC::Message
> reply_message_
;
401 bool updater_finished_
;
403 DISALLOW_COPY_AND_ASSIGN(ExtensionsUpdatedObserver
);
406 // Observes when a new browser has been opened and a tab within it has stopped
408 class BrowserOpenedNotificationObserver
: public content::NotificationObserver
{
410 BrowserOpenedNotificationObserver(AutomationProvider
* automation
,
411 IPC::Message
* reply_message
,
412 bool use_json_interface
);
413 virtual ~BrowserOpenedNotificationObserver();
415 // Overridden from content::NotificationObserver:
416 virtual void Observe(int type
,
417 const content::NotificationSource
& source
,
418 const content::NotificationDetails
& details
) OVERRIDE
;
420 void set_for_browser_command(bool for_browser_command
);
423 content::NotificationRegistrar registrar_
;
424 base::WeakPtr
<AutomationProvider
> automation_
;
425 scoped_ptr
<IPC::Message
> reply_message_
;
427 bool use_json_interface_
;
428 bool for_browser_command_
;
430 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver
);
433 class BrowserClosedNotificationObserver
: public content::NotificationObserver
{
435 BrowserClosedNotificationObserver(Browser
* browser
,
436 AutomationProvider
* automation
,
437 IPC::Message
* reply_message
,
438 bool use_json_interface
);
439 virtual ~BrowserClosedNotificationObserver();
441 // Overridden from content::NotificationObserver:
442 virtual void Observe(int type
,
443 const content::NotificationSource
& source
,
444 const content::NotificationDetails
& details
) OVERRIDE
;
446 void set_for_browser_command(bool for_browser_command
);
449 content::NotificationRegistrar registrar_
;
450 base::WeakPtr
<AutomationProvider
> automation_
;
451 scoped_ptr
<IPC::Message
> reply_message_
;
452 bool use_json_interface_
;
453 bool for_browser_command_
;
455 DISALLOW_COPY_AND_ASSIGN(BrowserClosedNotificationObserver
);
458 class BrowserCountChangeNotificationObserver
459 : public content::NotificationObserver
{
461 BrowserCountChangeNotificationObserver(int target_count
,
462 AutomationProvider
* automation
,
463 IPC::Message
* reply_message
);
464 virtual ~BrowserCountChangeNotificationObserver();
466 // Overridden from content::NotificationObserver:
467 virtual void Observe(int type
,
468 const content::NotificationSource
& source
,
469 const content::NotificationDetails
& details
) OVERRIDE
;
473 content::NotificationRegistrar registrar_
;
474 base::WeakPtr
<AutomationProvider
> automation_
;
475 scoped_ptr
<IPC::Message
> reply_message_
;
477 DISALLOW_COPY_AND_ASSIGN(BrowserCountChangeNotificationObserver
);
480 class ExecuteBrowserCommandObserver
: public content::NotificationObserver
{
482 virtual ~ExecuteBrowserCommandObserver();
484 static bool CreateAndRegisterObserver(AutomationProvider
* automation
,
487 IPC::Message
* reply_message
,
488 bool use_json_interface
);
490 // Overridden from content::NotificationObserver:
491 virtual void Observe(int type
,
492 const content::NotificationSource
& source
,
493 const content::NotificationDetails
& details
) OVERRIDE
;
496 ExecuteBrowserCommandObserver(AutomationProvider
* automation
,
497 IPC::Message
* reply_message
,
498 bool use_json_interface
);
500 bool Register(int command
);
502 bool Getint(int command
, int* type
);
504 IPC::Message
* ReleaseReply();
506 content::NotificationRegistrar registrar_
;
507 base::WeakPtr
<AutomationProvider
> automation_
;
508 int notification_type_
;
509 scoped_ptr
<IPC::Message
> reply_message_
;
510 bool use_json_interface_
;
512 DISALLOW_COPY_AND_ASSIGN(ExecuteBrowserCommandObserver
);
515 class FindInPageNotificationObserver
: public content::NotificationObserver
{
517 FindInPageNotificationObserver(AutomationProvider
* automation
,
518 content::WebContents
* parent_tab
,
519 bool reply_with_json
,
520 IPC::Message
* reply_message
);
521 virtual ~FindInPageNotificationObserver();
523 // Overridden from content::NotificationObserver:
524 virtual void Observe(int type
,
525 const content::NotificationSource
& source
,
526 const content::NotificationDetails
& details
) OVERRIDE
;
528 // The Find mechanism is over asynchronous IPC, so a search is kicked off and
529 // we wait for notification to find out what the results are. As the user is
530 // typing, new search requests can be issued and the Request ID helps us make
531 // sense of whether this is the current request or an old one. The unit tests,
532 // however, which uses this constant issues only one search at a time, so we
533 // don't need a rolling id to identify each search. But, we still need to
534 // specify one, so we just use a fixed one - its value does not matter.
535 static const int kFindInPageRequestId
;
538 content::NotificationRegistrar registrar_
;
539 base::WeakPtr
<AutomationProvider
> automation_
;
540 // We will at some point (before final update) be notified of the ordinal and
541 // we need to preserve it so we can send it later.
542 int active_match_ordinal_
;
543 // Send reply using json automation interface.
544 bool reply_with_json_
;
545 scoped_ptr
<IPC::Message
> reply_message_
;
547 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver
);
550 class DomOperationObserver
: public content::NotificationObserver
{
552 explicit DomOperationObserver(int automation_id
);
553 virtual ~DomOperationObserver();
555 // Overridden from content::NotificationObserver:
556 virtual void Observe(int type
,
557 const content::NotificationSource
& source
,
558 const content::NotificationDetails
& details
) OVERRIDE
;
560 virtual void OnDomOperationCompleted(const std::string
& json
) = 0;
561 virtual void OnJavascriptBlocked() = 0;
565 content::NotificationRegistrar registrar_
;
567 DISALLOW_COPY_AND_ASSIGN(DomOperationObserver
);
570 // Sends a message back to the automation client with the results of the DOM
572 class DomOperationMessageSender
: public DomOperationObserver
{
574 DomOperationMessageSender(AutomationProvider
* automation
,
575 IPC::Message
* reply_message
,
576 bool use_json_interface
);
577 virtual ~DomOperationMessageSender();
579 virtual void OnDomOperationCompleted(const std::string
& json
) OVERRIDE
;
580 virtual void OnJavascriptBlocked() OVERRIDE
;
583 base::WeakPtr
<AutomationProvider
> automation_
;
584 scoped_ptr
<IPC::Message
> reply_message_
;
585 bool use_json_interface_
;
587 DISALLOW_COPY_AND_ASSIGN(DomOperationMessageSender
);
590 // Collects METRIC_EVENT_DURATION notifications and keep track of the times.
591 class MetricEventDurationObserver
: public content::NotificationObserver
{
593 MetricEventDurationObserver();
594 virtual ~MetricEventDurationObserver();
596 // Get the duration of an event. Returns -1 if we haven't seen the event.
597 int GetEventDurationMs(const std::string
& event_name
);
599 // Overridden from content::NotificationObserver:
600 virtual void Observe(int type
,
601 const content::NotificationSource
& source
,
602 const content::NotificationDetails
& details
) OVERRIDE
;
605 content::NotificationRegistrar registrar_
;
607 typedef std::map
<std::string
, int> EventDurationMap
;
608 EventDurationMap durations_
;
610 DISALLOW_COPY_AND_ASSIGN(MetricEventDurationObserver
);
613 class InfoBarCountObserver
: public content::NotificationObserver
{
615 InfoBarCountObserver(AutomationProvider
* automation
,
616 IPC::Message
* reply_message
,
617 content::WebContents
* web_contents
,
618 size_t target_count
);
619 virtual ~InfoBarCountObserver();
621 // Overridden from content::NotificationObserver:
622 virtual void Observe(int type
,
623 const content::NotificationSource
& source
,
624 const content::NotificationDetails
& details
) OVERRIDE
;
627 // Checks whether the infobar count matches our target, and if so
628 // sends the reply message and deletes itself.
631 content::NotificationRegistrar registrar_
;
632 base::WeakPtr
<AutomationProvider
> automation_
;
633 scoped_ptr
<IPC::Message
> reply_message_
;
634 content::WebContents
* web_contents_
;
636 const size_t target_count_
;
638 DISALLOW_COPY_AND_ASSIGN(InfoBarCountObserver
);
641 #if defined(OS_CHROMEOS)
642 class LoginObserver
: public chromeos::LoginStatusConsumer
{
644 LoginObserver(chromeos::ExistingUserController
* controller
,
645 AutomationProvider
* automation
,
646 IPC::Message
* reply_message
);
648 virtual ~LoginObserver();
650 virtual void OnLoginFailure(const chromeos::LoginFailure
& error
);
652 virtual void OnLoginSuccess(const chromeos::UserContext
& user_context
);
655 chromeos::ExistingUserController
* controller_
;
656 base::WeakPtr
<AutomationProvider
> automation_
;
657 scoped_ptr
<IPC::Message
> reply_message_
;
659 DISALLOW_COPY_AND_ASSIGN(LoginObserver
);
662 // Waits for a screen change notification from WizardController.
663 class WizardControllerObserver
: public chromeos::WizardController::Observer
,
664 public content::NotificationObserver
{
666 WizardControllerObserver(chromeos::WizardController
* wizard_controller
,
667 AutomationProvider
* automation
,
668 IPC::Message
* reply_message
);
669 virtual ~WizardControllerObserver();
671 // If non-empty, waits for a specific change to screen with this name.
672 std::string
screen_to_wait_for() { return screen_to_wait_for_
; }
673 void set_screen_to_wait_for(const std::string
& screen_name
) {
674 screen_to_wait_for_
= screen_name
;
678 // chromeos::WizardController::Observer overrides:
679 virtual void OnScreenChanged(chromeos::WizardScreen
* next_screen
) OVERRIDE
;
680 virtual void OnSessionStart() OVERRIDE
;
682 // content::NotificationObserver overrides:
683 void Observe(int type
,
684 const content::NotificationSource
& source
,
685 const content::NotificationDetails
& details
);
687 // Sends reply with the given screen name and deletes |this|.
688 void SendReply(const std::string
& screen_name
);
690 content::NotificationRegistrar registrar_
;
691 chromeos::WizardController
* wizard_controller_
;
692 base::WeakPtr
<AutomationProvider
> automation_
;
693 scoped_ptr
<IPC::Message
> reply_message_
;
694 std::string screen_to_wait_for_
;
696 DISALLOW_COPY_AND_ASSIGN(WizardControllerObserver
);
699 // Collects SCREEN_LOCK_STATE_CHANGED notifications and returns
700 // whether authentication succeeded to the automation provider.
701 class ScreenLockUnlockObserver
: public content::NotificationObserver
{
703 // Set lock_screen to true to observe lock screen events,
704 // false for unlock screen events.
705 ScreenLockUnlockObserver(AutomationProvider
* automation
,
706 IPC::Message
* reply_message
,
708 virtual ~ScreenLockUnlockObserver();
710 // Overridden from content::NotificationObserver:
711 virtual void Observe(int type
,
712 const content::NotificationSource
& source
,
713 const content::NotificationDetails
& details
) OVERRIDE
;
716 base::WeakPtr
<AutomationProvider
> automation_
;
717 scoped_ptr
<IPC::Message
> reply_message_
;
720 content::NotificationRegistrar registrar_
;
723 DISALLOW_COPY_AND_ASSIGN(ScreenLockUnlockObserver
);
726 // Watches SCREEN_LOCK_STATE_CHANGED notifications like the
727 // ScreenLockUnlockObserver, but additionally adds itself as an observer
728 // to a screen locker in order to monitor unlock failure cases.
729 class ScreenUnlockObserver
: public ScreenLockUnlockObserver
,
730 public chromeos::LoginStatusConsumer
{
732 ScreenUnlockObserver(AutomationProvider
* automation
,
733 IPC::Message
* reply_message
);
734 virtual ~ScreenUnlockObserver();
736 virtual void OnLoginFailure(const chromeos::LoginFailure
& error
);
738 virtual void OnLoginSuccess(const chromeos::UserContext
& user_context
) {}
741 DISALLOW_COPY_AND_ASSIGN(ScreenUnlockObserver
);
744 #endif // defined(OS_CHROMEOS)
746 // Waits for the bookmark model to load.
747 class AutomationProviderBookmarkModelObserver
: public BookmarkModelObserver
{
749 AutomationProviderBookmarkModelObserver(AutomationProvider
* provider
,
750 IPC::Message
* reply_message
,
751 BookmarkModel
* model
,
752 bool use_json_interface
);
753 virtual ~AutomationProviderBookmarkModelObserver();
755 // BookmarkModelObserver:
756 virtual void BookmarkModelLoaded(BookmarkModel
* model
,
757 bool ids_reassigned
) OVERRIDE
;
758 virtual void BookmarkModelBeingDeleted(BookmarkModel
* model
) OVERRIDE
;
759 virtual void BookmarkNodeMoved(BookmarkModel
* model
,
760 const BookmarkNode
* old_parent
,
762 const BookmarkNode
* new_parent
,
763 int new_index
) OVERRIDE
{}
764 virtual void BookmarkNodeAdded(BookmarkModel
* model
,
765 const BookmarkNode
* parent
,
766 int index
) OVERRIDE
{}
767 virtual void BookmarkNodeRemoved(BookmarkModel
* model
,
768 const BookmarkNode
* parent
,
770 const BookmarkNode
* node
) OVERRIDE
{}
771 virtual void BookmarkAllNodesRemoved(BookmarkModel
* model
) OVERRIDE
{}
772 virtual void BookmarkNodeChanged(BookmarkModel
* model
,
773 const BookmarkNode
* node
) OVERRIDE
{}
774 virtual void BookmarkNodeFaviconChanged(BookmarkModel
* model
,
775 const BookmarkNode
* node
) OVERRIDE
{}
776 virtual void BookmarkNodeChildrenReordered(
777 BookmarkModel
* model
,
778 const BookmarkNode
* node
) OVERRIDE
{}
780 IPC::Message
* ReleaseReply();
783 // Reply to the automation message with the given success value,
784 // then delete myself (which removes myself from the bookmark model
786 void ReplyAndDelete(bool success
);
788 base::WeakPtr
<AutomationProvider
> automation_provider_
;
789 scoped_ptr
<IPC::Message
> reply_message_
;
790 BookmarkModel
* model_
;
791 bool use_json_interface_
;
793 DISALLOW_COPY_AND_ASSIGN(AutomationProviderBookmarkModelObserver
);
796 // Allows the automation provider to wait until the download has been updated
798 class AutomationProviderDownloadUpdatedObserver
799 : public content::DownloadItem::Observer
{
801 AutomationProviderDownloadUpdatedObserver(
802 AutomationProvider
* provider
,
803 IPC::Message
* reply_message
,
806 virtual ~AutomationProviderDownloadUpdatedObserver();
808 virtual void OnDownloadUpdated(content::DownloadItem
* download
);
809 virtual void OnDownloadOpened(content::DownloadItem
* download
);
812 base::WeakPtr
<AutomationProvider
> provider_
;
813 scoped_ptr
<IPC::Message
> reply_message_
;
817 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadUpdatedObserver
);
820 // Allows the automation provider to wait until the download model has changed
821 // (because a new download has been added or removed).
822 class AutomationProviderDownloadModelChangedObserver
823 : public AllDownloadItemNotifier::Observer
{
825 AutomationProviderDownloadModelChangedObserver(
826 AutomationProvider
* provider
,
827 IPC::Message
* reply_message
,
828 content::DownloadManager
* download_manager
);
829 virtual ~AutomationProviderDownloadModelChangedObserver();
831 virtual void OnDownloadCreated(
832 content::DownloadManager
* manager
, content::DownloadItem
* item
) OVERRIDE
;
833 virtual void OnDownloadRemoved(
834 content::DownloadManager
* manager
, content::DownloadItem
* item
) OVERRIDE
;
839 base::WeakPtr
<AutomationProvider
> provider_
;
840 scoped_ptr
<IPC::Message
> reply_message_
;
841 AllDownloadItemNotifier notifier_
;
843 DISALLOW_COPY_AND_ASSIGN(AutomationProviderDownloadModelChangedObserver
);
846 // Observes when all pending downloads have completed.
847 class AllDownloadsCompleteObserver
848 : public content::DownloadManager::Observer
,
849 public content::DownloadItem::Observer
{
851 AllDownloadsCompleteObserver(
852 AutomationProvider
* provider
,
853 IPC::Message
* reply_message
,
854 content::DownloadManager
* download_manager
,
855 base::ListValue
* pre_download_ids
);
856 virtual ~AllDownloadsCompleteObserver();
858 // content::DownloadManager::Observer.
859 virtual void OnDownloadCreated(
860 content::DownloadManager
* manager
, content::DownloadItem
* item
) OVERRIDE
;
861 virtual void ManagerGoingDown(content::DownloadManager
* manager
) OVERRIDE
;
863 // content::DownloadItem::Observer.
864 virtual void OnDownloadUpdated(content::DownloadItem
* download
) OVERRIDE
;
867 void ReplyIfNecessary();
869 base::WeakPtr
<AutomationProvider
> provider_
;
870 scoped_ptr
<IPC::Message
> reply_message_
;
871 content::DownloadManager
* download_manager_
;
872 std::set
<int> pre_download_ids_
;
873 std::set
<content::DownloadItem
*> pending_downloads_
;
875 DISALLOW_COPY_AND_ASSIGN(AllDownloadsCompleteObserver
);
878 // Allows automation provider to wait until TemplateURLService has loaded
879 // before looking up/returning search engine info.
880 class AutomationProviderSearchEngineObserver
881 : public TemplateURLServiceObserver
{
883 AutomationProviderSearchEngineObserver(
884 AutomationProvider
* provider
,
886 IPC::Message
* reply_message
);
887 virtual ~AutomationProviderSearchEngineObserver();
889 virtual void OnTemplateURLServiceChanged();
892 base::WeakPtr
<AutomationProvider
> provider_
;
894 scoped_ptr
<IPC::Message
> reply_message_
;
896 DISALLOW_COPY_AND_ASSIGN(AutomationProviderSearchEngineObserver
);
899 // Allows the automation provider to wait for history queries to finish.
900 class AutomationProviderHistoryObserver
{
902 AutomationProviderHistoryObserver(
903 AutomationProvider
* provider
,
904 IPC::Message
* reply_message
);
905 virtual ~AutomationProviderHistoryObserver();
907 void HistoryQueryComplete(HistoryService::Handle request_handle
,
908 history::QueryResults
* results
);
911 base::WeakPtr
<AutomationProvider
> provider_
;
912 scoped_ptr
<IPC::Message
> reply_message_
;
915 // Allows the automation provider to wait for import queries to finish.
916 class AutomationProviderImportSettingsObserver
917 : public importer::ImporterProgressObserver
{
919 AutomationProviderImportSettingsObserver(
920 AutomationProvider
* provider
,
921 IPC::Message
* reply_message
);
922 virtual ~AutomationProviderImportSettingsObserver();
924 // importer::ImporterProgressObserver:
925 virtual void ImportStarted() OVERRIDE
;
926 virtual void ImportItemStarted(importer::ImportItem item
) OVERRIDE
;
927 virtual void ImportItemEnded(importer::ImportItem item
) OVERRIDE
;
928 virtual void ImportEnded() OVERRIDE
;
931 base::WeakPtr
<AutomationProvider
> provider_
;
932 scoped_ptr
<IPC::Message
> reply_message_
;
935 // Allows automation provider to wait for getting passwords to finish.
936 class AutomationProviderGetPasswordsObserver
: public PasswordStoreConsumer
{
938 AutomationProviderGetPasswordsObserver(
939 AutomationProvider
* provider
,
940 IPC::Message
* reply_message
);
941 virtual ~AutomationProviderGetPasswordsObserver();
943 // PasswordStoreConsumer implementation.
944 virtual void OnGetPasswordStoreResults(
945 const std::vector
<autofill::PasswordForm
*>& results
) OVERRIDE
;
948 base::WeakPtr
<AutomationProvider
> provider_
;
949 scoped_ptr
<IPC::Message
> reply_message_
;
952 // Allows automation provider to wait until page load after selecting an item
953 // in the omnibox popup.
954 class OmniboxAcceptNotificationObserver
: public content::NotificationObserver
{
956 OmniboxAcceptNotificationObserver(content::NavigationController
* controller
,
957 AutomationProvider
* automation
,
958 IPC::Message
* reply_message
);
959 virtual ~OmniboxAcceptNotificationObserver();
961 // Overridden from content::NotificationObserver:
962 virtual void Observe(int type
,
963 const content::NotificationSource
& source
,
964 const content::NotificationDetails
& details
) OVERRIDE
;
967 content::NotificationRegistrar registrar_
;
968 base::WeakPtr
<AutomationProvider
> automation_
;
969 scoped_ptr
<IPC::Message
> reply_message_
;
970 content::NavigationController
* controller_
;
972 DISALLOW_COPY_AND_ASSIGN(OmniboxAcceptNotificationObserver
);
975 // Allows the automation provider to wait for a save package notification.
976 class SavePackageNotificationObserver
977 : public content::DownloadManager::Observer
{
979 SavePackageNotificationObserver(content::DownloadManager
* download_manager
,
980 AutomationProvider
* automation
,
981 IPC::Message
* reply_message
);
982 virtual ~SavePackageNotificationObserver();
984 // Overridden from content::DownloadManager::Observer:
985 virtual void OnSavePackageSuccessfullyFinished(
986 content::DownloadManager
* manager
, content::DownloadItem
* item
) OVERRIDE
;
987 virtual void ManagerGoingDown(content::DownloadManager
* manager
) OVERRIDE
;
990 content::DownloadManager
* download_manager_
;
991 base::WeakPtr
<AutomationProvider
> automation_
;
992 scoped_ptr
<IPC::Message
> reply_message_
;
994 DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver
);
997 class NTPInfoObserver
: public content::NotificationObserver
{
999 NTPInfoObserver(AutomationProvider
* automation
, IPC::Message
* reply_message
);
1000 virtual ~NTPInfoObserver();
1002 // Overridden from content::NotificationObserver:
1003 virtual void Observe(int type
,
1004 const content::NotificationSource
& source
,
1005 const content::NotificationDetails
& details
) OVERRIDE
;
1008 void OnTopSitesLoaded();
1009 void OnTopSitesReceived(const history::MostVisitedURLList
& visited_list
);
1011 base::WeakPtr
<AutomationProvider
> automation_
;
1012 scoped_ptr
<IPC::Message
> reply_message_
;
1013 CancelableRequestProvider::Handle request_
;
1014 scoped_ptr
<base::DictionaryValue
> ntp_info_
;
1015 history::TopSites
* top_sites_
;
1016 content::NotificationRegistrar registrar_
;
1018 DISALLOW_COPY_AND_ASSIGN(NTPInfoObserver
);
1021 // Observes when an app has been launched, as indicated by a notification that
1022 // a content load in some tab has stopped.
1023 class AppLaunchObserver
: public content::NotificationObserver
{
1025 AppLaunchObserver(content::NavigationController
* controller
,
1026 AutomationProvider
* automation
,
1027 IPC::Message
* reply_message
,
1028 extensions::LaunchContainer launch_container
);
1029 virtual ~AppLaunchObserver();
1031 // Overridden from content::NotificationObserver:
1032 virtual void Observe(int type
,
1033 const content::NotificationSource
& source
,
1034 const content::NotificationDetails
& details
) OVERRIDE
;
1037 content::NavigationController
* controller_
;
1038 base::WeakPtr
<AutomationProvider
> automation_
;
1039 scoped_ptr
<IPC::Message
> reply_message_
;
1040 content::NotificationRegistrar registrar_
;
1041 extensions::LaunchContainer launch_container_
;
1044 DISALLOW_COPY_AND_ASSIGN(AppLaunchObserver
);
1047 // Allows the automation provider to wait for a RENDERER_PROCESS_CLOSED
1049 class RendererProcessClosedObserver
: public content::NotificationObserver
{
1051 RendererProcessClosedObserver(AutomationProvider
* automation
,
1052 IPC::Message
* reply_message
);
1053 virtual ~RendererProcessClosedObserver();
1055 // Overridden from content::NotificationObserver:
1056 virtual void Observe(int type
,
1057 const content::NotificationSource
& source
,
1058 const content::NotificationDetails
& details
) OVERRIDE
;
1061 content::NotificationRegistrar registrar_
;
1062 base::WeakPtr
<AutomationProvider
> automation_
;
1063 scoped_ptr
<IPC::Message
> reply_message_
;
1065 DISALLOW_COPY_AND_ASSIGN(RendererProcessClosedObserver
);
1068 // Allows the automation provider to wait for acknowledgement that a certain
1069 // type and number of input events has been processed by the renderer.
1070 class InputEventAckNotificationObserver
: public content::NotificationObserver
{
1072 InputEventAckNotificationObserver(AutomationProvider
* automation
,
1073 IPC::Message
* reply_message
,
1074 int event_type
, int count
);
1075 virtual ~InputEventAckNotificationObserver();
1077 // Overridden from content::NotificationObserver:
1078 virtual void Observe(int type
,
1079 const content::NotificationSource
& source
,
1080 const content::NotificationDetails
& details
) OVERRIDE
;
1083 content::NotificationRegistrar registrar_
;
1084 base::WeakPtr
<AutomationProvider
> automation_
;
1085 scoped_ptr
<IPC::Message
> reply_message_
;
1089 DISALLOW_COPY_AND_ASSIGN(InputEventAckNotificationObserver
);
1092 // Observer used to listen for new tab creation to complete.
1093 class NewTabObserver
: public content::NotificationObserver
{
1095 NewTabObserver(AutomationProvider
* automation
,
1096 IPC::Message
* reply_message
,
1097 bool use_json_interface
);
1099 // Overridden from content::NotificationObserver:
1100 virtual void Observe(int type
,
1101 const content::NotificationSource
& source
,
1102 const content::NotificationDetails
& details
) OVERRIDE
;
1105 virtual ~NewTabObserver();
1107 content::NotificationRegistrar registrar_
;
1108 base::WeakPtr
<AutomationProvider
> automation_
;
1109 scoped_ptr
<IPC::Message
> reply_message_
;
1110 bool use_json_interface_
;
1112 DISALLOW_COPY_AND_ASSIGN(NewTabObserver
);
1115 // Posts a task to the PROCESS_LAUNCHER thread, once processed posts a task
1116 // back to the UI thread that notifies the provider we're done.
1117 class WaitForProcessLauncherThreadToGoIdleObserver
1118 : public base::RefCountedThreadSafe
<
1119 WaitForProcessLauncherThreadToGoIdleObserver
,
1120 content::BrowserThread::DeleteOnUIThread
> {
1122 WaitForProcessLauncherThreadToGoIdleObserver(
1123 AutomationProvider
* automation
, IPC::Message
* reply_message
);
1126 friend struct content::BrowserThread::DeleteOnThread
<
1127 content::BrowserThread::UI
>;
1128 friend class base::DeleteHelper
<WaitForProcessLauncherThreadToGoIdleObserver
>;
1130 virtual ~WaitForProcessLauncherThreadToGoIdleObserver();
1132 // Schedules a task on the PROCESS_LAUNCHER thread to execute
1133 // |RunOnProcessLauncherThread2|. By the time the task is executed the
1134 // PROCESS_LAUNCHER thread should be some what idle.
1135 void RunOnProcessLauncherThread();
1137 // When executed the PROCESS_LAUNCHER thread should have processed any pending
1138 // tasks. Schedules a task on the UI thread that sends the message saying
1140 void RunOnProcessLauncherThread2();
1142 // Sends the |reply_message_| to |automation_| indicating we're done.
1143 void RunOnUIThread();
1145 base::WeakPtr
<AutomationProvider
> automation_
;
1146 scoped_ptr
<IPC::Message
> reply_message_
;
1148 DISALLOW_COPY_AND_ASSIGN(WaitForProcessLauncherThreadToGoIdleObserver
);
1151 // Allows the automation provider to wait for acknowledgement that a drop
1152 // operation has been processed by the renderer.
1153 class DragTargetDropAckNotificationObserver
1154 : public content::NotificationObserver
{
1156 DragTargetDropAckNotificationObserver(AutomationProvider
* automation
,
1157 IPC::Message
* reply_message
);
1158 virtual ~DragTargetDropAckNotificationObserver();
1160 // Overridden from content::NotificationObserver:
1161 virtual void Observe(int type
,
1162 const content::NotificationSource
& source
,
1163 const content::NotificationDetails
& details
) OVERRIDE
;
1166 content::NotificationRegistrar registrar_
;
1167 base::WeakPtr
<AutomationProvider
> automation_
;
1168 scoped_ptr
<IPC::Message
> reply_message_
;
1170 DISALLOW_COPY_AND_ASSIGN(DragTargetDropAckNotificationObserver
);
1173 // Allows the automation provider to wait for process memory details to be
1174 // available before sending this information to the client.
1175 class ProcessInfoObserver
: public MemoryDetails
{
1177 ProcessInfoObserver(AutomationProvider
* automation
,
1178 IPC::Message
* reply_message
);
1180 virtual void OnDetailsAvailable() OVERRIDE
;
1183 virtual ~ProcessInfoObserver();
1184 base::WeakPtr
<AutomationProvider
> automation_
;
1185 scoped_ptr
<IPC::Message
> reply_message_
;
1187 DISALLOW_COPY_AND_ASSIGN(ProcessInfoObserver
);
1190 // Observes when new v8 heap statistics are computed for a renderer process.
1191 class V8HeapStatsObserver
: public content::NotificationObserver
{
1193 V8HeapStatsObserver(AutomationProvider
* automation
,
1194 IPC::Message
* reply_message
,
1195 base::ProcessId renderer_id
);
1196 virtual ~V8HeapStatsObserver();
1198 // Overridden from content::NotificationObserver:
1199 virtual void Observe(int type
,
1200 const content::NotificationSource
& source
,
1201 const content::NotificationDetails
& details
) OVERRIDE
;
1204 content::NotificationRegistrar registrar_
;
1205 base::WeakPtr
<AutomationProvider
> automation_
;
1206 scoped_ptr
<IPC::Message
> reply_message_
;
1207 base::ProcessId renderer_id_
;
1209 DISALLOW_COPY_AND_ASSIGN(V8HeapStatsObserver
);
1212 // Observes when a new FPS value is computed for a renderer process.
1213 class FPSObserver
: public content::NotificationObserver
{
1215 FPSObserver(AutomationProvider
* automation
,
1216 IPC::Message
* reply_message
,
1217 base::ProcessId renderer_id
,
1219 virtual ~FPSObserver();
1221 // Overridden from content::NotificationObserver:
1222 virtual void Observe(int type
,
1223 const content::NotificationSource
& source
,
1224 const content::NotificationDetails
& details
) OVERRIDE
;
1227 content::NotificationRegistrar registrar_
;
1228 base::WeakPtr
<AutomationProvider
> automation_
;
1229 scoped_ptr
<IPC::Message
> reply_message_
;
1230 base::ProcessId renderer_id_
;
1233 DISALLOW_COPY_AND_ASSIGN(FPSObserver
);
1236 // Manages the process of creating a new Profile and opening a new browser with
1237 // that profile. This observer should be created, and then a new Profile
1238 // should be created through the ProfileManager using
1239 // profile_manager->CreateMultiProfileAsync(). The Observer watches for profile
1240 // creation, upon which it creates a new browser window; after observing
1241 // window creation, it creates a new tab and then finally observes it finish
1243 class BrowserOpenedWithNewProfileNotificationObserver
1244 : public content::NotificationObserver
{
1246 BrowserOpenedWithNewProfileNotificationObserver(
1247 AutomationProvider
* automation
,
1248 IPC::Message
* reply_message
);
1249 virtual ~BrowserOpenedWithNewProfileNotificationObserver();
1251 // Overridden from content::NotificationObserver:
1252 virtual void Observe(int type
,
1253 const content::NotificationSource
& source
,
1254 const content::NotificationDetails
& details
) OVERRIDE
;
1257 content::NotificationRegistrar registrar_
;
1258 base::WeakPtr
<AutomationProvider
> automation_
;
1259 scoped_ptr
<IPC::Message
> reply_message_
;
1262 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedWithNewProfileNotificationObserver
);
1265 // Waits for an extension popup to appear and load.
1266 class ExtensionPopupObserver
: public content::NotificationObserver
{
1268 ExtensionPopupObserver(
1269 AutomationProvider
* automation
,
1270 IPC::Message
* reply_message
,
1271 const std::string
& extension_id
);
1272 ~ExtensionPopupObserver();
1274 // Overridden from content::NotificationObserver:
1275 virtual void Observe(int type
,
1276 const content::NotificationSource
& source
,
1277 const content::NotificationDetails
& details
) OVERRIDE
;
1280 base::WeakPtr
<AutomationProvider
> automation_
;
1281 scoped_ptr
<IPC::Message
> reply_message_
;
1282 std::string extension_id_
;
1283 content::NotificationRegistrar registrar_
;
1285 DISALLOW_COPY_AND_ASSIGN(ExtensionPopupObserver
);
1288 #if defined(OS_LINUX)
1289 // Allows the automation provider to wait for a WINDOW_MAXIMIZED notification.
1290 class WindowMaximizedObserver
: public content::NotificationObserver
{
1292 WindowMaximizedObserver(AutomationProvider
* automation
,
1293 IPC::Message
* reply_message
);
1294 virtual ~WindowMaximizedObserver();
1296 // Overridden from content::NotificationObserver:
1297 virtual void Observe(int type
,
1298 const content::NotificationSource
& source
,
1299 const content::NotificationDetails
& details
) OVERRIDE
;
1302 content::NotificationRegistrar registrar_
;
1303 base::WeakPtr
<AutomationProvider
> automation_
;
1304 scoped_ptr
<IPC::Message
> reply_message_
;
1306 DISALLOW_COPY_AND_ASSIGN(WindowMaximizedObserver
);
1308 #endif // defined(OS_LINUX)
1310 // Wait for a new browser window to get created (for an existing profile).
1311 // Useful when reopening a multi-profile window.
1312 class BrowserOpenedWithExistingProfileNotificationObserver
1313 : public content::NotificationObserver
{
1315 BrowserOpenedWithExistingProfileNotificationObserver(
1316 AutomationProvider
* automation
,
1317 IPC::Message
* reply_message
,
1319 virtual ~BrowserOpenedWithExistingProfileNotificationObserver();
1321 virtual void Observe(int type
,
1322 const content::NotificationSource
& source
,
1323 const content::NotificationDetails
& details
);
1325 content::NotificationRegistrar registrar_
;
1326 base::WeakPtr
<AutomationProvider
> automation_
;
1327 scoped_ptr
<IPC::Message
> reply_message_
;
1331 DISALLOW_COPY_AND_ASSIGN(
1332 BrowserOpenedWithExistingProfileNotificationObserver
);
1335 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_