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 25 matching lines...) Expand all Loading... |
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/session_storage_namespace.h" | 41 #include "content/public/browser/session_storage_namespace.h" |
42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
43 #include "content/public/browser/web_contents_delegate.h" | 43 #include "content/public/browser/web_contents_delegate.h" |
44 #include "content/public/common/frame_navigate_params.h" | 44 #include "content/public/common/frame_navigate_params.h" |
45 #include "ui/base/page_transition_types.h" | 45 #include "ui/base/page_transition_types.h" |
46 #include "ui/gfx/geometry/rect.h" | 46 #include "ui/gfx/geometry/size.h" |
47 | 47 |
48 using content::BrowserThread; | 48 using content::BrowserThread; |
49 using content::DownloadItem; | 49 using content::DownloadItem; |
50 using content::OpenURLParams; | 50 using content::OpenURLParams; |
51 using content::RenderViewHost; | 51 using content::RenderViewHost; |
52 using content::ResourceRedirectDetails; | 52 using content::ResourceRedirectDetails; |
53 using content::ResourceType; | 53 using content::ResourceType; |
54 using content::SessionStorageNamespace; | 54 using content::SessionStorageNamespace; |
55 using content::WebContents; | 55 using content::WebContents; |
56 | 56 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 const GURL& url, | 162 const GURL& url, |
163 bool user_gesture) override { | 163 bool user_gesture) override { |
164 // TODO(mmenke): Consider supporting this if it is a common case during | 164 // TODO(mmenke): Consider supporting this if it is a common case during |
165 // prerenders. | 165 // prerenders. |
166 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); | 166 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); |
167 } | 167 } |
168 | 168 |
169 gfx::Size GetSizeForNewRenderView(WebContents* web_contents) const override { | 169 gfx::Size GetSizeForNewRenderView(WebContents* web_contents) const override { |
170 // Have to set the size of the RenderView on initialization to be sure it is | 170 // Have to set the size of the RenderView on initialization to be sure it is |
171 // set before the RenderView is hidden on all platforms (esp. Android). | 171 // set before the RenderView is hidden on all platforms (esp. Android). |
172 return prerender_contents_->size_; | 172 return prerender_contents_->bounds_.size(); |
173 } | 173 } |
174 | 174 |
175 private: | 175 private: |
176 PrerenderContents* prerender_contents_; | 176 PrerenderContents* prerender_contents_; |
177 }; | 177 }; |
178 | 178 |
179 void PrerenderContents::Observer::OnPrerenderStopLoading( | 179 void PrerenderContents::Observer::OnPrerenderStopLoading( |
180 PrerenderContents* contents) { | 180 PrerenderContents* contents) { |
181 } | 181 } |
182 | 182 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (!web_contents) | 228 if (!web_contents) |
229 return NULL; | 229 return NULL; |
230 PrerenderManager* prerender_manager = PrerenderManagerFactory::GetForProfile( | 230 PrerenderManager* prerender_manager = PrerenderManagerFactory::GetForProfile( |
231 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 231 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
232 if (!prerender_manager) | 232 if (!prerender_manager) |
233 return NULL; | 233 return NULL; |
234 return prerender_manager->GetPrerenderContents(web_contents); | 234 return prerender_manager->GetPrerenderContents(web_contents); |
235 } | 235 } |
236 | 236 |
237 void PrerenderContents::StartPrerendering( | 237 void PrerenderContents::StartPrerendering( |
238 const gfx::Size& size, | 238 const gfx::Rect& bounds, |
239 SessionStorageNamespace* session_storage_namespace) { | 239 SessionStorageNamespace* session_storage_namespace) { |
240 DCHECK(profile_); | 240 DCHECK(profile_); |
241 DCHECK(!size.IsEmpty()); | 241 DCHECK(!bounds.IsEmpty()); |
242 DCHECK(!prerendering_has_started_); | 242 DCHECK(!prerendering_has_started_); |
243 DCHECK(!prerender_contents_); | 243 DCHECK(!prerender_contents_); |
244 DCHECK(size_.IsEmpty()); | |
245 DCHECK_EQ(1U, alias_urls_.size()); | 244 DCHECK_EQ(1U, alias_urls_.size()); |
246 | 245 |
247 session_storage_namespace_id_ = session_storage_namespace->id(); | 246 session_storage_namespace_id_ = session_storage_namespace->id(); |
248 size_ = size; | 247 bounds_ = bounds; |
249 | 248 |
250 DCHECK(load_start_time_.is_null()); | 249 DCHECK(load_start_time_.is_null()); |
251 load_start_time_ = base::TimeTicks::Now(); | 250 load_start_time_ = base::TimeTicks::Now(); |
252 | 251 |
253 // Everything after this point sets up the WebContents object and associated | 252 // Everything after this point sets up the WebContents object and associated |
254 // RenderView for the prerender page. Don't do this for members of the | 253 // RenderView for the prerender page. Don't do this for members of the |
255 // control group. | 254 // control group. |
256 if (prerender_manager_->IsControlGroup()) | 255 if (prerender_manager_->IsControlGroup()) |
257 return; | 256 return; |
258 | 257 |
259 prerendering_has_started_ = true; | 258 prerendering_has_started_ = true; |
260 | 259 |
261 prerender_contents_.reset(CreateWebContents(session_storage_namespace)); | 260 prerender_contents_.reset(CreateWebContents(session_storage_namespace)); |
262 TabHelpers::AttachTabHelpers(prerender_contents_.get()); | 261 TabHelpers::AttachTabHelpers(prerender_contents_.get()); |
263 content::WebContentsObserver::Observe(prerender_contents_.get()); | 262 content::WebContentsObserver::Observe(prerender_contents_.get()); |
264 | 263 |
265 // Tag the prerender contents with the task manager specific prerender tag, so | 264 // Tag the prerender contents with the task manager specific prerender tag, so |
266 // that it shows up in the task manager. | 265 // that it shows up in the task manager. |
267 task_manager::WebContentsTags::CreateForPrerenderContents( | 266 task_manager::WebContentsTags::CreateForPrerenderContents( |
268 prerender_contents_.get()); | 267 prerender_contents_.get()); |
269 | 268 |
270 web_contents_delegate_.reset(new WebContentsDelegateImpl(this)); | 269 web_contents_delegate_.reset(new WebContentsDelegateImpl(this)); |
271 prerender_contents_.get()->SetDelegate(web_contents_delegate_.get()); | 270 prerender_contents_.get()->SetDelegate(web_contents_delegate_.get()); |
272 // Set the size of the prerender WebContents. | 271 // Set the size of the prerender WebContents. |
273 ResizeWebContents(prerender_contents_.get(), size_); | 272 ResizeWebContents(prerender_contents_.get(), bounds_); |
274 | 273 |
275 // TODO(davidben): This logic assumes each prerender has at most one | 274 // TODO(davidben): This logic assumes each prerender has at most one |
276 // route. https://crbug.com/440544 | 275 // route. https://crbug.com/440544 |
277 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); | 276 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); |
278 route_id_ = GetRenderViewHost()->GetRoutingID(); | 277 route_id_ = GetRenderViewHost()->GetRoutingID(); |
279 | 278 |
280 // TODO(davidben): This logic assumes each prerender has at most one | 279 // TODO(davidben): This logic assumes each prerender has at most one |
281 // process. https://crbug.com/440544 | 280 // process. https://crbug.com/440544 |
282 prerender_manager()->AddPrerenderProcessHost( | 281 prerender_manager()->AddPrerenderProcessHost( |
283 GetRenderViewHost()->GetProcess()); | 282 GetRenderViewHost()->GetProcess()); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 void PrerenderContents::AddResourceThrottle( | 719 void PrerenderContents::AddResourceThrottle( |
721 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 720 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
722 resource_throttles_.push_back(throttle); | 721 resource_throttles_.push_back(throttle); |
723 } | 722 } |
724 | 723 |
725 void PrerenderContents::AddNetworkBytes(int64_t bytes) { | 724 void PrerenderContents::AddNetworkBytes(int64_t bytes) { |
726 network_bytes_ += bytes; | 725 network_bytes_ += bytes; |
727 } | 726 } |
728 | 727 |
729 } // namespace prerender | 728 } // namespace prerender |
OLD | NEW |