Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/automation/automation_tab_helper.h

Issue 14977013: Delete Automation[Tab/Renderer]Helper and users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update now that 202087 is committed Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_
6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h"
16
17 class AutomationTabHelper;
18
19 // An observer API implemented by classes which are interested in various
20 // tab events from AutomationTabHelper(s).
21 class TabEventObserver {
22 public:
23 // |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.
25 // 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
27 // a navigation to an error page which causes another load start and stop.
28 //
29 // A pending load is a load that is currently in progress or one that is
30 // scheduled to occur immediately. The only scheduled loads that are
31 // tracked are client redirects, such as javascript redirects.
32 // TODO(kkania): Handle redirects that are scheduled to occur later, and
33 // change this definition of a pending load.
34 // TODO(kkania): Track other types of scheduled navigations.
35
36 // Called when the tab that had no pending loads now has a new pending
37 // load. |web_contents| will always be valid.
38 virtual void OnFirstPendingLoad(content::WebContents* web_contents) { }
39
40 // Called when the tab that had one or more pending loads now has no
41 // pending loads. |web_contents| will always be valid.
42 //
43 // This method will always be called if |OnFirstPendingLoad| was called.
44 virtual void OnNoMorePendingLoads(content::WebContents* web_contents) { }
45
46 // Called as a result of a tab being snapshotted.
47 virtual void OnSnapshotEntirePageACK(
48 bool success,
49 const std::vector<unsigned char>& png_data,
50 const std::string& error_msg) { }
51
52 protected:
53 TabEventObserver();
54 virtual ~TabEventObserver();
55
56 // On construction, this class does not observe any events. This method
57 // sets us up to observe events from the given |AutomationTabHelper|.
58 void StartObserving(AutomationTabHelper* tab_helper);
59
60 // 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
62 // destructed while it is still observing an |AutomationTabHelper|.
63 void StopObserving(AutomationTabHelper* tab_helper);
64
65 private:
66 friend class AutomationTabHelperTest;
67 typedef std::vector<base::WeakPtr<AutomationTabHelper> > EventSourceVector;
68
69 // Vector of all the event sources we are observing. Tracked so that this
70 // class can remove itself from each source at its destruction.
71 EventSourceVector event_sources_;
72
73 DISALLOW_COPY_AND_ASSIGN(TabEventObserver);
74 };
75
76 // Per-tab automation support class. Receives automation/testing messages
77 // from the renderer. Broadcasts tab events to |TabEventObserver|s.
78 class AutomationTabHelper
79 : public content::WebContentsObserver,
80 public base::SupportsWeakPtr<AutomationTabHelper>,
81 public content::WebContentsUserData<AutomationTabHelper> {
82 public:
83 virtual ~AutomationTabHelper();
84
85 void AddObserver(TabEventObserver* observer);
86 void RemoveObserver(TabEventObserver* observer);
87
88 // Snapshots the entire page without resizing.
89 void SnapshotEntirePage();
90
91 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
92 // Dumps a heap profile.
93 void HeapProfilerDump(const std::string& reason);
94 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
95
96 // Returns true if the tab is loading or the tab is scheduled to load
97 // immediately. Note that scheduled loads may be canceled.
98 bool has_pending_loads() const;
99
100 private:
101 explicit AutomationTabHelper(content::WebContents* web_contents);
102 friend class content::WebContentsUserData<AutomationTabHelper>;
103
104 friend class AutomationTabHelperTest;
105
106 void OnSnapshotEntirePageACK(
107 bool success,
108 const std::vector<unsigned char>& png_data,
109 const std::string& error_msg);
110
111 // content::WebContentsObserver implementation.
112 virtual void DidStartLoading(
113 content::RenderViewHost* render_view_host) OVERRIDE;
114 virtual void DidStopLoading(
115 content::RenderViewHost* render_view_host) OVERRIDE;
116 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
117 virtual void WebContentsDestroyed(
118 content::WebContents* web_contents) OVERRIDE;
119 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
120
121 void OnWillPerformClientRedirect(int64 frame_id, double delay_seconds);
122 void OnDidCompleteOrCancelClientRedirect(int64 frame_id);
123 void OnTabOrRenderViewDestroyed(content::WebContents* web_contents);
124
125 // True if the tab is currently loading. If a navigation is scheduled but not
126 // yet loading, this will be false.
127 bool is_loading_;
128
129 // Set of all the frames (by frame ID) that are scheduled to perform a client
130 // redirect.
131 std::set<int64> pending_client_redirects_;
132
133 // List of all the |TabEventObserver|s, which we broadcast events to.
134 ObserverList<TabEventObserver> observers_;
135
136 DISALLOW_COPY_AND_ASSIGN(AutomationTabHelper);
137 };
138
139 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.cc ('k') | chrome/browser/automation/automation_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698