diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 23:19:51 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 23:19:51 +0000 |
commit | 6acc28c769ecd78fc1d37fb6b595ff35b549c2dc (patch) | |
tree | 2c33f5dee02fea4f75b90c0163280e7225db6d25 | |
parent | 699ab0da64a44444bc99108592004d1354f5f89f (diff) | |
download | chromium_src-6acc28c769ecd78fc1d37fb6b595ff35b549c2dc.zip chromium_src-6acc28c769ecd78fc1d37fb6b595ff35b549c2dc.tar.gz chromium_src-6acc28c769ecd78fc1d37fb6b595ff35b549c2dc.tar.bz2 |
Check for view source mode in DOM UI mode.
BUG=9183
Review URL: http://codereview.chromium.org/67030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14379 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 20 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_unittest.cc | 24 |
2 files changed, 37 insertions, 7 deletions
diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 2832765..6d8fe3e 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -321,10 +321,14 @@ const string16& WebContents::GetTitle() const { DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ? render_manager_.pending_dom_ui() : render_manager_.dom_ui(); if (our_dom_ui) { - // Give the DOM UI the chance to override our title. - const string16& title = our_dom_ui->overridden_title(); - if (!title.empty()) - return title; + // Don't override the title in view source mode. + NavigationEntry* entry = controller_.GetActiveEntry(); + if (!(entry && entry->IsViewSourceMode())) { + // Give the DOM UI the chance to override our title. + const string16& title = our_dom_ui->overridden_title(); + if (!title.empty()) + return title; + } } // We use the title for the last committed entry rather than a pending @@ -350,6 +354,10 @@ SiteInstance* WebContents::GetSiteInstance() const { } bool WebContents::ShouldDisplayURL() { + // Don't hide the url in view source mode. + NavigationEntry* entry = controller_.GetActiveEntry(); + if (entry && entry->IsViewSourceMode()) + return true; DOMUI* dom_ui = GetDOMUIForCurrentState(); if (dom_ui) return !dom_ui->should_hide_url(); @@ -739,7 +747,9 @@ void WebContents::RenderViewCreated(RenderViewHost* render_view_host) { // use the pending DOM UI rather than any possibly existing committed one. if (render_manager_.pending_dom_ui()) { render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host); - } else if (entry->IsViewSourceMode()) { + } + + if (entry->IsViewSourceMode()) { // Put the renderer in view source mode. render_view_host->Send( new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc index 1c936c5..37d49ee 100644 --- a/chrome/browser/tab_contents/web_contents_unittest.cc +++ b/chrome/browser/tab_contents/web_contents_unittest.cc @@ -209,8 +209,28 @@ TEST_F(WebContentsTest, UpdateTitle) { controller().RendererDidNavigate(params, &details); contents()->UpdateTitle(rvh(), 0, L" Lots O' Whitespace\n"); - EXPECT_EQ(std::wstring(L"Lots O' Whitespace"), - UTF16ToWideHack(contents()->GetTitle())); + EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); +} + +// Test view source mode for the new tabs page. +TEST_F(WebContentsTest, NTPViewSource) { + const char kUrl[] = "view-source:chrome-ui://newtab/"; + const GURL kGURL(kUrl); + + process()->sink().ClearMessages(); + controller().LoadURL(kGURL, GURL(), PageTransition::TYPED); + rvh()->delegate()->RenderViewCreated(rvh()); + // Did we get the expected message? + EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( + ViewMsg_EnableViewSourceMode::ID)); + + ViewHostMsg_FrameNavigate_Params params; + InitNavigateParams(¶ms, 0, kGURL); + NavigationController::LoadCommittedDetails details; + controller().RendererDidNavigate(params, &details); + // Also check title and url. + EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); + EXPECT_EQ(true, contents()->ShouldDisplayURL()); } // Test simple same-SiteInstance navigation. |