| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 <set> |
| 9 |
| 10 #include "chrome/common/notification_observer.h" |
| 11 #include "chrome/common/notification_registrar.h" |
| 12 #include "chrome/common/notification_type.h" |
| 13 #include "chrome/test/automation/automation_messages.h" |
| 14 |
| 15 class AutomationProvider; |
| 16 class Browser; |
| 17 class NavigationController; |
| 18 class TabContents; |
| 19 |
| 20 namespace IPC { |
| 21 class Message; |
| 22 } |
| 23 |
| 24 class InitialLoadObserver : public NotificationObserver { |
| 25 public: |
| 26 InitialLoadObserver(size_t tab_count, AutomationProvider* automation); |
| 27 ~InitialLoadObserver(); |
| 28 |
| 29 virtual void Observe(NotificationType type, |
| 30 const NotificationSource& source, |
| 31 const NotificationDetails& details); |
| 32 |
| 33 private: |
| 34 typedef std::set<uintptr_t> TabSet; |
| 35 |
| 36 void ConditionMet(); |
| 37 |
| 38 NotificationRegistrar registrar_; |
| 39 |
| 40 AutomationProvider* automation_; |
| 41 size_t outstanding_tab_count_; |
| 42 TabSet loading_tabs_; |
| 43 TabSet finished_tabs_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(InitialLoadObserver); |
| 46 }; |
| 47 |
| 48 // Watches for NewTabUI page loads for performance timing purposes. |
| 49 class NewTabUILoadObserver : public NotificationObserver { |
| 50 public: |
| 51 explicit NewTabUILoadObserver(AutomationProvider* automation); |
| 52 ~NewTabUILoadObserver(); |
| 53 |
| 54 virtual void Observe(NotificationType type, |
| 55 const NotificationSource& source, |
| 56 const NotificationDetails& details); |
| 57 |
| 58 private: |
| 59 NotificationRegistrar registrar_; |
| 60 AutomationProvider* automation_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(NewTabUILoadObserver); |
| 63 }; |
| 64 |
| 65 class NavigationControllerRestoredObserver : public NotificationObserver { |
| 66 public: |
| 67 NavigationControllerRestoredObserver(AutomationProvider* automation, |
| 68 NavigationController* controller, |
| 69 IPC::Message* reply_message); |
| 70 ~NavigationControllerRestoredObserver(); |
| 71 |
| 72 virtual void Observe(NotificationType type, |
| 73 const NotificationSource& source, |
| 74 const NotificationDetails& details); |
| 75 |
| 76 private: |
| 77 bool FinishedRestoring(); |
| 78 void SendDone(); |
| 79 |
| 80 NotificationRegistrar registrar_; |
| 81 AutomationProvider* automation_; |
| 82 NavigationController* controller_; |
| 83 IPC::Message* reply_message_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver); |
| 86 }; |
| 87 |
| 88 class NavigationNotificationObserver : public NotificationObserver { |
| 89 public: |
| 90 NavigationNotificationObserver(NavigationController* controller, |
| 91 AutomationProvider* automation, |
| 92 IPC::Message* reply_message, |
| 93 int number_of_navigations); |
| 94 ~NavigationNotificationObserver(); |
| 95 |
| 96 virtual void Observe(NotificationType type, |
| 97 const NotificationSource& source, |
| 98 const NotificationDetails& details); |
| 99 |
| 100 private: |
| 101 void ConditionMet(AutomationMsg_NavigationResponseValues navigation_result); |
| 102 |
| 103 NotificationRegistrar registrar_; |
| 104 AutomationProvider* automation_; |
| 105 IPC::Message* reply_message_; |
| 106 NavigationController* controller_; |
| 107 int navigations_remaining_; |
| 108 bool navigation_started_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); |
| 111 }; |
| 112 |
| 113 class TabStripNotificationObserver : public NotificationObserver { |
| 114 public: |
| 115 TabStripNotificationObserver(NotificationType notification, |
| 116 AutomationProvider* automation); |
| 117 virtual ~TabStripNotificationObserver(); |
| 118 |
| 119 virtual void Observe(NotificationType type, |
| 120 const NotificationSource& source, |
| 121 const NotificationDetails& details); |
| 122 |
| 123 virtual void ObserveTab(NavigationController* controller) = 0; |
| 124 |
| 125 protected: |
| 126 NotificationRegistrar registrar_; |
| 127 AutomationProvider* automation_; |
| 128 NotificationType notification_; |
| 129 }; |
| 130 |
| 131 class TabAppendedNotificationObserver : public TabStripNotificationObserver { |
| 132 public: |
| 133 TabAppendedNotificationObserver(Browser* parent, |
| 134 AutomationProvider* automation, |
| 135 IPC::Message* reply_message); |
| 136 |
| 137 virtual void ObserveTab(NavigationController* controller); |
| 138 |
| 139 protected: |
| 140 Browser* parent_; |
| 141 IPC::Message* reply_message_; |
| 142 |
| 143 private: |
| 144 DISALLOW_COPY_AND_ASSIGN(TabAppendedNotificationObserver); |
| 145 }; |
| 146 |
| 147 class TabClosedNotificationObserver : public TabStripNotificationObserver { |
| 148 public: |
| 149 TabClosedNotificationObserver(AutomationProvider* automation, |
| 150 bool wait_until_closed, |
| 151 IPC::Message* reply_message); |
| 152 |
| 153 virtual void ObserveTab(NavigationController* controller); |
| 154 |
| 155 void set_for_browser_command(bool for_browser_command); |
| 156 |
| 157 protected: |
| 158 IPC::Message* reply_message_; |
| 159 bool for_browser_command_; |
| 160 |
| 161 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(TabClosedNotificationObserver); |
| 163 }; |
| 164 |
| 165 class BrowserOpenedNotificationObserver : public NotificationObserver { |
| 166 public: |
| 167 BrowserOpenedNotificationObserver(AutomationProvider* automation, |
| 168 IPC::Message* reply_message); |
| 169 ~BrowserOpenedNotificationObserver(); |
| 170 |
| 171 virtual void Observe(NotificationType type, |
| 172 const NotificationSource& source, |
| 173 const NotificationDetails& details); |
| 174 |
| 175 void set_for_browser_command(bool for_browser_command); |
| 176 |
| 177 private: |
| 178 NotificationRegistrar registrar_; |
| 179 AutomationProvider* automation_; |
| 180 IPC::Message* reply_message_; |
| 181 bool for_browser_command_; |
| 182 |
| 183 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver); |
| 184 }; |
| 185 |
| 186 class BrowserClosedNotificationObserver : public NotificationObserver { |
| 187 public: |
| 188 BrowserClosedNotificationObserver(Browser* browser, |
| 189 AutomationProvider* automation, |
| 190 IPC::Message* reply_message); |
| 191 |
| 192 virtual void Observe(NotificationType type, |
| 193 const NotificationSource& source, |
| 194 const NotificationDetails& details); |
| 195 |
| 196 void set_for_browser_command(bool for_browser_command); |
| 197 |
| 198 private: |
| 199 NotificationRegistrar registrar_; |
| 200 AutomationProvider* automation_; |
| 201 IPC::Message* reply_message_; |
| 202 bool for_browser_command_; |
| 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(BrowserClosedNotificationObserver); |
| 205 }; |
| 206 |
| 207 class BrowserCountChangeNotificationObserver : public NotificationObserver { |
| 208 public: |
| 209 BrowserCountChangeNotificationObserver(int target_count, |
| 210 AutomationProvider* automation, |
| 211 IPC::Message* reply_message); |
| 212 |
| 213 virtual void Observe(NotificationType type, |
| 214 const NotificationSource& source, |
| 215 const NotificationDetails& details); |
| 216 |
| 217 private: |
| 218 int target_count_; |
| 219 NotificationRegistrar registrar_; |
| 220 AutomationProvider* automation_; |
| 221 IPC::Message* reply_message_; |
| 222 |
| 223 DISALLOW_COPY_AND_ASSIGN(BrowserCountChangeNotificationObserver); |
| 224 }; |
| 225 |
| 226 class AppModalDialogShownObserver : public NotificationObserver { |
| 227 public: |
| 228 AppModalDialogShownObserver(AutomationProvider* automation, |
| 229 IPC::Message* reply_message); |
| 230 ~AppModalDialogShownObserver(); |
| 231 |
| 232 virtual void Observe(NotificationType type, |
| 233 const NotificationSource& source, |
| 234 const NotificationDetails& details); |
| 235 |
| 236 private: |
| 237 NotificationRegistrar registrar_; |
| 238 AutomationProvider* automation_; |
| 239 IPC::Message* reply_message_; |
| 240 |
| 241 DISALLOW_COPY_AND_ASSIGN(AppModalDialogShownObserver); |
| 242 }; |
| 243 |
| 244 class ExecuteBrowserCommandObserver : public NotificationObserver { |
| 245 public: |
| 246 ~ExecuteBrowserCommandObserver(); |
| 247 |
| 248 static bool CreateAndRegisterObserver(AutomationProvider* automation, |
| 249 Browser* browser, |
| 250 int command, |
| 251 IPC::Message* reply_message); |
| 252 |
| 253 virtual void Observe(NotificationType type, |
| 254 const NotificationSource& source, |
| 255 const NotificationDetails& details); |
| 256 |
| 257 private: |
| 258 ExecuteBrowserCommandObserver(AutomationProvider* automation, |
| 259 IPC::Message* reply_message); |
| 260 |
| 261 bool Register(int command); |
| 262 |
| 263 bool GetNotificationType(int command, NotificationType::Type* type); |
| 264 |
| 265 NotificationRegistrar registrar_; |
| 266 AutomationProvider* automation_; |
| 267 NotificationType::Type notification_type_; |
| 268 IPC::Message* reply_message_; |
| 269 |
| 270 DISALLOW_COPY_AND_ASSIGN(ExecuteBrowserCommandObserver); |
| 271 }; |
| 272 |
| 273 class FindInPageNotificationObserver : public NotificationObserver { |
| 274 public: |
| 275 FindInPageNotificationObserver(AutomationProvider* automation, |
| 276 TabContents* parent_tab, |
| 277 IPC::Message* reply_message); |
| 278 ~FindInPageNotificationObserver(); |
| 279 |
| 280 virtual void Observe(NotificationType type, |
| 281 const NotificationSource& source, |
| 282 const NotificationDetails& details); |
| 283 |
| 284 // The Find mechanism is over asynchronous IPC, so a search is kicked off and |
| 285 // we wait for notification to find out what the results are. As the user is |
| 286 // typing, new search requests can be issued and the Request ID helps us make |
| 287 // sense of whether this is the current request or an old one. The unit tests, |
| 288 // however, which uses this constant issues only one search at a time, so we |
| 289 // don't need a rolling id to identify each search. But, we still need to |
| 290 // specify one, so we just use a fixed one - its value does not matter. |
| 291 static const int kFindInPageRequestId; |
| 292 |
| 293 private: |
| 294 NotificationRegistrar registrar_; |
| 295 AutomationProvider* automation_; |
| 296 // We will at some point (before final update) be notified of the ordinal and |
| 297 // we need to preserve it so we can send it later. |
| 298 int active_match_ordinal_; |
| 299 IPC::Message* reply_message_; |
| 300 |
| 301 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); |
| 302 }; |
| 303 |
| 304 class DomOperationNotificationObserver : public NotificationObserver { |
| 305 public: |
| 306 explicit DomOperationNotificationObserver(AutomationProvider* automation); |
| 307 ~DomOperationNotificationObserver(); |
| 308 |
| 309 virtual void Observe(NotificationType type, |
| 310 const NotificationSource& source, |
| 311 const NotificationDetails& details); |
| 312 |
| 313 private: |
| 314 NotificationRegistrar registrar_; |
| 315 AutomationProvider* automation_; |
| 316 |
| 317 DISALLOW_COPY_AND_ASSIGN(DomOperationNotificationObserver); |
| 318 }; |
| 319 |
| 320 #if defined(OS_WIN) |
| 321 // TODO(port): Enable when printing is ported. |
| 322 class DocumentPrintedNotificationObserver : public NotificationObserver { |
| 323 public: |
| 324 DocumentPrintedNotificationObserver(AutomationProvider* automation, |
| 325 IPC::Message* reply_message); |
| 326 ~DocumentPrintedNotificationObserver(); |
| 327 |
| 328 virtual void Observe(NotificationType type, const NotificationSource& source, |
| 329 const NotificationDetails& details); |
| 330 |
| 331 private: |
| 332 NotificationRegistrar registrar_; |
| 333 scoped_refptr<AutomationProvider> automation_; |
| 334 bool success_; |
| 335 IPC::Message* reply_message_; |
| 336 |
| 337 DISALLOW_COPY_AND_ASSIGN(DocumentPrintedNotificationObserver); |
| 338 }; |
| 339 #endif // defined(OS_WIN) |
| 340 |
| 341 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ |
| OLD | NEW |