| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 14 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| 15 #include "content/browser/frame_host/cross_site_transferring_request.h" | 15 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 16 #include "content/browser/frame_host/debug_urls.h" | 16 #include "content/browser/frame_host/debug_urls.h" |
| 17 #include "content/browser/frame_host/interstitial_page_impl.h" | 17 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 18 #include "content/browser/frame_host/navigation_before_commit_info.h" | 18 #include "content/browser/frame_host/navigation_before_commit_info.h" |
| 19 #include "content/browser/frame_host/navigation_controller_impl.h" | 19 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 20 #include "content/browser/frame_host/navigation_entry_impl.h" | 20 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 21 #include "content/browser/frame_host/navigation_request.h" | |
| 22 #include "content/browser/frame_host/navigation_request_info.h" | |
| 23 #include "content/browser/frame_host/navigator.h" | 21 #include "content/browser/frame_host/navigator.h" |
| 24 #include "content/browser/frame_host/render_frame_host_factory.h" | 22 #include "content/browser/frame_host/render_frame_host_factory.h" |
| 25 #include "content/browser/frame_host/render_frame_host_impl.h" | 23 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 26 #include "content/browser/frame_host/render_frame_proxy_host.h" | 24 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 27 #include "content/browser/renderer_host/render_process_host_impl.h" | 25 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 28 #include "content/browser/renderer_host/render_view_host_factory.h" | 26 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 29 #include "content/browser/renderer_host/render_view_host_impl.h" | 27 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 30 #include "content/browser/site_instance_impl.h" | 28 #include "content/browser/site_instance_impl.h" |
| 31 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 29 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 32 #include "content/browser/webui/web_ui_impl.h" | 30 #include "content/browser/webui/web_ui_impl.h" |
| 33 #include "content/common/navigation_params.h" | 31 #include "content/common/frame_messages.h" |
| 34 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
| 35 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
| 36 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 38 #include "content/public/browser/render_widget_host_iterator.h" | 36 #include "content/public/browser/render_widget_host_iterator.h" |
| 39 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 40 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 41 #include "content/public/browser/web_ui_controller.h" | 39 #include "content/public/browser/web_ui_controller.h" |
| 42 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
| 43 #include "content/public/common/referrer.h" | 41 #include "content/public/common/referrer.h" |
| 44 #include "content/public/common/url_constants.h" | 42 #include "content/public/common/url_constants.h" |
| 45 #include "net/base/load_flags.h" | |
| 46 | 43 |
| 47 namespace content { | 44 namespace content { |
| 48 | 45 |
| 49 // PlzNavigate | |
| 50 // Returns the net load flags to use based on the navigation type. | |
| 51 // TODO(clamy): unify the code with what is happening on the renderer side. | |
| 52 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) { | |
| 53 int load_flags = net::LOAD_NORMAL; | |
| 54 switch (navigation_type) { | |
| 55 case FrameMsg_Navigate_Type::RELOAD: | |
| 56 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL: | |
| 57 load_flags |= net::LOAD_VALIDATE_CACHE; | |
| 58 break; | |
| 59 case FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE: | |
| 60 load_flags |= net::LOAD_BYPASS_CACHE; | |
| 61 break; | |
| 62 case FrameMsg_Navigate_Type::RESTORE: | |
| 63 load_flags |= net::LOAD_PREFERRING_CACHE; | |
| 64 break; | |
| 65 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: | |
| 66 load_flags |= net::LOAD_ONLY_FROM_CACHE; | |
| 67 break; | |
| 68 case FrameMsg_Navigate_Type::NORMAL: | |
| 69 default: | |
| 70 break; | |
| 71 } | |
| 72 return load_flags; | |
| 73 } | |
| 74 | |
| 75 // PlzNavigate | |
| 76 // Generates a default FrameHostMsg_BeginNavigation_Params to be used when there | |
| 77 // is no live renderer. | |
| 78 FrameHostMsg_BeginNavigation_Params MakeDefaultBeginNavigation( | |
| 79 const RequestNavigationParams& request_params, | |
| 80 FrameMsg_Navigate_Type::Value navigation_type) { | |
| 81 FrameHostMsg_BeginNavigation_Params begin_navigation_params; | |
| 82 begin_navigation_params.method = request_params.is_post ? "POST" : "GET"; | |
| 83 begin_navigation_params.load_flags = | |
| 84 LoadFlagFromNavigationType(navigation_type); | |
| 85 | |
| 86 // TODO(clamy): Post data from the browser should be put in the request body. | |
| 87 // Headers should be filled in as well. | |
| 88 | |
| 89 begin_navigation_params.has_user_gesture = false; | |
| 90 return begin_navigation_params; | |
| 91 } | |
| 92 | |
| 93 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { | 46 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { |
| 94 node->render_manager()->pending_delete_hosts_.clear(); | 47 node->render_manager()->pending_delete_hosts_.clear(); |
| 95 return true; | 48 return true; |
| 96 } | 49 } |
| 97 | 50 |
| 98 RenderFrameHostManager::RenderFrameHostManager( | 51 RenderFrameHostManager::RenderFrameHostManager( |
| 99 FrameTreeNode* frame_tree_node, | 52 FrameTreeNode* frame_tree_node, |
| 100 RenderFrameHostDelegate* render_frame_delegate, | 53 RenderFrameHostDelegate* render_frame_delegate, |
| 101 RenderViewHostDelegate* render_view_delegate, | 54 RenderViewHostDelegate* render_view_delegate, |
| 102 RenderWidgetHostDelegate* render_widget_delegate, | 55 RenderWidgetHostDelegate* render_widget_delegate, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 114 | 67 |
| 115 RenderFrameHostManager::~RenderFrameHostManager() { | 68 RenderFrameHostManager::~RenderFrameHostManager() { |
| 116 if (pending_render_frame_host_) | 69 if (pending_render_frame_host_) |
| 117 CancelPending(); | 70 CancelPending(); |
| 118 | 71 |
| 119 // We should always have a current RenderFrameHost except in some tests. | 72 // We should always have a current RenderFrameHost except in some tests. |
| 120 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); | 73 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); |
| 121 | 74 |
| 122 // Delete any swapped out RenderFrameHosts. | 75 // Delete any swapped out RenderFrameHosts. |
| 123 STLDeleteValues(&proxy_hosts_); | 76 STLDeleteValues(&proxy_hosts_); |
| 124 | |
| 125 // PlzNavigate | |
| 126 // There is an active navigation request for this RFHM so it needs to be | |
| 127 // canceled. | |
| 128 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 129 switches::kEnableBrowserSideNavigation)) { | |
| 130 if (navigation_request_.get()) | |
| 131 navigation_request_->CancelNavigation(); | |
| 132 } | |
| 133 | |
| 134 } | 77 } |
| 135 | 78 |
| 136 void RenderFrameHostManager::Init(BrowserContext* browser_context, | 79 void RenderFrameHostManager::Init(BrowserContext* browser_context, |
| 137 SiteInstance* site_instance, | 80 SiteInstance* site_instance, |
| 138 int view_routing_id, | 81 int view_routing_id, |
| 139 int frame_routing_id) { | 82 int frame_routing_id) { |
| 140 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It | 83 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It |
| 141 // is important to immediately give this SiteInstance to a RenderViewHost so | 84 // is important to immediately give this SiteInstance to a RenderViewHost so |
| 142 // that the SiteInstance is ref counted. | 85 // that the SiteInstance is ref counted. |
| 143 if (!site_instance) | 86 if (!site_instance) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 ->render_manager() | 129 ->render_manager() |
| 187 ->current_frame_host() | 130 ->current_frame_host() |
| 188 ->GetSiteInstance() | 131 ->GetSiteInstance() |
| 189 ->GetId()); | 132 ->GetId()); |
| 190 if (iter == proxy_hosts_.end()) | 133 if (iter == proxy_hosts_.end()) |
| 191 return NULL; | 134 return NULL; |
| 192 | 135 |
| 193 return iter->second; | 136 return iter->second; |
| 194 } | 137 } |
| 195 | 138 |
| 196 void RenderFrameHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) { | 139 void RenderFrameHostManager::SetPendingWebUI(const GURL& url, |
| 140 int bindings) { |
| 197 pending_web_ui_.reset( | 141 pending_web_ui_.reset( |
| 198 delegate_->CreateWebUIForRenderManager(entry.GetURL())); | 142 delegate_->CreateWebUIForRenderManager(url)); |
| 199 pending_and_current_web_ui_.reset(); | 143 pending_and_current_web_ui_.reset(); |
| 200 | 144 |
| 201 // If we have assigned (zero or more) bindings to this NavigationEntry in the | 145 // If we have assigned (zero or more) bindings to this NavigationEntry in the |
| 202 // past, make sure we're not granting it different bindings than it had | 146 // past, make sure we're not granting it different bindings than it had |
| 203 // before. If so, note it and don't give it any bindings, to avoid a | 147 // before. If so, note it and don't give it any bindings, to avoid a |
| 204 // potential privilege escalation. | 148 // potential privilege escalation. |
| 205 if (pending_web_ui_.get() && | 149 if (pending_web_ui_.get() && |
| 206 entry.bindings() != NavigationEntryImpl::kInvalidBindings && | 150 bindings != NavigationEntryImpl::kInvalidBindings && |
| 207 pending_web_ui_->GetBindings() != entry.bindings()) { | 151 pending_web_ui_->GetBindings() != bindings) { |
| 208 RecordAction( | 152 RecordAction( |
| 209 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | 153 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
| 210 pending_web_ui_.reset(); | 154 pending_web_ui_.reset(); |
| 211 } | 155 } |
| 212 } | 156 } |
| 213 | 157 |
| 214 RenderFrameHostImpl* RenderFrameHostManager::Navigate( | 158 RenderFrameHostImpl* RenderFrameHostManager::Navigate( |
| 215 const NavigationEntryImpl& entry) { | 159 const NavigationEntryImpl& entry) { |
| 216 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate", | 160 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate", |
| 217 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 161 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); |
| 218 // Create a pending RenderFrameHost to use for the navigation. | 162 // Create a pending RenderFrameHost to use for the navigation. |
| 219 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate(entry); | 163 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate( |
| 164 entry.GetURL(), |
| 165 entry.site_instance(), |
| 166 entry.GetTransitionType(), |
| 167 entry.restore_type() != NavigationEntryImpl::RESTORE_NONE, |
| 168 entry.IsViewSourceMode(), |
| 169 entry.transferred_global_request_id(), |
| 170 entry.bindings()); |
| 220 if (!dest_render_frame_host) | 171 if (!dest_render_frame_host) |
| 221 return NULL; // We weren't able to create a pending render frame host. | 172 return NULL; // We weren't able to create a pending render frame host. |
| 222 | 173 |
| 223 // If the current render_frame_host_ isn't live, we should create it so | 174 // If the current render_frame_host_ isn't live, we should create it so |
| 224 // that we don't show a sad tab while the dest_render_frame_host fetches | 175 // that we don't show a sad tab while the dest_render_frame_host fetches |
| 225 // its first page. (Bug 1145340) | 176 // its first page. (Bug 1145340) |
| 226 if (dest_render_frame_host != render_frame_host_ && | 177 if (dest_render_frame_host != render_frame_host_ && |
| 227 !render_frame_host_->IsRenderFrameLive()) { | 178 !render_frame_host_->IsRenderFrameLive()) { |
| 228 // Note: we don't call InitRenderView here because we are navigating away | 179 // Note: we don't call InitRenderView here because we are navigating away |
| 229 // soon anyway, and we don't have the NavigationEntry for this host. | 180 // soon anyway, and we don't have the NavigationEntry for this host. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 static_cast<RenderProcessHostImpl*>(render_frame_host_->GetProcess()); | 393 static_cast<RenderProcessHostImpl*>(render_frame_host_->GetProcess()); |
| 443 process->ResumeResponseDeferredAtStart(*response_started_id_); | 394 process->ResumeResponseDeferredAtStart(*response_started_id_); |
| 444 | 395 |
| 445 render_frame_host_->ClearPendingTransitionRequestData(); | 396 render_frame_host_->ClearPendingTransitionRequestData(); |
| 446 | 397 |
| 447 response_started_id_.reset(); | 398 response_started_id_.reset(); |
| 448 } | 399 } |
| 449 | 400 |
| 450 void RenderFrameHostManager::DidNavigateFrame( | 401 void RenderFrameHostManager::DidNavigateFrame( |
| 451 RenderFrameHostImpl* render_frame_host) { | 402 RenderFrameHostImpl* render_frame_host) { |
| 452 // PlzNavigate | |
| 453 // The navigation request has been committed so the browser process doesn't | |
| 454 // need to care about it anymore. | |
| 455 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 456 switches::kEnableBrowserSideNavigation)) { | |
| 457 navigation_request_.reset(); | |
| 458 } | |
| 459 | |
| 460 if (!cross_navigation_pending_) { | 403 if (!cross_navigation_pending_) { |
| 461 DCHECK(!pending_render_frame_host_); | 404 DCHECK(!pending_render_frame_host_); |
| 462 | 405 |
| 463 // We should only hear this from our current renderer. | 406 // We should only hear this from our current renderer. |
| 464 DCHECK_EQ(render_frame_host_, render_frame_host); | 407 DCHECK_EQ(render_frame_host_, render_frame_host); |
| 465 | 408 |
| 466 // Even when there is no pending RVH, there may be a pending Web UI. | 409 // Even when there is no pending RVH, there may be a pending Web UI. |
| 467 if (pending_web_ui()) | 410 if (pending_web_ui()) |
| 468 CommitPending(); | 411 CommitPending(); |
| 469 return; | 412 return; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 pending_delete_hosts_.find(site_instance_id); | 512 pending_delete_hosts_.find(site_instance_id); |
| 570 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh) | 513 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh) |
| 571 pending_delete_hosts_.erase(site_instance_id); | 514 pending_delete_hosts_.erase(site_instance_id); |
| 572 } | 515 } |
| 573 | 516 |
| 574 void RenderFrameHostManager::ResetProxyHosts() { | 517 void RenderFrameHostManager::ResetProxyHosts() { |
| 575 STLDeleteValues(&proxy_hosts_); | 518 STLDeleteValues(&proxy_hosts_); |
| 576 } | 519 } |
| 577 | 520 |
| 578 // PlzNavigate | 521 // PlzNavigate |
| 579 bool RenderFrameHostManager::RequestNavigation( | 522 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( |
| 580 scoped_ptr<NavigationRequest> navigation_request, | 523 const GURL& url, |
| 581 const RequestNavigationParams& request_params) { | 524 ui::PageTransition transition) { |
| 582 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 525 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 583 switches::kEnableBrowserSideNavigation)); | 526 switches::kEnableBrowserSideNavigation)); |
| 584 | 527 // TODO(clamy): When we handle renderer initiated navigations, make sure not |
| 585 // TODO(clamy): Check if navigations are blocked and if so store the | 528 // to use a different process for subframes if --site-per-process is not |
| 586 // parameters. | 529 // enabled. |
| 587 | |
| 588 // If there is an ongoing request it must be canceled. | |
| 589 if (navigation_request_.get()) | |
| 590 navigation_request_->CancelNavigation(); | |
| 591 | |
| 592 navigation_request_ = navigation_request.Pass(); | |
| 593 | |
| 594 if (render_frame_host_->IsRenderFrameLive()) { | |
| 595 // TODO(clamy): send a RequestNavigation IPC. | |
| 596 return true; | |
| 597 } | |
| 598 | |
| 599 // The navigation request is sent directly to the IO thread. | |
| 600 OnBeginNavigation( | |
| 601 MakeDefaultBeginNavigation( | |
| 602 request_params, navigation_request_->common_params().navigation_type), | |
| 603 navigation_request_->common_params()); | |
| 604 return true; | |
| 605 } | |
| 606 | |
| 607 // PlzNavigate | |
| 608 void RenderFrameHostManager::OnBeginNavigation( | |
| 609 const FrameHostMsg_BeginNavigation_Params& params, | |
| 610 const CommonNavigationParams& common_params) { | |
| 611 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | |
| 612 switches::kEnableBrowserSideNavigation)); | |
| 613 // TODO(clamy): In case of a renderer initiated navigation create a new | |
| 614 // NavigationRequest. | |
| 615 DCHECK(navigation_request_.get()); | |
| 616 // Update the referrer with the one received from the renderer. | |
| 617 navigation_request_->common_params().referrer = common_params.referrer; | |
| 618 | |
| 619 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params)); | |
| 620 | |
| 621 info->first_party_for_cookies = | |
| 622 frame_tree_node_->IsMainFrame() | |
| 623 ? navigation_request_->common_params().url | |
| 624 : frame_tree_node_->frame_tree()->root()->current_url(); | |
| 625 info->is_main_frame = frame_tree_node_->IsMainFrame(); | |
| 626 info->parent_is_main_frame = !frame_tree_node_->parent() ? | |
| 627 false : frame_tree_node_->parent()->IsMainFrame(); | |
| 628 | |
| 629 // TODO(clamy): Check if the current RFH should be initialized (in case it has | |
| 630 // crashed) not to display a sad tab while navigating. | |
| 631 // TODO(clamy): Spawn a speculative renderer process if we do not have one to | |
| 632 // use for the navigation. | |
| 633 | |
| 634 navigation_request_->BeginNavigation(info.Pass(), params.request_body); | |
| 635 } | |
| 636 | |
| 637 // PlzNavigate | |
| 638 void RenderFrameHostManager::CommitNavigation( | |
| 639 const NavigationBeforeCommitInfo& info) { | |
| 640 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | |
| 641 switches::kEnableBrowserSideNavigation)); | |
| 642 DCHECK(navigation_request_.get()); | |
| 643 // Ignores navigation commits if the request ID doesn't match the current | |
| 644 // active request. | |
| 645 if (navigation_request_->navigation_request_id() != | |
| 646 info.navigation_request_id) { | |
| 647 return; | |
| 648 } | |
| 649 | 530 |
| 650 // Pick the right RenderFrameHost to commit the navigation. | 531 // Pick the right RenderFrameHost to commit the navigation. |
| 651 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 532 // TODO(clamy): Replace the default values by the right ones. |
| 652 // TODO(clamy): Replace the default values by the right ones. This may require | 533 RenderFrameHostImpl* render_frame_host = UpdateStateForNavigate( |
| 653 // some storing in RequestNavigation. | 534 url, NULL, transition, false, false, GlobalRequestID(), |
| 654 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 535 NavigationEntryImpl::kInvalidBindings); |
| 655 info.navigation_url, | |
| 656 NULL, | |
| 657 navigation_request_->common_params().transition, | |
| 658 false, | |
| 659 false); | |
| 660 DCHECK(!pending_render_frame_host_.get()); | |
| 661 | |
| 662 // TODO(clamy): Update how pending WebUI objects are handled. | |
| 663 if (current_instance != new_instance.get()) { | |
| 664 CreateRenderFrameHostForNewSiteInstance( | |
| 665 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame()); | |
| 666 DCHECK(pending_render_frame_host_.get()); | |
| 667 // TODO(clamy): Wait until the navigation has committed before swapping | |
| 668 // renderers. | |
| 669 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = | |
| 670 SetRenderFrameHost(pending_render_frame_host_.Pass()); | |
| 671 if (frame_tree_node_->IsMainFrame()) | |
| 672 render_frame_host_->render_view_host()->AttachToFrameTree(); | |
| 673 } | |
| 674 | 536 |
| 675 // If the renderer that needs to navigate is not live (it was just created or | 537 // If the renderer that needs to navigate is not live (it was just created or |
| 676 // it crashed), initialize it. | 538 // it crashed), initialize it. |
| 677 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { | 539 if (!render_frame_host->render_view_host()->IsRenderViewLive()) { |
| 678 // Recreate the opener chain. | 540 // Recreate the opener chain. |
| 679 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | 541 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( |
| 680 render_frame_host_->GetSiteInstance()); | 542 render_frame_host->GetSiteInstance()); |
| 681 if (!InitRenderView(render_frame_host_->render_view_host(), | 543 if (!InitRenderView(render_frame_host->render_view_host(), |
| 682 opener_route_id, | 544 opener_route_id, |
| 683 MSG_ROUTING_NONE, | 545 MSG_ROUTING_NONE, |
| 684 frame_tree_node_->IsMainFrame())) { | 546 frame_tree_node_->IsMainFrame())) { |
| 685 return; | 547 return NULL; |
| 686 } | 548 } |
| 687 } | 549 } |
| 688 | 550 return render_frame_host; |
| 689 frame_tree_node_->navigator()->CommitNavigation( | |
| 690 render_frame_host_.get(), | |
| 691 info.stream_url, | |
| 692 navigation_request_->common_params(), | |
| 693 navigation_request_->commit_params()); | |
| 694 } | 551 } |
| 695 | 552 |
| 696 void RenderFrameHostManager::Observe( | 553 void RenderFrameHostManager::Observe( |
| 697 int type, | 554 int type, |
| 698 const NotificationSource& source, | 555 const NotificationSource& source, |
| 699 const NotificationDetails& details) { | 556 const NotificationDetails& details) { |
| 700 switch (type) { | 557 switch (type) { |
| 701 case NOTIFICATION_RENDERER_PROCESS_CLOSED: | 558 case NOTIFICATION_RENDERER_PROCESS_CLOSED: |
| 702 case NOTIFICATION_RENDERER_PROCESS_CLOSING: | 559 case NOTIFICATION_RENDERER_PROCESS_CLOSING: |
| 703 RendererProcessClosing( | 560 RendererProcessClosing( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat | 667 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat |
| 811 // it as a new navigation). So require a BrowsingInstance switch. | 668 // it as a new navigation). So require a BrowsingInstance switch. |
| 812 if (current_is_view_source_mode != new_is_view_source_mode) | 669 if (current_is_view_source_mode != new_is_view_source_mode) |
| 813 return true; | 670 return true; |
| 814 | 671 |
| 815 return false; | 672 return false; |
| 816 } | 673 } |
| 817 | 674 |
| 818 bool RenderFrameHostManager::ShouldReuseWebUI( | 675 bool RenderFrameHostManager::ShouldReuseWebUI( |
| 819 const NavigationEntry* current_entry, | 676 const NavigationEntry* current_entry, |
| 820 const NavigationEntryImpl* new_entry) const { | 677 const GURL& new_url) const { |
| 821 NavigationControllerImpl& controller = | 678 NavigationControllerImpl& controller = |
| 822 delegate_->GetControllerForRenderManager(); | 679 delegate_->GetControllerForRenderManager(); |
| 823 return current_entry && web_ui_.get() && | 680 return current_entry && web_ui_.get() && |
| 824 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 681 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 825 controller.GetBrowserContext(), current_entry->GetURL()) == | 682 controller.GetBrowserContext(), current_entry->GetURL()) == |
| 826 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 683 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 827 controller.GetBrowserContext(), new_entry->GetURL())); | 684 controller.GetBrowserContext(), new_url)); |
| 828 } | 685 } |
| 829 | 686 |
| 830 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( | 687 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( |
| 831 const GURL& dest_url, | 688 const GURL& dest_url, |
| 832 SiteInstance* dest_instance, | 689 SiteInstance* dest_instance, |
| 833 ui::PageTransition dest_transition, | 690 ui::PageTransition dest_transition, |
| 834 bool dest_is_restore, | 691 bool dest_is_restore, |
| 835 bool dest_is_view_source_mode) { | 692 bool dest_is_view_source_mode) { |
| 836 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 693 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
| 837 SiteInstance* new_instance = current_instance; | 694 SiteInstance* new_instance = current_instance; |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 // |rvh| to Shutdown. | 1339 // |rvh| to Shutdown. |
| 1483 FrameTree* tree = rvh->GetDelegate()->GetFrameTree(); | 1340 FrameTree* tree = rvh->GetDelegate()->GetFrameTree(); |
| 1484 tree->ForEach(base::Bind( | 1341 tree->ForEach(base::Bind( |
| 1485 &RenderFrameHostManager::ClearProxiesInSiteInstance, | 1342 &RenderFrameHostManager::ClearProxiesInSiteInstance, |
| 1486 site_instance_id)); | 1343 site_instance_id)); |
| 1487 } | 1344 } |
| 1488 } | 1345 } |
| 1489 } | 1346 } |
| 1490 | 1347 |
| 1491 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate( | 1348 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate( |
| 1492 const NavigationEntryImpl& entry) { | 1349 const GURL& url, |
| 1350 SiteInstance* instance, |
| 1351 ui::PageTransition transition, |
| 1352 bool is_restore, |
| 1353 bool is_view_source_mode, |
| 1354 const GlobalRequestID& transferred_request_id, |
| 1355 int bindings) { |
| 1493 // If we are currently navigating cross-process, we want to get back to normal | 1356 // If we are currently navigating cross-process, we want to get back to normal |
| 1494 // and then navigate as usual. | 1357 // and then navigate as usual. |
| 1495 if (cross_navigation_pending_) { | 1358 if (cross_navigation_pending_) { |
| 1496 if (pending_render_frame_host_) | 1359 if (pending_render_frame_host_) |
| 1497 CancelPending(); | 1360 CancelPending(); |
| 1498 cross_navigation_pending_ = false; | 1361 cross_navigation_pending_ = false; |
| 1499 } | 1362 } |
| 1500 | 1363 |
| 1501 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1364 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
| 1502 scoped_refptr<SiteInstance> new_instance = | 1365 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
| 1503 GetSiteInstanceForNavigation( | 1366 url, instance, transition, is_restore, is_view_source_mode); |
| 1504 entry.GetURL(), | |
| 1505 entry.site_instance(), | |
| 1506 entry.GetTransitionType(), | |
| 1507 entry.restore_type() != NavigationEntryImpl::RESTORE_NONE, | |
| 1508 entry.IsViewSourceMode()); | |
| 1509 | 1367 |
| 1510 const NavigationEntry* current_entry = | 1368 const NavigationEntry* current_entry = |
| 1511 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1369 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
| 1512 | 1370 |
| 1513 if (new_instance.get() != current_instance) { | 1371 if (new_instance.get() != current_instance) { |
| 1514 TRACE_EVENT_INSTANT2( | 1372 TRACE_EVENT_INSTANT2( |
| 1515 "navigation", | 1373 "navigation", |
| 1516 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", | 1374 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", |
| 1517 TRACE_EVENT_SCOPE_THREAD, | 1375 TRACE_EVENT_SCOPE_THREAD, |
| 1518 "current_instance id", current_instance->GetId(), | 1376 "current_instance id", current_instance->GetId(), |
| 1519 "new_instance id", new_instance->GetId()); | 1377 "new_instance id", new_instance->GetId()); |
| 1520 | 1378 |
| 1521 // New SiteInstance: create a pending RFH to navigate. | 1379 // New SiteInstance: create a pending RFH to navigate. |
| 1522 DCHECK(!cross_navigation_pending_); | 1380 DCHECK(!cross_navigation_pending_); |
| 1523 | 1381 |
| 1524 // This will possibly create (set to NULL) a Web UI object for the pending | 1382 // This will possibly create (set to NULL) a Web UI object for the pending |
| 1525 // page. We'll use this later to give the page special access. This must | 1383 // page. We'll use this later to give the page special access. This must |
| 1526 // happen before the new renderer is created below so it will get bindings. | 1384 // happen before the new renderer is created below so it will get bindings. |
| 1527 // It must also happen after the above conditional call to CancelPending(), | 1385 // It must also happen after the above conditional call to CancelPending(), |
| 1528 // otherwise CancelPending may clear the pending_web_ui_ and the page will | 1386 // otherwise CancelPending may clear the pending_web_ui_ and the page will |
| 1529 // not have its bindings set appropriately. | 1387 // not have its bindings set appropriately. |
| 1530 SetPendingWebUI(entry); | 1388 SetPendingWebUI(url, bindings); |
| 1531 CreateRenderFrameHostForNewSiteInstance( | 1389 CreateRenderFrameHostForNewSiteInstance( |
| 1532 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame()); | 1390 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame()); |
| 1533 if (!pending_render_frame_host_.get()) { | 1391 if (!pending_render_frame_host_.get()) { |
| 1534 return NULL; | 1392 return NULL; |
| 1535 } | 1393 } |
| 1536 | 1394 |
| 1537 // Check if our current RFH is live before we set up a transition. | 1395 // Check if our current RFH is live before we set up a transition. |
| 1538 if (!render_frame_host_->IsRenderFrameLive()) { | 1396 if (!render_frame_host_->IsRenderFrameLive()) { |
| 1539 if (!cross_navigation_pending_) { | 1397 if (!cross_navigation_pending_) { |
| 1540 // The current RFH is not live. There's no reason to sit around with a | 1398 // The current RFH is not live. There's no reason to sit around with a |
| 1541 // sad tab or a newly created RFH while we wait for the pending RFH to | 1399 // sad tab or a newly created RFH while we wait for the pending RFH to |
| 1542 // navigate. Just switch to the pending RFH now and go back to non | 1400 // navigate. Just switch to the pending RFH now and go back to non |
| 1543 // cross-navigating (Note that we don't care about on{before}unload | 1401 // cross-navigating (Note that we don't care about on{before}unload |
| 1544 // handlers if the current RFH isn't live.) | 1402 // handlers if the current RFH isn't live.) |
| 1545 CommitPending(); | 1403 CommitPending(); |
| 1546 return render_frame_host_.get(); | 1404 return render_frame_host_.get(); |
| 1547 } else { | 1405 } else { |
| 1548 NOTREACHED(); | 1406 NOTREACHED(); |
| 1549 return render_frame_host_.get(); | 1407 return render_frame_host_.get(); |
| 1550 } | 1408 } |
| 1551 } | 1409 } |
| 1552 // Otherwise, it's safe to treat this as a pending cross-site transition. | 1410 // Otherwise, it's safe to treat this as a pending cross-site transition. |
| 1553 | 1411 |
| 1412 // We now have a pending RFH. |
| 1413 DCHECK(!cross_navigation_pending_); |
| 1414 cross_navigation_pending_ = true; |
| 1415 |
| 1416 // PlzNavigate: There is no notion of transfer navigations, and the old |
| 1417 // renderer before unload handler has already run at that point, so return |
| 1418 // here. |
| 1419 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1420 switches::kEnableBrowserSideNavigation)) { |
| 1421 return pending_render_frame_host_.get(); |
| 1422 } |
| 1423 |
| 1554 // We need to wait until the beforeunload handler has run, unless we are | 1424 // We need to wait until the beforeunload handler has run, unless we are |
| 1555 // transferring an existing request (in which case it has already run). | 1425 // transferring an existing request (in which case it has already run). |
| 1556 // Suspend the new render view (i.e., don't let it send the cross-site | 1426 // Suspend the new render view (i.e., don't let it send the cross-site |
| 1557 // Navigate message) until we hear back from the old renderer's | 1427 // Navigate message) until we hear back from the old renderer's |
| 1558 // beforeunload handler. If the handler returns false, we'll have to | 1428 // beforeunload handler. If the handler returns false, we'll have to |
| 1559 // cancel the request. | 1429 // cancel the request. |
| 1430 // |
| 1560 DCHECK(!pending_render_frame_host_->are_navigations_suspended()); | 1431 DCHECK(!pending_render_frame_host_->are_navigations_suspended()); |
| 1561 bool is_transfer = | 1432 bool is_transfer = transferred_request_id != GlobalRequestID(); |
| 1562 entry.transferred_global_request_id() != GlobalRequestID(); | |
| 1563 if (is_transfer) { | 1433 if (is_transfer) { |
| 1564 // We don't need to stop the old renderer or run beforeunload/unload | 1434 // We don't need to stop the old renderer or run beforeunload/unload |
| 1565 // handlers, because those have already been done. | 1435 // handlers, because those have already been done. |
| 1566 DCHECK(cross_site_transferring_request_->request_id() == | 1436 DCHECK(cross_site_transferring_request_->request_id() == |
| 1567 entry.transferred_global_request_id()); | 1437 transferred_request_id); |
| 1568 } else { | 1438 } else { |
| 1569 // Also make sure the old render view stops, in case a load is in | 1439 // Also make sure the old render view stops, in case a load is in |
| 1570 // progress. (We don't want to do this for transfers, since it will | 1440 // progress. (We don't want to do this for transfers, since it will |
| 1571 // interrupt the transfer with an unexpected DidStopLoading.) | 1441 // interrupt the transfer with an unexpected DidStopLoading.) |
| 1572 render_frame_host_->Send(new FrameMsg_Stop( | 1442 render_frame_host_->Send(new FrameMsg_Stop( |
| 1573 render_frame_host_->GetRoutingID())); | 1443 render_frame_host_->GetRoutingID())); |
| 1574 pending_render_frame_host_->SetNavigationsSuspended(true, | 1444 pending_render_frame_host_->SetNavigationsSuspended(true, |
| 1575 base::TimeTicks()); | 1445 base::TimeTicks()); |
| 1446 // Unless we are transferring an existing request, we should now tell the |
| 1447 // old render view to run its beforeunload handler, since it doesn't |
| 1448 // otherwise know that the cross-site request is happening. This will |
| 1449 // trigger a call to OnBeforeUnloadACK with the reply. |
| 1450 render_frame_host_->DispatchBeforeUnload(true); |
| 1576 } | 1451 } |
| 1577 | 1452 |
| 1578 // We now have a pending RFH. | |
| 1579 DCHECK(!cross_navigation_pending_); | |
| 1580 cross_navigation_pending_ = true; | |
| 1581 | |
| 1582 // Unless we are transferring an existing request, we should now | |
| 1583 // tell the old render view to run its beforeunload handler, since it | |
| 1584 // doesn't otherwise know that the cross-site request is happening. This | |
| 1585 // will trigger a call to OnBeforeUnloadACK with the reply. | |
| 1586 if (!is_transfer) | |
| 1587 render_frame_host_->DispatchBeforeUnload(true); | |
| 1588 | |
| 1589 return pending_render_frame_host_.get(); | 1453 return pending_render_frame_host_.get(); |
| 1590 } | 1454 } |
| 1591 | 1455 |
| 1592 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. | 1456 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. |
| 1593 DCHECK(!cross_navigation_pending_); | 1457 DCHECK(!cross_navigation_pending_); |
| 1594 | 1458 |
| 1595 // It's possible to swap out the current RFH and then decide to navigate in it | 1459 // It's possible to swap out the current RFH and then decide to navigate in it |
| 1596 // anyway (e.g., a cross-process navigation that redirects back to the | 1460 // anyway (e.g., a cross-process navigation that redirects back to the |
| 1597 // original site). In that case, we have a proxy for the current RFH but | 1461 // original site). In that case, we have a proxy for the current RFH but |
| 1598 // haven't deleted it yet. The new navigation will swap it back in, so we can | 1462 // haven't deleted it yet. The new navigation will swap it back in, so we can |
| 1599 // delete the proxy. | 1463 // delete the proxy. |
| 1600 DeleteRenderFrameProxyHost(new_instance.get()); | 1464 DeleteRenderFrameProxyHost(new_instance.get()); |
| 1601 | 1465 |
| 1602 if (ShouldReuseWebUI(current_entry, &entry)) { | 1466 if (ShouldReuseWebUI(current_entry, url)) { |
| 1603 pending_web_ui_.reset(); | 1467 pending_web_ui_.reset(); |
| 1604 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); | 1468 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); |
| 1605 } else { | 1469 } else { |
| 1606 SetPendingWebUI(entry); | 1470 SetPendingWebUI(url, bindings); |
| 1607 | |
| 1608 // Make sure the new RenderViewHost has the right bindings. | 1471 // Make sure the new RenderViewHost has the right bindings. |
| 1609 if (pending_web_ui() && | 1472 if (pending_web_ui() && |
| 1610 !render_frame_host_->GetProcess()->IsIsolatedGuest()) { | 1473 !render_frame_host_->GetProcess()->IsIsolatedGuest()) { |
| 1611 render_frame_host_->render_view_host()->AllowBindings( | 1474 render_frame_host_->render_view_host()->AllowBindings( |
| 1612 pending_web_ui()->GetBindings()); | 1475 pending_web_ui()->GetBindings()); |
| 1613 } | 1476 } |
| 1614 } | 1477 } |
| 1615 | 1478 |
| 1616 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) { | 1479 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) { |
| 1617 pending_web_ui()->GetController()->RenderViewReused( | 1480 pending_web_ui()->GetController()->RenderViewReused( |
| 1618 render_frame_host_->render_view_host()); | 1481 render_frame_host_->render_view_host()); |
| 1619 } | 1482 } |
| 1620 | 1483 |
| 1621 // The renderer can exit view source mode when any error or cancellation | 1484 // The renderer can exit view source mode when any error or cancellation |
| 1622 // happen. We must overwrite to recover the mode. | 1485 // happen. We must overwrite to recover the mode. |
| 1623 if (entry.IsViewSourceMode()) { | 1486 if (is_view_source_mode) { |
| 1624 render_frame_host_->render_view_host()->Send( | 1487 render_frame_host_->render_view_host()->Send( |
| 1625 new ViewMsg_EnableViewSourceMode( | 1488 new ViewMsg_EnableViewSourceMode( |
| 1626 render_frame_host_->render_view_host()->GetRoutingID())); | 1489 render_frame_host_->render_view_host()->GetRoutingID())); |
| 1627 } | 1490 } |
| 1628 | 1491 |
| 1629 return render_frame_host_.get(); | 1492 return render_frame_host_.get(); |
| 1630 } | 1493 } |
| 1631 | 1494 |
| 1632 void RenderFrameHostManager::CancelPending() { | 1495 void RenderFrameHostManager::CancelPending() { |
| 1633 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending", | 1496 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending", |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 1600 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
| 1738 SiteInstance* instance) { | 1601 SiteInstance* instance) { |
| 1739 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 1602 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
| 1740 if (iter != proxy_hosts_.end()) { | 1603 if (iter != proxy_hosts_.end()) { |
| 1741 delete iter->second; | 1604 delete iter->second; |
| 1742 proxy_hosts_.erase(iter); | 1605 proxy_hosts_.erase(iter); |
| 1743 } | 1606 } |
| 1744 } | 1607 } |
| 1745 | 1608 |
| 1746 } // namespace content | 1609 } // namespace content |
| OLD | NEW |