OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ | 5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ |
6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ | 6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/sequenced_task_runner_helpers.h" | 18 #include "base/sequenced_task_runner_helpers.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/automation/automation_provider_json.h" | 21 #include "chrome/browser/automation/automation_provider_json.h" |
22 #include "chrome/browser/automation/automation_tab_helper.h" | |
23 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
24 #include "components/autofill/browser/personal_data_manager.h" | 23 #include "components/autofill/browser/personal_data_manager.h" |
25 #include "components/autofill/browser/personal_data_manager_observer.h" | 24 #include "components/autofill/browser/personal_data_manager_observer.h" |
26 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
27 #include "chrome/browser/chromeos/cros/network_library.h" | 26 #include "chrome/browser/chromeos/cros/network_library.h" |
28 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" | 27 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" |
29 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 28 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
30 #include "chrome/browser/chromeos/login/user_manager.h" | 29 #include "chrome/browser/chromeos/login/user_manager.h" |
31 #include "chrome/browser/chromeos/login/wizard_controller.h" | 30 #include "chrome/browser/chromeos/login/wizard_controller.h" |
32 #endif // defined(OS_CHROMEOS) | 31 #endif // defined(OS_CHROMEOS) |
(...skipping 13 matching lines...) Expand all Loading... |
46 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
47 #include "content/public/browser/download_item.h" | 46 #include "content/public/browser/download_item.h" |
48 #include "content/public/browser/download_manager.h" | 47 #include "content/public/browser/download_manager.h" |
49 #include "content/public/browser/notification_observer.h" | 48 #include "content/public/browser/notification_observer.h" |
50 #include "content/public/browser/notification_registrar.h" | 49 #include "content/public/browser/notification_registrar.h" |
51 #include "content/public/browser/notification_types.h" | 50 #include "content/public/browser/notification_types.h" |
52 #include "content/public/browser/render_view_host_observer.h" | 51 #include "content/public/browser/render_view_host_observer.h" |
53 #include "ui/gfx/point.h" | 52 #include "ui/gfx/point.h" |
54 #include "ui/gfx/size.h" | 53 #include "ui/gfx/size.h" |
55 | 54 |
56 struct AutomationMouseEvent; | |
57 class AutomationProvider; | 55 class AutomationProvider; |
58 class BalloonCollection; | 56 class BalloonCollection; |
59 class Browser; | 57 class Browser; |
60 class ExtensionProcessManager; | 58 class ExtensionProcessManager; |
61 class ExtensionService; | 59 class ExtensionService; |
62 class Notification; | 60 class Notification; |
63 class Profile; | 61 class Profile; |
64 class SavePackage; | 62 class SavePackage; |
65 | 63 |
66 namespace automation { | 64 namespace automation { |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; | 1257 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; |
1260 | 1258 |
1261 private: | 1259 private: |
1262 content::DownloadManager* download_manager_; | 1260 content::DownloadManager* download_manager_; |
1263 base::WeakPtr<AutomationProvider> automation_; | 1261 base::WeakPtr<AutomationProvider> automation_; |
1264 scoped_ptr<IPC::Message> reply_message_; | 1262 scoped_ptr<IPC::Message> reply_message_; |
1265 | 1263 |
1266 DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver); | 1264 DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver); |
1267 }; | 1265 }; |
1268 | 1266 |
1269 // This class manages taking a snapshot of a page. | |
1270 class PageSnapshotTaker : public TabEventObserver, | |
1271 public content::NotificationObserver { | |
1272 public: | |
1273 PageSnapshotTaker(AutomationProvider* automation, | |
1274 IPC::Message* reply_message, | |
1275 content::WebContents* web_contents, | |
1276 const base::FilePath& path); | |
1277 virtual ~PageSnapshotTaker(); | |
1278 | |
1279 // Start the process of taking a snapshot of the entire page. | |
1280 void Start(); | |
1281 | |
1282 private: | |
1283 // Overridden from TabEventObserver: | |
1284 virtual void OnSnapshotEntirePageACK( | |
1285 bool success, | |
1286 const std::vector<unsigned char>& png_data, | |
1287 const std::string& error_msg) OVERRIDE; | |
1288 | |
1289 // Overridden from content::NotificationObserver: | |
1290 virtual void Observe(int type, | |
1291 const content::NotificationSource& source, | |
1292 const content::NotificationDetails& details) OVERRIDE; | |
1293 | |
1294 // Helper method to send a response back to the client. Deletes this. | |
1295 void SendMessage(bool success, const std::string& error_msg); | |
1296 | |
1297 base::WeakPtr<AutomationProvider> automation_; | |
1298 scoped_ptr<IPC::Message> reply_message_; | |
1299 content::WebContents* web_contents_; | |
1300 base::FilePath image_path_; | |
1301 content::NotificationRegistrar registrar_; | |
1302 | |
1303 DISALLOW_COPY_AND_ASSIGN(PageSnapshotTaker); | |
1304 }; | |
1305 | |
1306 // Processes automation mouse events and invokes a callback when processing | |
1307 // has completed. | |
1308 class AutomationMouseEventProcessor : public content::RenderViewHostObserver, | |
1309 public content::NotificationObserver { | |
1310 public: | |
1311 typedef base::Callback<void(const gfx::Point&)> CompletionCallback; | |
1312 typedef base::Callback<void(const automation::Error&)> ErrorCallback; | |
1313 | |
1314 // Creates a new processor which immediately processes the given event. | |
1315 // Either the |completion_callback| or |error_callback| will be called | |
1316 // exactly once. After invoking the callback, this class will delete itself. | |
1317 // The |completion_callback| will be given the point at which the mouse event | |
1318 // occurred. | |
1319 AutomationMouseEventProcessor(content::RenderViewHost* render_view_host, | |
1320 const AutomationMouseEvent& event, | |
1321 const CompletionCallback& completion_callback, | |
1322 const ErrorCallback& error_callback); | |
1323 virtual ~AutomationMouseEventProcessor(); | |
1324 | |
1325 private: | |
1326 // IPC message handlers. | |
1327 virtual void OnWillProcessMouseEventAt(const gfx::Point& point); | |
1328 virtual void OnProcessMouseEventACK( | |
1329 bool success, | |
1330 const std::string& error_msg); | |
1331 | |
1332 // Overriden from RenderViewHostObserver. | |
1333 virtual void RenderViewHostDestroyed(content::RenderViewHost* host) OVERRIDE; | |
1334 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
1335 | |
1336 // Overridden from content::NotificationObserver: | |
1337 virtual void Observe(int type, | |
1338 const content::NotificationSource& source, | |
1339 const content::NotificationDetails& details) OVERRIDE; | |
1340 | |
1341 // Helper method to invoke the appropriate callback. Uses the given error | |
1342 // only if the operation failed. Deletes this. | |
1343 void InvokeCallback(const automation::Error& error); | |
1344 | |
1345 content::NotificationRegistrar registrar_; | |
1346 CompletionCallback completion_callback_; | |
1347 ErrorCallback error_callback_; | |
1348 bool has_point_; | |
1349 gfx::Point point_; | |
1350 | |
1351 DISALLOW_COPY_AND_ASSIGN(AutomationMouseEventProcessor); | |
1352 }; | |
1353 | |
1354 class NTPInfoObserver : public content::NotificationObserver { | 1267 class NTPInfoObserver : public content::NotificationObserver { |
1355 public: | 1268 public: |
1356 NTPInfoObserver(AutomationProvider* automation, IPC::Message* reply_message); | 1269 NTPInfoObserver(AutomationProvider* automation, IPC::Message* reply_message); |
1357 virtual ~NTPInfoObserver(); | 1270 virtual ~NTPInfoObserver(); |
1358 | 1271 |
1359 // Overridden from content::NotificationObserver: | 1272 // Overridden from content::NotificationObserver: |
1360 virtual void Observe(int type, | 1273 virtual void Observe(int type, |
1361 const content::NotificationSource& source, | 1274 const content::NotificationSource& source, |
1362 const content::NotificationDetails& details) OVERRIDE; | 1275 const content::NotificationDetails& details) OVERRIDE; |
1363 | 1276 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 private: | 1431 private: |
1519 content::NotificationRegistrar registrar_; | 1432 content::NotificationRegistrar registrar_; |
1520 base::WeakPtr<AutomationProvider> automation_; | 1433 base::WeakPtr<AutomationProvider> automation_; |
1521 scoped_ptr<IPC::Message> reply_message_; | 1434 scoped_ptr<IPC::Message> reply_message_; |
1522 int event_type_; | 1435 int event_type_; |
1523 int count_; | 1436 int count_; |
1524 | 1437 |
1525 DISALLOW_COPY_AND_ASSIGN(InputEventAckNotificationObserver); | 1438 DISALLOW_COPY_AND_ASSIGN(InputEventAckNotificationObserver); |
1526 }; | 1439 }; |
1527 | 1440 |
1528 // Allows the automation provider to wait for all render views to finish any | |
1529 // pending loads. This wait is only guaranteed for views that exist at the | |
1530 // observer's creation. Will send a message on construction if no views are | |
1531 // currently loading. | |
1532 class AllViewsStoppedLoadingObserver : public TabEventObserver, | |
1533 public content::NotificationObserver { | |
1534 public: | |
1535 AllViewsStoppedLoadingObserver( | |
1536 AutomationProvider* automation, | |
1537 IPC::Message* reply_message, | |
1538 ExtensionProcessManager* extension_process_manager); | |
1539 virtual ~AllViewsStoppedLoadingObserver(); | |
1540 | |
1541 // TabEventObserver implementation. | |
1542 virtual void OnFirstPendingLoad(content::WebContents* web_contents) OVERRIDE; | |
1543 virtual void OnNoMorePendingLoads( | |
1544 content::WebContents* web_contents) OVERRIDE; | |
1545 | |
1546 // Overridden from content::NotificationObserver: | |
1547 virtual void Observe(int type, | |
1548 const content::NotificationSource& source, | |
1549 const content::NotificationDetails& details) OVERRIDE; | |
1550 | |
1551 private: | |
1552 typedef std::set<content::WebContents*> TabSet; | |
1553 | |
1554 // Checks if there are no pending loads. If none, it will send an automation | |
1555 // relpy and delete itself. | |
1556 void CheckIfNoMorePendingLoads(); | |
1557 | |
1558 base::WeakPtr<AutomationProvider> automation_; | |
1559 scoped_ptr<IPC::Message> reply_message_; | |
1560 ExtensionProcessManager* extension_process_manager_; | |
1561 content::NotificationRegistrar registrar_; | |
1562 TabSet pending_tabs_; | |
1563 | |
1564 DISALLOW_COPY_AND_ASSIGN(AllViewsStoppedLoadingObserver); | |
1565 }; | |
1566 | |
1567 // Observer used to listen for new tab creation to complete. | 1441 // Observer used to listen for new tab creation to complete. |
1568 class NewTabObserver : public content::NotificationObserver { | 1442 class NewTabObserver : public content::NotificationObserver { |
1569 public: | 1443 public: |
1570 NewTabObserver(AutomationProvider* automation, | 1444 NewTabObserver(AutomationProvider* automation, |
1571 IPC::Message* reply_message, | 1445 IPC::Message* reply_message, |
1572 bool use_json_interface); | 1446 bool use_json_interface); |
1573 | 1447 |
1574 // Overridden from content::NotificationObserver: | 1448 // Overridden from content::NotificationObserver: |
1575 virtual void Observe(int type, | 1449 virtual void Observe(int type, |
1576 const content::NotificationSource& source, | 1450 const content::NotificationSource& source, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 base::WeakPtr<AutomationProvider> automation_; | 1675 base::WeakPtr<AutomationProvider> automation_; |
1802 scoped_ptr<IPC::Message> reply_message_; | 1676 scoped_ptr<IPC::Message> reply_message_; |
1803 int new_window_id_; | 1677 int new_window_id_; |
1804 int num_loads_; | 1678 int num_loads_; |
1805 | 1679 |
1806 DISALLOW_COPY_AND_ASSIGN( | 1680 DISALLOW_COPY_AND_ASSIGN( |
1807 BrowserOpenedWithExistingProfileNotificationObserver); | 1681 BrowserOpenedWithExistingProfileNotificationObserver); |
1808 }; | 1682 }; |
1809 | 1683 |
1810 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ | 1684 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ |
OLD | NEW |