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 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 }; | 71 }; |
72 | 72 |
73 class Observer { | 73 class Observer { |
74 public: | 74 public: |
75 // Signals that the prerender has started running. | 75 // Signals that the prerender has started running. |
76 virtual void OnPrerenderStart(PrerenderContents* contents) = 0; | 76 virtual void OnPrerenderStart(PrerenderContents* contents) = 0; |
77 | 77 |
78 // Signals that the prerender has had its load event. | 78 // Signals that the prerender has had its load event. |
79 virtual void OnPrerenderStopLoading(PrerenderContents* contents); | 79 virtual void OnPrerenderStopLoading(PrerenderContents* contents); |
80 | 80 |
81 // Signals that the prerender has stopped running. | 81 // Signals that the prerender has stopped running. A PrerenderContents with |
| 82 // an unset final status will always call OnPrerenderStop before being |
| 83 // destroyed. |
82 virtual void OnPrerenderStop(PrerenderContents* contents) = 0; | 84 virtual void OnPrerenderStop(PrerenderContents* contents) = 0; |
83 | 85 |
84 // Signals that this prerender has just become a MatchComplete replacement. | 86 // Signals that this prerender has just become a MatchComplete replacement. |
85 virtual void OnPrerenderCreatedMatchCompleteReplacement( | 87 virtual void OnPrerenderCreatedMatchCompleteReplacement( |
86 PrerenderContents* contents, PrerenderContents* replacement); | 88 PrerenderContents* contents, PrerenderContents* replacement); |
87 | 89 |
88 protected: | 90 protected: |
89 Observer(); | 91 Observer(); |
90 virtual ~Observer() = 0; | 92 virtual ~Observer() = 0; |
91 }; | 93 }; |
92 | 94 |
93 // A container for extra data on pending prerenders. | |
94 struct PendingPrerenderInfo { | |
95 public: | |
96 PendingPrerenderInfo( | |
97 base::WeakPtr<PrerenderHandle> weak_prerender_handle, | |
98 Origin origin, | |
99 const GURL& url, | |
100 const content::Referrer& referrer, | |
101 const gfx::Size& size); | |
102 | |
103 ~PendingPrerenderInfo(); | |
104 | |
105 base::WeakPtr<PrerenderHandle> weak_prerender_handle; | |
106 Origin origin; | |
107 GURL url; | |
108 content::Referrer referrer; | |
109 gfx::Size size; | |
110 }; | |
111 | |
112 // Indicates how this PrerenderContents relates to MatchComplete. This is to | 95 // Indicates how this PrerenderContents relates to MatchComplete. This is to |
113 // figure out which histograms to use to record the FinalStatus, Match (record | 96 // figure out which histograms to use to record the FinalStatus, Match (record |
114 // all prerenders and control group prerenders) or MatchComplete (record | 97 // all prerenders and control group prerenders) or MatchComplete (record |
115 // running prerenders only in the way they would have been recorded in the | 98 // running prerenders only in the way they would have been recorded in the |
116 // control group). | 99 // control group). |
117 enum MatchCompleteStatus { | 100 enum MatchCompleteStatus { |
118 // A regular prerender which will be recorded both in Match and | 101 // A regular prerender which will be recorded both in Match and |
119 // MatchComplete. | 102 // MatchComplete. |
120 MATCH_COMPLETE_DEFAULT, | 103 MATCH_COMPLETE_DEFAULT, |
121 // A prerender that used to be a regular prerender, but has since been | 104 // A prerender that used to be a regular prerender, but has since been |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 176 } |
194 | 177 |
195 // Sets the parameter to the value of the associated RenderViewHost's child id | 178 // Sets the parameter to the value of the associated RenderViewHost's child id |
196 // and returns a boolean indicating the validity of that id. | 179 // and returns a boolean indicating the validity of that id. |
197 virtual bool GetChildId(int* child_id) const; | 180 virtual bool GetChildId(int* child_id) const; |
198 | 181 |
199 // Sets the parameter to the value of the associated RenderViewHost's route id | 182 // Sets the parameter to the value of the associated RenderViewHost's route id |
200 // and returns a boolean indicating the validity of that id. | 183 // and returns a boolean indicating the validity of that id. |
201 virtual bool GetRouteId(int* route_id) const; | 184 virtual bool GetRouteId(int* route_id) const; |
202 | 185 |
203 // Set the final status for how the PrerenderContents was used. This | |
204 // should only be called once, and should be called before the prerender | |
205 // contents are destroyed. | |
206 void SetFinalStatus(FinalStatus final_status); | |
207 FinalStatus final_status() const { return final_status_; } | 186 FinalStatus final_status() const { return final_status_; } |
208 | 187 |
209 Origin origin() const { return origin_; } | 188 Origin origin() const { return origin_; } |
210 uint8 experiment_id() const { return experiment_id_; } | 189 uint8 experiment_id() const { return experiment_id_; } |
211 int child_id() const { return child_id_; } | 190 int child_id() const { return child_id_; } |
212 | 191 |
213 base::TimeTicks load_start_time() const { return load_start_time_; } | 192 base::TimeTicks load_start_time() const { return load_start_time_; } |
214 | 193 |
215 // Indicates whether this prerendered page can be used for the provided | 194 // Indicates whether this prerendered page can be used for the provided |
216 // |url| and |session_storage_namespace|. | 195 // |url| and |session_storage_namespace|. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // new tab. | 261 // new tab. |
283 void CommitHistory(content::WebContents* tab); | 262 void CommitHistory(content::WebContents* tab); |
284 | 263 |
285 base::Value* GetAsValue() const; | 264 base::Value* GetAsValue() const; |
286 | 265 |
287 // Returns whether a pending cross-site navigation is happening. | 266 // Returns whether a pending cross-site navigation is happening. |
288 // This could happen with renderer-issued navigations, such as a | 267 // This could happen with renderer-issued navigations, such as a |
289 // MouseEvent being dispatched by a link to a website installed as an app. | 268 // MouseEvent being dispatched by a link to a website installed as an app. |
290 bool IsCrossSiteNavigationPending() const; | 269 bool IsCrossSiteNavigationPending() const; |
291 | 270 |
292 // Adds a pending prerender to the list. If |weak_prerender_handle| still | 271 // Marks prerender as used and releases any throttled resource requests. |
293 // exists when this page is made visible, it will be launched. | |
294 virtual void AddPendingPrerender( | |
295 scoped_ptr<PendingPrerenderInfo> pending_prerender_info); | |
296 | |
297 // Reissues any pending prerender requests from the prerendered page. Also | |
298 // clears the list of pending requests. Sends notifications. | |
299 void PrepareForUse(); | 272 void PrepareForUse(); |
300 | 273 |
301 content::SessionStorageNamespace* GetSessionStorageNamespace() const; | 274 content::SessionStorageNamespace* GetSessionStorageNamespace() const; |
302 | 275 |
303 // Cookie events | 276 // Cookie events |
304 enum CookieEvent { | 277 enum CookieEvent { |
305 COOKIE_EVENT_SEND = 0, | 278 COOKIE_EVENT_SEND = 0, |
306 COOKIE_EVENT_CHANGE = 1, | 279 COOKIE_EVENT_CHANGE = 1, |
307 COOKIE_EVENT_MAX | 280 COOKIE_EVENT_MAX |
308 }; | 281 }; |
(...skipping 14 matching lines...) Expand all Loading... |
323 const base::WeakPtr<PrerenderResourceThrottle>& throttle); | 296 const base::WeakPtr<PrerenderResourceThrottle>& throttle); |
324 | 297 |
325 protected: | 298 protected: |
326 PrerenderContents(PrerenderManager* prerender_manager, | 299 PrerenderContents(PrerenderManager* prerender_manager, |
327 Profile* profile, | 300 Profile* profile, |
328 const GURL& url, | 301 const GURL& url, |
329 const content::Referrer& referrer, | 302 const content::Referrer& referrer, |
330 Origin origin, | 303 Origin origin, |
331 uint8 experiment_id); | 304 uint8 experiment_id); |
332 | 305 |
| 306 // Set the final status for how the PrerenderContents was used. This |
| 307 // should only be called once, and should be called before the prerender |
| 308 // contents are destroyed. |
| 309 void SetFinalStatus(FinalStatus final_status); |
| 310 |
333 // These call out to methods on our Observers, using our observer_list_. Note | 311 // These call out to methods on our Observers, using our observer_list_. Note |
334 // that NotifyPrerenderStop() also clears the observer list. | 312 // that NotifyPrerenderStop() also clears the observer list. |
335 void NotifyPrerenderStart(); | 313 void NotifyPrerenderStart(); |
336 void NotifyPrerenderStopLoading(); | 314 void NotifyPrerenderStopLoading(); |
337 void NotifyPrerenderStop(); | 315 void NotifyPrerenderStop(); |
338 void NotifyPrerenderCreatedMatchCompleteReplacement( | 316 void NotifyPrerenderCreatedMatchCompleteReplacement( |
339 PrerenderContents* replacement); | 317 PrerenderContents* replacement); |
340 | 318 |
341 // Called whenever a RenderViewHost is created for prerendering. Only called | 319 // Called whenever a RenderViewHost is created for prerendering. Only called |
342 // once the RenderViewHost has a RenderView and RenderWidgetHostView. | 320 // once the RenderViewHost has a RenderView and RenderWidgetHostView. |
343 virtual void OnRenderViewHostCreated( | 321 virtual void OnRenderViewHostCreated( |
344 content::RenderViewHost* new_render_view_host); | 322 content::RenderViewHost* new_render_view_host); |
345 | 323 |
346 content::NotificationRegistrar& notification_registrar() { | 324 content::NotificationRegistrar& notification_registrar() { |
347 return notification_registrar_; | 325 return notification_registrar_; |
348 } | 326 } |
349 | 327 |
350 size_t pending_prerender_count() const; | |
351 | |
352 bool prerendering_has_been_cancelled() const { | 328 bool prerendering_has_been_cancelled() const { |
353 return prerendering_has_been_cancelled_; | 329 return prerendering_has_been_cancelled_; |
354 } | 330 } |
355 | 331 |
356 content::WebContents* CreateWebContents( | 332 content::WebContents* CreateWebContents( |
357 content::SessionStorageNamespace* session_storage_namespace); | 333 content::SessionStorageNamespace* session_storage_namespace); |
358 | 334 |
359 bool prerendering_has_started_; | 335 bool prerendering_has_started_; |
360 | 336 |
361 // Time at which we started to load the URL. This is used to compute | 337 // Time at which we started to load the URL. This is used to compute |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 // These are -1 before a RenderView is created. | 420 // These are -1 before a RenderView is created. |
445 int child_id_; | 421 int child_id_; |
446 int route_id_; | 422 int route_id_; |
447 | 423 |
448 // Origin for this prerender. | 424 // Origin for this prerender. |
449 Origin origin_; | 425 Origin origin_; |
450 | 426 |
451 // Experiment during which this prerender is performed. | 427 // Experiment during which this prerender is performed. |
452 uint8 experiment_id_; | 428 uint8 experiment_id_; |
453 | 429 |
454 // Prerenders that the prerendered page has tried to prerender. They remain | |
455 // pending until this page is displayed. | |
456 ScopedVector<PendingPrerenderInfo> pending_prerenders_; | |
457 | |
458 // The process that created the child id. | 430 // The process that created the child id. |
459 int creator_child_id_; | 431 int creator_child_id_; |
460 | 432 |
461 // The size of the WebView from the launching page. | 433 // The size of the WebView from the launching page. |
462 gfx::Size size_; | 434 gfx::Size size_; |
463 | 435 |
464 typedef std::vector<history::HistoryAddPageArgs> AddPageVector; | 436 typedef std::vector<history::HistoryAddPageArgs> AddPageVector; |
465 | 437 |
466 // Caches pages to be added to the history. | 438 // Caches pages to be added to the history. |
467 AddPageVector add_page_vector_; | 439 AddPageVector add_page_vector_; |
468 | 440 |
469 // The alias session storage namespace for this prerender. | 441 // The alias session storage namespace for this prerender. |
470 scoped_refptr<content::SessionStorageNamespace> | 442 scoped_refptr<content::SessionStorageNamespace> |
471 alias_session_storage_namespace; | 443 alias_session_storage_namespace; |
472 | 444 |
473 // Indicates what internal cookie events (see prerender_contents.cc) have | 445 // Indicates what internal cookie events (see prerender_contents.cc) have |
474 // occurred, using 1 bit for each possible InternalCookieEvent. | 446 // occurred, using 1 bit for each possible InternalCookieEvent. |
475 int cookie_status_; | 447 int cookie_status_; |
476 | 448 |
477 // Resources that are throttled, pending a prerender use. Can only access a | 449 // Resources that are throttled, pending a prerender use. Can only access a |
478 // throttle on the IO thread. | 450 // throttle on the IO thread. |
479 std::vector<base::WeakPtr<PrerenderResourceThrottle> > resource_throttles_; | 451 std::vector<base::WeakPtr<PrerenderResourceThrottle> > resource_throttles_; |
480 | 452 |
481 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 453 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); |
482 }; | 454 }; |
483 | 455 |
484 } // namespace prerender | 456 } // namespace prerender |
485 | 457 |
486 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 458 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
OLD | NEW |