| 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 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/tab_contents/web_contents_user_data.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 | 16 |
| 16 class AutomationTabHelper; | 17 class AutomationTabHelper; |
| 17 | 18 |
| 18 // An observer API implemented by classes which are interested in various | 19 // An observer API implemented by classes which are interested in various |
| 19 // tab events from AutomationTabHelper(s). | 20 // tab events from AutomationTabHelper(s). |
| 20 class TabEventObserver { | 21 class TabEventObserver { |
| 21 public: | 22 public: |
| 22 // |LOAD_START| and |LOAD_STOP| notifications may occur several times for a | 23 // |LOAD_START| and |LOAD_STOP| notifications may occur several times for a |
| 23 // sequence of loads that may appear as one complete navigation to a user. | 24 // sequence of loads that may appear as one complete navigation to a user. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // class can remove itself from each source at its destruction. | 70 // class can remove itself from each source at its destruction. |
| 70 EventSourceVector event_sources_; | 71 EventSourceVector event_sources_; |
| 71 | 72 |
| 72 DISALLOW_COPY_AND_ASSIGN(TabEventObserver); | 73 DISALLOW_COPY_AND_ASSIGN(TabEventObserver); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 // Per-tab automation support class. Receives automation/testing messages | 76 // Per-tab automation support class. Receives automation/testing messages |
| 76 // from the renderer. Broadcasts tab events to |TabEventObserver|s. | 77 // from the renderer. Broadcasts tab events to |TabEventObserver|s. |
| 77 class AutomationTabHelper | 78 class AutomationTabHelper |
| 78 : public content::WebContentsObserver, | 79 : public content::WebContentsObserver, |
| 79 public base::SupportsWeakPtr<AutomationTabHelper> { | 80 public base::SupportsWeakPtr<AutomationTabHelper>, |
| 81 public WebContentsUserData<AutomationTabHelper> { |
| 80 public: | 82 public: |
| 81 explicit AutomationTabHelper(content::WebContents* web_contents); | |
| 82 virtual ~AutomationTabHelper(); | 83 virtual ~AutomationTabHelper(); |
| 83 | 84 |
| 84 void AddObserver(TabEventObserver* observer); | 85 void AddObserver(TabEventObserver* observer); |
| 85 void RemoveObserver(TabEventObserver* observer); | 86 void RemoveObserver(TabEventObserver* observer); |
| 86 | 87 |
| 87 // Snapshots the entire page without resizing. | 88 // Snapshots the entire page without resizing. |
| 88 void SnapshotEntirePage(); | 89 void SnapshotEntirePage(); |
| 89 | 90 |
| 90 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 91 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 91 // Dumps a heap profile. | 92 // Dumps a heap profile. |
| 92 void HeapProfilerDump(const std::string& reason); | 93 void HeapProfilerDump(const std::string& reason); |
| 93 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 94 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 94 | 95 |
| 95 // Returns true if the tab is loading or the tab is scheduled to load | 96 // Returns true if the tab is loading or the tab is scheduled to load |
| 96 // immediately. Note that scheduled loads may be canceled. | 97 // immediately. Note that scheduled loads may be canceled. |
| 97 bool has_pending_loads() const; | 98 bool has_pending_loads() const; |
| 98 | 99 |
| 99 private: | 100 private: |
| 101 explicit AutomationTabHelper(content::WebContents* web_contents); |
| 102 static int kUserDataKey; |
| 103 friend class WebContentsUserData<AutomationTabHelper>; |
| 104 |
| 100 friend class AutomationTabHelperTest; | 105 friend class AutomationTabHelperTest; |
| 101 | 106 |
| 102 void OnSnapshotEntirePageACK( | 107 void OnSnapshotEntirePageACK( |
| 103 bool success, | 108 bool success, |
| 104 const std::vector<unsigned char>& png_data, | 109 const std::vector<unsigned char>& png_data, |
| 105 const std::string& error_msg); | 110 const std::string& error_msg); |
| 106 | 111 |
| 107 // content::WebContentsObserver implementation. | 112 // content::WebContentsObserver implementation. |
| 108 virtual void DidStartLoading( | 113 virtual void DidStartLoading( |
| 109 content::RenderViewHost* render_view_host) OVERRIDE; | 114 content::RenderViewHost* render_view_host) OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 126 // redirect. | 131 // redirect. |
| 127 std::set<int64> pending_client_redirects_; | 132 std::set<int64> pending_client_redirects_; |
| 128 | 133 |
| 129 // List of all the |TabEventObserver|s, which we broadcast events to. | 134 // List of all the |TabEventObserver|s, which we broadcast events to. |
| 130 ObserverList<TabEventObserver> observers_; | 135 ObserverList<TabEventObserver> observers_; |
| 131 | 136 |
| 132 DISALLOW_COPY_AND_ASSIGN(AutomationTabHelper); | 137 DISALLOW_COPY_AND_ASSIGN(AutomationTabHelper); |
| 133 }; | 138 }; |
| 134 | 139 |
| 135 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ | 140 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_ |
| OLD | NEW |