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 #include "chrome/browser/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/common/render_messages.h" | 31 #include "chrome/common/render_messages.h" |
| 32 #include "components/history/core/browser/history_types.h" | 32 #include "components/history/core/browser/history_types.h" |
| 33 #include "content/public/browser/browser_child_process_host.h" | 33 #include "content/public/browser/browser_child_process_host.h" |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
| 37 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
| 38 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/render_widget_host.h" | 39 #include "content/public/browser/render_widget_host.h" |
| 40 #include "content/public/browser/resource_request_details.h" | 40 #include "content/public/browser/resource_request_details.h" |
| 41 #include "content/public/browser/service_worker_context.h" | |
| 41 #include "content/public/browser/session_storage_namespace.h" | 42 #include "content/public/browser/session_storage_namespace.h" |
| 43 #include "content/public/browser/storage_partition.h" | |
| 42 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/browser/web_contents_delegate.h" | 45 #include "content/public/browser/web_contents_delegate.h" |
| 44 #include "content/public/common/frame_navigate_params.h" | 46 #include "content/public/common/frame_navigate_params.h" |
| 45 #include "ui/base/page_transition_types.h" | 47 #include "ui/base/page_transition_types.h" |
| 46 #include "ui/gfx/geometry/size.h" | 48 #include "ui/gfx/geometry/size.h" |
| 47 | 49 |
| 48 using content::BrowserThread; | 50 using content::BrowserThread; |
| 49 using content::OpenURLParams; | 51 using content::OpenURLParams; |
| 50 using content::RenderViewHost; | 52 using content::RenderViewHost; |
| 51 using content::ResourceRedirectDetails; | 53 using content::ResourceRedirectDetails; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 prerender_url_(url), | 203 prerender_url_(url), |
| 202 referrer_(referrer), | 204 referrer_(referrer), |
| 203 profile_(profile), | 205 profile_(profile), |
| 204 has_stopped_loading_(false), | 206 has_stopped_loading_(false), |
| 205 has_finished_loading_(false), | 207 has_finished_loading_(false), |
| 206 final_status_(FINAL_STATUS_MAX), | 208 final_status_(FINAL_STATUS_MAX), |
| 207 prerendering_has_been_cancelled_(false), | 209 prerendering_has_been_cancelled_(false), |
| 208 child_id_(-1), | 210 child_id_(-1), |
| 209 route_id_(-1), | 211 route_id_(-1), |
| 210 origin_(origin), | 212 origin_(origin), |
| 211 network_bytes_(0) { | 213 network_bytes_(0), |
| 214 weak_factory_(this) { | |
| 212 DCHECK(prerender_manager); | 215 DCHECK(prerender_manager); |
| 213 } | 216 } |
| 214 | 217 |
| 215 bool PrerenderContents::Init() { | 218 bool PrerenderContents::Init() { |
| 216 return AddAliasURL(prerender_url_); | 219 return AddAliasURL(prerender_url_); |
| 217 } | 220 } |
| 218 | 221 |
| 219 void PrerenderContents::SetPrerenderMode(PrerenderMode mode) { | 222 void PrerenderContents::SetPrerenderMode(PrerenderMode mode) { |
| 220 DCHECK(!prerendering_has_started_); | 223 DCHECK(!prerendering_has_started_); |
| 221 prerender_mode_ = mode; | 224 prerender_mode_ = mode; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 | 312 |
| 310 // Register to inform new RenderViews that we're prerendering. | 313 // Register to inform new RenderViews that we're prerendering. |
| 311 notification_registrar_.Add( | 314 notification_registrar_.Add( |
| 312 this, content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 315 this, content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 313 content::Source<WebContents>(prerender_contents_.get())); | 316 content::Source<WebContents>(prerender_contents_.get())); |
| 314 | 317 |
| 315 // Transfer over the user agent override. | 318 // Transfer over the user agent override. |
| 316 prerender_contents_.get()->SetUserAgentOverride( | 319 prerender_contents_.get()->SetUserAgentOverride( |
| 317 prerender_manager_->config().user_agent_override); | 320 prerender_manager_->config().user_agent_override); |
| 318 | 321 |
| 322 // Start URL load only after checking for a ServiceWorker if we're doing | |
| 323 // NoStatePrefetch. | |
| 324 if (prerender_manager_->IsNoStatePrefetch()) { | |
| 325 content::BrowserContext* browser_context = | |
| 326 prerender_contents_->GetBrowserContext(); | |
| 327 content::StoragePartition* storage_partition = | |
| 328 content::BrowserContext::GetStoragePartition( | |
| 329 Profile::FromBrowserContext(browser_context), | |
| 330 prerender_contents_->GetSiteInstance()); | |
| 331 | |
| 332 storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker( | |
| 333 prerender_url_, prerender_url_, | |
| 334 base::Bind(&PrerenderContents::ContinuePrerenderIfNoServiceWorker, | |
| 335 weak_factory_.GetWeakPtr())); | |
| 336 } else { | |
| 337 // Full prerender doesn't care if we have a service worker, so we continue | |
| 338 // the prerender unconditionally. | |
| 339 ContinuePrerenderIfNoServiceWorker(false /* has_service_worker, ignored */); | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 void PrerenderContents::ContinuePrerenderIfNoServiceWorker( | |
|
droger
2016/12/13 12:43:01
Naming nit (optional): there are cases where the p
mattcary
2016/12/13 12:58:37
That's a good point. The wrinkle is that this is a
| |
| 344 bool has_service_worker) { | |
| 345 if (prerender_manager_->IsNoStatePrefetch() && has_service_worker) { | |
| 346 this->Destroy(FINAL_STATUS_SERVICE_WORKER); | |
| 347 return; | |
|
droger
2016/12/13 12:43:01
Early return here means that the page will be cons
mattcary
2016/12/13 12:58:36
Mmmm, good point.
As far as I can tell, we can't
droger
2016/12/13 13:25:48
I don't see any use of WebContents in the code you
mattcary
2016/12/13 13:30:50
prerender_contents_ is actually a WebContents (yay
droger
2016/12/13 13:36:36
prerender_contents_->GetBrowserContext() is just t
mattcary
2016/12/13 13:53:46
ah, good point, will look.
| |
| 348 } | |
| 349 | |
| 319 content::NavigationController::LoadURLParams load_url_params( | 350 content::NavigationController::LoadURLParams load_url_params( |
| 320 prerender_url_); | 351 prerender_url_); |
| 321 load_url_params.referrer = referrer_; | 352 load_url_params.referrer = referrer_; |
| 322 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 353 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
| 323 if (origin_ == ORIGIN_OMNIBOX) { | 354 if (origin_ == ORIGIN_OMNIBOX) { |
| 324 load_url_params.transition_type = ui::PageTransitionFromInt( | 355 load_url_params.transition_type = ui::PageTransitionFromInt( |
| 325 ui::PAGE_TRANSITION_TYPED | | 356 ui::PAGE_TRANSITION_TYPED | |
| 326 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 357 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 327 } else if (origin_ == ORIGIN_INSTANT) { | 358 } else if (origin_ == ORIGIN_INSTANT) { |
| 328 load_url_params.transition_type = ui::PageTransitionFromInt( | 359 load_url_params.transition_type = ui::PageTransitionFromInt( |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 void PrerenderContents::AddResourceThrottle( | 777 void PrerenderContents::AddResourceThrottle( |
| 747 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 778 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
| 748 resource_throttles_.push_back(throttle); | 779 resource_throttles_.push_back(throttle); |
| 749 } | 780 } |
| 750 | 781 |
| 751 void PrerenderContents::AddNetworkBytes(int64_t bytes) { | 782 void PrerenderContents::AddNetworkBytes(int64_t bytes) { |
| 752 network_bytes_ += bytes; | 783 network_bytes_ += bytes; |
| 753 } | 784 } |
| 754 | 785 |
| 755 } // namespace prerender | 786 } // namespace prerender |
| OLD | NEW |