| 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 2464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2475 EXPECT_FALSE( | 2475 EXPECT_FALSE( |
| 2476 web_contents->GetRenderManagerForTesting()->speculative_frame_host()); | 2476 web_contents->GetRenderManagerForTesting()->speculative_frame_host()); |
| 2477 } else { | 2477 } else { |
| 2478 EXPECT_FALSE( | 2478 EXPECT_FALSE( |
| 2479 web_contents->GetRenderManagerForTesting()->pending_frame_host()); | 2479 web_contents->GetRenderManagerForTesting()->pending_frame_host()); |
| 2480 } | 2480 } |
| 2481 | 2481 |
| 2482 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 2482 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 2483 } | 2483 } |
| 2484 | 2484 |
| 2485 // Check that if a sandboxed subframe opens a cross-process popup such that the |
| 2486 // popup's opener won't be set, the popup still inherits the subframe's sandbox |
| 2487 // flags. This matters for rel=noopener and rel=noreferrer links, as well as |
| 2488 // for some situations in non-site-per-process mode where the popup would |
| 2489 // normally maintain the opener, but loses it due to being placed in a new |
| 2490 // process and not creating subframe proxies. The latter might happen when |
| 2491 // opening the default search provider site. See https://crbug.com/576204. |
| 2492 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 2493 CrossProcessPopupInheritsSandboxFlagsWithNoOpener) { |
| 2494 StartEmbeddedServer(); |
| 2495 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 2496 ->GetFrameTree() |
| 2497 ->root(); |
| 2498 |
| 2499 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 2500 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 2501 |
| 2502 // Add a sandboxed about:blank iframe. |
| 2503 { |
| 2504 std::string script = |
| 2505 "var frame = document.createElement('iframe');\n" |
| 2506 "frame.sandbox = 'allow-scripts allow-popups';\n" |
| 2507 "document.body.appendChild(frame);\n"; |
| 2508 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| 2509 } |
| 2510 |
| 2511 // Navigate iframe to a page with target=_blank links, and rewrite the links |
| 2512 // to point to valid cross-site URLs. |
| 2513 GURL frame_url( |
| 2514 embedded_test_server()->GetURL("a.com", "/click-noreferrer-links.html")); |
| 2515 NavigateFrameToURL(root->child_at(0), frame_url); |
| 2516 std::string script = "setOriginForLinks('http://b.com:" + |
| 2517 embedded_test_server()->base_url().port() + "/');"; |
| 2518 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script)); |
| 2519 |
| 2520 // Helper to click on the 'rel=noreferrer target=_blank' and 'rel=noopener |
| 2521 // target=_blank' links. Checks that these links open a popup that ends up |
| 2522 // in a new SiteInstance even without site-per-process and then verifies that |
| 2523 // the popup is still sandboxed. |
| 2524 auto click_link_and_verify_popup = [this, |
| 2525 root](std::string link_opening_script) { |
| 2526 ShellAddedObserver new_shell_observer; |
| 2527 bool success = false; |
| 2528 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2529 root->child_at(0)->current_frame_host(), |
| 2530 "window.domAutomationController.send(" + link_opening_script + ")", |
| 2531 &success)); |
| 2532 EXPECT_TRUE(success); |
| 2533 |
| 2534 Shell* new_shell = new_shell_observer.GetShell(); |
| 2535 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); |
| 2536 EXPECT_NE(new_shell->web_contents()->GetSiteInstance(), |
| 2537 shell()->web_contents()->GetSiteInstance()); |
| 2538 |
| 2539 // Check that the popup is sandboxed by checking its document.origin, which |
| 2540 // should be unique. |
| 2541 std::string origin; |
| 2542 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2543 new_shell->web_contents(), |
| 2544 "domAutomationController.send(document.origin)", &origin)); |
| 2545 EXPECT_EQ("null", origin); |
| 2546 }; |
| 2547 |
| 2548 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); |
| 2549 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); |
| 2550 } |
| 2551 |
| 2485 } // namespace content | 2552 } // namespace content |
| OLD | NEW |