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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 EXPECT_FALSE( | 2552 EXPECT_FALSE( |
2553 web_contents->GetRenderManagerForTesting()->speculative_frame_host()); | 2553 web_contents->GetRenderManagerForTesting()->speculative_frame_host()); |
2554 } else { | 2554 } else { |
2555 EXPECT_FALSE( | 2555 EXPECT_FALSE( |
2556 web_contents->GetRenderManagerForTesting()->pending_frame_host()); | 2556 web_contents->GetRenderManagerForTesting()->pending_frame_host()); |
2557 } | 2557 } |
2558 | 2558 |
2559 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 2559 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
2560 } | 2560 } |
2561 | 2561 |
| 2562 // Check that if a sandboxed subframe opens a cross-process popup such that the |
| 2563 // popup's opener won't be set, the popup still inherits the subframe's sandbox |
| 2564 // flags. This matters for rel=noopener and rel=noreferrer links, as well as |
| 2565 // for some situations in non-site-per-process mode where the popup would |
| 2566 // normally maintain the opener, but loses it due to being placed in a new |
| 2567 // process and not creating subframe proxies. The latter might happen when |
| 2568 // opening the default search provider site. See https://crbug.com/576204. |
| 2569 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 2570 CrossProcessPopupInheritsSandboxFlagsWithNoOpener) { |
| 2571 StartEmbeddedServer(); |
| 2572 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 2573 ->GetFrameTree() |
| 2574 ->root(); |
| 2575 |
| 2576 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 2577 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 2578 |
| 2579 // Add a sandboxed about:blank iframe. |
| 2580 { |
| 2581 std::string script = |
| 2582 "var frame = document.createElement('iframe');\n" |
| 2583 "frame.sandbox = 'allow-scripts allow-popups';\n" |
| 2584 "document.body.appendChild(frame);\n"; |
| 2585 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| 2586 } |
| 2587 |
| 2588 // Navigate iframe to a page with target=_blank links, and rewrite the links |
| 2589 // to point to valid cross-site URLs. |
| 2590 GURL frame_url( |
| 2591 embedded_test_server()->GetURL("a.com", "/click-noreferrer-links.html")); |
| 2592 NavigateFrameToURL(root->child_at(0), frame_url); |
| 2593 std::string script = "setOriginForLinks('http://b.com:" + |
| 2594 embedded_test_server()->base_url().port() + "/');"; |
| 2595 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script)); |
| 2596 |
| 2597 // Helper to click on the 'rel=noreferrer target=_blank' and 'rel=noopener |
| 2598 // target=_blank' links. Checks that these links open a popup that ends up |
| 2599 // in a new SiteInstance even without site-per-process and then verifies that |
| 2600 // the popup is still sandboxed. |
| 2601 auto click_link_and_verify_popup = [this, |
| 2602 root](std::string link_opening_script) { |
| 2603 ShellAddedObserver new_shell_observer; |
| 2604 bool success = false; |
| 2605 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2606 root->child_at(0)->current_frame_host(), |
| 2607 "window.domAutomationController.send(" + link_opening_script + ")", |
| 2608 &success)); |
| 2609 EXPECT_TRUE(success); |
| 2610 |
| 2611 Shell* new_shell = new_shell_observer.GetShell(); |
| 2612 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); |
| 2613 EXPECT_NE(new_shell->web_contents()->GetSiteInstance(), |
| 2614 shell()->web_contents()->GetSiteInstance()); |
| 2615 |
| 2616 // Check that the popup is sandboxed by checking its document.origin, which |
| 2617 // should be unique. |
| 2618 std::string origin; |
| 2619 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2620 new_shell->web_contents(), |
| 2621 "domAutomationController.send(document.origin)", &origin)); |
| 2622 EXPECT_EQ("null", origin); |
| 2623 }; |
| 2624 |
| 2625 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); |
| 2626 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); |
| 2627 } |
| 2628 |
2562 } // namespace content | 2629 } // namespace content |
OLD | NEW |