| 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_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 | 16 |
| 17 struct AutomationMouseEvent; |
| 17 class AutomationTabHelper; | 18 class AutomationTabHelper; |
| 18 | 19 |
| 20 namespace gfx { |
| 21 class Point; |
| 22 } |
| 23 |
| 19 // An observer API implemented by classes which are interested in various | 24 // An observer API implemented by classes which are interested in various |
| 20 // tab events from AutomationTabHelper(s). | 25 // tab events from AutomationTabHelper(s). |
| 21 class TabEventObserver { | 26 class TabEventObserver { |
| 22 public: | 27 public: |
| 23 // |LOAD_START| and |LOAD_STOP| notifications may occur several times for a | 28 // |LOAD_START| and |LOAD_STOP| notifications may occur several times for a |
| 24 // sequence of loads that may appear as one complete navigation to a user. | 29 // sequence of loads that may appear as one complete navigation to a user. |
| 25 // For instance, navigating to a non-existent page will cause a load start | 30 // For instance, navigating to a non-existent page will cause a load start |
| 26 // and stop for the non-existent page; following that, Chrome will schedule | 31 // and stop for the non-existent page; following that, Chrome will schedule |
| 27 // a navigation to an error page which causes another load start and stop. | 32 // a navigation to an error page which causes another load start and stop. |
| 28 // | 33 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 42 // | 47 // |
| 43 // This method will always be called if |OnFirstPendingLoad| was called. | 48 // This method will always be called if |OnFirstPendingLoad| was called. |
| 44 virtual void OnNoMorePendingLoads(content::WebContents* web_contents) { } | 49 virtual void OnNoMorePendingLoads(content::WebContents* web_contents) { } |
| 45 | 50 |
| 46 // Called as a result of a tab being snapshotted. | 51 // Called as a result of a tab being snapshotted. |
| 47 virtual void OnSnapshotEntirePageACK( | 52 virtual void OnSnapshotEntirePageACK( |
| 48 bool success, | 53 bool success, |
| 49 const std::vector<unsigned char>& png_data, | 54 const std::vector<unsigned char>& png_data, |
| 50 const std::string& error_msg) { } | 55 const std::string& error_msg) { } |
| 51 | 56 |
| 57 // Called immediately before the tab processes an automation mouse event. |
| 58 virtual void OnWillProcessMouseEventAt(const gfx::Point& point) { } |
| 59 |
| 60 // Called after the tab processes an automation mouse event. |
| 61 // If |success| is false, |error_msg| will be set. |
| 62 virtual void OnProcessMouseEventACK(bool success, |
| 63 const std::string& error_msg) { } |
| 64 |
| 52 protected: | 65 protected: |
| 53 TabEventObserver(); | 66 TabEventObserver(); |
| 54 virtual ~TabEventObserver(); | 67 virtual ~TabEventObserver(); |
| 55 | 68 |
| 56 // On construction, this class does not observe any events. This method | 69 // On construction, this class does not observe any events. This method |
| 57 // sets us up to observe events from the given |AutomationTabHelper|. | 70 // sets us up to observe events from the given |AutomationTabHelper|. |
| 58 void StartObserving(AutomationTabHelper* tab_helper); | 71 void StartObserving(AutomationTabHelper* tab_helper); |
| 59 | 72 |
| 60 // Stop observing events from the given |AutomationTabHelper|. This does not | 73 // Stop observing events from the given |AutomationTabHelper|. This does not |
| 61 // need to be called before the helper dies, and it is ok if this object is | 74 // need to be called before the helper dies, and it is ok if this object is |
| (...skipping 24 matching lines...) Expand all Loading... |
| 86 void RemoveObserver(TabEventObserver* observer); | 99 void RemoveObserver(TabEventObserver* observer); |
| 87 | 100 |
| 88 // Snapshots the entire page without resizing. | 101 // Snapshots the entire page without resizing. |
| 89 void SnapshotEntirePage(); | 102 void SnapshotEntirePage(); |
| 90 | 103 |
| 91 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 104 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 92 // Dumps a heap profile. | 105 // Dumps a heap profile. |
| 93 void HeapProfilerDump(const std::string& reason); | 106 void HeapProfilerDump(const std::string& reason); |
| 94 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 107 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 95 | 108 |
| 109 void ProcessMouseEvent(const AutomationMouseEvent& event); |
| 110 |
| 96 // Returns true if the tab is loading or the tab is scheduled to load | 111 // Returns true if the tab is loading or the tab is scheduled to load |
| 97 // immediately. Note that scheduled loads may be canceled. | 112 // immediately. Note that scheduled loads may be canceled. |
| 98 bool has_pending_loads() const; | 113 bool has_pending_loads() const; |
| 99 | 114 |
| 100 private: | 115 private: |
| 101 friend class AutomationTabHelperTest; | 116 friend class AutomationTabHelperTest; |
| 102 | 117 |
| 103 void OnSnapshotEntirePageACK( | 118 void OnSnapshotEntirePageACK( |
| 104 bool success, | 119 bool success, |
| 105 const std::vector<unsigned char>& png_data, | 120 const std::vector<unsigned char>& png_data, |
| 106 const std::string& error_msg); | 121 const std::string& error_msg); |
| 122 void OnWillProcessMouseEventAt(const gfx::Point& point); |
| 123 void OnProcessMouseEventACK(bool success, |
| 124 const std::string& error_msg); |
| 107 | 125 |
| 108 // content::WebContentsObserver implementation. | 126 // content::WebContentsObserver implementation. |
| 109 virtual void DidStartLoading() OVERRIDE; | 127 virtual void DidStartLoading() OVERRIDE; |
| 110 virtual void DidStopLoading() OVERRIDE; | 128 virtual void DidStopLoading() OVERRIDE; |
| 111 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 129 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 112 virtual void WebContentsDestroyed( | 130 virtual void WebContentsDestroyed( |
| 113 content::WebContents* web_contents) OVERRIDE; | 131 content::WebContents* web_contents) OVERRIDE; |
| 114 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 132 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 115 | 133 |
| 116 void OnWillPerformClientRedirect(int64 frame_id, double delay_seconds); | 134 void OnWillPerformClientRedirect(int64 frame_id, double delay_seconds); |
| 117 void OnDidCompleteOrCancelClientRedirect(int64 frame_id); | 135 void OnDidCompleteOrCancelClientRedirect(int64 frame_id); |
| 118 void OnTabOrRenderViewDestroyed(content::WebContents* web_contents); | 136 void OnTabOrRenderViewDestroyed(content::WebContents* web_contents); |
| 119 | 137 |
| 120 // True if the tab is currently loading. If a navigation is scheduled but not | 138 // True if the tab is currently loading. If a navigation is scheduled but not |
| 121 // yet loading, this will be false. | 139 // yet loading, this will be false. |
| 122 bool is_loading_; | 140 bool is_loading_; |
| 123 | 141 |
| 124 // Set of all the frames (by frame ID) that are scheduled to perform a client | 142 // Set of all the frames (by frame ID) that are scheduled to perform a client |
| 125 // redirect. | 143 // redirect. |
| 126 std::set<int64> pending_client_redirects_; | 144 std::set<int64> pending_client_redirects_; |
| 127 | 145 |
| 128 // List of all the |TabEventObserver|s, which we broadcast events to. | 146 // List of all the |TabEventObserver|s, which we broadcast events to. |
| 129 ObserverList<TabEventObserver> observers_; | 147 ObserverList<TabEventObserver> observers_; |
| 130 | 148 |
| 131 DISALLOW_COPY_AND_ASSIGN(AutomationTabHelper); | 149 DISALLOW_COPY_AND_ASSIGN(AutomationTabHelper); |
| 132 }; | 150 }; |
| 133 | 151 |
| 134 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ | 152 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ |
| OLD | NEW |