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