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 "chrome/browser/prerender/prerender_histograms.h"
12 #include "chrome/browser/prerender/prerender_origin.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
21 namespace password_manager
{
22 class PasswordManager
;
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
> {
35 ~PrerenderTabHelper() override
;
37 // content::WebContentsObserver implementation.
38 void DidGetRedirectForResourceRequest(
39 content::RenderFrameHost
* render_frame_host
,
40 const content::ResourceRedirectDetails
& details
) override
;
41 void DidStopLoading() override
;
42 void DidStartProvisionalLoadForFrame(
43 content::RenderFrameHost
* render_frame_host
,
44 const GURL
& validated_url
,
46 bool is_iframe_srcdoc
) override
;
47 void DidCommitProvisionalLoadForFrame(
48 content::RenderFrameHost
* render_frame_host
,
49 const GURL
& validated_url
,
50 ui::PageTransition transition_type
) override
;
52 // Called when the URL of the main frame changed, either when the load
53 // commits, or a redirect happens.
54 void MainFrameUrlDidChange(const GURL
& url
);
56 // Called when this prerendered WebContents has just been swapped in.
57 void PrerenderSwappedIn();
59 // Called when a control prerender is resolved. Applies to the next load.
60 void WouldHavePrerenderedNextLoad(Origin origin
);
63 explicit PrerenderTabHelper(content::WebContents
* web_contents
);
64 friend class content::WebContentsUserData
<PrerenderTabHelper
>;
66 void RecordPerceivedPageLoadTime(
67 base::TimeDelta perceived_page_load_time
,
68 double fraction_plt_elapsed_at_swap_in
);
70 // Retrieves the PrerenderManager, or NULL, if none was found.
71 PrerenderManager
* MaybeGetPrerenderManager() const;
73 // Returns whether the WebContents being observed is currently prerendering.
74 bool IsPrerendering();
76 // The type the current pending navigation, if there is one. If the tab is a
77 // prerender before swap, the value is always NAVIGATION_TYPE_PRERENDERED,
78 // even if the prerender is not currently loading.
79 NavigationType navigation_type_
;
81 // If |navigation_type_| is not NAVIGATION_TYPE_NORMAL, the origin of the
82 // relevant prerender. Otherwise, ORIGIN_NONE.
85 // True if the next load will be associated with a control prerender. This
86 // extra state is needed because control prerenders are resolved before the
87 // actual load begins. |next_load_origin_| gives the origin of the control
89 bool next_load_is_control_prerender_
;
90 Origin next_load_origin_
;
92 // System time at which the current load was started for the purpose of
93 // the perceived page load time (PPLT). If null, there is no current
95 base::TimeTicks pplt_load_start_
;
97 // System time at which the actual pageload started (pre-swapin), if
98 // a applicable (in cases when a prerender that was still loading was
100 base::TimeTicks actual_load_start_
;
102 // Current URL being loaded.
105 base::WeakPtrFactory
<PrerenderTabHelper
> weak_factory_
;
107 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper
);
110 } // namespace prerender
112 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_