[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
| 6 | #define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 7 | |
[email protected] | 9831b61 | 2012-05-15 00:56:47 | [diff] [blame] | 8 | #include "base/memory/scoped_ptr.h" |
[email protected] | 20a47b97 | 2013-04-17 17:26:39 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 10 | #include "base/time.h" |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 11 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 12 | #include "content/public/browser/web_contents_user_data.h" |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 13 | #include "googleurl/src/gurl.h" |
[email protected] | 4c94b8c | 2011-05-17 16:17:45 | [diff] [blame] | 14 | |
[email protected] | 20a47b97 | 2013-04-17 17:26:39 | [diff] [blame] | 15 | namespace predictors { |
| 16 | class LoggedInPredictorTable; |
| 17 | } |
| 18 | |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 19 | namespace prerender { |
| 20 | |
| 21 | class PrerenderManager; |
| 22 | |
[email protected] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 23 | // PrerenderTabHelper is responsible for recording perceived pageload times |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 24 | // to compare PLT's with prerendering enabled and disabled. |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 25 | class PrerenderTabHelper |
| 26 | : public content::WebContentsObserver, |
| 27 | public content::WebContentsUserData<PrerenderTabHelper> { |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 28 | public: |
[email protected] | 20a47b97 | 2013-04-17 17:26:39 | [diff] [blame] | 29 | 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] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 40 | virtual ~PrerenderTabHelper(); |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 41 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 42 | // content::WebContentsObserver implementation. |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 43 | virtual void ProvisionalChangeToMainFrameUrl( |
| 44 | const GURL& url, |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 45 | content::RenderViewHost* render_view_host) OVERRIDE; |
[email protected] | 8979307 | 2012-07-23 22:25:29 | [diff] [blame] | 46 | virtual void DidStopLoading( |
| 47 | content::RenderViewHost* render_view_host) OVERRIDE; |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 48 | virtual void DidStartProvisionalLoadForFrame( |
| 49 | int64 frame_id, |
[email protected] | d37c33e | 2012-10-12 13:35:13 | [diff] [blame] | 50 | int64 parent_frame_id, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 51 | bool is_main_frame, |
| 52 | const GURL& validated_url, |
| 53 | bool is_error_page, |
[email protected] | ead9009e | 2013-01-07 22:06:32 | [diff] [blame] | 54 | bool is_iframe_srcdoc, |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 55 | content::RenderViewHost* render_view_host) OVERRIDE; |
[email protected] | 7856620 | 2012-05-14 20:46:51 | [diff] [blame] | 56 | virtual void DidCommitProvisionalLoadForFrame( |
[email protected] | 290beec | 2012-04-22 02:57:38 | [diff] [blame] | 57 | int64 frame_id, |
| 58 | bool is_main_frame, |
| 59 | const GURL& validated_url, |
[email protected] | ef16c3e | 2012-05-16 22:13:46 | [diff] [blame] | 60 | content::PageTransition transition_type, |
| 61 | content::RenderViewHost* render_view_host) OVERRIDE; |
[email protected] | 20a47b97 | 2013-04-17 17:26:39 | [diff] [blame] | 62 | virtual void DidNavigateAnyFrame( |
| 63 | const content::LoadCommittedDetails& details, |
| 64 | const content::FrameNavigateParams& params) OVERRIDE; |
| 65 | |
[email protected] | a562aea2 | 2012-12-11 22:43:12 | [diff] [blame] | 66 | // Called when this prerendered WebContents has just been swapped in. |
[email protected] | 8f201ee5 | 2011-07-27 17:32:48 | [diff] [blame] | 67 | void PrerenderSwappedIn(); |
| 68 | |
| 69 | private: |
[email protected] | e2baaa8f | 2012-10-01 21:42:01 | [diff] [blame] | 70 | explicit PrerenderTabHelper(content::WebContents* web_contents); |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 71 | friend class content::WebContentsUserData<PrerenderTabHelper>; |
[email protected] | e2baaa8f | 2012-10-01 21:42:01 | [diff] [blame] | 72 | |
[email protected] | 20a47b97 | 2013-04-17 17:26:39 | [diff] [blame] | 73 | 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] | 9831b61 | 2012-05-15 00:56:47 | [diff] [blame] | 77 | // 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] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 83 | // Retrieves the PrerenderManager, or NULL, if none was found. |
[email protected] | 6005d68 | 2011-08-29 23:40:08 | [diff] [blame] | 84 | PrerenderManager* MaybeGetPrerenderManager() const; |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 85 | |
[email protected] | 0932b30c | 2012-04-17 13:25:10 | [diff] [blame] | 86 | // Returns whether the WebContents being observed is currently prerendering. |
[email protected] | 34f8edf | 2011-05-10 02:36:54 | [diff] [blame] | 87 | bool IsPrerendering(); |
| 88 | |
[email protected] | 9831b61 | 2012-05-15 00:56:47 | [diff] [blame] | 89 | // Returns whether the WebContents being observed was prerendered. |
| 90 | bool IsPrerendered(); |
| 91 | |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 92 | // 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] | b86aad87 | 2012-03-16 22:34:12 | [diff] [blame] | 96 | // 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] | c97f7e66 | 2011-10-04 00:50:36 | [diff] [blame] | 101 | // Current URL being loaded. |
| 102 | GURL url_; |
| 103 | |
[email protected] | 20a47b97 | 2013-04-17 17:26:39 | [diff] [blame] | 104 | base::WeakPtrFactory<PrerenderTabHelper> weak_factory_; |
| 105 | |
[email protected] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 107 | }; |
| 108 | |
[email protected] | 8fdb6f3 | 2011-04-26 15:22:59 | [diff] [blame] | 109 | } // namespace prerender |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 110 | |
[email protected] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 111 | #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |