From 652bcad9d05b36b4905b896bcf93628e18647893 Mon Sep 17 00:00:00 2001 From: "glen@google.com" Date: Thu, 31 Jul 2008 23:27:13 +0000 Subject: Stop the new tab page fading in if it's not your startup tab. BUG=1295355 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/dom_ui/new_tab_ui.cc | 34 ++++++++++++++++++---------------- chrome/browser/dom_ui/new_tab_ui.h | 13 +++++++------ chrome/browser/resources/new_tab.html | 21 +++------------------ 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 894414c..e45c6ef 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -43,8 +43,9 @@ #include "chrome/browser/template_url.h" #include "chrome/browser/user_metrics.h" #include "chrome/browser/views/keyword_editor_view.h" -#include "chrome/common/l10n_util.h" #include "chrome/common/jstemplate_builder.h" +#include "chrome/common/l10n_util.h" +#include "chrome/common/pref_names.h" #include "chrome/common/resource_bundle.h" #include "generated_resources.h" @@ -72,6 +73,8 @@ static const int kRecentBookmarks = 9; static const wchar_t kRTLHtmlTextDirection[] = L"rtl"; static const wchar_t kDefaultHtmlTextDirection[] = L"ltr"; +bool NewTabHTMLSource::first_view_ = true; + namespace { // To measure end-to-end performance of the new tab page, we observe paint @@ -166,9 +169,8 @@ void SetURLAndTitle(DictionaryValue* dictionary, std::wstring title, } // end anonymous namespace -NewTabHTMLSource::NewTabHTMLSource(int message_id) - : DataSource("new-tab", MessageLoop::current()), - message_id_(message_id) { +NewTabHTMLSource::NewTabHTMLSource() + : DataSource("new-tab", MessageLoop::current()) { } void NewTabHTMLSource::StartDataRequest(const std::string& path, @@ -202,17 +204,10 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path, (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? kRTLHtmlTextDirection : kDefaultHtmlTextDirection); - // Let the page know whether this is the first New Tab view for - // this session (and let it trigger all manner of fancy). - static bool new_session = true; - localized_strings.SetString(L"newsession", - new_session ? L"true" : std::wstring()); - new_session = false; - - if (message_id_) - localized_strings.SetString(L"motd", l10n_util::GetString(message_id_)); - else - localized_strings.SetString(L"motd", std::wstring()); + // Let the tab know whether it's the first tab being viewed. + localized_strings.SetString(L"firstview", + first_view_ ? L"true" : std::wstring()); + first_view_ = false; static const StringPiece new_tab_html( ResourceBundle::GetSharedInstance().GetRawDataResource( @@ -751,6 +746,13 @@ NewTabUIContents::NewTabUIContents(Profile* profile, if (profile->IsOffTheRecord()) incognito_ = true; + if (NewTabHTMLSource::first_view() && + (profile->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || + !profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) + ) { + NewTabHTMLSource::set_first_view(false); + } + render_view_host()->SetPaintObserver(new PaintTimer); } @@ -783,7 +785,7 @@ void NewTabUIContents::AttachMessageHandlers() { AddMessageHandler(new RecentlyClosedTabsHandler(this)); AddMessageHandler(new HistoryHandler(this)); - NewTabHTMLSource* html_source = new NewTabHTMLSource(0); + NewTabHTMLSource* html_source = new NewTabHTMLSource(); g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(&chrome_url_data_manager, diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index e7adf4c..71a4f50 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -54,17 +54,19 @@ bool NewTabUIHandleURL(GURL* url, TabContentsType* result_type); class NewTabHTMLSource : public ChromeURLDataManager::DataSource { public: - // Creates our datasource and sets our user message to a specific message - // from our string bundle. - NewTabHTMLSource(int message_id); + NewTabHTMLSource(); // Called when the network layer has requested a resource underneath // the path we registered. virtual void StartDataRequest(const std::string& path, int request_id); + // Setters and getters for first_view. + static void set_first_view(bool first_view) { first_view_ = first_view; } + static bool first_view() { return first_view_; } private: - // The ID of the message from our string bundle to display to the user. - int message_id_; + // Whether this is the is the first viewing of the new tab page and + // we think it is the user's startup page. + static bool first_view_; DISALLOW_EVIL_CONSTRUCTORS(NewTabHTMLSource); }; @@ -306,7 +308,6 @@ class NewTabUIContents : public DOMUIHost { // Clicking a URL on the page should count as an autobookmark click. virtual void RequestOpenURL(const GURL& url, WindowOpenDisposition disposition); - private: // The message id that should be displayed in this NewTabUIContents // instance's motd area. diff --git a/chrome/browser/resources/new_tab.html b/chrome/browser/resources/new_tab.html index fed6f9e..3c16644 100644 --- a/chrome/browser/resources/new_tab.html +++ b/chrome/browser/resources/new_tab.html @@ -1,4 +1,4 @@ - +