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( | |
|
dominich
2012/06/28 00:34:32
can this be a separate CL?
| |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 149 |
| 147 // Set the final status for how the PrerenderContents was used. This | 150 // Set the final status for how the PrerenderContents was used. This |
| 148 // should only be called once, and should be called before the prerender | 151 // should only be called once, and should be called before the prerender |
| 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 |
| 159 int client_count() const { return client_count_; } | |
|
dominich
2012/06/28 00:34:32
usage count? instance count?
| |
| 160 void IncrementClientCount(); | |
| 161 void DecrementClientCount(); | |
| 162 | |
| 156 base::TimeTicks load_start_time() const { return load_start_time_; } | 163 base::TimeTicks load_start_time() const { return load_start_time_; } |
| 157 | 164 |
| 158 // Indicates whether this prerendered page can be used for the provided | 165 // 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 | 166 // URL, i.e. whether there is a match. |matching_url| is optional and will be |
| 160 // set to the URL that is found as a match if it is provided. | 167 // set to the URL that is found as a match if it is provided. |
| 161 // TODO(gavinp,mmenke): Rework matching to be based on both the URL | 168 // TODO(gavinp,mmenke): Rework matching to be based on both the URL |
| 162 // and the session WebStorage. | 169 // and the session WebStorage. |
| 163 bool MatchesURL(const GURL& url, GURL* matching_url) const; | 170 bool Matches( |
|
dominich
2012/06/28 00:34:32
we didn't use the returned matching_url anywhere?
| |
| 171 const GURL& url, | |
| 172 const content::SessionStorageNamespace* session_storage_namespace); | |
| 164 | 173 |
| 165 // content::WebContentsObserver implementation. | 174 // content::WebContentsObserver implementation. |
| 166 virtual void DidStopLoading() OVERRIDE; | 175 virtual void DidStopLoading() OVERRIDE; |
| 167 virtual void DidStartProvisionalLoadForFrame( | 176 virtual void DidStartProvisionalLoadForFrame( |
| 168 int64 frame_id, | 177 int64 frame_id, |
| 169 bool is_main_frame, | 178 bool is_main_frame, |
| 170 const GURL& validated_url, | 179 const GURL& validated_url, |
| 171 bool is_error_page, | 180 bool is_error_page, |
| 172 content::RenderViewHost* render_view_host) OVERRIDE; | 181 content::RenderViewHost* render_view_host) OVERRIDE; |
| 173 virtual void DidFinishLoad(int64 frame_id, | 182 virtual void DidFinishLoad(int64 frame_id, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 // new tab. | 214 // new tab. |
| 206 void CommitHistory(TabContents* tab); | 215 void CommitHistory(TabContents* tab); |
| 207 | 216 |
| 208 base::Value* GetAsValue() const; | 217 base::Value* GetAsValue() const; |
| 209 | 218 |
| 210 // Returns whether a pending cross-site navigation is happening. | 219 // Returns whether a pending cross-site navigation is happening. |
| 211 // This could happen with renderer-issued navigations, such as a | 220 // This could happen with renderer-issued navigations, such as a |
| 212 // MouseEvent being dispatched by a link to a website installed as an app. | 221 // MouseEvent being dispatched by a link to a website installed as an app. |
| 213 bool IsCrossSiteNavigationPending() const; | 222 bool IsCrossSiteNavigationPending() const; |
| 214 | 223 |
| 215 // Adds a pending prerender to the list. | 224 virtual PrerenderHandle AddPendingPrerender(const GURL& url, |
| 216 virtual void AddPendingPrerender(const GURL& url, | 225 const content::Referrer& referrer, |
| 217 const content::Referrer& referrer, | 226 const gfx::Size& size); |
| 218 const gfx::Size& size); | |
| 219 | 227 |
| 220 // Returns true if |url| corresponds to a pending prerender. | 228 // Returns true if |url| corresponds to a pending prerender. |
|
dominich
2012/06/28 00:34:32
comment
| |
| 221 bool IsPendingEntry(const GURL& url) const; | 229 bool IsPendingEntry(PrerenderHandle prerender_handle) const; |
| 222 | 230 |
| 223 // Reissues any pending prerender requests from the prerendered page. Also | 231 // Reissues any pending prerender requests from the prerendered page. Also |
| 224 // clears the list of pending requests. | 232 // clears the list of pending requests. |
| 225 void StartPendingPrerenders(); | 233 void StartPendingPrerenders(); |
| 226 | 234 |
| 227 protected: | 235 protected: |
| 236 // Information on pages that the prerendered page has tried to prerender. | |
| 237 struct PendingPrerenderInfo { | |
|
dominich
2012/06/28 00:34:32
I believe this can just be a forward reference her
| |
| 238 PendingPrerenderInfo(PrerenderHandleImpl* prerender_handle_impl, | |
| 239 const GURL& url, | |
| 240 const content::Referrer& referrer, | |
| 241 const gfx::Size& size); | |
| 242 | |
| 243 PrerenderHandleImpl* prerender_handle_impl; | |
|
dominich
2012/06/28 00:34:32
const PrerenderHandleImpl?
| |
| 244 const GURL url; | |
| 245 const content::Referrer referrer; | |
| 246 const gfx::Size size; | |
| 247 }; | |
| 248 typedef std::list<PendingPrerenderInfo> PendingPrerenderList; | |
| 249 | |
|
dominich
2012/06/28 00:34:32
nit: extra blank line
| |
| 250 | |
| 228 PrerenderContents(PrerenderManager* prerender_manager, | 251 PrerenderContents(PrerenderManager* prerender_manager, |
| 229 PrerenderTracker* prerender_tracker, | 252 PrerenderTracker* prerender_tracker, |
| 230 Profile* profile, | 253 Profile* profile, |
| 231 const GURL& url, | 254 const GURL& url, |
| 232 const content::Referrer& referrer, | 255 const content::Referrer& referrer, |
| 233 Origin origin, | 256 Origin origin, |
| 234 uint8 experiment_id); | 257 uint8 experiment_id); |
| 235 | 258 |
| 236 // Called whenever a RenderViewHost is created for prerendering. Only called | 259 // Called whenever a RenderViewHost is created for prerendering. Only called |
| 237 // once the RenderViewHost has a RenderView and RenderWidgetHostView. | 260 // once the RenderViewHost has a RenderView and RenderWidgetHostView. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 248 | 271 |
| 249 bool prerendering_has_been_cancelled() const { | 272 bool prerendering_has_been_cancelled() const { |
| 250 return prerendering_has_been_cancelled_; | 273 return prerendering_has_been_cancelled_; |
| 251 } | 274 } |
| 252 | 275 |
| 253 virtual content::WebContents* CreateWebContents( | 276 virtual content::WebContents* CreateWebContents( |
| 254 content::SessionStorageNamespace* session_storage_namespace); | 277 content::SessionStorageNamespace* session_storage_namespace); |
| 255 | 278 |
| 256 bool prerendering_has_started_; | 279 bool prerendering_has_started_; |
| 257 | 280 |
| 281 // Time at which we started to load the URL. This is used to compute | |
| 282 // the time elapsed from initiating a prerender until the time the | |
| 283 // (potentially only partially) prerendered page is shown to the user. | |
| 284 base::TimeTicks load_start_time_; | |
| 285 | |
| 258 private: | 286 private: |
| 259 class TabContentsDelegateImpl; | 287 class TabContentsDelegateImpl; |
| 260 | 288 |
| 261 // Needs to be able to call the constructor. | 289 // Needs to be able to call the constructor. |
| 262 friend class PrerenderContentsFactoryImpl; | 290 friend class PrerenderContentsFactoryImpl; |
| 263 | 291 |
| 264 friend class PrerenderRenderViewHostObserver; | 292 friend class PrerenderRenderViewHostObserver; |
| 265 | 293 |
| 266 // Message handlers. | 294 // Message handlers. |
| 267 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); | 295 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 296 int32 page_id_; | 324 int32 page_id_; |
| 297 GURL url_; | 325 GURL url_; |
| 298 GURL icon_url_; | 326 GURL icon_url_; |
| 299 content::NotificationRegistrar notification_registrar_; | 327 content::NotificationRegistrar notification_registrar_; |
| 300 | 328 |
| 301 // A vector of URLs that this prerendered page matches against. | 329 // A vector of URLs that this prerendered page matches against. |
| 302 // This array can contain more than element as a result of redirects, | 330 // This array can contain more than element as a result of redirects, |
| 303 // such as HTTP redirects or javascript redirects. | 331 // such as HTTP redirects or javascript redirects. |
| 304 std::vector<GURL> alias_urls_; | 332 std::vector<GURL> alias_urls_; |
| 305 | 333 |
| 334 // The session storage namespace for use in Matching. We must save it | |
| 335 // rather than get it from the RenderViewHost since in the control group | |
| 336 // we won't have a RenderViewHost. | |
| 337 content::SessionStorageNamespace* session_storage_namespace_; | |
| 338 | |
| 339 // Number of distinct clients of this prerendered page (distinct link elements | |
|
dominich
2012/06/28 00:34:32
instances?
| |
| 340 // for instance). | |
| 341 int client_count_; | |
| 342 | |
| 306 bool has_stopped_loading_; | 343 bool has_stopped_loading_; |
| 307 | 344 |
| 308 // True when the main frame has finished loading. | 345 // True when the main frame has finished loading. |
| 309 bool has_finished_loading_; | 346 bool has_finished_loading_; |
| 310 | 347 |
| 311 // This must be the same value as the PrerenderTracker has recorded for | 348 // This must be the same value as the PrerenderTracker has recorded for |
| 312 // |this|, when |this| has a RenderView. | 349 // |this|, when |this| has a RenderView. |
| 313 FinalStatus final_status_; | 350 FinalStatus final_status_; |
| 314 | 351 |
| 315 // The MatchComplete status of the prerender, indicating how it relates | 352 // The MatchComplete status of the prerender, indicating how it relates |
| 316 // to being a MatchComplete dummy (see definition of MatchCompleteStatus | 353 // to being a MatchComplete dummy (see definition of MatchCompleteStatus |
| 317 // above). | 354 // above). |
| 318 MatchCompleteStatus match_complete_status_; | 355 MatchCompleteStatus match_complete_status_; |
| 319 | 356 |
| 320 // Tracks whether or not prerendering has been cancelled by calling Destroy. | 357 // Tracks whether or not prerendering has been cancelled by calling Destroy. |
| 321 // Used solely to prevent double deletion. | 358 // Used solely to prevent double deletion. |
| 322 bool prerendering_has_been_cancelled_; | 359 bool prerendering_has_been_cancelled_; |
| 323 | 360 |
| 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 | 361 // Process Metrics of the render process associated with the |
| 330 // RenderViewHost for this object. | 362 // RenderViewHost for this object. |
| 331 scoped_ptr<base::ProcessMetrics> process_metrics_; | 363 scoped_ptr<base::ProcessMetrics> process_metrics_; |
| 332 | 364 |
| 333 // The prerendered TabContents; may be null. | 365 // The prerendered TabContents; may be null. |
| 334 scoped_ptr<TabContents> prerender_contents_; | 366 scoped_ptr<TabContents> prerender_contents_; |
| 335 | 367 |
| 336 scoped_ptr<PrerenderRenderViewHostObserver> render_view_host_observer_; | 368 scoped_ptr<PrerenderRenderViewHostObserver> render_view_host_observer_; |
| 337 | 369 |
| 338 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_; | 370 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 355 | 387 |
| 356 // The size of the WebView from the launching page. | 388 // The size of the WebView from the launching page. |
| 357 gfx::Size size_; | 389 gfx::Size size_; |
| 358 | 390 |
| 359 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 391 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); |
| 360 }; | 392 }; |
| 361 | 393 |
| 362 } // namespace prerender | 394 } // namespace prerender |
| 363 | 395 |
| 364 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 396 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
| OLD | NEW |