diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 04:07:18 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 04:07:18 +0000 |
commit | 8d2b6c3e969cdbb83b0cf23493e527869ff25e9e (patch) | |
tree | 5b61f36327c9ad3e01783ea5244b394738662448 /chrome/browser/dom_ui/dom_ui_contents.cc | |
parent | 347141f37842c06c3b832b9721f484c4f278b159 (diff) | |
download | chromium_src-8d2b6c3e969cdbb83b0cf23493e527869ff25e9e.zip chromium_src-8d2b6c3e969cdbb83b0cf23493e527869ff25e9e.tar.gz chromium_src-8d2b6c3e969cdbb83b0cf23493e527869ff25e9e.tar.bz2 |
Make New Tab Page work correctly in incognito mode (8294)
Add a workaround to force the New Tab Page title to 'New Tab' (8282)
Make DOMUI Pages get focus correctly (8271)
Please also sanity-check DOMUI/DOMUIContents integration.
BUG=8294,8282,8271
Review URL: http://codereview.chromium.org/39057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui/dom_ui_contents.cc')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_contents.cc | 77 |
1 files changed, 54 insertions, 23 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_contents.cc b/chrome/browser/dom_ui/dom_ui_contents.cc index fd6a5c3..90a2bbb 100644 --- a/chrome/browser/dom_ui/dom_ui_contents.cc +++ b/chrome/browser/dom_ui/dom_ui_contents.cc @@ -13,9 +13,12 @@ #include "chrome/browser/extensions/extensions_ui.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/navigation_entry.h" +#include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/url_constants.h" +#include "grit/generated_resources.h" + // The path used in internal URLs to thumbnail data. static const char kThumbnailPath[] = "thumb"; @@ -141,7 +144,8 @@ DOMUIContents::DOMUIContents(Profile* profile, render_view_factory, MSG_ROUTING_NONE, NULL), - current_ui_(NULL) { + current_ui_(NULL), + current_url_(GURL()) { set_type(TAB_CONTENTS_DOM_UI); } @@ -175,49 +179,54 @@ void DOMUIContents::RenderViewCreated(RenderViewHost* render_view_host) { } bool DOMUIContents::ShouldDisplayFavIcon() { - if (current_ui_) + if (InitCurrentUI(false)) return current_ui_->ShouldDisplayFavIcon(); return true; } bool DOMUIContents::IsBookmarkBarAlwaysVisible() { - if (current_ui_) + if (InitCurrentUI(false)) return current_ui_->IsBookmarkBarAlwaysVisible(); return false; } -void DOMUIContents::SetInitialFocus() { - if (current_ui_) - current_ui_->SetInitialFocus(); +void DOMUIContents::SetInitialFocus(bool reverse) { + if (InitCurrentUI(false)) + current_ui_->SetInitialFocus(reverse); + else + TabContents::SetInitialFocus(reverse); +} + +const std::wstring& DOMUIContents::GetTitle() const { + // Workaround for new tab page - we may be asked for a title before + // the content is ready, and we don't even want to display a 'loading...' + // message, so we force it here. + if (controller()->GetActiveEntry() && + controller()->GetActiveEntry()->url().host() == + NewTabUI::GetBaseURL().host()) { + std::wstring* title = new std::wstring( + l10n_util::GetString(IDS_NEW_TAB_TITLE)); + return *title; + } + return WebContents::GetTitle(); } bool DOMUIContents::ShouldDisplayURL() { - if (current_ui_) + if (InitCurrentUI(false)) return current_ui_->ShouldDisplayURL(); - return true; + return TabContents::ShouldDisplayURL(); } void DOMUIContents::RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition) { - if (current_ui_) + if (InitCurrentUI(false)) current_ui_->RequestOpenURL(url, referrer, disposition); + else + WebContents::RequestOpenURL(url, referrer, disposition); } bool DOMUIContents::NavigateToPendingEntry(bool reload) { - if (current_ui_) { - // Shut down our existing DOMUI. - delete current_ui_; - current_ui_ = NULL; - } - - // Set up a new DOMUI. - NavigationEntry* pending_entry = controller()->GetPendingEntry(); - current_ui_ = GetDOMUIForURL(pending_entry->url()); - if (current_ui_) - current_ui_->Init(); - else - return false; - + InitCurrentUI(reload); // Let WebContents do whatever it's meant to do. return WebContents::NavigateToPendingEntry(reload); } @@ -228,6 +237,28 @@ void DOMUIContents::ProcessDOMUIMessage(const std::string& message, current_ui_->ProcessDOMUIMessage(message, content); } +bool DOMUIContents::InitCurrentUI(bool reload) { + GURL url = controller()->GetActiveEntry()->url(); + + if (reload || url != current_url_) { + // Shut down our existing DOMUI. + delete current_ui_; + current_ui_ = NULL; + + // Set up a new DOMUI. + current_ui_ = GetDOMUIForURL(url); + if (current_ui_) { + current_ui_->Init(); + current_url_ = url; + return true; + } + } else if (current_ui_) { + return true; + } + + return false; +} + // static const std::string DOMUIContents::GetScheme() { return chrome::kChromeUIScheme; |