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 <set> | 5 #include <set> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/browser/webui/web_ui_impl.h" | 17 #include "content/browser/webui/web_ui_impl.h" |
17 #include "content/common/content_constants_internal.h" | 18 #include "content/common/content_constants_internal.h" |
18 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/common/bindings_policy.h" | 24 #include "content/public/common/bindings_policy.h" |
24 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/file_chooser_file_info.h" |
| 27 #include "content/public/common/file_chooser_params.h" |
| 28 #include "content/public/common/page_state.h" |
25 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
26 #include "content/public/test/browser_test_utils.h" | 30 #include "content/public/test/browser_test_utils.h" |
27 #include "content/public/test/content_browser_test.h" | 31 #include "content/public/test/content_browser_test.h" |
28 #include "content/public/test/content_browser_test_utils.h" | 32 #include "content/public/test/content_browser_test_utils.h" |
29 #include "content/public/test/test_navigation_observer.h" | 33 #include "content/public/test/test_navigation_observer.h" |
30 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
31 #include "content/shell/browser/shell.h" | 35 #include "content/shell/browser/shell.h" |
32 #include "net/base/net_util.h" | 36 #include "net/base/net_util.h" |
33 #include "net/dns/mock_host_resolver.h" | 37 #include "net/dns/mock_host_resolver.h" |
34 #include "net/test/spawned_test_server/spawned_test_server.h" | 38 #include "net/test/spawned_test_server/spawned_test_server.h" |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1508 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
1505 | 1509 |
1506 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 1510 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
1507 | 1511 |
1508 GURL regular_page_url(test_server()->GetURL("files/title2.html")); | 1512 GURL regular_page_url(test_server()->GetURL("files/title2.html")); |
1509 NavigateToURL(shell(), regular_page_url); | 1513 NavigateToURL(shell(), regular_page_url); |
1510 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1514 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
1511 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1515 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
1512 } | 1516 } |
1513 | 1517 |
| 1518 class FileChooserDelegate : public WebContentsDelegate { |
| 1519 public: |
| 1520 FileChooserDelegate(const base::FilePath& file) |
| 1521 : file_(file), file_chosen_(false) {} |
| 1522 |
| 1523 void RunFileChooser(WebContents* web_contents, |
| 1524 const FileChooserParams& params) override { |
| 1525 // Send the selected file to the renderer process. |
| 1526 FileChooserFileInfo file_info; |
| 1527 file_info.file_path = file_; |
| 1528 std::vector<FileChooserFileInfo> files; |
| 1529 files.push_back(file_info); |
| 1530 web_contents->GetRenderViewHost()->FilesSelectedInChooser( |
| 1531 files, FileChooserParams::Open); |
| 1532 |
| 1533 file_chosen_ = true; |
| 1534 } |
| 1535 |
| 1536 bool file_chosen() { return file_chosen_; } |
| 1537 |
| 1538 private: |
| 1539 base::FilePath file_; |
| 1540 bool file_chosen_; |
| 1541 }; |
| 1542 |
| 1543 // Test for http://crbug.com/262948. |
| 1544 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1545 RestoreFileAccessForHistoryNavigation) { |
| 1546 StartServer(); |
| 1547 base::FilePath file_path; |
| 1548 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); |
| 1549 file_path = file_path.AppendASCII("bar"); |
| 1550 |
| 1551 // Navigate to url and get it to reference a file in its PageState. |
| 1552 GURL url1(test_server()->GetURL("files/file_input.html")); |
| 1553 NavigateToURL(shell(), url1); |
| 1554 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
| 1555 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file_path)); |
| 1556 shell()->web_contents()->SetDelegate(delegate.get()); |
| 1557 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 1558 "document.getElementById('fileinput').click();")); |
| 1559 EXPECT_TRUE(delegate->file_chosen()); |
| 1560 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1561 process_id, file_path)); |
| 1562 |
| 1563 // Navigate to a different process without access to the file, and wait for |
| 1564 // the old process to exit. |
| 1565 RenderProcessHostWatcher exit_observer( |
| 1566 shell()->web_contents()->GetRenderProcessHost(), |
| 1567 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
| 1568 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); |
| 1569 exit_observer.Wait(); |
| 1570 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1571 shell()->web_contents()->GetRenderProcessHost()->GetID(), file_path)); |
| 1572 |
| 1573 // Ensure that the file ended up in the PageState of the previous entry. |
| 1574 NavigationEntry* prev_entry = |
| 1575 shell()->web_contents()->GetController().GetEntryAtIndex(0); |
| 1576 EXPECT_EQ(url1, prev_entry->GetURL()); |
| 1577 const std::vector<base::FilePath>& file_paths = |
| 1578 prev_entry->GetPageState().GetReferencedFiles(); |
| 1579 ASSERT_EQ(1U, file_paths.size()); |
| 1580 EXPECT_EQ(file_path, file_paths.at(0)); |
| 1581 |
| 1582 // Go back, ending up in a different RenderProcessHost than before. |
| 1583 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); |
| 1584 shell()->web_contents()->GetController().GoBack(); |
| 1585 back_nav_load_observer.Wait(); |
| 1586 EXPECT_NE(process_id, |
| 1587 shell()->web_contents()->GetRenderProcessHost()->GetID()); |
| 1588 |
| 1589 // Ensure that the file access still exists in the new process ID. |
| 1590 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1591 shell()->web_contents()->GetRenderProcessHost()->GetID(), file_path)); |
| 1592 |
| 1593 // Navigate to a same site page to trigger a PageState update and ensure the |
| 1594 // renderer is not killed. |
| 1595 EXPECT_TRUE( |
| 1596 NavigateToURL(shell(), test_server()->GetURL("files/title2.html"))); |
| 1597 } |
| 1598 |
1514 } // namespace content | 1599 } // namespace content |
OLD | NEW |