| 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> | 
| 11 | 11 | 
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" | 
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" | 
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" | 
|  | 15 #include "base/observer_list.h" | 
| 15 #include "base/time.h" | 16 #include "base/time.h" | 
| 16 #include "base/values.h" | 17 #include "base/values.h" | 
| 17 #include "chrome/browser/prerender/prerender_final_status.h" | 18 #include "chrome/browser/prerender/prerender_final_status.h" | 
| 18 #include "chrome/browser/prerender/prerender_origin.h" | 19 #include "chrome/browser/prerender/prerender_origin.h" | 
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" | 
| 20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" | 
| 21 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" | 
| 22 #include "content/public/common/referrer.h" | 23 #include "content/public/common/referrer.h" | 
| 23 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" | 
| 24 | 25 | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 38 | 39 | 
| 39 namespace history { | 40 namespace history { | 
| 40 struct HistoryAddPageArgs; | 41 struct HistoryAddPageArgs; | 
| 41 } | 42 } | 
| 42 | 43 | 
| 43 namespace prerender { | 44 namespace prerender { | 
| 44 | 45 | 
| 45 class PrerenderHandle; | 46 class PrerenderHandle; | 
| 46 class PrerenderManager; | 47 class PrerenderManager; | 
| 47 class PrerenderRenderViewHostObserver; | 48 class PrerenderRenderViewHostObserver; | 
| 48 class PrerenderTracker; |  | 
| 49 | 49 | 
| 50 class PrerenderContents : public content::NotificationObserver, | 50 class PrerenderContents : public content::NotificationObserver, | 
| 51                           public content::WebContentsObserver { | 51                           public content::WebContentsObserver { | 
| 52  public: | 52  public: | 
| 53   // PrerenderContents::Create uses the currently registered Factory to create | 53   // PrerenderContents::Create uses the currently registered Factory to create | 
| 54   // the PrerenderContents. Factory is intended for testing. | 54   // the PrerenderContents. Factory is intended for testing. | 
| 55   class Factory { | 55   class Factory { | 
| 56    public: | 56    public: | 
| 57     Factory() {} | 57     Factory() {} | 
| 58     virtual ~Factory() {} | 58     virtual ~Factory() {} | 
| 59 | 59 | 
| 60     // Ownership is not transfered through this interface as prerender_manager, | 60     // Ownership is not transfered through this interface as prerender_manager, | 
| 61     // prerender_tracker, and profile are stored as weak pointers. | 61     // prerender_tracker, and profile are stored as weak pointers. | 
| 62     virtual PrerenderContents* CreatePrerenderContents( | 62     virtual PrerenderContents* CreatePrerenderContents( | 
| 63         PrerenderManager* prerender_manager, | 63         PrerenderManager* prerender_manager, | 
| 64         PrerenderTracker* prerender_tracker, |  | 
| 65         Profile* profile, | 64         Profile* profile, | 
| 66         const GURL& url, | 65         const GURL& url, | 
| 67         const content::Referrer& referrer, | 66         const content::Referrer& referrer, | 
| 68         Origin origin, | 67         Origin origin, | 
| 69         uint8 experiment_id) = 0; | 68         uint8 experiment_id) = 0; | 
| 70 | 69 | 
| 71    private: | 70    private: | 
| 72     DISALLOW_COPY_AND_ASSIGN(Factory); | 71     DISALLOW_COPY_AND_ASSIGN(Factory); | 
| 73   }; | 72   }; | 
| 74 | 73 | 
|  | 74   class Observer { | 
|  | 75    public: | 
|  | 76     // Signals that the prerender has started running. | 
|  | 77     virtual void OnPrerenderStart(PrerenderContents* contents) = 0; | 
|  | 78 | 
|  | 79     // Signals that the prerender has stopped running. | 
|  | 80     virtual void OnPrerenderStop(PrerenderContents* contents) = 0; | 
|  | 81 | 
|  | 82    protected: | 
|  | 83     Observer(); | 
|  | 84     virtual ~Observer() = 0; | 
|  | 85   }; | 
|  | 86 | 
| 75   // A container for extra data on pending prerenders. | 87   // A container for extra data on pending prerenders. | 
| 76   struct PendingPrerenderInfo { | 88   struct PendingPrerenderInfo { | 
| 77    public: | 89    public: | 
| 78     PendingPrerenderInfo( | 90     PendingPrerenderInfo( | 
| 79         base::WeakPtr<PrerenderHandle> weak_prerender_handle, | 91         base::WeakPtr<PrerenderHandle> weak_prerender_handle, | 
| 80         Origin origin, | 92         Origin origin, | 
| 81         const GURL& url, | 93         const GURL& url, | 
| 82         const content::Referrer& referrer, | 94         const content::Referrer& referrer, | 
| 83         const gfx::Size& size); | 95         const gfx::Size& size); | 
| 84 | 96 | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 109     // we record in MatchComplete but not Match. | 121     // we record in MatchComplete but not Match. | 
| 110     MATCH_COMPLETE_REPLACEMENT, | 122     MATCH_COMPLETE_REPLACEMENT, | 
| 111     // A prerender that is a MatchComplete dummy, early in the process of being | 123     // A prerender that is a MatchComplete dummy, early in the process of being | 
| 112     // created. This prerender should not fail. Record for MatchComplete, but | 124     // created. This prerender should not fail. Record for MatchComplete, but | 
| 113     // not Match. | 125     // not Match. | 
| 114     MATCH_COMPLETE_REPLACEMENT_PENDING, | 126     MATCH_COMPLETE_REPLACEMENT_PENDING, | 
| 115   }; | 127   }; | 
| 116 | 128 | 
| 117   virtual ~PrerenderContents(); | 129   virtual ~PrerenderContents(); | 
| 118 | 130 | 
|  | 131   // All observers of a PrerenderContents are removed after the OnPrerenderStop | 
|  | 132   // event is sent, so there is no need for a RemoveObserver() method. | 
|  | 133   void AddObserver(Observer* observer); | 
|  | 134 | 
| 119   // For MatchComplete correctness, create a dummy replacement prerender | 135   // For MatchComplete correctness, create a dummy replacement prerender | 
| 120   // contents to stand in for this prerender contents that (which we are about | 136   // contents to stand in for this prerender contents that (which we are about | 
| 121   // to destroy). | 137   // to destroy). | 
| 122   PrerenderContents* CreateMatchCompleteReplacement() const; | 138   PrerenderContents* CreateMatchCompleteReplacement() const; | 
| 123 | 139 | 
| 124   bool Init(); | 140   bool Init(); | 
| 125 | 141 | 
| 126   static Factory* CreateFactory(); | 142   static Factory* CreateFactory(); | 
| 127 | 143 | 
| 128   // Start rendering the contents in the prerendered state. If | 144   // Start rendering the contents in the prerendered state. If | 
| 129   // |is_control_group| is true, this will go through some of the mechanics of | 145   // |is_control_group| is true, this will go through some of the mechanics of | 
| 130   // starting a prerender, without actually creating the RenderView. | 146   // starting a prerender, without actually creating the RenderView. | 
| 131   // |creator_child_id| is the id of the child process that caused the prerender | 147   // |creator_child_id| is the id of the child process that caused the prerender | 
| 132   // to be created, and is needed so that the prerendered URLs can be sent to it | 148   // to be created, and is needed so that the prerendered URLs can be sent to it | 
| 133   // so render-initiated navigations will swap in the prerendered page. |size| | 149   // so render-initiated navigations will swap in the prerendered page. |size| | 
| 134   // indicates the rectangular dimensions that the prerendered page should be. | 150   // indicates the rectangular dimensions that the prerendered page should be. | 
| 135   // |session_storage_namespace| indicates the namespace that the prerendered | 151   // |session_storage_namespace| indicates the namespace that the prerendered | 
| 136   // page should be part of. | 152   // page should be part of. | 
| 137   virtual void StartPrerendering( | 153   virtual void StartPrerendering( | 
| 138       int creator_child_id, | 154       int creator_child_id, | 
| 139       const gfx::Size& size, | 155       const gfx::Size& size, | 
| 140       content::SessionStorageNamespace* session_storage_namespace, | 156       content::SessionStorageNamespace* session_storage_namespace); | 
| 141       bool is_control_group); |  | 
| 142 | 157 | 
| 143   // Verifies that the prerendering is not using too many resources, and kills | 158   // Verifies that the prerendering is not using too many resources, and kills | 
| 144   // it if not. | 159   // it if not. | 
| 145   void DestroyWhenUsingTooManyResources(); | 160   void DestroyWhenUsingTooManyResources(); | 
| 146 | 161 | 
| 147   content::RenderViewHost* GetRenderViewHostMutable(); | 162   content::RenderViewHost* GetRenderViewHostMutable(); | 
| 148   const content::RenderViewHost* GetRenderViewHost() const; | 163   const content::RenderViewHost* GetRenderViewHost() const; | 
| 149 | 164 | 
|  | 165   PrerenderManager* prerender_manager() { return prerender_manager_; } | 
|  | 166 | 
| 150   string16 title() const { return title_; } | 167   string16 title() const { return title_; } | 
| 151   int32 page_id() const { return page_id_; } | 168   int32 page_id() const { return page_id_; } | 
| 152   GURL icon_url() const { return icon_url_; } | 169   GURL icon_url() const { return icon_url_; } | 
| 153   const GURL& prerender_url() const { return prerender_url_; } | 170   const GURL& prerender_url() const { return prerender_url_; } | 
| 154   const content::Referrer& referrer() const { return referrer_; } | 171   const content::Referrer& referrer() const { return referrer_; } | 
| 155   bool has_stopped_loading() const { return has_stopped_loading_; } | 172   bool has_stopped_loading() const { return has_stopped_loading_; } | 
| 156   bool has_finished_loading() const { return has_finished_loading_; } | 173   bool has_finished_loading() const { return has_finished_loading_; } | 
| 157   bool prerendering_has_started() const { return prerendering_has_started_; } | 174   bool prerendering_has_started() const { return prerendering_has_started_; } | 
| 158   MatchCompleteStatus match_complete_status() const { | 175   MatchCompleteStatus match_complete_status() const { | 
| 159     return match_complete_status_; | 176     return match_complete_status_; | 
| 160   } | 177   } | 
| 161   void set_match_complete_status(MatchCompleteStatus status) { | 178   void set_match_complete_status(MatchCompleteStatus status) { | 
| 162     match_complete_status_ = status; | 179     match_complete_status_ = status; | 
| 163   } | 180   } | 
| 164 | 181 | 
| 165   // Sets the parameter to the value of the associated RenderViewHost's child id | 182   // Sets the parameter to the value of the associated RenderViewHost's child id | 
| 166   // and returns a boolean indicating the validity of that id. | 183   // and returns a boolean indicating the validity of that id. | 
| 167   virtual bool GetChildId(int* child_id) const; | 184   virtual bool GetChildId(int* child_id) const; | 
| 168 | 185 | 
| 169   // Sets the parameter to the value of the associated RenderViewHost's route id | 186   // Sets the parameter to the value of the associated RenderViewHost's route id | 
| 170   // and returns a boolean indicating the validity of that id. | 187   // and returns a boolean indicating the validity of that id. | 
| 171   virtual bool GetRouteId(int* route_id) const; | 188   virtual bool GetRouteId(int* route_id) const; | 
| 172 | 189 | 
| 173   // Set the final status for how the PrerenderContents was used. This | 190   // Set the final status for how the PrerenderContents was used. This | 
| 174   // should only be called once, and should be called before the prerender | 191   // should only be called once, and should be called before the prerender | 
| 175   // contents are destroyed. | 192   // contents are destroyed. | 
| 176   void set_final_status(FinalStatus final_status); | 193   void SetFinalStatus(FinalStatus final_status); | 
| 177   FinalStatus final_status() const { return final_status_; } | 194   FinalStatus final_status() const { return final_status_; } | 
| 178 | 195 | 
| 179   Origin origin() const { return origin_; } | 196   Origin origin() const { return origin_; } | 
| 180   uint8 experiment_id() const { return experiment_id_; } | 197   uint8 experiment_id() const { return experiment_id_; } | 
| 181 | 198 | 
| 182   base::TimeTicks load_start_time() const { return load_start_time_; } | 199   base::TimeTicks load_start_time() const { return load_start_time_; } | 
| 183 | 200 | 
| 184   // Indicates whether this prerendered page can be used for the provided | 201   // Indicates whether this prerendered page can be used for the provided | 
| 185   // |url| and |session_storage_namespace|. | 202   // |url| and |session_storage_namespace|. | 
| 186   bool Matches( | 203   bool Matches( | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 249   // exists when this page is made visible, it will be launched. | 266   // exists when this page is made visible, it will be launched. | 
| 250   virtual void AddPendingPrerender( | 267   virtual void AddPendingPrerender( | 
| 251       scoped_ptr<PendingPrerenderInfo> pending_prerender_info); | 268       scoped_ptr<PendingPrerenderInfo> pending_prerender_info); | 
| 252 | 269 | 
| 253   // Reissues any pending prerender requests from the prerendered page.  Also | 270   // Reissues any pending prerender requests from the prerendered page.  Also | 
| 254   // clears the list of pending requests. | 271   // clears the list of pending requests. | 
| 255   void StartPendingPrerenders(); | 272   void StartPendingPrerenders(); | 
| 256 | 273 | 
| 257  protected: | 274  protected: | 
| 258   PrerenderContents(PrerenderManager* prerender_manager, | 275   PrerenderContents(PrerenderManager* prerender_manager, | 
| 259                     PrerenderTracker* prerender_tracker, |  | 
| 260                     Profile* profile, | 276                     Profile* profile, | 
| 261                     const GURL& url, | 277                     const GURL& url, | 
| 262                     const content::Referrer& referrer, | 278                     const content::Referrer& referrer, | 
| 263                     Origin origin, | 279                     Origin origin, | 
| 264                     uint8 experiment_id); | 280                     uint8 experiment_id); | 
| 265 | 281 | 
|  | 282   // These call out to methods on our Observers, using our observer_list_. Note | 
|  | 283   // that NotifyPrerenderStop() also clears the observer list. | 
|  | 284   void NotifyPrerenderStart(); | 
|  | 285   void NotifyPrerenderStop(); | 
|  | 286 | 
| 266   // Called whenever a RenderViewHost is created for prerendering.  Only called | 287   // Called whenever a RenderViewHost is created for prerendering.  Only called | 
| 267   // once the RenderViewHost has a RenderView and RenderWidgetHostView. | 288   // once the RenderViewHost has a RenderView and RenderWidgetHostView. | 
| 268   virtual void OnRenderViewHostCreated( | 289   virtual void OnRenderViewHostCreated( | 
| 269       content::RenderViewHost* new_render_view_host); | 290       content::RenderViewHost* new_render_view_host); | 
| 270 | 291 | 
| 271   content::NotificationRegistrar& notification_registrar() { | 292   content::NotificationRegistrar& notification_registrar() { | 
| 272     return notification_registrar_; | 293     return notification_registrar_; | 
| 273   } | 294   } | 
| 274 | 295 | 
| 275   size_t pending_prerender_count() const; | 296   size_t pending_prerender_count() const; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 295   friend class PrerenderContentsFactoryImpl; | 316   friend class PrerenderContentsFactoryImpl; | 
| 296 | 317 | 
| 297   friend class PrerenderRenderViewHostObserver; | 318   friend class PrerenderRenderViewHostObserver; | 
| 298 | 319 | 
| 299   // Returns the RenderViewHost Delegate for this prerender. | 320   // Returns the RenderViewHost Delegate for this prerender. | 
| 300   content::WebContents* GetWebContents(); | 321   content::WebContents* GetWebContents(); | 
| 301 | 322 | 
| 302   // Returns the ProcessMetrics for the render process, if it exists. | 323   // Returns the ProcessMetrics for the render process, if it exists. | 
| 303   base::ProcessMetrics* MaybeGetProcessMetrics(); | 324   base::ProcessMetrics* MaybeGetProcessMetrics(); | 
| 304 | 325 | 
|  | 326   ObserverList<Observer> observer_list_; | 
|  | 327 | 
| 305   // The prerender manager owning this object. | 328   // The prerender manager owning this object. | 
| 306   PrerenderManager* prerender_manager_; | 329   PrerenderManager* prerender_manager_; | 
| 307 | 330 | 
| 308   // The prerender tracker tracking prerenders. |  | 
| 309   PrerenderTracker* prerender_tracker_; |  | 
| 310 |  | 
| 311   // The URL being prerendered. | 331   // The URL being prerendered. | 
| 312   GURL prerender_url_; | 332   GURL prerender_url_; | 
| 313 | 333 | 
| 314   // The referrer. | 334   // The referrer. | 
| 315   content::Referrer referrer_; | 335   content::Referrer referrer_; | 
| 316 | 336 | 
| 317   // The profile being used | 337   // The profile being used | 
| 318   Profile* profile_; | 338   Profile* profile_; | 
| 319 | 339 | 
| 320   // Information about the title and URL of the page that this class as a | 340   // Information about the title and URL of the page that this class as a | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 391 | 411 | 
| 392   // Caches pages to be added to the history. | 412   // Caches pages to be added to the history. | 
| 393   AddPageVector add_page_vector_; | 413   AddPageVector add_page_vector_; | 
| 394 | 414 | 
| 395   DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 415   DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 
| 396 }; | 416 }; | 
| 397 | 417 | 
| 398 }  // namespace prerender | 418 }  // namespace prerender | 
| 399 | 419 | 
| 400 #endif  // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 420 #endif  // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 
| OLD | NEW | 
|---|