| 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 <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/prerender/prerender_final_status.h" | 17 #include "chrome/browser/prerender/prerender_final_status.h" |
| 17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "content/public/common/referrer.h" | 21 #include "content/public/common/referrer.h" |
| 22 #include "ui/gfx/size.h" |
| 21 | 23 |
| 22 class Profile; | 24 class Profile; |
| 23 class TabContentsWrapper; | 25 class TabContentsWrapper; |
| 24 struct FaviconURL; | 26 struct FaviconURL; |
| 25 | 27 |
| 26 namespace base { | 28 namespace base { |
| 27 class ProcessMetrics; | 29 class ProcessMetrics; |
| 28 } | 30 } |
| 29 | 31 |
| 30 namespace content { | 32 namespace content { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 59 const GURL& url, | 61 const GURL& url, |
| 60 const content::Referrer& referrer, | 62 const content::Referrer& referrer, |
| 61 Origin origin, | 63 Origin origin, |
| 62 uint8 experiment_id) = 0; | 64 uint8 experiment_id) = 0; |
| 63 | 65 |
| 64 private: | 66 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(Factory); | 67 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 // Information on pages that the prerendered page has tried to prerender. | 70 // Information on pages that the prerendered page has tried to prerender. |
| 69 struct PendingPrerenderData { | 71 struct PendingPrerenderInfo; |
| 70 PendingPrerenderData(Origin origin, | 72 typedef std::list<PendingPrerenderInfo> PendingPrerenderList; |
| 71 const GURL& url, | |
| 72 const content::Referrer& referrer); | |
| 73 | |
| 74 Origin origin; | |
| 75 GURL url; | |
| 76 content::Referrer referrer; | |
| 77 }; | |
| 78 typedef std::list<PendingPrerenderData> PendingPrerenderList; | |
| 79 | 73 |
| 80 // Indicates how this PrerenderContents relates to MatchComplete. | 74 // Indicates how this PrerenderContents relates to MatchComplete. |
| 81 // This is important to figure out in what histograms to record the | 75 // This is important to figure out in what histograms to record the |
| 82 // FinalStatus in, as described below. | 76 // FinalStatus in, as described below. |
| 83 enum MatchCompleteStatus { | 77 enum MatchCompleteStatus { |
| 84 // A regular prerender which will be recorded both in Match and | 78 // A regular prerender which will be recorded both in Match and |
| 85 // MatchComplete. | 79 // MatchComplete. |
| 86 MATCH_COMPLETE_DEFAULT, | 80 MATCH_COMPLETE_DEFAULT, |
| 87 // A prerender that used to be a regular prerender, but has since | 81 // A prerender that used to be a regular prerender, but has since |
| 88 // been replaced by a MatchComplete dummy. Therefore, we will record | 82 // been replaced by a MatchComplete dummy. Therefore, we will record |
| 89 // this only for Match, but not for MatchComplete. | 83 // this only for Match, but not for MatchComplete. |
| 90 MATCH_COMPLETE_REPLACED, | 84 MATCH_COMPLETE_REPLACED, |
| 91 // A prerender that is a MatchComplete dummy replacing a regular | 85 // A prerender that is a MatchComplete dummy replacing a regular |
| 92 // prerender. Therefore, we will record this only for MatchComplete, | 86 // prerender. Therefore, we will record this only for MatchComplete, |
| 93 // but not Match. | 87 // but not Match. |
| 94 MATCH_COMPLETE_REPLACEMENT | 88 MATCH_COMPLETE_REPLACEMENT |
| 95 }; | 89 }; |
| 96 | 90 |
| 97 virtual ~PrerenderContents(); | 91 virtual ~PrerenderContents(); |
| 98 | 92 |
| 99 bool Init(); | 93 bool Init(); |
| 100 | 94 |
| 101 static Factory* CreateFactory(); | 95 static Factory* CreateFactory(); |
| 102 | 96 |
| 103 // |source_render_view_host| is the RenderViewHost that initiated | 97 // |source_render_view_host| is the RenderViewHost that initiated |
| 104 // prerendering. | 98 // prerendering. |
| 105 virtual void StartPrerendering( | 99 virtual void StartPrerendering( |
| 106 const content::RenderViewHost* source_render_view_host, | 100 int creator_child_id, |
| 101 const gfx::Size& size, |
| 107 content::SessionStorageNamespace* session_storage_namespace); | 102 content::SessionStorageNamespace* session_storage_namespace); |
| 108 | 103 |
| 109 // Verifies that the prerendering is not using too many resources, and kills | 104 // Verifies that the prerendering is not using too many resources, and kills |
| 110 // it if not. | 105 // it if not. |
| 111 void DestroyWhenUsingTooManyResources(); | 106 void DestroyWhenUsingTooManyResources(); |
| 112 | 107 |
| 113 content::RenderViewHost* GetRenderViewHostMutable(); | 108 content::RenderViewHost* GetRenderViewHostMutable(); |
| 114 const content::RenderViewHost* GetRenderViewHost() const; | 109 const content::RenderViewHost* GetRenderViewHost() const; |
| 115 | 110 |
| 116 string16 title() const { return title_; } | 111 string16 title() const { return title_; } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 143 FinalStatus final_status() const { return final_status_; } | 138 FinalStatus final_status() const { return final_status_; } |
| 144 | 139 |
| 145 Origin origin() const { return origin_; } | 140 Origin origin() const { return origin_; } |
| 146 uint8 experiment_id() const { return experiment_id_; } | 141 uint8 experiment_id() const { return experiment_id_; } |
| 147 | 142 |
| 148 base::TimeTicks load_start_time() const { return load_start_time_; } | 143 base::TimeTicks load_start_time() const { return load_start_time_; } |
| 149 | 144 |
| 150 // Indicates whether this prerendered page can be used for the provided | 145 // Indicates whether this prerendered page can be used for the provided |
| 151 // URL, i.e. whether there is a match. |matching_url| is optional and will be | 146 // URL, i.e. whether there is a match. |matching_url| is optional and will be |
| 152 // set to the URL that is found as a match if it is provided. | 147 // set to the URL that is found as a match if it is provided. |
| 148 // TODO(gavinp,mmenke): Rework matching to be based on both the URL |
| 149 // and the session WebStorage. |
| 153 bool MatchesURL(const GURL& url, GURL* matching_url) const; | 150 bool MatchesURL(const GURL& url, GURL* matching_url) const; |
| 154 | 151 |
| 155 void OnJSOutOfMemory(); | 152 void OnJSOutOfMemory(); |
| 156 bool ShouldSuppressDialogs(); | 153 bool ShouldSuppressDialogs(); |
| 157 | 154 |
| 158 // content::WebContentsObserver implementation. | 155 // content::WebContentsObserver implementation. |
| 159 virtual void DidStopLoading() OVERRIDE; | 156 virtual void DidStopLoading() OVERRIDE; |
| 160 virtual void DidStartProvisionalLoadForFrame( | 157 virtual void DidStartProvisionalLoadForFrame( |
| 161 int64 frame_id, | 158 int64 frame_id, |
| 162 bool is_main_frame, | 159 bool is_main_frame, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void CommitHistory(TabContentsWrapper* tab); | 196 void CommitHistory(TabContentsWrapper* tab); |
| 200 | 197 |
| 201 base::Value* GetAsValue() const; | 198 base::Value* GetAsValue() const; |
| 202 | 199 |
| 203 // Returns whether a pending cross-site navigation is happening. | 200 // Returns whether a pending cross-site navigation is happening. |
| 204 // This could happen with renderer-issued navigations, such as a | 201 // This could happen with renderer-issued navigations, such as a |
| 205 // MouseEvent being dispatched by a link to a website installed as an app. | 202 // MouseEvent being dispatched by a link to a website installed as an app. |
| 206 bool IsCrossSiteNavigationPending() const; | 203 bool IsCrossSiteNavigationPending() const; |
| 207 | 204 |
| 208 // Adds a pending prerender to the list. | 205 // Adds a pending prerender to the list. |
| 209 virtual void AddPendingPrerender(Origin origin, | 206 virtual void AddPendingPrerender(const GURL& url, |
| 210 const GURL& url, | 207 const content::Referrer& referrer, |
| 211 const content::Referrer& referrer); | 208 const gfx::Size& size); |
| 212 | 209 |
| 213 // Returns true if |url| corresponds to a pending prerender. | 210 // Returns true if |url| corresponds to a pending prerender. |
| 214 bool IsPendingEntry(const GURL& url) const; | 211 bool IsPendingEntry(const GURL& url) const; |
| 215 | 212 |
| 216 // Reissues any pending prerender requests from the prerendered page. Also | 213 // Reissues any pending prerender requests from the prerendered page. Also |
| 217 // clears the list of pending requests. | 214 // clears the list of pending requests. |
| 218 void StartPendingPrerenders(); | 215 void StartPendingPrerenders(); |
| 219 | 216 |
| 220 protected: | 217 protected: |
| 221 PrerenderContents(PrerenderManager* prerender_manager, | 218 PrerenderContents(PrerenderManager* prerender_manager, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 232 content::RenderViewHost* new_render_view_host); | 229 content::RenderViewHost* new_render_view_host); |
| 233 | 230 |
| 234 content::NotificationRegistrar& notification_registrar() { | 231 content::NotificationRegistrar& notification_registrar() { |
| 235 return notification_registrar_; | 232 return notification_registrar_; |
| 236 } | 233 } |
| 237 | 234 |
| 238 const PendingPrerenderList* pending_prerender_list() const { | 235 const PendingPrerenderList* pending_prerender_list() const { |
| 239 return &pending_prerender_list_; | 236 return &pending_prerender_list_; |
| 240 } | 237 } |
| 241 | 238 |
| 239 bool prerendering_has_been_cancelled() const { |
| 240 return prerendering_has_been_cancelled_; |
| 241 } |
| 242 |
| 242 virtual content::WebContents* CreateWebContents( | 243 virtual content::WebContents* CreateWebContents( |
| 243 content::SessionStorageNamespace* session_storage_namespace); | 244 content::SessionStorageNamespace* session_storage_namespace); |
| 244 | 245 |
| 245 private: | 246 private: |
| 246 class TabContentsDelegateImpl; | 247 class TabContentsDelegateImpl; |
| 247 | 248 |
| 248 // Needs to be able to call the constructor. | 249 // Needs to be able to call the constructor. |
| 249 friend class PrerenderContentsFactoryImpl; | 250 friend class PrerenderContentsFactoryImpl; |
| 250 | 251 |
| 251 friend class PrerenderRenderViewHostObserver; | 252 friend class PrerenderRenderViewHostObserver; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 336 |
| 336 // Experiment during which this prerender is performed. | 337 // Experiment during which this prerender is performed. |
| 337 uint8 experiment_id_; | 338 uint8 experiment_id_; |
| 338 | 339 |
| 339 // List of all pages the prerendered page has tried to prerender. | 340 // List of all pages the prerendered page has tried to prerender. |
| 340 PendingPrerenderList pending_prerender_list_; | 341 PendingPrerenderList pending_prerender_list_; |
| 341 | 342 |
| 342 // The process that created the child id. | 343 // The process that created the child id. |
| 343 int creator_child_id_; | 344 int creator_child_id_; |
| 344 | 345 |
| 346 // The size of the WebView from the launching page. |
| 347 gfx::Size size_; |
| 348 |
| 345 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 349 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); |
| 346 }; | 350 }; |
| 347 | 351 |
| 348 } // namespace prerender | 352 } // namespace prerender |
| 349 | 353 |
| 350 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 354 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
| OLD | NEW |