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 | |
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')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.h | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_contents.cc | 77 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_contents.h | 10 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 13 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 11 |
6 files changed, 69 insertions, 48 deletions
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index b0efcad..9b8b069 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -79,6 +79,10 @@ void DOMUI::RegisterMessageCallback(const std::string &message, message_callbacks_.insert(std::make_pair(message, callback)); } +void DOMUI::SetInitialFocus(bool reverse) { + get_contents()->render_view_host()->SetInitialFocus(reverse); +} + void DOMUI::RequestOpenURL(const GURL& url, const GURL& /* referer */, WindowOpenDisposition disposition) { diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h index c9d34ed..3164d64 100644 --- a/chrome/browser/dom_ui/dom_ui.h +++ b/chrome/browser/dom_ui/dom_ui.h @@ -51,7 +51,7 @@ class DOMUI { // No special bookmark bar behavior virtual bool IsBookmarkBarAlwaysVisible() { return false; } // When NTP gets the initial focus, focus the URL bar. - virtual void SetInitialFocus() {}; + virtual void SetInitialFocus(bool reverse); // Whether we want to display the page's URL. virtual bool ShouldDisplayURL() { return true; } // Hide the referrer. 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; diff --git a/chrome/browser/dom_ui/dom_ui_contents.h b/chrome/browser/dom_ui/dom_ui_contents.h index 948ea6f..d7d4d67 100644 --- a/chrome/browser/dom_ui/dom_ui_contents.h +++ b/chrome/browser/dom_ui/dom_ui_contents.h @@ -106,9 +106,11 @@ class DOMUIContents : public WebContents { // The bookmark bar is always visible on the new tab. virtual bool IsBookmarkBarAlwaysVisible(); // When NTP gets the initial focus, focus the URL bar. - virtual void SetInitialFocus(); + virtual void SetInitialFocus(bool reverse); // Whether we want to display the page's URL. virtual bool ShouldDisplayURL(); + // Get the title for this page. + virtual const std::wstring& GetTitle() const; // We may wish to control what happens when a URL is opened. virtual void RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); @@ -129,9 +131,15 @@ class DOMUIContents : public WebContents { // Return a DOM UI for the provided URL. DOMUI* GetDOMUIForURL(const GURL& url); + // Initialize our current UI. + bool InitCurrentUI(bool reload); + // The DOMUI we own and show. DOMUI* current_ui_; + // URL that our current_ui_ is serving. + GURL current_url_; + DISALLOW_COPY_AND_ASSIGN(DOMUIContents); }; diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index afb7baa..105061b 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -257,7 +257,7 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path, // IncognitoTabHTMLSource IncognitoTabHTMLSource::IncognitoTabHTMLSource() - : DataSource("new-tab", MessageLoop::current()) { + : DataSource(kNewTabHost, MessageLoop::current()) { } void IncognitoTabHTMLSource::StartDataRequest(const std::string& path, @@ -795,17 +795,6 @@ NewTabUI::NewTabUI(DOMUIContents* contents) : motd_message_id_(0), incognito_(false), most_visited_handler_(NULL) { - // Show profile name in the title if the current profile is not the default. - std::wstring title; - if (UserDataManager::Get()->is_current_profile_default()) { - title = l10n_util::GetString(IDS_NEW_TAB_TITLE); - } else { - title = l10n_util::GetStringF( - IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, - UserDataManager::Get()->current_profile_name()); - } - set_forced_title(title); - if (get_profile()->IsOffTheRecord()) incognito_ = true; diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index 9e1d8c68..98b0abe 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -255,13 +255,6 @@ class NewTabUI : public DOMUI { // DOMUI Implementation virtual void Init(); - // Set the title that overrides any other title provided for the tab. - // This lets you set the title that's displayed before the content loads, - // as well as override any "Loading..." text. - void set_forced_title(const std::wstring& title) { - forced_title_ = title; - } - // Overridden from DOMUI. // Favicon should not be displayed. virtual bool ShouldDisplayFavIcon() { return false; } @@ -286,10 +279,6 @@ class NewTabUI : public DOMUI { // what HTML to load. bool incognito_; - // A title for the page we force display of. - // This prevents intermediate titles (like "Loading...") from displaying. - std::wstring forced_title_; - // A pointer to the handler for most visited. // Owned by the DOMUIHost. MostVisitedHandler* most_visited_handler_; |