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" |
(...skipping 12 matching lines...) Expand all Loading... | |
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 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) { | |
Charlie Reis
2014/09/19 23:12:31
Where is this code from? (In other words, how doe
clamy
2014/09/23 21:13:25
This code is here to handle the case where we don'
| |
52 int load_flags = net::LOAD_NORMAL; | |
53 switch (navigation_type) { | |
54 case FrameMsg_Navigate_Type::RELOAD: | |
55 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL: | |
56 load_flags |= net::LOAD_VALIDATE_CACHE; | |
57 break; | |
58 case FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE: | |
59 load_flags |= net::LOAD_BYPASS_CACHE; | |
60 break; | |
61 case FrameMsg_Navigate_Type::RESTORE: | |
62 load_flags |= net::LOAD_PREFERRING_CACHE; | |
63 break; | |
64 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: | |
65 load_flags |= net::LOAD_ONLY_FROM_CACHE; | |
66 break; | |
67 case FrameMsg_Navigate_Type::NORMAL: | |
68 default: | |
69 break; | |
70 } | |
71 return load_flags; | |
72 } | |
49 | 73 |
50 // PlzNavigate | 74 // PlzNavigate |
51 // Simulates a renderer response to a navigation request when there is no live | 75 // Generates a default FrameHostMsg_BeginNavigation_Params to be used when there |
52 // renderer. | 76 // is no live renderer. |
53 FrameHostMsg_BeginNavigation_Params BeginNavigationFromNavigate( | 77 FrameHostMsg_BeginNavigation_Params MakeDefaultBeginNavigation( |
54 const FrameMsg_Navigate_Params& navigate_params) { | 78 const RequestNavigationParams& request_params, |
79 FrameMsg_Navigate_Type::Value navigation_type) { | |
55 FrameHostMsg_BeginNavigation_Params begin_navigation_params; | 80 FrameHostMsg_BeginNavigation_Params begin_navigation_params; |
56 begin_navigation_params.method = navigate_params.is_post ? "POST" : "GET"; | 81 begin_navigation_params.method = request_params.is_post ? "POST" : "GET"; |
57 begin_navigation_params.url = navigate_params.url; | 82 begin_navigation_params.load_flags = |
58 begin_navigation_params.referrer = | 83 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 | 84 |
65 // TODO(clamy): Post data from the browser should be put in the request body. | 85 // TODO(clamy): Post data from the browser should be put in the request body. |
86 // Headers should be filled in as well. | |
66 | 87 |
67 begin_navigation_params.has_user_gesture = false; | 88 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; | 89 return begin_navigation_params; |
74 } | 90 } |
75 | 91 |
76 } // namespace | |
77 | |
78 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { | 92 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { |
79 node->render_manager()->pending_delete_hosts_.clear(); | 93 node->render_manager()->pending_delete_hosts_.clear(); |
80 return true; | 94 return true; |
81 } | 95 } |
82 | 96 |
83 RenderFrameHostManager::RenderFrameHostManager( | 97 RenderFrameHostManager::RenderFrameHostManager( |
84 FrameTreeNode* frame_tree_node, | 98 FrameTreeNode* frame_tree_node, |
85 RenderFrameHostDelegate* render_frame_delegate, | 99 RenderFrameHostDelegate* render_frame_delegate, |
86 RenderViewHostDelegate* render_view_delegate, | 100 RenderViewHostDelegate* render_view_delegate, |
87 RenderWidgetHostDelegate* render_widget_delegate, | 101 RenderWidgetHostDelegate* render_widget_delegate, |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh) | 573 if (iter != pending_delete_hosts_.end() && iter->second.get() == rfh) |
560 pending_delete_hosts_.erase(site_instance_id); | 574 pending_delete_hosts_.erase(site_instance_id); |
561 } | 575 } |
562 | 576 |
563 void RenderFrameHostManager::ResetProxyHosts() { | 577 void RenderFrameHostManager::ResetProxyHosts() { |
564 STLDeleteValues(&proxy_hosts_); | 578 STLDeleteValues(&proxy_hosts_); |
565 } | 579 } |
566 | 580 |
567 // PlzNavigate | 581 // PlzNavigate |
568 bool RenderFrameHostManager::RequestNavigation( | 582 bool RenderFrameHostManager::RequestNavigation( |
569 const NavigationEntryImpl& entry, | 583 scoped_ptr<CoreNavigationParams> core_params, |
570 const FrameMsg_Navigate_Params& navigate_params) { | 584 const RequestNavigationParams& request_params, |
585 scoped_ptr<CommitNavigationParams> commit_params) { | |
571 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 586 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
572 switches::kEnableBrowserSideNavigation)); | 587 switches::kEnableBrowserSideNavigation)); |
588 DCHECK(commit_params.get() && core_params.get()); | |
589 core_navigation_params_ = core_params.Pass(); | |
590 commit_navigation_params_ = commit_params.Pass(); | |
573 if (render_frame_host_->IsRenderFrameLive()) { | 591 if (render_frame_host_->IsRenderFrameLive()) { |
574 // TODO(clamy): send a RequestNavigation IPC. | 592 // TODO(clamy): send a RequestNavigation IPC. |
575 return true; | 593 return true; |
576 } | 594 } |
577 | 595 |
578 // The navigation request is sent directly to the IO thread. | 596 // The navigation request is sent directly to the IO thread. |
579 OnBeginNavigation(BeginNavigationFromNavigate(navigate_params)); | 597 OnBeginNavigation( |
598 MakeDefaultBeginNavigation(request_params, | |
599 core_navigation_params_->navigation_type), | |
600 *core_navigation_params_); | |
580 return true; | 601 return true; |
581 } | 602 } |
582 | 603 |
583 // PlzNavigate | 604 // PlzNavigate |
584 void RenderFrameHostManager::OnBeginNavigation( | 605 void RenderFrameHostManager::OnBeginNavigation( |
585 const FrameHostMsg_BeginNavigation_Params& params) { | 606 const FrameHostMsg_BeginNavigation_Params& params, |
607 const CoreNavigationParams& core_params) { | |
586 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 608 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
587 switches::kEnableBrowserSideNavigation)); | 609 switches::kEnableBrowserSideNavigation)); |
610 DCHECK(core_navigation_params_.get()); | |
611 core_navigation_params_->referrer = core_params.referrer; | |
588 // TODO(clamy): Check if navigations are blocked and if so, return | 612 // TODO(clamy): Check if navigations are blocked and if so, return |
589 // immediately. | 613 // immediately. |
590 NavigationRequestInfo info(params); | 614 NavigationRequestInfo info(*core_navigation_params_, params); |
591 | 615 |
592 info.first_party_for_cookies = frame_tree_node_->IsMainFrame() ? | 616 info.first_party_for_cookies = |
593 params.url : frame_tree_node_->frame_tree()->root()->current_url(); | 617 frame_tree_node_->IsMainFrame() |
618 ? core_navigation_params_->url | |
619 : frame_tree_node_->frame_tree()->root()->current_url(); | |
594 info.is_main_frame = frame_tree_node_->IsMainFrame(); | 620 info.is_main_frame = frame_tree_node_->IsMainFrame(); |
595 info.parent_is_main_frame = !frame_tree_node_->parent() ? | 621 info.parent_is_main_frame = !frame_tree_node_->parent() ? |
596 false : frame_tree_node_->parent()->IsMainFrame(); | 622 false : frame_tree_node_->parent()->IsMainFrame(); |
623 info.allow_download = core_navigation_params_->allow_download; | |
597 | 624 |
598 // TODO(clamy): Check if the current RFH should be initialized (in case it has | 625 // TODO(clamy): Check if the current RFH should be initialized (in case it has |
599 // crashed) not to display a sad tab while navigating. | 626 // crashed) not to display a sad tab while navigating. |
600 // TODO(clamy): Spawn a speculative renderer process if we do not have one to | 627 // TODO(clamy): Spawn a speculative renderer process if we do not have one to |
601 // use for the navigation. | 628 // use for the navigation. |
602 | 629 |
603 // If there is an ongoing request it must be canceled. | 630 // If there is an ongoing request it must be canceled. |
604 if (navigation_request_.get()) | 631 if (navigation_request_.get()) |
605 navigation_request_->CancelNavigation(); | 632 navigation_request_->CancelNavigation(); |
606 | 633 |
607 navigation_request_.reset(new NavigationRequest( | 634 navigation_request_.reset(new NavigationRequest( |
608 info, frame_tree_node_->frame_tree_node_id())); | 635 info, frame_tree_node_->frame_tree_node_id())); |
609 navigation_request_->BeginNavigation(params.request_body); | 636 navigation_request_->BeginNavigation(params.request_body); |
610 } | 637 } |
611 | 638 |
612 // PlzNavigate | 639 // PlzNavigate |
613 void RenderFrameHostManager::CommitNavigation( | 640 void RenderFrameHostManager::CommitNavigation( |
614 const NavigationBeforeCommitInfo& info) { | 641 const NavigationBeforeCommitInfo& info) { |
615 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 642 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
616 switches::kEnableBrowserSideNavigation)); | 643 switches::kEnableBrowserSideNavigation)); |
617 DCHECK(navigation_request_.get()); | 644 DCHECK(navigation_request_.get()); |
618 // Ignores navigation commits if the request ID doesn't match the current | 645 // Ignores navigation commits if the request ID doesn't match the current |
619 // active request. | 646 // active request. |
620 if (navigation_request_->navigation_request_id() != | 647 if (navigation_request_->navigation_request_id() != |
621 info.navigation_request_id) { | 648 info.navigation_request_id) { |
622 return; | 649 return; |
623 } | 650 } |
624 | 651 |
652 DCHECK(commit_navigation_params_.get()); | |
653 DCHECK(core_navigation_params_.get()); | |
625 // Pick the right RenderFrameHost to commit the navigation. | 654 // Pick the right RenderFrameHost to commit the navigation. |
626 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 655 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
627 // TODO(clamy): Replace the default values by the right ones. This may require | 656 // TODO(clamy): Replace the default values by the right ones. This may require |
628 // some storing in RequestNavigation. | 657 // some storing in RequestNavigation. |
629 SiteInstance* new_instance = GetSiteInstanceForNavigation( | 658 SiteInstance* new_instance = GetSiteInstanceForNavigation( |
630 info.navigation_url, | 659 info.navigation_url, |
631 NULL, | 660 NULL, |
632 navigation_request_->info().navigation_params.transition_type, | 661 core_navigation_params_->transition, |
633 false, | 662 false, |
634 false); | 663 false); |
635 DCHECK(!pending_render_frame_host_.get()); | 664 DCHECK(!pending_render_frame_host_.get()); |
636 | 665 |
637 // TODO(clamy): Update how pending WebUI objects are handled. | 666 // TODO(clamy): Update how pending WebUI objects are handled. |
638 if (current_instance != new_instance) { | 667 if (current_instance != new_instance) { |
639 CreateRenderFrameHostForNewSiteInstance( | 668 CreateRenderFrameHostForNewSiteInstance( |
640 current_instance, new_instance, frame_tree_node_->IsMainFrame()); | 669 current_instance, new_instance, frame_tree_node_->IsMainFrame()); |
641 DCHECK(pending_render_frame_host_.get()); | 670 DCHECK(pending_render_frame_host_.get()); |
642 // TODO(clamy): Wait until the navigation has committed before swapping | 671 // TODO(clamy): Wait until the navigation has committed before swapping |
(...skipping 11 matching lines...) Expand all Loading... | |
654 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | 683 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( |
655 render_frame_host_->GetSiteInstance()); | 684 render_frame_host_->GetSiteInstance()); |
656 if (!InitRenderView(render_frame_host_->render_view_host(), | 685 if (!InitRenderView(render_frame_host_->render_view_host(), |
657 opener_route_id, | 686 opener_route_id, |
658 MSG_ROUTING_NONE, | 687 MSG_ROUTING_NONE, |
659 frame_tree_node_->IsMainFrame())) { | 688 frame_tree_node_->IsMainFrame())) { |
660 return; | 689 return; |
661 } | 690 } |
662 } | 691 } |
663 | 692 |
664 frame_tree_node_->navigator()->CommitNavigation( | 693 frame_tree_node_->navigator()->CommitNavigation(render_frame_host_.get(), |
665 render_frame_host_.get(), info); | 694 info.stream_url, |
695 *core_navigation_params_, | |
Charlie Reis
2014/09/19 23:12:31
These are scoped_ptrs. Shouldn't we be passing ow
clamy
2014/09/23 21:13:25
They are now members of NavigationRequest.
| |
696 *commit_navigation_params_); | |
666 } | 697 } |
667 | 698 |
668 void RenderFrameHostManager::Observe( | 699 void RenderFrameHostManager::Observe( |
669 int type, | 700 int type, |
670 const NotificationSource& source, | 701 const NotificationSource& source, |
671 const NotificationDetails& details) { | 702 const NotificationDetails& details) { |
672 switch (type) { | 703 switch (type) { |
673 case NOTIFICATION_RENDERER_PROCESS_CLOSED: | 704 case NOTIFICATION_RENDERER_PROCESS_CLOSED: |
674 case NOTIFICATION_RENDERER_PROCESS_CLOSING: | 705 case NOTIFICATION_RENDERER_PROCESS_CLOSING: |
675 RendererProcessClosing( | 706 RendererProcessClosing( |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1711 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 1742 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
1712 SiteInstance* instance) { | 1743 SiteInstance* instance) { |
1713 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 1744 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
1714 if (iter != proxy_hosts_.end()) { | 1745 if (iter != proxy_hosts_.end()) { |
1715 delete iter->second; | 1746 delete iter->second; |
1716 proxy_hosts_.erase(iter); | 1747 proxy_hosts_.erase(iter); |
1717 } | 1748 } |
1718 } | 1749 } |
1719 | 1750 |
1720 } // namespace content | 1751 } // namespace content |
OLD | NEW |