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.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h"
15 class PasswordManager;
21 namespace predictors {
22 class LoggedInPredictorTable;
27 class PrerenderManager;
29 // PrerenderTabHelper is responsible for recording perceived pageload times
30 // to compare PLT's with prerendering enabled and disabled.
31 class PrerenderTabHelper
32 : public content::WebContentsObserver,
33 public content::WebContentsUserData<PrerenderTabHelper> {
36 EVENT_LOGGED_IN_TABLE_REQUESTED = 0,
37 EVENT_LOGGED_IN_TABLE_PRESENT = 1,
38 EVENT_MAINFRAME_CHANGE = 2,
39 EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN = 3,
40 EVENT_MAINFRAME_COMMIT = 4,
41 EVENT_MAINFRAME_COMMIT_DOMAIN_LOGGED_IN = 5,
42 EVENT_LOGIN_ACTION_ADDED = 6,
43 EVENT_LOGIN_ACTION_ADDED_PW_EMPTY = 7,
47 static void CreateForWebContentsWithPasswordManager(
48 content::WebContents* web_contents,
49 PasswordManager* password_manager);
51 virtual ~PrerenderTabHelper();
53 // content::WebContentsObserver implementation.
54 virtual void ProvisionalChangeToMainFrameUrl(
56 content::RenderViewHost* render_view_host) OVERRIDE;
57 virtual void DidStopLoading(
58 content::RenderViewHost* render_view_host) OVERRIDE;
59 virtual void DidStartProvisionalLoadForFrame(
61 int64 parent_frame_id,
63 const GURL& validated_url,
65 bool is_iframe_srcdoc,
66 content::RenderViewHost* render_view_host) OVERRIDE;
67 virtual void DidCommitProvisionalLoadForFrame(
69 const string16& frame_unique_name,
71 const GURL& validated_url,
72 content::PageTransition transition_type,
73 content::RenderViewHost* render_view_host) OVERRIDE;
75 // Called when a password form has been submitted.
76 void PasswordSubmitted(const autofill::PasswordForm& form);
78 // Called when this prerendered WebContents has just been swapped in.
79 void PrerenderSwappedIn();
82 PrerenderTabHelper(content::WebContents* web_contents,
83 PasswordManager* password_manager);
84 friend class content::WebContentsUserData<PrerenderTabHelper>;
86 void RecordEvent(Event event) const;
87 void RecordEventIfLoggedInURL(Event event, const GURL& url);
88 void RecordEventIfLoggedInURLResult(Event event, scoped_ptr<bool> is_present,
89 scoped_ptr<bool> lookup_succeeded);
90 // Helper class to compute pixel-based stats on the paint progress
91 // between when a prerendered page is swapped in and when the onload event
94 scoped_ptr<PixelStats> pixel_stats_;
96 // Retrieves the PrerenderManager, or NULL, if none was found.
97 PrerenderManager* MaybeGetPrerenderManager() const;
99 // Returns whether the WebContents being observed is currently prerendering.
100 bool IsPrerendering();
102 // Returns whether the WebContents being observed was prerendered.
103 bool IsPrerendered();
105 // System time at which the current load was started for the purpose of
106 // the perceived page load time (PPLT).
107 base::TimeTicks pplt_load_start_;
109 // System time at which the actual pageload started (pre-swapin), if
110 // a applicable (in cases when a prerender that was still loading was
112 base::TimeTicks actual_load_start_;
114 // Current URL being loaded.
117 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_;
119 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper);
122 } // namespace prerender
124 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_