blob: f20368f019990cf2f2174d14365a3a01a1061c7c [file] [log] [blame]
[email protected]a0358d72012-03-09 14:06:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]4850a7f2011-03-08 23:36:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]68761472011-08-31 18:55:145#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
6#define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
[email protected]4850a7f2011-03-08 23:36:597
[email protected]9831b612012-05-15 00:56:478#include "base/memory/scoped_ptr.h"
[email protected]20a47b972013-04-17 17:26:399#include "base/memory/weak_ptr.h"
[email protected]46b3c982012-10-09 18:38:3010#include "base/time.h"
[email protected]71fde352011-12-29 03:29:5611#include "content/public/browser/web_contents_observer.h"
[email protected]46b3c982012-10-09 18:38:3012#include "content/public/browser/web_contents_user_data.h"
[email protected]71fde352011-12-29 03:29:5613#include "googleurl/src/gurl.h"
[email protected]4c94b8c2011-05-17 16:17:4514
[email protected]20a47b972013-04-17 17:26:3915namespace predictors {
16class LoggedInPredictorTable;
17}
18
[email protected]4850a7f2011-03-08 23:36:5919namespace prerender {
20
21class PrerenderManager;
22
[email protected]68761472011-08-31 18:55:1423// PrerenderTabHelper is responsible for recording perceived pageload times
[email protected]4850a7f2011-03-08 23:36:5924// to compare PLT's with prerendering enabled and disabled.
[email protected]46b3c982012-10-09 18:38:3025class PrerenderTabHelper
26 : public content::WebContentsObserver,
27 public content::WebContentsUserData<PrerenderTabHelper> {
[email protected]4850a7f2011-03-08 23:36:5928 public:
[email protected]20a47b972013-04-17 17:26:3929 enum Event {
30 EVENT_LOGGED_IN_TABLE_REQUESTED = 0,
31 EVENT_LOGGED_IN_TABLE_PRESENT = 1,
32 EVENT_MAINFRAME_CHANGE = 2,
33 EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN = 3,
34 EVENT_MAINFRAME_COMMIT = 4,
35 EVENT_MAINFRAME_COMMIT_DOMAIN_LOGGED_IN = 5,
36 EVENT_LOGIN_ACTION_ADDED = 6,
37 EVENT_MAX_VALUE
38 };
39
[email protected]68761472011-08-31 18:55:1440 virtual ~PrerenderTabHelper();
[email protected]4850a7f2011-03-08 23:36:5941
[email protected]d8c660432011-12-22 20:51:2542 // content::WebContentsObserver implementation.
[email protected]400992b2012-06-14 00:03:5443 virtual void ProvisionalChangeToMainFrameUrl(
44 const GURL& url,
[email protected]400992b2012-06-14 00:03:5445 content::RenderViewHost* render_view_host) OVERRIDE;
[email protected]89793072012-07-23 22:25:2946 virtual void DidStopLoading(
47 content::RenderViewHost* render_view_host) OVERRIDE;
[email protected]d952a052011-09-06 18:42:4548 virtual void DidStartProvisionalLoadForFrame(
49 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:1350 int64 parent_frame_id,
[email protected]d952a052011-09-06 18:42:4551 bool is_main_frame,
52 const GURL& validated_url,
53 bool is_error_page,
[email protected]ead9009e2013-01-07 22:06:3254 bool is_iframe_srcdoc,
[email protected]eaabba22012-03-07 15:02:1155 content::RenderViewHost* render_view_host) OVERRIDE;
[email protected]78566202012-05-14 20:46:5156 virtual void DidCommitProvisionalLoadForFrame(
[email protected]290beec2012-04-22 02:57:3857 int64 frame_id,
58 bool is_main_frame,
59 const GURL& validated_url,
[email protected]ef16c3e2012-05-16 22:13:4660 content::PageTransition transition_type,
61 content::RenderViewHost* render_view_host) OVERRIDE;
[email protected]20a47b972013-04-17 17:26:3962 virtual void DidNavigateAnyFrame(
63 const content::LoadCommittedDetails& details,
64 const content::FrameNavigateParams& params) OVERRIDE;
65
[email protected]a562aea22012-12-11 22:43:1266 // Called when this prerendered WebContents has just been swapped in.
[email protected]8f201ee52011-07-27 17:32:4867 void PrerenderSwappedIn();
68
69 private:
[email protected]e2baaa8f2012-10-01 21:42:0170 explicit PrerenderTabHelper(content::WebContents* web_contents);
[email protected]46b3c982012-10-09 18:38:3071 friend class content::WebContentsUserData<PrerenderTabHelper>;
[email protected]e2baaa8f2012-10-01 21:42:0172
[email protected]20a47b972013-04-17 17:26:3973 void RecordEvent(Event event) const;
74 void RecordEventIfLoggedInURL(Event event, const GURL& url);
75 void RecordEventIfLoggedInURLResult(Event event, scoped_ptr<bool> is_present,
76 scoped_ptr<bool> lookup_succeeded);
[email protected]9831b612012-05-15 00:56:4777 // Helper class to compute pixel-based stats on the paint progress
78 // between when a prerendered page is swapped in and when the onload event
79 // fires.
80 class PixelStats;
81 scoped_ptr<PixelStats> pixel_stats_;
82
[email protected]4850a7f2011-03-08 23:36:5983 // Retrieves the PrerenderManager, or NULL, if none was found.
[email protected]6005d682011-08-29 23:40:0884 PrerenderManager* MaybeGetPrerenderManager() const;
[email protected]4850a7f2011-03-08 23:36:5985
[email protected]0932b30c2012-04-17 13:25:1086 // Returns whether the WebContents being observed is currently prerendering.
[email protected]34f8edf2011-05-10 02:36:5487 bool IsPrerendering();
88
[email protected]9831b612012-05-15 00:56:4789 // Returns whether the WebContents being observed was prerendered.
90 bool IsPrerendered();
91
[email protected]4850a7f2011-03-08 23:36:5992 // System time at which the current load was started for the purpose of
93 // the perceived page load time (PPLT).
94 base::TimeTicks pplt_load_start_;
95
[email protected]b86aad872012-03-16 22:34:1296 // System time at which the actual pageload started (pre-swapin), if
97 // a applicable (in cases when a prerender that was still loading was
98 // swapped in).
99 base::TimeTicks actual_load_start_;
100
[email protected]c97f7e662011-10-04 00:50:36101 // Current URL being loaded.
102 GURL url_;
103
[email protected]20a47b972013-04-17 17:26:39104 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_;
105
[email protected]68761472011-08-31 18:55:14106 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper);
[email protected]4850a7f2011-03-08 23:36:59107};
108
[email protected]8fdb6f32011-04-26 15:22:59109} // namespace prerender
[email protected]4850a7f2011-03-08 23:36:59110
[email protected]68761472011-08-31 18:55:14111#endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_