Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / automation / automation_event_observers.h
bloba509e36a28bea41e4d7716b9fb20534ddf24acbc
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_EVENT_OBSERVERS_H_
6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_OBSERVERS_H_
8 #include "base/compiler_specific.h"
9 #include "base/values.h"
10 #include "chrome/browser/automation/automation_event_queue.h"
11 #include "chrome/browser/automation/automation_provider.h"
12 #include "chrome/browser/automation/automation_provider_observers.h"
13 #if defined(OS_CHROMEOS)
14 #include "chrome/browser/chromeos/login/login_status_consumer.h"
15 #endif // defined(OS_CHROMEOS)
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
19 // AutomationEventObserver watches for a specific event, and pushes an
20 // AutomationEvent into the AutomationEventQueue for each occurance.
21 class AutomationEventObserver {
22 public:
23 explicit AutomationEventObserver(AutomationEventQueue* event_queue,
24 bool recurring);
25 virtual ~AutomationEventObserver();
27 virtual void Init(int observer_id);
28 void NotifyEvent(base::DictionaryValue* value);
29 int GetId() const;
31 protected:
32 void RemoveIfDone(); // This may delete the object.
34 private:
35 AutomationEventQueue* event_queue_;
36 bool recurring_;
37 int observer_id_;
38 // TODO(craigdh): Add a PyAuto hook to retrieve the number of times an event
39 // has occurred.
40 int event_count_;
42 DISALLOW_COPY_AND_ASSIGN(AutomationEventObserver);
45 // AutomationEventObserver implementation that listens for explicitly raised
46 // events. A webpage explicitly raises events by calling:
47 // window.domAutomationController.sendWithId(automation_id, event_name);
48 class DomEventObserver
49 : public AutomationEventObserver, public content::NotificationObserver {
50 public:
51 DomEventObserver(AutomationEventQueue* event_queue,
52 const std::string& event_name,
53 int automation_id,
54 bool recurring);
55 virtual ~DomEventObserver();
57 virtual void Init(int observer_id) OVERRIDE;
58 virtual void Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE;
62 private:
63 std::string event_name_;
64 std::string event_name_base_;
65 int automation_id_;
66 content::NotificationRegistrar registrar_;
68 // The first instance of this string in an event name will be replaced with
69 // the id of this observer.
70 static const char* kSubstringReplaceWithObserverId;
72 DISALLOW_COPY_AND_ASSIGN(DomEventObserver);
75 #if defined(OS_CHROMEOS)
77 namespace chromeos {
78 struct UserContext;
81 // Event observer that listens for the completion of login.
82 class LoginEventObserver
83 : public AutomationEventObserver,
84 public chromeos::LoginStatusConsumer {
85 public:
86 LoginEventObserver(AutomationEventQueue* event_queue,
87 AutomationProvider* automation);
88 virtual ~LoginEventObserver();
90 // chromeos::LoginStatusConsumer:
91 virtual void OnLoginFailure(const chromeos::LoginFailure& error) OVERRIDE;
92 virtual void OnLoginSuccess(
93 const chromeos::UserContext& user_context) OVERRIDE;
95 private:
96 base::WeakPtr<AutomationProvider> automation_;
98 void _NotifyLoginEvent(const std::string& error_string);
100 DISALLOW_COPY_AND_ASSIGN(LoginEventObserver);
103 #endif // defined(OS_CHROMEOS)
105 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EVENT_OBSERVERS_H_