diff options
-rw-r--r-- | chrome/browser/tab_contents/view_source_browsertest.cc | 35 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 6 |
2 files changed, 39 insertions, 2 deletions
diff --git a/chrome/browser/tab_contents/view_source_browsertest.cc b/chrome/browser/tab_contents/view_source_browsertest.cc index 9a8b9b5..2218210 100644 --- a/chrome/browser/tab_contents/view_source_browsertest.cc +++ b/chrome/browser/tab_contents/view_source_browsertest.cc @@ -10,7 +10,12 @@ #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_types.h" +#include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "content/public/test/browser_test_utils.h" #include "googleurl/src/gurl.h" #include "net/test/test_server.h" @@ -84,3 +89,33 @@ IN_PROC_BROWSER_TEST_F(ViewSourceTest, EXPECT_FALSE(chrome::CanViewSource(browser())); } + +// Tests that reload initiated by the script on the view-source page leaves +// the page in view-source mode. +IN_PROC_BROWSER_TEST_F(ViewSourceTest, TestViewSourceReload) { + ASSERT_TRUE(test_server()->Start()); + + GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + + test_server()->GetURL(kTestHtml).spec()); + + content::WindowedNotificationObserver observer( + content::NOTIFICATION_LOAD_STOP, + content::NotificationService::AllSources()); + ui_test_utils::NavigateToURL(browser(), url_viewsource); + observer.Wait(); + + content::RenderViewHost* rvh = + chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(); + + ASSERT_TRUE( + content::ExecuteJavaScript(rvh, + L"", + L"window.location.reload();")); + + content::WindowedNotificationObserver observer2( + content::NOTIFICATION_LOAD_STOP, + content::NotificationService::AllSources()); + observer2.Wait(); + ASSERT_TRUE(chrome::GetWebContentsAt(browser(), 0)->GetController(). + GetActiveEntry()->IsViewSourceMode()); +} diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 3e59258..729ad00 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2777,7 +2777,8 @@ WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( // must be handled by the browser process so that the correct bindings and // data sources can be registered. // Similarly, navigations to view-source URLs or within ViewSource mode - // must be handled by the browser process. + // must be handled by the browser process (except for reloads - those are + // safe to leave within the renderer). // Lastly, access to file:// URLs from non-file:// URL pages must be // handled by the browser so that ordinary renderer processes don't get // blessed with file permissions. @@ -2787,7 +2788,8 @@ WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( GetContentClient()->HasWebUIScheme(url) || (cumulative_bindings & BINDINGS_POLICY_WEB_UI) || url.SchemeIs(chrome::kViewSourceScheme) || - frame->isViewSourceModeEnabled(); + (frame->isViewSourceModeEnabled() && + type != WebKit::WebNavigationTypeReload); if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { // Fork non-file to file opens. Check the opener URL if this is the |