Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 10198040: New link rel=prerender api, using WebKit::WebPrerenderingPlatform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the urls_to_id_map_, and follow consequences through. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 public: 89 public:
90 virtual PrerenderContents* CreatePrerenderContents( 90 virtual PrerenderContents* CreatePrerenderContents(
91 PrerenderManager* prerender_manager, PrerenderTracker* prerender_tracker, 91 PrerenderManager* prerender_manager, PrerenderTracker* prerender_tracker,
92 Profile* profile, const GURL& url, const content::Referrer& referrer, 92 Profile* profile, const GURL& url, const content::Referrer& referrer,
93 Origin origin, uint8 experiment_id) OVERRIDE { 93 Origin origin, uint8 experiment_id) OVERRIDE {
94 return new PrerenderContents(prerender_manager, prerender_tracker, profile, 94 return new PrerenderContents(prerender_manager, prerender_tracker, profile,
95 url, referrer, origin, experiment_id); 95 url, referrer, origin, experiment_id);
96 } 96 }
97 }; 97 };
98 98
99 PrerenderContents::PendingPrerenderData::PendingPrerenderData(
100 Origin origin,
101 const GURL& url,
102 const content::Referrer& referrer)
103 : origin(origin),
104 url(url),
105 referrer(referrer) {
106 }
107
108 // TabContentsDelegateImpl ----------------------------------------------------- 99 // TabContentsDelegateImpl -----------------------------------------------------
109 100
110 class PrerenderContents::TabContentsDelegateImpl 101 class PrerenderContents::TabContentsDelegateImpl
111 : public content::WebContentsDelegate { 102 : public content::WebContentsDelegate {
112 public: 103 public:
113 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) : 104 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) :
114 prerender_contents_(prerender_contents) { 105 prerender_contents_(prerender_contents) {
115 } 106 }
116 107
117 virtual WebContents* OpenURLFromTab(WebContents* source, 108 virtual WebContents* OpenURLFromTab(WebContents* source,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 private: 181 private:
191 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > 182 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> >
192 AddPageVector; 183 AddPageVector;
193 184
194 // Caches pages to be added to the history. 185 // Caches pages to be added to the history.
195 AddPageVector add_page_vector_; 186 AddPageVector add_page_vector_;
196 187
197 PrerenderContents* prerender_contents_; 188 PrerenderContents* prerender_contents_;
198 }; 189 };
199 190
200 void PrerenderContents::AddPendingPrerender(Origin origin, 191 void PrerenderContents::AddPendingPrerender(const GURL& url,
dominich 2012/04/29 18:52:55 I was worried about the loss of Origin here, but i
gavinp 2012/04/30 11:43:16 I'll ping Timo, who's writing the history navigato
dominich 2012/04/30 15:52:05 None that are in active development, and it would
201 const GURL& url,
202 const content::Referrer& referrer) { 192 const content::Referrer& referrer) {
203 pending_prerender_list_.push_back( 193 pending_prerender_list_.push_back(
dominich 2012/04/29 18:52:55 nit: this line should be merged with the one below
gavinp 2012/04/30 11:43:16 Done.
204 PendingPrerenderData(origin, url, referrer)); 194 PendingPrerenderData(url, referrer));
205 } 195 }
206 196
207 bool PrerenderContents::IsPendingEntry(const GURL& url) const { 197 bool PrerenderContents::IsPendingEntry(const GURL& url) const {
208 for (PendingPrerenderList::const_iterator it = 198 for (PendingPrerenderList::const_iterator it =
209 pending_prerender_list_.begin(); 199 pending_prerender_list_.begin();
210 it != pending_prerender_list_.end(); 200 it != pending_prerender_list_.end();
211 ++it) { 201 ++it) {
212 if (it->url == url) 202 if (it->first == url)
213 return true; 203 return true;
214 } 204 }
215 return false; 205 return false;
216 } 206 }
217 207
218 void PrerenderContents::StartPendingPrerenders() { 208 void PrerenderContents::StartPendingPrerenders() {
219 PendingPrerenderList pending_prerender_list; 209 PendingPrerenderList pending_prerender_list;
220 pending_prerender_list.swap(pending_prerender_list_); 210 pending_prerender_list.swap(pending_prerender_list_);
221 for (PendingPrerenderList::iterator it = pending_prerender_list.begin(); 211 for (PendingPrerenderList::iterator it = pending_prerender_list.begin();
222 it != pending_prerender_list.end(); 212 it != pending_prerender_list.end();
223 ++it) { 213 ++it) {
224 prerender_manager_->AddPrerender(it->origin, 214 RenderViewHost* render_view_host = RenderViewHost::FromID(child_id_,
225 std::make_pair(child_id_, route_id_), 215 route_id_);
226 it->url, 216 prerender_manager_->AddPrerenderFromLinkRelPrerender(
dominich 2012/04/29 18:52:55 as above, this assumption makes me nervous.
gavinp 2012/04/30 11:43:16 I think it's easy enough to add back if we need to
227 it->referrer, 217 child_id_, route_id_, it->first, it->second, size_,
dominich 2012/04/29 18:52:55 is it possible that the WebView size has changed s
gavinp 2012/04/30 11:43:16 I believe that the prerender can't change size whi
dominich 2012/04/30 15:52:05 It sounds like we already have an issue that we mi
mmenke 2012/04/30 18:35:22 It's currently not possible for a hidden WebView t
228 NULL); 218 render_view_host->GetSessionStorageNamespace());
229 } 219 }
230 } 220 }
231 221
232 PrerenderContents::PrerenderContents( 222 PrerenderContents::PrerenderContents(
233 PrerenderManager* prerender_manager, 223 PrerenderManager* prerender_manager,
234 PrerenderTracker* prerender_tracker, 224 PrerenderTracker* prerender_tracker,
235 Profile* profile, 225 Profile* profile,
236 const GURL& url, 226 const GURL& url,
237 const content::Referrer& referrer, 227 const content::Referrer& referrer,
238 Origin origin, 228 Origin origin,
(...skipping 21 matching lines...) Expand all
260 bool PrerenderContents::Init() { 250 bool PrerenderContents::Init() {
261 return AddAliasURL(prerender_url_); 251 return AddAliasURL(prerender_url_);
262 } 252 }
263 253
264 // static 254 // static
265 PrerenderContents::Factory* PrerenderContents::CreateFactory() { 255 PrerenderContents::Factory* PrerenderContents::CreateFactory() {
266 return new PrerenderContentsFactoryImpl(); 256 return new PrerenderContentsFactoryImpl();
267 } 257 }
268 258
269 void PrerenderContents::StartPrerendering( 259 void PrerenderContents::StartPrerendering(
270 const RenderViewHost* source_render_view_host, 260 int creator_child_id,
261 const gfx::Size& size,
271 content::SessionStorageNamespace* session_storage_namespace) { 262 content::SessionStorageNamespace* session_storage_namespace) {
272 DCHECK(profile_ != NULL); 263 DCHECK(profile_ != NULL);
273 DCHECK(!prerendering_has_started_); 264 DCHECK(!prerendering_has_started_);
274 DCHECK(prerender_contents_.get() == NULL); 265 DCHECK(prerender_contents_.get() == NULL);
266 DCHECK_EQ(-1, creator_child_id_);
267 DCHECK(size_.IsEmpty());
268
269 creator_child_id_ = creator_child_id;
270 size_ = size;
275 271
276 prerendering_has_started_ = true; 272 prerendering_has_started_ = true;
277 DCHECK(creator_child_id_ == -1); 273 DCHECK_EQ(1U, alias_urls_.size());
278 DCHECK(alias_urls_.size() == 1);
279 if (source_render_view_host)
280 creator_child_id_ = source_render_view_host->GetProcess()->GetID();
281 InformRenderProcessAboutPrerender(prerender_url_, true, 274 InformRenderProcessAboutPrerender(prerender_url_, true,
282 creator_child_id_); 275 creator_child_id_);
283 276
284 WebContents* new_contents = CreateWebContents(session_storage_namespace); 277 WebContents* new_contents = CreateWebContents(session_storage_namespace);
285 prerender_contents_.reset(new TabContentsWrapper(new_contents)); 278 prerender_contents_.reset(new TabContentsWrapper(new_contents));
286 content::WebContentsObserver::Observe(new_contents); 279 content::WebContentsObserver::Observe(new_contents);
287 280
288 gfx::Rect tab_bounds = prerender_manager_->config().default_tab_bounds; 281 if (size_.IsEmpty()) {
dominich 2012/04/29 18:52:55 will this ever happen now the size is coming from
gavinp 2012/04/30 11:43:16 Yes. Omnibox prerendering is probably the biggest
289 if (source_render_view_host) { 282 size_ = prerender_manager_->config().default_tab_bounds.size();
290 DCHECK(source_render_view_host->GetView() != NULL);
291 WebContents* source_wc =
292 source_render_view_host->GetDelegate()->GetAsWebContents();
293 if (source_wc) {
294 // Set the size of the new TC to that of the old TC.
295 source_wc->GetView()->GetContainerBounds(&tab_bounds);
296 }
297 } else {
298 #if !defined(OS_ANDROID) 283 #if !defined(OS_ANDROID)
299 // Try to get the active tab of the active browser and use that for tab 284 // Try to get the active tab of the active browser and use that for tab
300 // bounds. If the browser has never been active, we will fail to get a size 285 // bounds. If the browser has never been active, we will fail to get a size
301 // but we shouldn't be prerendering in that case anyway. 286 // but we shouldn't be prerendering in that case anyway.
302 // 287 //
303 // This code is unneeded on Android as we do not have a Browser object so we 288 // This code is unneeded on Android as we do not have a Browser object so we
304 // can't get the size, and |default_tab_bounds| will be set to the right 289 // can't get the size, and |default_tab_bounds| will be set to the right
305 // value. 290 // value.
306 Browser* active_browser = BrowserList::GetLastActiveWithProfile(profile_); 291 if (Browser* active_browser =
307 if (active_browser) { 292 BrowserList::GetLastActiveWithProfile(profile_)) {
308 WebContents* active_web_contents = active_browser->GetWebContentsAt( 293 WebContents* active_web_contents = active_browser->GetWebContentsAt(
309 active_browser->active_index()); 294 active_browser->active_index());
295 gfx::Rect container_bounds;
310 if (active_web_contents) 296 if (active_web_contents)
311 active_web_contents->GetView()->GetContainerBounds(&tab_bounds); 297 active_web_contents->GetView()->GetContainerBounds(&container_bounds);
298 size_ = container_bounds.size();
312 } 299 }
313 #endif // !defined(OS_ANDROID) 300 #endif // !defined(OS_ANDROID)
314 } 301 }
315 302
316 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); 303 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this));
317 new_contents->SetDelegate(tab_contents_delegate_.get()); 304 new_contents->SetDelegate(tab_contents_delegate_.get());
318 305
319 // Set the size of the prerender WebContents. 306 // Set the size of the prerender WebContents.
320 prerender_contents_->web_contents()->GetView()->SizeContents( 307 prerender_contents_->web_contents()->GetView()->SizeContents(size_);
321 tab_bounds.size());
322 308
323 // Register as an observer of the RenderViewHost so we get messages. 309 // Register as an observer of the RenderViewHost so we get messages.
324 render_view_host_observer_.reset( 310 render_view_host_observer_.reset(
325 new PrerenderRenderViewHostObserver(this, GetRenderViewHostMutable())); 311 new PrerenderRenderViewHostObserver(this, GetRenderViewHostMutable()));
326 312
327 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); 313 child_id_ = GetRenderViewHost()->GetProcess()->GetID();
328 route_id_ = GetRenderViewHost()->GetRoutingID(); 314 route_id_ = GetRenderViewHost()->GetRoutingID();
329 315
330 // Register this with the ResourceDispatcherHost as a prerender 316 // Register this with the ResourceDispatcherHost as a prerender
331 // RenderViewHost. This must be done before the Navigate message to catch all 317 // RenderViewHost. This must be done before the Navigate message to catch all
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 bool PrerenderContents::IsCrossSiteNavigationPending() const { 691 bool PrerenderContents::IsCrossSiteNavigationPending() const {
706 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) 692 if (!prerender_contents_.get() || !prerender_contents_->web_contents())
707 return false; 693 return false;
708 const WebContents* web_contents = prerender_contents_->web_contents(); 694 const WebContents* web_contents = prerender_contents_->web_contents();
709 return (web_contents->GetSiteInstance() != 695 return (web_contents->GetSiteInstance() !=
710 web_contents->GetPendingSiteInstance()); 696 web_contents->GetPendingSiteInstance());
711 } 697 }
712 698
713 699
714 } // namespace prerender 700 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698