OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/history/history_tab_helper.h" | 13 #include "chrome/browser/history/history_tab_helper.h" |
14 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/browser/prerender/prerender_final_status.h" | 15 #include "chrome/browser/prerender/prerender_final_status.h" |
16 #include "chrome/browser/prerender/prerender_manager.h" | 16 #include "chrome/browser/prerender/prerender_manager.h" |
17 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" | 17 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" |
18 #include "chrome/browser/prerender/prerender_tracker.h" | 18 #include "chrome/browser/prerender/prerender_tracker.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
21 #include "chrome/browser/ui/download/download_tab_helper.h" | 21 #include "chrome/browser/ui/download/download_tab_helper.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 23 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/icon_messages.h" | 24 #include "chrome/common/icon_messages.h" |
24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
26 #include "content/browser/renderer_host/render_view_host.h" | 27 #include "content/browser/renderer_host/render_view_host.h" |
27 #include "content/browser/renderer_host/resource_request_details.h" | 28 #include "content/browser/renderer_host/resource_request_details.h" |
28 #include "content/browser/tab_contents/tab_contents_delegate.h" | 29 #include "content/browser/tab_contents/tab_contents_delegate.h" |
29 #include "content/browser/tab_contents/tab_contents_view.h" | 30 #include "content/browser/tab_contents/tab_contents_view.h" |
30 #include "content/common/notification_service.h" | 31 #include "content/common/notification_service.h" |
31 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
32 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // Register this with the ResourceDispatcherHost as a prerender | 216 // Register this with the ResourceDispatcherHost as a prerender |
216 // RenderViewHost. This must be done before the Navigate message to catch all | 217 // RenderViewHost. This must be done before the Navigate message to catch all |
217 // resource requests, but as it is on the same thread as the Navigate message | 218 // resource requests, but as it is on the same thread as the Navigate message |
218 // (IO) there is no race condition. | 219 // (IO) there is no race condition. |
219 prerender_tracker_->OnPrerenderingStarted( | 220 prerender_tracker_->OnPrerenderingStarted( |
220 child_id_, | 221 child_id_, |
221 route_id_, | 222 route_id_, |
222 prerender_manager_); | 223 prerender_manager_); |
223 | 224 |
224 // Close ourselves when the application is shutting down. | 225 // Close ourselves when the application is shutting down. |
225 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, | 226 notification_registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
226 NotificationService::AllSources()); | 227 NotificationService::AllSources()); |
227 | 228 |
228 // Register for our parent profile to shutdown, so we can shut ourselves down | 229 // Register for our parent profile to shutdown, so we can shut ourselves down |
229 // as well (should only be called for OTR profiles, as we should receive | 230 // as well (should only be called for OTR profiles, as we should receive |
230 // APP_TERMINATING before non-OTR profiles are destroyed). | 231 // APP_TERMINATING before non-OTR profiles are destroyed). |
231 // TODO(tburkard): figure out if this is needed. | 232 // TODO(tburkard): figure out if this is needed. |
232 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 233 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
233 Source<Profile>(profile_)); | 234 Source<Profile>(profile_)); |
234 | 235 |
235 // Register to inform new RenderViews that we're prerendering. | 236 // Register to inform new RenderViews that we're prerendering. |
236 notification_registrar_.Add( | 237 notification_registrar_.Add( |
237 this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 238 this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
238 Source<TabContents>(new_contents)); | 239 Source<TabContents>(new_contents)); |
239 | 240 |
240 // Register to be told when the RenderView is ready, so we can hide it. | 241 // Register to be told when the RenderView is ready, so we can hide it. |
241 // It will automatically be set to visible when we resize it, otherwise. | 242 // It will automatically be set to visible when we resize it, otherwise. |
242 notification_registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, | 243 notification_registrar_.Add(this, |
| 244 content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
243 Source<TabContents>(new_contents)); | 245 Source<TabContents>(new_contents)); |
244 | 246 |
245 // Register for redirect notifications sourced from |this|. | 247 // Register for redirect notifications sourced from |this|. |
246 notification_registrar_.Add( | 248 notification_registrar_.Add( |
247 this, NotificationType::RESOURCE_RECEIVED_REDIRECT, | 249 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
248 Source<RenderViewHostDelegate>(GetRenderViewHostDelegate())); | 250 Source<RenderViewHostDelegate>(GetRenderViewHostDelegate())); |
249 | 251 |
250 // Register for new windows from any source. | 252 // Register for new windows from any source. |
251 notification_registrar_.Add(this, | 253 notification_registrar_.Add( |
252 NotificationType::CREATING_NEW_WINDOW_CANCELLED, | 254 this, content::NOTIFICATION_CREATING_NEW_WINDOW_CANCELLED, |
253 Source<TabContents>(new_contents)); | 255 Source<TabContents>(new_contents)); |
254 | 256 |
255 DCHECK(load_start_time_.is_null()); | 257 DCHECK(load_start_time_.is_null()); |
256 load_start_time_ = base::TimeTicks::Now(); | 258 load_start_time_ = base::TimeTicks::Now(); |
257 | 259 |
258 new_contents->controller().LoadURL(prerender_url_, | 260 new_contents->controller().LoadURL(prerender_url_, |
259 referrer_, PageTransition::LINK); | 261 referrer_, PageTransition::LINK); |
260 } | 262 } |
261 | 263 |
262 bool PrerenderContents::GetChildId(int* child_id) const { | 264 bool PrerenderContents::GetChildId(int* child_id) const { |
263 CHECK(child_id); | 265 CHECK(child_id); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 306 |
305 // If we still have a TabContents, clean up anything we need to and then | 307 // If we still have a TabContents, clean up anything we need to and then |
306 // destroy it. | 308 // destroy it. |
307 if (prerender_contents_.get()) | 309 if (prerender_contents_.get()) |
308 delete ReleasePrerenderContents(); | 310 delete ReleasePrerenderContents(); |
309 | 311 |
310 // The following URLs are no longer rendering. | 312 // The following URLs are no longer rendering. |
311 prerender_tracker_->RemovePrerenderURLsOnUIThread(alias_urls_); | 313 prerender_tracker_->RemovePrerenderURLsOnUIThread(alias_urls_); |
312 } | 314 } |
313 | 315 |
314 void PrerenderContents::Observe(NotificationType type, | 316 void PrerenderContents::Observe(int type, |
315 const NotificationSource& source, | 317 const NotificationSource& source, |
316 const NotificationDetails& details) { | 318 const NotificationDetails& details) { |
317 switch (type.value) { | 319 switch (type) { |
318 case NotificationType::PROFILE_DESTROYED: | 320 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
319 Destroy(FINAL_STATUS_PROFILE_DESTROYED); | 321 Destroy(FINAL_STATUS_PROFILE_DESTROYED); |
320 return; | 322 return; |
321 | 323 |
322 case NotificationType::APP_TERMINATING: | 324 case content::NOTIFICATION_APP_TERMINATING: |
323 Destroy(FINAL_STATUS_APP_TERMINATING); | 325 Destroy(FINAL_STATUS_APP_TERMINATING); |
324 return; | 326 return; |
325 | 327 |
326 case NotificationType::RESOURCE_RECEIVED_REDIRECT: { | 328 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { |
327 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page. | 329 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page. |
328 // If it's a redirect on the top-level resource, the name needs | 330 // If it's a redirect on the top-level resource, the name needs |
329 // to be remembered for future matching, and if it redirects to | 331 // to be remembered for future matching, and if it redirects to |
330 // an https resource, it needs to be canceled. If a subresource | 332 // an https resource, it needs to be canceled. If a subresource |
331 // is redirected, nothing changes. | 333 // is redirected, nothing changes. |
332 DCHECK(Source<RenderViewHostDelegate>(source).ptr() == | 334 DCHECK(Source<RenderViewHostDelegate>(source).ptr() == |
333 GetRenderViewHostDelegate()); | 335 GetRenderViewHostDelegate()); |
334 ResourceRedirectDetails* resource_redirect_details = | 336 ResourceRedirectDetails* resource_redirect_details = |
335 Details<ResourceRedirectDetails>(details).ptr(); | 337 Details<ResourceRedirectDetails>(details).ptr(); |
336 CHECK(resource_redirect_details); | 338 CHECK(resource_redirect_details); |
337 if (resource_redirect_details->resource_type() == | 339 if (resource_redirect_details->resource_type() == |
338 ResourceType::MAIN_FRAME) { | 340 ResourceType::MAIN_FRAME) { |
339 if (!AddAliasURL(resource_redirect_details->new_url())) | 341 if (!AddAliasURL(resource_redirect_details->new_url())) |
340 return; | 342 return; |
341 } | 343 } |
342 break; | 344 break; |
343 } | 345 } |
344 | 346 |
345 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 347 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
346 if (prerender_contents_.get()) { | 348 if (prerender_contents_.get()) { |
347 DCHECK_EQ(Source<TabContents>(source).ptr(), | 349 DCHECK_EQ(Source<TabContents>(source).ptr(), |
348 prerender_contents_->tab_contents()); | 350 prerender_contents_->tab_contents()); |
349 | 351 |
350 Details<RenderViewHost> new_render_view_host(details); | 352 Details<RenderViewHost> new_render_view_host(details); |
351 OnRenderViewHostCreated(new_render_view_host.ptr()); | 353 OnRenderViewHostCreated(new_render_view_host.ptr()); |
352 | 354 |
353 // When a new RenderView is created for a prerendering TabContents, | 355 // When a new RenderView is created for a prerendering TabContents, |
354 // tell the new RenderView it's being used for prerendering before any | 356 // tell the new RenderView it's being used for prerendering before any |
355 // navigations occur. Note that this is always triggered before the | 357 // navigations occur. Note that this is always triggered before the |
356 // first navigation, so there's no need to send the message just after | 358 // first navigation, so there's no need to send the message just after |
357 // the TabContents is created. | 359 // the TabContents is created. |
358 new_render_view_host->Send( | 360 new_render_view_host->Send( |
359 new ViewMsg_SetIsPrerendering(new_render_view_host->routing_id(), | 361 new ViewMsg_SetIsPrerendering(new_render_view_host->routing_id(), |
360 true)); | 362 true)); |
361 } | 363 } |
362 break; | 364 break; |
363 } | 365 } |
364 | 366 |
365 case NotificationType::TAB_CONTENTS_CONNECTED: { | 367 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: { |
366 if (prerender_contents_.get()) { | 368 if (prerender_contents_.get()) { |
367 DCHECK_EQ(Source<TabContents>(source).ptr(), | 369 DCHECK_EQ(Source<TabContents>(source).ptr(), |
368 prerender_contents_->tab_contents()); | 370 prerender_contents_->tab_contents()); |
369 // Set the new TabContents and its RenderViewHost as hidden, to reduce | 371 // Set the new TabContents and its RenderViewHost as hidden, to reduce |
370 // resource usage. This can only be done after the size has been sent | 372 // resource usage. This can only be done after the size has been sent |
371 // to the RenderView, which is why it's done here. | 373 // to the RenderView, which is why it's done here. |
372 prerender_contents_->tab_contents()->HideContents(); | 374 prerender_contents_->tab_contents()->HideContents(); |
373 } | 375 } |
374 return; | 376 return; |
375 } | 377 } |
376 | 378 |
377 case NotificationType::CREATING_NEW_WINDOW_CANCELLED: { | 379 case content::NOTIFICATION_CREATING_NEW_WINDOW_CANCELLED: { |
378 if (prerender_contents_.get()) { | 380 if (prerender_contents_.get()) { |
379 CHECK(Source<TabContents>(source).ptr() == | 381 CHECK(Source<TabContents>(source).ptr() == |
380 prerender_contents_->tab_contents()); | 382 prerender_contents_->tab_contents()); |
381 // Since we don't want to permit child windows that would have a | 383 // Since we don't want to permit child windows that would have a |
382 // window.opener property, terminate prerendering. | 384 // window.opener property, terminate prerendering. |
383 Destroy(FINAL_STATUS_CREATE_NEW_WINDOW); | 385 Destroy(FINAL_STATUS_CREATE_NEW_WINDOW); |
384 } | 386 } |
385 break; | 387 break; |
386 } | 388 } |
387 | 389 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 return NULL; | 595 return NULL; |
594 DictionaryValue* dict_value = new DictionaryValue(); | 596 DictionaryValue* dict_value = new DictionaryValue(); |
595 dict_value->SetString("url", prerender_url_.spec()); | 597 dict_value->SetString("url", prerender_url_.spec()); |
596 base::TimeTicks current_time = base::TimeTicks::Now(); | 598 base::TimeTicks current_time = base::TimeTicks::Now(); |
597 base::TimeDelta duration = current_time - load_start_time_; | 599 base::TimeDelta duration = current_time - load_start_time_; |
598 dict_value->SetInteger("duration", duration.InSeconds()); | 600 dict_value->SetInteger("duration", duration.InSeconds()); |
599 return dict_value; | 601 return dict_value; |
600 } | 602 } |
601 | 603 |
602 } // namespace prerender | 604 } // namespace prerender |
OLD | NEW |