| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 496 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
| 497 // a regression test for bug 9364. | 497 // a regression test for bug 9364. |
| 498 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 498 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
| 499 set_should_create_webui(true); | 499 set_should_create_webui(true); |
| 500 const GURL kChromeUrl("chrome://foo"); | 500 const GURL kChromeUrl("chrome://foo"); |
| 501 const GURL kDestUrl("http://www.google.com/"); | 501 const GURL kDestUrl("http://www.google.com/"); |
| 502 | 502 |
| 503 // Navigate our first tab to the chrome url and then to the destination, | 503 // Navigate our first tab to the chrome url and then to the destination, |
| 504 // ensuring we grant bindings to the chrome URL. | 504 // ensuring we grant bindings to the chrome URL. |
| 505 NavigateActiveAndCommit(kChromeUrl); | 505 NavigateActiveAndCommit(kChromeUrl); |
| 506 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 506 EXPECT_TRUE(contents()->GetMainFrame()->GetEnabledBindings() & |
| 507 BINDINGS_POLICY_WEB_UI); |
| 507 NavigateActiveAndCommit(kDestUrl); | 508 NavigateActiveAndCommit(kDestUrl); |
| 508 | 509 |
| 509 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 510 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
| 510 | 511 |
| 511 // Make a second tab. | 512 // Make a second tab. |
| 512 std::unique_ptr<TestWebContents> contents2( | 513 std::unique_ptr<TestWebContents> contents2( |
| 513 TestWebContents::Create(browser_context(), NULL)); | 514 TestWebContents::Create(browser_context(), NULL)); |
| 514 | 515 |
| 515 // Load the two URLs in the second tab. Note that the first navigation creates | 516 // Load the two URLs in the second tab. Note that the first navigation creates |
| 516 // a RFH that's not pending (since there is no cross-site transition), so | 517 // a RFH that's not pending (since there is no cross-site transition), so |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 EXPECT_EQ(host->web_ui(), manager->GetNavigatingWebUI()); | 1026 EXPECT_EQ(host->web_ui(), manager->GetNavigatingWebUI()); |
| 1026 EXPECT_EQ(host->web_ui(), host->pending_web_ui()); | 1027 EXPECT_EQ(host->web_ui(), host->pending_web_ui()); |
| 1027 } else { | 1028 } else { |
| 1028 // The WebUI was immediately committed and there should be none navigating. | 1029 // The WebUI was immediately committed and there should be none navigating. |
| 1029 EXPECT_FALSE(manager->GetNavigatingWebUI()); | 1030 EXPECT_FALSE(manager->GetNavigatingWebUI()); |
| 1030 } | 1031 } |
| 1031 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | 1032 EXPECT_TRUE(manager->current_frame_host()->web_ui()); |
| 1032 | 1033 |
| 1033 // Commit. | 1034 // Commit. |
| 1034 manager->DidNavigateFrame(host, true); | 1035 manager->DidNavigateFrame(host, true); |
| 1035 EXPECT_TRUE( | 1036 EXPECT_TRUE(host->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1036 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1039 // Tests that we can open a WebUI link in a new tab from a WebUI page and still |
| 1040 // grant the correct bindings. http://crbug.com/189101. | 1040 // grant the correct bindings. http://crbug.com/189101. |
| 1041 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { | 1041 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { |
| 1042 set_should_create_webui(true); | 1042 set_should_create_webui(true); |
| 1043 scoped_refptr<SiteInstance> blank_instance = | 1043 scoped_refptr<SiteInstance> blank_instance = |
| 1044 SiteInstance::Create(browser_context()); | 1044 SiteInstance::Create(browser_context()); |
| 1045 blank_instance->GetProcess()->Init(); | 1045 blank_instance->GetProcess()->Init(); |
| 1046 | 1046 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1060 NavigationEntryImpl entry1(NULL /* instance */, kUrl1, | 1060 NavigationEntryImpl entry1(NULL /* instance */, kUrl1, |
| 1061 Referrer(), base::string16() /* title */, | 1061 Referrer(), base::string16() /* title */, |
| 1062 ui::PAGE_TRANSITION_TYPED, | 1062 ui::PAGE_TRANSITION_TYPED, |
| 1063 false /* is_renderer_init */); | 1063 false /* is_renderer_init */); |
| 1064 RenderFrameHostImpl* host1 = NavigateToEntry(manager1, entry1); | 1064 RenderFrameHostImpl* host1 = NavigateToEntry(manager1, entry1); |
| 1065 | 1065 |
| 1066 // We should have a pending navigation to the WebUI RenderViewHost. | 1066 // We should have a pending navigation to the WebUI RenderViewHost. |
| 1067 // It should already have bindings. | 1067 // It should already have bindings. |
| 1068 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); | 1068 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); |
| 1069 EXPECT_NE(host1, manager1->current_frame_host()); | 1069 EXPECT_NE(host1, manager1->current_frame_host()); |
| 1070 EXPECT_TRUE( | 1070 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1071 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
| 1072 | 1071 |
| 1073 // Commit and ensure we still have bindings. | 1072 // Commit and ensure we still have bindings. |
| 1074 manager1->DidNavigateFrame(host1, true); | 1073 manager1->DidNavigateFrame(host1, true); |
| 1075 SiteInstance* webui_instance = host1->GetSiteInstance(); | 1074 SiteInstance* webui_instance = host1->GetSiteInstance(); |
| 1076 EXPECT_EQ(host1, manager1->current_frame_host()); | 1075 EXPECT_EQ(host1, manager1->current_frame_host()); |
| 1077 EXPECT_TRUE( | 1076 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1078 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
| 1079 | 1077 |
| 1080 // Now simulate clicking a link that opens in a new tab. | 1078 // Now simulate clicking a link that opens in a new tab. |
| 1081 std::unique_ptr<TestWebContents> web_contents2( | 1079 std::unique_ptr<TestWebContents> web_contents2( |
| 1082 TestWebContents::Create(browser_context(), webui_instance)); | 1080 TestWebContents::Create(browser_context(), webui_instance)); |
| 1083 RenderFrameHostManager* manager2 = | 1081 RenderFrameHostManager* manager2 = |
| 1084 web_contents2->GetRenderManagerForTesting(); | 1082 web_contents2->GetRenderManagerForTesting(); |
| 1085 // Make sure the new RVH is considered live. This is usually done in | 1083 // Make sure the new RVH is considered live. This is usually done in |
| 1086 // RenderWidgetHost::Init when opening a new tab from a link. | 1084 // RenderWidgetHost::Init when opening a new tab from a link. |
| 1087 manager2->current_host()->CreateRenderView(-1, MSG_ROUTING_NONE, | 1085 manager2->current_host()->CreateRenderView(-1, MSG_ROUTING_NONE, |
| 1088 FrameReplicationState(), false); | 1086 FrameReplicationState(), false); |
| 1089 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); | 1087 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); |
| 1090 | 1088 |
| 1091 const GURL kUrl2("chrome://foo/bar"); | 1089 const GURL kUrl2("chrome://foo/bar"); |
| 1092 NavigationEntryImpl entry2(NULL /* instance */, kUrl2, | 1090 NavigationEntryImpl entry2(NULL /* instance */, kUrl2, |
| 1093 Referrer(), base::string16() /* title */, | 1091 Referrer(), base::string16() /* title */, |
| 1094 ui::PAGE_TRANSITION_LINK, | 1092 ui::PAGE_TRANSITION_LINK, |
| 1095 true /* is_renderer_init */); | 1093 true /* is_renderer_init */); |
| 1096 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); | 1094 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); |
| 1097 | 1095 |
| 1098 // No cross-process transition happens because we are already in the right | 1096 // No cross-process transition happens because we are already in the right |
| 1099 // SiteInstance. We should grant bindings immediately. | 1097 // SiteInstance. We should grant bindings immediately. |
| 1100 EXPECT_EQ(host2, manager2->current_frame_host()); | 1098 EXPECT_EQ(host2, manager2->current_frame_host()); |
| 1101 EXPECT_TRUE(manager2->GetNavigatingWebUI()); | 1099 EXPECT_TRUE(manager2->GetNavigatingWebUI()); |
| 1102 EXPECT_FALSE(host2->web_ui()); | 1100 EXPECT_FALSE(host2->web_ui()); |
| 1103 EXPECT_TRUE( | 1101 EXPECT_TRUE(host2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1104 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
| 1105 | 1102 |
| 1106 manager2->DidNavigateFrame(host2, true); | 1103 manager2->DidNavigateFrame(host2, true); |
| 1107 } | 1104 } |
| 1108 | 1105 |
| 1109 // Tests that a WebUI is correctly reused between chrome:// pages. | 1106 // Tests that a WebUI is correctly reused between chrome:// pages. |
| 1110 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { | 1107 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { |
| 1111 set_should_create_webui(true); | 1108 set_should_create_webui(true); |
| 1112 | 1109 |
| 1113 // Navigate to a WebUI page. | 1110 // Navigate to a WebUI page. |
| 1114 const GURL kUrl1("chrome://foo"); | 1111 const GURL kUrl1("chrome://foo"); |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { | 1546 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { |
| 1550 set_should_create_webui(true); | 1547 set_should_create_webui(true); |
| 1551 const GURL kSettingsUrl("chrome://chrome/settings"); | 1548 const GURL kSettingsUrl("chrome://chrome/settings"); |
| 1552 const GURL kPluginUrl("chrome://plugins"); | 1549 const GURL kPluginUrl("chrome://plugins"); |
| 1553 | 1550 |
| 1554 // Navigate to an initial WebUI URL. | 1551 // Navigate to an initial WebUI URL. |
| 1555 contents()->NavigateAndCommit(kSettingsUrl); | 1552 contents()->NavigateAndCommit(kSettingsUrl); |
| 1556 | 1553 |
| 1557 // Ensure the RVH has WebUI bindings. | 1554 // Ensure the RVH has WebUI bindings. |
| 1558 TestRenderViewHost* rvh1 = test_rvh(); | 1555 TestRenderViewHost* rvh1 = test_rvh(); |
| 1559 EXPECT_TRUE(rvh1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1556 EXPECT_TRUE(rvh1->GetMainFrame()->GetEnabledBindings() & |
| 1557 BINDINGS_POLICY_WEB_UI); |
| 1560 | 1558 |
| 1561 // Create a new tab and simulate it being the opener for the main | 1559 // Create a new tab and simulate it being the opener for the main |
| 1562 // tab. It should be in the same SiteInstance. | 1560 // tab. It should be in the same SiteInstance. |
| 1563 std::unique_ptr<TestWebContents> opener1( | 1561 std::unique_ptr<TestWebContents> opener1( |
| 1564 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); | 1562 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); |
| 1565 RenderFrameHostManager* opener1_manager = | 1563 RenderFrameHostManager* opener1_manager = |
| 1566 opener1->GetRenderManagerForTesting(); | 1564 opener1->GetRenderManagerForTesting(); |
| 1567 contents()->SetOpener(opener1.get()); | 1565 contents()->SetOpener(opener1.get()); |
| 1568 | 1566 |
| 1569 // Navigate to a different WebUI URL (different SiteInstance, same | 1567 // Navigate to a different WebUI URL (different SiteInstance, same |
| 1570 // BrowsingInstance). | 1568 // BrowsingInstance). |
| 1571 contents()->NavigateAndCommit(kPluginUrl); | 1569 contents()->NavigateAndCommit(kPluginUrl); |
| 1572 TestRenderViewHost* rvh2 = test_rvh(); | 1570 TestRenderViewHost* rvh2 = test_rvh(); |
| 1573 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 1571 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
| 1574 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 1572 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
| 1575 rvh2->GetSiteInstance())); | 1573 rvh2->GetSiteInstance())); |
| 1576 | 1574 |
| 1577 // Ensure a proxy and swapped out RVH are created in the first opener tab. | 1575 // Ensure a proxy and swapped out RVH are created in the first opener tab. |
| 1578 EXPECT_TRUE( | 1576 EXPECT_TRUE( |
| 1579 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance())); | 1577 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance())); |
| 1580 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 1578 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
| 1581 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1579 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 1582 EXPECT_FALSE(opener1_rvh->is_active()); | 1580 EXPECT_FALSE(opener1_rvh->is_active()); |
| 1583 | 1581 |
| 1584 // Ensure the new RVH has WebUI bindings. | 1582 // Ensure the new RVH has WebUI bindings. |
| 1585 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1583 EXPECT_TRUE(rvh2->GetMainFrame()->GetEnabledBindings() & |
| 1584 BINDINGS_POLICY_WEB_UI); |
| 1586 } | 1585 } |
| 1587 | 1586 |
| 1588 // Test that we reuse the same guest SiteInstance if we navigate across sites. | 1587 // Test that we reuse the same guest SiteInstance if we navigate across sites. |
| 1589 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { | 1588 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { |
| 1590 GURL guest_url(std::string(kGuestScheme).append("://abc123")); | 1589 GURL guest_url(std::string(kGuestScheme).append("://abc123")); |
| 1591 scoped_refptr<SiteInstance> instance = | 1590 scoped_refptr<SiteInstance> instance = |
| 1592 SiteInstance::CreateForURL(browser_context(), guest_url); | 1591 SiteInstance::CreateForURL(browser_context(), guest_url); |
| 1593 std::unique_ptr<TestWebContents> web_contents( | 1592 std::unique_ptr<TestWebContents> web_contents( |
| 1594 TestWebContents::Create(browser_context(), instance)); | 1593 TestWebContents::Create(browser_context(), instance)); |
| 1595 | 1594 |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 // Start a pending WebUI navigation in the main frame and verify that the | 2134 // Start a pending WebUI navigation in the main frame and verify that the |
| 2136 // pending RVH has bindings. | 2135 // pending RVH has bindings. |
| 2137 const GURL kWebUIUrl("chrome://foo"); | 2136 const GURL kWebUIUrl("chrome://foo"); |
| 2138 NavigationEntryImpl webui_entry( | 2137 NavigationEntryImpl webui_entry( |
| 2139 nullptr /* instance */, kWebUIUrl, Referrer(), | 2138 nullptr /* instance */, kWebUIUrl, Referrer(), |
| 2140 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 2139 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 2141 false /* is_renderer_init */); | 2140 false /* is_renderer_init */); |
| 2142 RenderFrameHostManager* main_rfhm = contents()->GetRenderManagerForTesting(); | 2141 RenderFrameHostManager* main_rfhm = contents()->GetRenderManagerForTesting(); |
| 2143 RenderFrameHostImpl* webui_rfh = NavigateToEntry(main_rfhm, webui_entry); | 2142 RenderFrameHostImpl* webui_rfh = NavigateToEntry(main_rfhm, webui_entry); |
| 2144 EXPECT_EQ(webui_rfh, GetPendingFrameHost(main_rfhm)); | 2143 EXPECT_EQ(webui_rfh, GetPendingFrameHost(main_rfhm)); |
| 2145 EXPECT_TRUE(webui_rfh->render_view_host()->GetEnabledBindings() & | 2144 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 2146 BINDINGS_POLICY_WEB_UI); | |
| 2147 | 2145 |
| 2148 // Before it commits, do a cross-process navigation in a subframe. This | 2146 // Before it commits, do a cross-process navigation in a subframe. This |
| 2149 // should not grant WebUI bindings to the subframe's RVH. | 2147 // should not grant WebUI bindings to the subframe's RVH. |
| 2150 const GURL kSubframeUrl("http://bar.com"); | 2148 const GURL kSubframeUrl("http://bar.com"); |
| 2151 NavigationEntryImpl subframe_entry( | 2149 NavigationEntryImpl subframe_entry( |
| 2152 nullptr /* instance */, kSubframeUrl, Referrer(), | 2150 nullptr /* instance */, kSubframeUrl, Referrer(), |
| 2153 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 2151 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 2154 false /* is_renderer_init */); | 2152 false /* is_renderer_init */); |
| 2155 RenderFrameHostImpl* bar_rfh = NavigateToEntry(subframe_rfhm, subframe_entry); | 2153 RenderFrameHostImpl* bar_rfh = NavigateToEntry(subframe_rfhm, subframe_entry); |
| 2156 EXPECT_FALSE(bar_rfh->render_view_host()->GetEnabledBindings() & | 2154 EXPECT_FALSE(bar_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 2157 BINDINGS_POLICY_WEB_UI); | |
| 2158 } | 2155 } |
| 2159 | 2156 |
| 2160 // Test that opener proxies are created properly with a cycle on the opener | 2157 // Test that opener proxies are created properly with a cycle on the opener |
| 2161 // chain. | 2158 // chain. |
| 2162 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWithCycleOnOpenerChain) { | 2159 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWithCycleOnOpenerChain) { |
| 2163 const GURL kUrl1("http://www.google.com/"); | 2160 const GURL kUrl1("http://www.google.com/"); |
| 2164 const GURL kUrl2("http://www.chromium.org/"); | 2161 const GURL kUrl2("http://www.chromium.org/"); |
| 2165 | 2162 |
| 2166 // Navigate to an initial URL. | 2163 // Navigate to an initial URL. |
| 2167 contents()->NavigateAndCommit(kUrl1); | 2164 contents()->NavigateAndCommit(kUrl1); |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3148 ASSERT_FALSE(delete_observer.deleted()); | 3145 ASSERT_FALSE(delete_observer.deleted()); |
| 3149 EXPECT_FALSE(initial_rfh->is_active()); | 3146 EXPECT_FALSE(initial_rfh->is_active()); |
| 3150 | 3147 |
| 3151 // The initial RFH receives a DidStartProvisionalLoad IPC. It should not | 3148 // The initial RFH receives a DidStartProvisionalLoad IPC. It should not |
| 3152 // create a NavigationHandle. | 3149 // create a NavigationHandle. |
| 3153 initial_rfh->SimulateNavigationStart(kUrl3); | 3150 initial_rfh->SimulateNavigationStart(kUrl3); |
| 3154 EXPECT_FALSE(initial_rfh->navigation_handle()); | 3151 EXPECT_FALSE(initial_rfh->navigation_handle()); |
| 3155 } | 3152 } |
| 3156 | 3153 |
| 3157 } // namespace content | 3154 } // namespace content |
| OLD | NEW |