| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
| 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | |
| 10 #include <string> | 9 #include <string> |
| 11 #include <utility> | 10 #include <utility> |
| 12 #include <vector> | 11 #include <vector> |
| 13 | 12 |
| 14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/time.h" | 14 #include "base/time.h" |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "chrome/browser/prerender/prerender_final_status.h" | 16 #include "chrome/browser/prerender/prerender_final_status.h" |
| 17 #include "chrome/browser/prerender/prerender_handle.h" |
| 18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/common/referrer.h" | 21 #include "content/public/common/referrer.h" |
| 22 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
| 23 | 23 |
| 24 class Profile; | 24 class Profile; |
| 25 class TabContents; | 25 class TabContents; |
| 26 struct FaviconURL; | 26 struct FaviconURL; |
| 27 | 27 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 Profile* profile, | 59 Profile* profile, |
| 60 const GURL& url, | 60 const GURL& url, |
| 61 const content::Referrer& referrer, | 61 const content::Referrer& referrer, |
| 62 Origin origin, | 62 Origin origin, |
| 63 uint8 experiment_id) = 0; | 63 uint8 experiment_id) = 0; |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(Factory); | 66 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 // Information on pages that the prerendered page has tried to prerender. | |
| 70 struct PendingPrerenderInfo; | |
| 71 typedef std::list<PendingPrerenderInfo> PendingPrerenderList; | |
| 72 | |
| 73 // Indicates how this PrerenderContents relates to MatchComplete. This is to | 69 // Indicates how this PrerenderContents relates to MatchComplete. This is to |
| 74 // figure out which histograms to use to record the FinalStatus, Match (record | 70 // figure out which histograms to use to record the FinalStatus, Match (record |
| 75 // all prerenders and control group prerenders) or MatchComplete (record | 71 // all prerenders and control group prerenders) or MatchComplete (record |
| 76 // running prerenders only in the way they would have been recorded in the | 72 // running prerenders only in the way they would have been recorded in the |
| 77 // control group). | 73 // control group). |
| 78 enum MatchCompleteStatus { | 74 enum MatchCompleteStatus { |
| 79 // A regular prerender which will be recorded both in Match and | 75 // A regular prerender which will be recorded both in Match and |
| 80 // MatchComplete. | 76 // MatchComplete. |
| 81 MATCH_COMPLETE_DEFAULT, | 77 MATCH_COMPLETE_DEFAULT, |
| 82 // A prerender that used to be a regular prerender, but has since been | 78 // A prerender that used to be a regular prerender, but has since been |
| 83 // replaced by a MatchComplete dummy. Therefore, we will record this only | 79 // replaced by a MatchComplete dummy. Therefore, we will record this only |
| 84 // for Match, but not for MatchComplete. | 80 // for Match, but not for MatchComplete. |
| 85 MATCH_COMPLETE_REPLACED, | 81 MATCH_COMPLETE_REPLACED, |
| 86 // A prerender that is a MatchComplete dummy replacing a regular prerender. | 82 // A prerender that is a MatchComplete dummy replacing a regular prerender. |
| 87 // In the control group, our prerender never would have been canceled, so | 83 // In the control group, our prerender never would have been canceled, so |
| 88 // we record in MatchComplete but not Match. | 84 // we record in MatchComplete but not Match. |
| 89 MATCH_COMPLETE_REPLACEMENT, | 85 MATCH_COMPLETE_REPLACEMENT, |
| 90 // A prerender that is a MatchComplete dummy, early in the process of being | 86 // A prerender that is a MatchComplete dummy, early in the process of being |
| 91 // created. This prerender should not fail. Record for MatchComplete, but | 87 // created. This prerender should not fail. Record for MatchComplete, but |
| 92 // not Match. | 88 // not Match. |
| 93 MATCH_COMPLETE_REPLACEMENT_PENDING, | 89 MATCH_COMPLETE_REPLACEMENT_PENDING, |
| 94 }; | 90 }; |
| 95 | 91 |
| 96 virtual ~PrerenderContents(); | 92 virtual ~PrerenderContents(); |
| 97 | 93 |
| 94 // For MatchComplete correctness, create a dummy replacement prerender |
| 95 // contents to stand in for this prerender contents that (which we are about |
| 96 // to destroy). |
| 97 void MakeIntoDummyReplacementOf( |
| 98 const PrerenderContents* original_prerender_contents); |
| 99 |
| 98 bool Init(); | 100 bool Init(); |
| 99 | 101 |
| 100 static Factory* CreateFactory(); | 102 static Factory* CreateFactory(); |
| 101 | 103 |
| 102 // Start rendering the contents in the prerendered state. If | 104 // Start rendering the contents in the prerendered state. If |
| 103 // |is_control_group| is true, this will go through some of the mechanics of | 105 // |is_control_group| is true, this will go through some of the mechanics of |
| 104 // starting a prerender, without actually creating the RenderView. | 106 // starting a prerender, without actually creating the RenderView. |
| 105 // |creator_child_id| is the id of the child process that caused the prerender | 107 // |creator_child_id| is the id of the child process that caused the prerender |
| 106 // to be created, and is needed so that the prerendered URLs can be sent to it | 108 // to be created, and is needed so that the prerendered URLs can be sent to it |
| 107 // so render-initiated navigations will swap in the prerendered page. |size| | 109 // so render-initiated navigations will swap in the prerendered page. |size| |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // contents are destroyed. | 151 // contents are destroyed. |
| 150 void set_final_status(FinalStatus final_status); | 152 void set_final_status(FinalStatus final_status); |
| 151 FinalStatus final_status() const { return final_status_; } | 153 FinalStatus final_status() const { return final_status_; } |
| 152 | 154 |
| 153 Origin origin() const { return origin_; } | 155 Origin origin() const { return origin_; } |
| 154 uint8 experiment_id() const { return experiment_id_; } | 156 uint8 experiment_id() const { return experiment_id_; } |
| 155 | 157 |
| 156 base::TimeTicks load_start_time() const { return load_start_time_; } | 158 base::TimeTicks load_start_time() const { return load_start_time_; } |
| 157 | 159 |
| 158 // Indicates whether this prerendered page can be used for the provided | 160 // Indicates whether this prerendered page can be used for the provided |
| 159 // URL, i.e. whether there is a match. |matching_url| is optional and will be | 161 // |url| and |session_storage_namespace|. |
| 160 // set to the URL that is found as a match if it is provided. | 162 bool Matches( |
| 161 // TODO(gavinp,mmenke): Rework matching to be based on both the URL | 163 const GURL& url, |
| 162 // and the session WebStorage. | 164 const content::SessionStorageNamespace* session_storage_namespace); |
| 163 bool MatchesURL(const GURL& url, GURL* matching_url) const; | |
| 164 | 165 |
| 165 // content::WebContentsObserver implementation. | 166 // content::WebContentsObserver implementation. |
| 166 virtual void DidStopLoading() OVERRIDE; | 167 virtual void DidStopLoading() OVERRIDE; |
| 167 virtual void DidStartProvisionalLoadForFrame( | 168 virtual void DidStartProvisionalLoadForFrame( |
| 168 int64 frame_id, | 169 int64 frame_id, |
| 169 bool is_main_frame, | 170 bool is_main_frame, |
| 170 const GURL& validated_url, | 171 const GURL& validated_url, |
| 171 bool is_error_page, | 172 bool is_error_page, |
| 172 content::RenderViewHost* render_view_host) OVERRIDE; | 173 content::RenderViewHost* render_view_host) OVERRIDE; |
| 173 virtual void DidFinishLoad(int64 frame_id, | 174 virtual void DidFinishLoad(int64 frame_id, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // new tab. | 206 // new tab. |
| 206 void CommitHistory(TabContents* tab); | 207 void CommitHistory(TabContents* tab); |
| 207 | 208 |
| 208 base::Value* GetAsValue() const; | 209 base::Value* GetAsValue() const; |
| 209 | 210 |
| 210 // Returns whether a pending cross-site navigation is happening. | 211 // Returns whether a pending cross-site navigation is happening. |
| 211 // This could happen with renderer-issued navigations, such as a | 212 // This could happen with renderer-issued navigations, such as a |
| 212 // MouseEvent being dispatched by a link to a website installed as an app. | 213 // MouseEvent being dispatched by a link to a website installed as an app. |
| 213 bool IsCrossSiteNavigationPending() const; | 214 bool IsCrossSiteNavigationPending() const; |
| 214 | 215 |
| 215 // Adds a pending prerender to the list. | 216 // Adds a pending prerender to the list. If |weak_prerender_handle| still |
| 216 virtual void AddPendingPrerender(const GURL& url, | 217 // exists when this page is made visible, it will be launched. |
| 217 const content::Referrer& referrer, | 218 virtual void AddPendingPrerender( |
| 218 const gfx::Size& size); | 219 base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
| 220 const GURL& url, |
| 221 const content::Referrer& referrer, |
| 222 const gfx::Size& size); |
| 219 | 223 |
| 220 // Returns true if |url| corresponds to a pending prerender. | 224 // Returns true if |url| corresponds to a pending prerender. |
| 221 bool IsPendingEntry(const GURL& url) const; | 225 bool IsPendingEntry(const PrerenderHandle& prerender_handle) const; |
| 222 | 226 |
| 223 // Reissues any pending prerender requests from the prerendered page. Also | 227 // Reissues any pending prerender requests from the prerendered page. Also |
| 224 // clears the list of pending requests. | 228 // clears the list of pending requests. |
| 225 void StartPendingPrerenders(); | 229 void StartPendingPrerenders(); |
| 226 | 230 |
| 227 protected: | 231 protected: |
| 232 // Information on pages that the prerendered page has tried to prerender. |
| 233 struct PendingPrerenderInfo { |
| 234 PendingPrerenderInfo( |
| 235 base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
| 236 const GURL& url, |
| 237 const content::Referrer& referrer, |
| 238 const gfx::Size& size); |
| 239 ~PendingPrerenderInfo(); |
| 240 |
| 241 base::WeakPtr<PrerenderHandle> weak_prerender_handle; |
| 242 GURL url; |
| 243 content::Referrer referrer; |
| 244 gfx::Size size; |
| 245 }; |
| 246 |
| 228 PrerenderContents(PrerenderManager* prerender_manager, | 247 PrerenderContents(PrerenderManager* prerender_manager, |
| 229 PrerenderTracker* prerender_tracker, | 248 PrerenderTracker* prerender_tracker, |
| 230 Profile* profile, | 249 Profile* profile, |
| 231 const GURL& url, | 250 const GURL& url, |
| 232 const content::Referrer& referrer, | 251 const content::Referrer& referrer, |
| 233 Origin origin, | 252 Origin origin, |
| 234 uint8 experiment_id); | 253 uint8 experiment_id); |
| 235 | 254 |
| 236 // Called whenever a RenderViewHost is created for prerendering. Only called | 255 // Called whenever a RenderViewHost is created for prerendering. Only called |
| 237 // once the RenderViewHost has a RenderView and RenderWidgetHostView. | 256 // once the RenderViewHost has a RenderView and RenderWidgetHostView. |
| 238 virtual void OnRenderViewHostCreated( | 257 virtual void OnRenderViewHostCreated( |
| 239 content::RenderViewHost* new_render_view_host); | 258 content::RenderViewHost* new_render_view_host); |
| 240 | 259 |
| 241 content::NotificationRegistrar& notification_registrar() { | 260 content::NotificationRegistrar& notification_registrar() { |
| 242 return notification_registrar_; | 261 return notification_registrar_; |
| 243 } | 262 } |
| 244 | 263 |
| 245 const PendingPrerenderList* pending_prerender_list() const { | 264 const std::vector<PendingPrerenderInfo>* pending_prerenders() const { |
| 246 return &pending_prerender_list_; | 265 return &pending_prerenders_; |
| 247 } | 266 } |
| 248 | 267 |
| 249 bool prerendering_has_been_cancelled() const { | 268 bool prerendering_has_been_cancelled() const { |
| 250 return prerendering_has_been_cancelled_; | 269 return prerendering_has_been_cancelled_; |
| 251 } | 270 } |
| 252 | 271 |
| 253 virtual content::WebContents* CreateWebContents( | 272 virtual content::WebContents* CreateWebContents( |
| 254 content::SessionStorageNamespace* session_storage_namespace); | 273 content::SessionStorageNamespace* session_storage_namespace); |
| 255 | 274 |
| 256 bool prerendering_has_started_; | 275 bool prerendering_has_started_; |
| 257 | 276 |
| 277 // Time at which we started to load the URL. This is used to compute |
| 278 // the time elapsed from initiating a prerender until the time the |
| 279 // (potentially only partially) prerendered page is shown to the user. |
| 280 base::TimeTicks load_start_time_; |
| 281 |
| 258 private: | 282 private: |
| 259 class TabContentsDelegateImpl; | 283 class TabContentsDelegateImpl; |
| 260 | 284 |
| 261 // Needs to be able to call the constructor. | 285 // Needs to be able to call the constructor. |
| 262 friend class PrerenderContentsFactoryImpl; | 286 friend class PrerenderContentsFactoryImpl; |
| 263 | 287 |
| 264 friend class PrerenderRenderViewHostObserver; | 288 friend class PrerenderRenderViewHostObserver; |
| 265 | 289 |
| 266 // Message handlers. | 290 // Message handlers. |
| 267 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); | 291 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 296 int32 page_id_; | 320 int32 page_id_; |
| 297 GURL url_; | 321 GURL url_; |
| 298 GURL icon_url_; | 322 GURL icon_url_; |
| 299 content::NotificationRegistrar notification_registrar_; | 323 content::NotificationRegistrar notification_registrar_; |
| 300 | 324 |
| 301 // A vector of URLs that this prerendered page matches against. | 325 // A vector of URLs that this prerendered page matches against. |
| 302 // This array can contain more than element as a result of redirects, | 326 // This array can contain more than element as a result of redirects, |
| 303 // such as HTTP redirects or javascript redirects. | 327 // such as HTTP redirects or javascript redirects. |
| 304 std::vector<GURL> alias_urls_; | 328 std::vector<GURL> alias_urls_; |
| 305 | 329 |
| 330 // The session storage namespace for use in Matching. We must save it |
| 331 // rather than get it from the RenderViewHost since in the control group |
| 332 // we won't have a RenderViewHost. |
| 333 content::SessionStorageNamespace* session_storage_namespace_; |
| 334 |
| 306 bool has_stopped_loading_; | 335 bool has_stopped_loading_; |
| 307 | 336 |
| 308 // True when the main frame has finished loading. | 337 // True when the main frame has finished loading. |
| 309 bool has_finished_loading_; | 338 bool has_finished_loading_; |
| 310 | 339 |
| 311 // This must be the same value as the PrerenderTracker has recorded for | 340 // This must be the same value as the PrerenderTracker has recorded for |
| 312 // |this|, when |this| has a RenderView. | 341 // |this|, when |this| has a RenderView. |
| 313 FinalStatus final_status_; | 342 FinalStatus final_status_; |
| 314 | 343 |
| 315 // The MatchComplete status of the prerender, indicating how it relates | 344 // The MatchComplete status of the prerender, indicating how it relates |
| 316 // to being a MatchComplete dummy (see definition of MatchCompleteStatus | 345 // to being a MatchComplete dummy (see definition of MatchCompleteStatus |
| 317 // above). | 346 // above). |
| 318 MatchCompleteStatus match_complete_status_; | 347 MatchCompleteStatus match_complete_status_; |
| 319 | 348 |
| 320 // Tracks whether or not prerendering has been cancelled by calling Destroy. | 349 // Tracks whether or not prerendering has been cancelled by calling Destroy. |
| 321 // Used solely to prevent double deletion. | 350 // Used solely to prevent double deletion. |
| 322 bool prerendering_has_been_cancelled_; | 351 bool prerendering_has_been_cancelled_; |
| 323 | 352 |
| 324 // Time at which we started to load the URL. This is used to compute | |
| 325 // the time elapsed from initiating a prerender until the time the | |
| 326 // (potentially only partially) prerendered page is shown to the user. | |
| 327 base::TimeTicks load_start_time_; | |
| 328 | |
| 329 // Process Metrics of the render process associated with the | 353 // Process Metrics of the render process associated with the |
| 330 // RenderViewHost for this object. | 354 // RenderViewHost for this object. |
| 331 scoped_ptr<base::ProcessMetrics> process_metrics_; | 355 scoped_ptr<base::ProcessMetrics> process_metrics_; |
| 332 | 356 |
| 333 // The prerendered TabContents; may be null. | 357 // The prerendered TabContents; may be null. |
| 334 scoped_ptr<TabContents> prerender_contents_; | 358 scoped_ptr<TabContents> prerender_contents_; |
| 335 | 359 |
| 336 scoped_ptr<PrerenderRenderViewHostObserver> render_view_host_observer_; | 360 scoped_ptr<PrerenderRenderViewHostObserver> render_view_host_observer_; |
| 337 | 361 |
| 338 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_; | 362 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_; |
| 339 | 363 |
| 340 // These are -1 before a RenderView is created. | 364 // These are -1 before a RenderView is created. |
| 341 int child_id_; | 365 int child_id_; |
| 342 int route_id_; | 366 int route_id_; |
| 343 | 367 |
| 344 // Origin for this prerender. | 368 // Origin for this prerender. |
| 345 Origin origin_; | 369 Origin origin_; |
| 346 | 370 |
| 347 // Experiment during which this prerender is performed. | 371 // Experiment during which this prerender is performed. |
| 348 uint8 experiment_id_; | 372 uint8 experiment_id_; |
| 349 | 373 |
| 350 // List of all pages the prerendered page has tried to prerender. | 374 // List of all pages the prerendered page has tried to prerender. |
| 351 PendingPrerenderList pending_prerender_list_; | 375 std::vector<PendingPrerenderInfo> pending_prerenders_; |
| 352 | 376 |
| 353 // The process that created the child id. | 377 // The process that created the child id. |
| 354 int creator_child_id_; | 378 int creator_child_id_; |
| 355 | 379 |
| 356 // The size of the WebView from the launching page. | 380 // The size of the WebView from the launching page. |
| 357 gfx::Size size_; | 381 gfx::Size size_; |
| 358 | 382 |
| 359 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 383 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); |
| 360 }; | 384 }; |
| 361 | 385 |
| 362 } // namespace prerender | 386 } // namespace prerender |
| 363 | 387 |
| 364 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 388 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
| OLD | NEW |