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 <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/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/history/history_tab_helper.h" | 12 #include "chrome/browser/history/history_tab_helper.h" |
13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
14 #include "chrome/browser/prerender/prerender_final_status.h" | 14 #include "chrome/browser/prerender/prerender_final_status.h" |
15 #include "chrome/browser/prerender/prerender_manager.h" | 15 #include "chrome/browser/prerender/prerender_manager.h" |
16 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" | 16 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" |
17 #include "chrome/browser/prerender/prerender_tracker.h" | 17 #include "chrome/browser/prerender/prerender_tracker.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.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/tab_contents/tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/icon_messages.h" | 23 #include "chrome/common/icon_messages.h" |
24 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/prerender_messages.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 26 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
27 #include "content/browser/renderer_host/render_view_host.h" | 27 #include "content/browser/renderer_host/render_view_host.h" |
28 #include "content/browser/renderer_host/resource_request_details.h" | 28 #include "content/browser/renderer_host/resource_request_details.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
33 #include "content/public/browser/web_contents_view.h" | 33 #include "content/public/browser/web_contents_view.h" |
34 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 | 233 |
234 bool PrerenderContents::Init() { | 234 bool PrerenderContents::Init() { |
235 return AddAliasURL(prerender_url_); | 235 return AddAliasURL(prerender_url_); |
236 } | 236 } |
237 | 237 |
238 // static | 238 // static |
239 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 239 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
240 return new PrerenderContentsFactoryImpl(); | 240 return new PrerenderContentsFactoryImpl(); |
241 } | 241 } |
242 | 242 |
243 void BroadcastPrerender(const GURL& url, bool is_add) { | |
244 content::RenderProcessHost::iterator host_it = | |
245 content::RenderProcessHost::AllHostsIterator(); | |
246 while (!host_it.IsAtEnd()) { | |
247 content::RenderProcessHost* host = host_it.GetCurrentValue(); | |
248 host_it.Advance(); | |
249 if (!host) | |
250 continue; | |
251 // TODO(cbentzel): Need to filter to the current profile only. | |
dominich
2012/02/28 16:21:00
Should you also filter to the RPH that was the sou
cbentzel
2012/02/29 18:16:13
I am limiting to that now, per your comment as wel
| |
252 IPC::Message* message = NULL; | |
dominich
2012/02/28 16:21:00
IPC::Message* message = is_add ? new PrerenderMsg_
cbentzel
2012/02/29 18:16:13
This doesn't work because then the operands of the
| |
253 if (is_add) { | |
254 message = new PrerenderMsg_AddPrerenderURL(url); | |
255 } else { | |
256 message = new PrerenderMsg_RemovePrerenderURL(url); | |
257 } | |
258 // TODO(cbentzel): Make sure that sending a message doesn't | |
259 // adjust the iterator. | |
260 host->Send(message); | |
261 } | |
262 } | |
263 | |
243 void PrerenderContents::StartPrerendering( | 264 void PrerenderContents::StartPrerendering( |
244 const RenderViewHost* source_render_view_host, | 265 const RenderViewHost* source_render_view_host, |
245 SessionStorageNamespace* session_storage_namespace) { | 266 SessionStorageNamespace* session_storage_namespace) { |
246 DCHECK(profile_ != NULL); | 267 DCHECK(profile_ != NULL); |
247 DCHECK(!prerendering_has_started_); | 268 DCHECK(!prerendering_has_started_); |
248 DCHECK(prerender_contents_.get() == NULL); | 269 DCHECK(prerender_contents_.get() == NULL); |
249 | 270 |
250 prerendering_has_started_ = true; | 271 prerendering_has_started_ = true; |
272 BroadcastPrerender(prerender_url_, true); | |
273 | |
251 WebContents* new_contents = WebContents::Create( | 274 WebContents* new_contents = WebContents::Create( |
252 profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); | 275 profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); |
253 prerender_contents_.reset(new TabContentsWrapper(new_contents)); | 276 prerender_contents_.reset(new TabContentsWrapper(new_contents)); |
254 content::WebContentsObserver::Observe(new_contents); | 277 content::WebContentsObserver::Observe(new_contents); |
255 | 278 |
256 gfx::Rect tab_bounds; | 279 gfx::Rect tab_bounds; |
257 if (source_render_view_host) { | 280 if (source_render_view_host) { |
258 DCHECK(source_render_view_host->view() != NULL); | 281 DCHECK(source_render_view_host->view() != NULL); |
259 WebContents* source_wc = | 282 WebContents* source_wc = |
260 source_render_view_host->delegate()->GetAsWebContents(); | 283 source_render_view_host->delegate()->GetAsWebContents(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 | 434 |
412 content::Details<RenderViewHost> new_render_view_host(details); | 435 content::Details<RenderViewHost> new_render_view_host(details); |
413 OnRenderViewHostCreated(new_render_view_host.ptr()); | 436 OnRenderViewHostCreated(new_render_view_host.ptr()); |
414 | 437 |
415 // When a new RenderView is created for a prerendering TabContents, | 438 // When a new RenderView is created for a prerendering TabContents, |
416 // tell the new RenderView it's being used for prerendering before any | 439 // tell the new RenderView it's being used for prerendering before any |
417 // navigations occur. Note that this is always triggered before the | 440 // navigations occur. Note that this is always triggered before the |
418 // first navigation, so there's no need to send the message just after | 441 // first navigation, so there's no need to send the message just after |
419 // the TabContents is created. | 442 // the TabContents is created. |
420 new_render_view_host->Send( | 443 new_render_view_host->Send( |
421 new ChromeViewMsg_SetIsPrerendering( | 444 new PrerenderMsg_SetIsPrerendering( |
422 new_render_view_host->routing_id(), | 445 new_render_view_host->routing_id(), |
423 true)); | 446 true)); |
424 | 447 |
425 // Make sure the size of the RenderViewHost has been passed to the new | 448 // Make sure the size of the RenderViewHost has been passed to the new |
426 // RenderView. Otherwise, the size may not be sent until the | 449 // RenderView. Otherwise, the size may not be sent until the |
427 // RenderViewReady event makes it from the render process to the UI | 450 // RenderViewReady event makes it from the render process to the UI |
428 // thread of the browser process. When the RenderView receives its | 451 // thread of the browser process. When the RenderView receives its |
429 // size, is also sets itself to be visible, which would then break the | 452 // size, is also sets itself to be visible, which would then break the |
430 // visibility API. | 453 // visibility API. |
431 new_render_view_host->WasResized(); | 454 new_render_view_host->WasResized(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 bool PrerenderContents::ShouldSuppressDialogs() { | 559 bool PrerenderContents::ShouldSuppressDialogs() { |
537 // Always suppress JavaScript messages if they're triggered by a page being | 560 // Always suppress JavaScript messages if they're triggered by a page being |
538 // prerendered. | 561 // prerendered. |
539 // We still want to show the user the message when they navigate to this | 562 // We still want to show the user the message when they navigate to this |
540 // page, so cancel this prerender. | 563 // page, so cancel this prerender. |
541 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); | 564 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); |
542 return true; | 565 return true; |
543 } | 566 } |
544 | 567 |
545 void PrerenderContents::Destroy(FinalStatus final_status) { | 568 void PrerenderContents::Destroy(FinalStatus final_status) { |
569 BroadcastPrerender(prerender_url_, false); | |
546 if (prerendering_has_been_cancelled_) | 570 if (prerendering_has_been_cancelled_) |
547 return; | 571 return; |
548 | 572 |
549 if (child_id_ != -1 && route_id_ != -1) { | 573 if (child_id_ != -1 && route_id_ != -1) { |
550 // Cancel the prerender in the PrerenderTracker. This is needed | 574 // Cancel the prerender in the PrerenderTracker. This is needed |
551 // because destroy may be called directly from the UI thread without calling | 575 // because destroy may be called directly from the UI thread without calling |
552 // TryCancel(). This is difficult to completely avoid, since prerendering | 576 // TryCancel(). This is difficult to completely avoid, since prerendering |
553 // can be cancelled before a RenderView is created. | 577 // can be cancelled before a RenderView is created. |
554 bool is_cancelled = prerender_tracker_->TryCancel( | 578 bool is_cancelled = prerender_tracker_->TryCancel( |
555 child_id_, route_id_, final_status); | 579 child_id_, route_id_, final_status); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 674 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
651 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 675 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
652 return false; | 676 return false; |
653 const WebContents* web_contents = prerender_contents_->web_contents(); | 677 const WebContents* web_contents = prerender_contents_->web_contents(); |
654 return (web_contents->GetSiteInstance() != | 678 return (web_contents->GetSiteInstance() != |
655 web_contents->GetPendingSiteInstance()); | 679 web_contents->GetPendingSiteInstance()); |
656 } | 680 } |
657 | 681 |
658 | 682 |
659 } // namespace prerender | 683 } // namespace prerender |
OLD | NEW |