Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.cc

Issue 483773002: PlzNavigate: implement CommitNavigation on the browser side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + fix compilation error Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 12 matching lines...) Expand all
23 #include "content/browser/frame_host/navigator.h" 23 #include "content/browser/frame_host/navigator.h"
24 #include "content/browser/frame_host/render_frame_host_factory.h" 24 #include "content/browser/frame_host/render_frame_host_factory.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 25 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/browser/frame_host/render_frame_proxy_host.h" 26 #include "content/browser/frame_host/render_frame_proxy_host.h"
27 #include "content/browser/renderer_host/render_process_host_impl.h" 27 #include "content/browser/renderer_host/render_process_host_impl.h"
28 #include "content/browser/renderer_host/render_view_host_factory.h" 28 #include "content/browser/renderer_host/render_view_host_factory.h"
29 #include "content/browser/renderer_host/render_view_host_impl.h" 29 #include "content/browser/renderer_host/render_view_host_impl.h"
30 #include "content/browser/site_instance_impl.h" 30 #include "content/browser/site_instance_impl.h"
31 #include "content/browser/webui/web_ui_controller_factory_registry.h" 31 #include "content/browser/webui/web_ui_controller_factory_registry.h"
32 #include "content/browser/webui/web_ui_impl.h" 32 #include "content/browser/webui/web_ui_impl.h"
33 #include "content/common/navigation_params.h"
33 #include "content/common/view_messages.h" 34 #include "content/common/view_messages.h"
34 #include "content/public/browser/content_browser_client.h" 35 #include "content/public/browser/content_browser_client.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_types.h" 37 #include "content/public/browser/notification_types.h"
37 #include "content/public/browser/render_widget_host_iterator.h" 38 #include "content/public/browser/render_widget_host_iterator.h"
38 #include "content/public/browser/render_widget_host_view.h" 39 #include "content/public/browser/render_widget_host_view.h"
39 #include "content/public/browser/user_metrics.h" 40 #include "content/public/browser/user_metrics.h"
40 #include "content/public/browser/web_ui_controller.h" 41 #include "content/public/browser/web_ui_controller.h"
41 #include "content/public/common/content_switches.h" 42 #include "content/public/common/content_switches.h"
42 #include "content/public/common/referrer.h" 43 #include "content/public/common/referrer.h"
43 #include "content/public/common/url_constants.h" 44 #include "content/public/common/url_constants.h"
44 #include "net/base/load_flags.h" 45 #include "net/base/load_flags.h"
45 46
46 namespace content { 47 namespace content {
47 48
48 namespace { 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 }
49 74
50 // PlzNavigate 75 // PlzNavigate
51 // Simulates a renderer response to a navigation request when there is no live 76 // Generates a default FrameHostMsg_BeginNavigation_Params to be used when there
52 // renderer. 77 // is no live renderer.
53 FrameHostMsg_BeginNavigation_Params BeginNavigationFromNavigate( 78 FrameHostMsg_BeginNavigation_Params MakeDefaultBeginNavigation(
54 const FrameMsg_Navigate_Params& navigate_params) { 79 const RequestNavigationParams& request_params,
80 FrameMsg_Navigate_Type::Value navigation_type) {
55 FrameHostMsg_BeginNavigation_Params begin_navigation_params; 81 FrameHostMsg_BeginNavigation_Params begin_navigation_params;
56 begin_navigation_params.method = navigate_params.is_post ? "POST" : "GET"; 82 begin_navigation_params.method = request_params.is_post ? "POST" : "GET";
57 begin_navigation_params.url = navigate_params.url; 83 begin_navigation_params.load_flags =
58 begin_navigation_params.referrer = 84 LoadFlagFromNavigationType(navigation_type);
59 Referrer(navigate_params.referrer.url, navigate_params.referrer.policy);
60
61 // TODO(clamy): This should be modified to take into account caching policy
62 // requirements (eg for POST reloads).
63 begin_navigation_params.load_flags = net::LOAD_NORMAL;
64 85
65 // TODO(clamy): Post data from the browser should be put in the request body. 86 // TODO(clamy): Post data from the browser should be put in the request body.
87 // Headers should be filled in as well.
66 88
67 begin_navigation_params.has_user_gesture = false; 89 begin_navigation_params.has_user_gesture = false;
68 begin_navigation_params.transition_type = navigate_params.transition;
69 begin_navigation_params.should_replace_current_entry =
70 navigate_params.should_replace_current_entry;
71 begin_navigation_params.allow_download =
72 navigate_params.allow_download;
73 return begin_navigation_params; 90 return begin_navigation_params;
74 } 91 }
75 92
76 } // namespace
77
78 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { 93 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) {
79 node->render_manager()->pending_delete_hosts_.clear(); 94 node->render_manager()->pending_delete_hosts_.clear();
80 return true; 95 return true;
81 } 96 }
82 97
83 RenderFrameHostManager::RenderFrameHostManager( 98 RenderFrameHostManager::RenderFrameHostManager(
84 FrameTreeNode* frame_tree_node, 99 FrameTreeNode* frame_tree_node,
85 RenderFrameHostDelegate* render_frame_delegate, 100 RenderFrameHostDelegate* render_frame_delegate,
86 RenderViewHostDelegate* render_view_delegate, 101 RenderViewHostDelegate* render_view_delegate,
87 RenderWidgetHostDelegate* render_widget_delegate, 102 RenderWidgetHostDelegate* render_widget_delegate,
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh) 573 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh)
559 pending_delete_hosts_.erase(site_instance_id); 574 pending_delete_hosts_.erase(site_instance_id);
560 } 575 }
561 576
562 void RenderFrameHostManager::ResetProxyHosts() { 577 void RenderFrameHostManager::ResetProxyHosts() {
563 STLDeleteValues(&proxy_hosts_); 578 STLDeleteValues(&proxy_hosts_);
564 } 579 }
565 580
566 // PlzNavigate 581 // PlzNavigate
567 bool RenderFrameHostManager::RequestNavigation( 582 bool RenderFrameHostManager::RequestNavigation(
568 const NavigationEntryImpl& entry, 583 scoped_ptr<NavigationRequest> navigation_request,
569 const FrameMsg_Navigate_Params& navigate_params) { 584 const RequestNavigationParams& request_params) {
570 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 585 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
571 switches::kEnableBrowserSideNavigation)); 586 switches::kEnableBrowserSideNavigation));
587
588 // TODO(clamy): Check if navigations are blocked and if so store the
589 // parameters.
590
591 // If there is an ongoing request it must be canceled.
592 if (navigation_request_.get())
593 navigation_request_->CancelNavigation();
594
595 navigation_request_ = navigation_request.Pass();
596
572 if (render_frame_host_->IsRenderFrameLive()) { 597 if (render_frame_host_->IsRenderFrameLive()) {
573 // TODO(clamy): send a RequestNavigation IPC. 598 // TODO(clamy): send a RequestNavigation IPC.
574 return true; 599 return true;
575 } 600 }
576 601
577 // The navigation request is sent directly to the IO thread. 602 // The navigation request is sent directly to the IO thread.
578 OnBeginNavigation(BeginNavigationFromNavigate(navigate_params)); 603 OnBeginNavigation(
604 MakeDefaultBeginNavigation(
605 request_params, navigation_request_->common_params().navigation_type),
606 navigation_request_->common_params());
579 return true; 607 return true;
580 } 608 }
581 609
582 // PlzNavigate 610 // PlzNavigate
583 void RenderFrameHostManager::OnBeginNavigation( 611 void RenderFrameHostManager::OnBeginNavigation(
584 const FrameHostMsg_BeginNavigation_Params& params) { 612 const FrameHostMsg_BeginNavigation_Params& params,
613 const CommonNavigationParams& common_params) {
585 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 614 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
586 switches::kEnableBrowserSideNavigation)); 615 switches::kEnableBrowserSideNavigation));
587 // TODO(clamy): Check if navigations are blocked and if so, return 616 // TODO(clamy): In case of a renderer initiated navigation create a new
588 // immediately. 617 // NavigationRequest.
589 NavigationRequestInfo info(params); 618 DCHECK(navigation_request_.get());
619 // Update the referrer with the one received from the renderer.
620 navigation_request_->common_params().referrer = common_params.referrer;
590 621
591 info.first_party_for_cookies = frame_tree_node_->IsMainFrame() ? 622 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params));
592 params.url : frame_tree_node_->frame_tree()->root()->current_url(); 623
593 info.is_main_frame = frame_tree_node_->IsMainFrame(); 624 info->first_party_for_cookies =
594 info.parent_is_main_frame = !frame_tree_node_->parent() ? 625 frame_tree_node_->IsMainFrame()
626 ? navigation_request_->common_params().url
627 : frame_tree_node_->frame_tree()->root()->current_url();
628 info->is_main_frame = frame_tree_node_->IsMainFrame();
629 info->parent_is_main_frame = !frame_tree_node_->parent() ?
595 false : frame_tree_node_->parent()->IsMainFrame(); 630 false : frame_tree_node_->parent()->IsMainFrame();
596 631
597 // TODO(clamy): Check if the current RFH should be initialized (in case it has 632 // TODO(clamy): Check if the current RFH should be initialized (in case it has
598 // crashed) not to display a sad tab while navigating. 633 // crashed) not to display a sad tab while navigating.
599 // TODO(clamy): Spawn a speculative renderer process if we do not have one to 634 // TODO(clamy): Spawn a speculative renderer process if we do not have one to
600 // use for the navigation. 635 // use for the navigation.
601 636
602 // If there is an ongoing request it must be canceled. 637 navigation_request_->BeginNavigation(info.Pass(), params.request_body);
603 if (navigation_request_.get())
604 navigation_request_->CancelNavigation();
605
606 navigation_request_.reset(new NavigationRequest(
607 info, frame_tree_node_->frame_tree_node_id()));
608 navigation_request_->BeginNavigation(params.request_body);
609 } 638 }
610 639
611 // PlzNavigate 640 // PlzNavigate
612 void RenderFrameHostManager::CommitNavigation( 641 void RenderFrameHostManager::CommitNavigation(
613 const NavigationBeforeCommitInfo& info) { 642 const NavigationBeforeCommitInfo& info) {
614 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 643 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
615 switches::kEnableBrowserSideNavigation)); 644 switches::kEnableBrowserSideNavigation));
616 DCHECK(navigation_request_.get()); 645 DCHECK(navigation_request_.get());
617 // Ignores navigation commits if the request ID doesn't match the current 646 // Ignores navigation commits if the request ID doesn't match the current
618 // active request. 647 // active request.
619 if (navigation_request_->navigation_request_id() != 648 if (navigation_request_->navigation_request_id() !=
620 info.navigation_request_id) { 649 info.navigation_request_id) {
621 return; 650 return;
622 } 651 }
623 652
624 // Pick the right RenderFrameHost to commit the navigation. 653 // Pick the right RenderFrameHost to commit the navigation.
625 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 654 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
626 // TODO(clamy): Replace the default values by the right ones. This may require 655 // TODO(clamy): Replace the default values by the right ones. This may require
627 // some storing in RequestNavigation. 656 // some storing in RequestNavigation.
628 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( 657 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation(
629 info.navigation_url, 658 info.navigation_url,
630 NULL, 659 NULL,
631 navigation_request_->info().navigation_params.transition_type, 660 navigation_request_->common_params().transition,
632 false, 661 false,
633 false); 662 false);
634 DCHECK(!pending_render_frame_host_.get()); 663 DCHECK(!pending_render_frame_host_.get());
635 664
636 // TODO(clamy): Update how pending WebUI objects are handled. 665 // TODO(clamy): Update how pending WebUI objects are handled.
637 if (current_instance != new_instance.get()) { 666 if (current_instance != new_instance.get()) {
638 CreateRenderFrameHostForNewSiteInstance( 667 CreateRenderFrameHostForNewSiteInstance(
639 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame()); 668 current_instance, new_instance.get(), frame_tree_node_->IsMainFrame());
640 DCHECK(pending_render_frame_host_.get()); 669 DCHECK(pending_render_frame_host_.get());
641 // TODO(clamy): Wait until the navigation has committed before swapping 670 // TODO(clamy): Wait until the navigation has committed before swapping
(...skipping 12 matching lines...) Expand all
654 render_frame_host_->GetSiteInstance()); 683 render_frame_host_->GetSiteInstance());
655 if (!InitRenderView(render_frame_host_->render_view_host(), 684 if (!InitRenderView(render_frame_host_->render_view_host(),
656 opener_route_id, 685 opener_route_id,
657 MSG_ROUTING_NONE, 686 MSG_ROUTING_NONE,
658 frame_tree_node_->IsMainFrame())) { 687 frame_tree_node_->IsMainFrame())) {
659 return; 688 return;
660 } 689 }
661 } 690 }
662 691
663 frame_tree_node_->navigator()->CommitNavigation( 692 frame_tree_node_->navigator()->CommitNavigation(
664 render_frame_host_.get(), info); 693 render_frame_host_.get(),
694 info.stream_url,
695 navigation_request_->common_params(),
696 navigation_request_->commit_params());
665 } 697 }
666 698
667 void RenderFrameHostManager::Observe( 699 void RenderFrameHostManager::Observe(
668 int type, 700 int type,
669 const NotificationSource& source, 701 const NotificationSource& source,
670 const NotificationDetails& details) { 702 const NotificationDetails& details) {
671 switch (type) { 703 switch (type) {
672 case NOTIFICATION_RENDERER_PROCESS_CLOSED: 704 case NOTIFICATION_RENDERER_PROCESS_CLOSED:
673 case NOTIFICATION_RENDERER_PROCESS_CLOSING: 705 case NOTIFICATION_RENDERER_PROCESS_CLOSING:
674 RendererProcessClosing( 706 RendererProcessClosing(
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 1740 void RenderFrameHostManager::DeleteRenderFrameProxyHost(
1709 SiteInstance* instance) { 1741 SiteInstance* instance) {
1710 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 1742 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId());
1711 if (iter != proxy_hosts_.end()) { 1743 if (iter != proxy_hosts_.end()) {
1712 delete iter->second; 1744 delete iter->second;
1713 proxy_hosts_.erase(iter); 1745 proxy_hosts_.erase(iter);
1714 } 1746 }
1715 } 1747 }
1716 1748
1717 } // namespace content 1749 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698