diff options
author | arv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-22 23:53:09 +0000 |
---|---|---|
committer | arv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-22 23:53:09 +0000 |
commit | 60287ffd30023b51d7f183abb6948a63f9f1eb90 (patch) | |
tree | a640367374681d389b091b4443d9b43ff4822983 /chrome/browser/dom_ui | |
parent | 930d1f1a0dd0bdfa65822af55d4717c6ab62515e (diff) | |
download | chromium_src-60287ffd30023b51d7f183abb6948a63f9f1eb90.zip chromium_src-60287ffd30023b51d7f183abb6948a63f9f1eb90.tar.gz chromium_src-60287ffd30023b51d7f183abb6948a63f9f1eb90.tar.bz2 |
Update the New New Tab Page. There are still a lot of things that are
not implemented but it is time to get this submitted and iron out the
remaining issues.
BUG=13362
TEST=Start chrome with --new-new-tab-page and look at play arouind with
the new tab page.
Review URL: http://codereview.chromium.org/132027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18989 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 40 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 54 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 40 |
3 files changed, 131 insertions, 3 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index e1dd96e..3bdb738 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -22,6 +22,7 @@ #include "chrome/browser/dom_ui/dom_ui_theme_source.h" #include "chrome/browser/dom_ui/downloads_dom_handler.h" #include "chrome/browser/dom_ui/history_ui.h" +#include "chrome/browser/dom_ui/shown_sections_handler.h" #include "chrome/browser/dom_ui/web_resource_handler.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/metrics/user_metrics.h" @@ -294,6 +295,38 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path, l10n_util::GetString(IDS_NEW_TAB_ATTRIBUTION_INTRO)); localized_strings.SetString(L"resourcecache", l10n_util::GetString(IDS_NEW_TAB_WEB_RESOURCE_CACHE)); + localized_strings.SetString(L"editthumbnail", + l10n_util::GetString(IDS_NEW_TAB_EDIT_THUMBNAIL)); + localized_strings.SetString(L"recentactivities", + l10n_util::GetString(IDS_NEW_TAB_RECENT_ACTIVITIES)); + localized_strings.SetString(L"downloads", + l10n_util::GetString(IDS_NEW_TAB_DOWNLOADS)); + localized_strings.SetString(L"viewfullhistory", + l10n_util::GetString(IDS_NEW_TAB_VIEW_FULL_HISTORY)); + localized_strings.SetString(L"viewalldownloads", + l10n_util::GetString(IDS_NEW_TAB_VIEW_ALL_DOWNLOADS)); + localized_strings.SetString(L"showthumbnails", + l10n_util::GetString(IDS_NEW_TAB_SHOW_THUMBNAILS)); + localized_strings.SetString(L"hidethumbnails", + l10n_util::GetString(IDS_NEW_TAB_HIDE_THUMBNAILS)); + localized_strings.SetString(L"showlist", + l10n_util::GetString(IDS_NEW_TAB_SHOW_LIST)); + localized_strings.SetString(L"hidelist", + l10n_util::GetString(IDS_NEW_TAB_HIDE_LIST)); + localized_strings.SetString(L"showrecent", + l10n_util::GetString(IDS_NEW_TAB_SHOW_RECENT)); + localized_strings.SetString(L"hiderecent", + l10n_util::GetString(IDS_NEW_TAB_HIDE_RECENT)); + localized_strings.SetString(L"showrecommendations", + l10n_util::GetString(IDS_NEW_TAB_SHOW_RECOMMENDATIONS)); + localized_strings.SetString(L"hiderecommendations", + l10n_util::GetString(IDS_NEW_TAB_HIDE_RECOMMENDATIONS)); + localized_strings.SetString(L"thumbnailremovednotification", + l10n_util::GetString(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION)); + localized_strings.SetString(L"undothumbnailremove", + l10n_util::GetString(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE)); + localized_strings.SetString(L"otrmessage", + l10n_util::GetString(IDS_NEW_TAB_OTR_MESSAGE)); SetFontAndTextDirection(&localized_strings); @@ -1376,11 +1409,10 @@ NewTabUI::NewTabUI(TabContents* contents) DownloadManager* dlm = GetProfile()->GetDownloadManager(); DownloadsDOMHandler* downloads_handler = new DownloadsDOMHandler(this, dlm); - AddMessageHandler(downloads_handler); - AddMessageHandler(new BrowsingHistoryHandler(this)); - downloads_handler->Init(); + + AddMessageHandler(new ShownSectionsHandler(this)); } if (EnableWebResources()) @@ -1443,6 +1475,8 @@ void NewTabUI::RegisterUserPrefs(PrefService* prefs) { MostVisitedHandler::RegisterUserPrefs(prefs); if (NewTabUI::EnableWebResources()) WebResourceHandler::RegisterUserPrefs(prefs); + if (NewTabUI::EnableNewNewTabPage()) + ShownSectionsHandler::RegisterUserPrefs(prefs); } // static diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc new file mode 100644 index 0000000..d9c3488 --- /dev/null +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/shown_sections_handler.h" + +#include "base/string_util.h" +#include "base/values.h" +#include "chrome/browser/profile.h" +#include "chrome/common/pref_names.h" + +ShownSectionsHandler::ShownSectionsHandler(DOMUI* dom_ui) + : DOMMessageHandler(dom_ui), + dom_ui_(dom_ui) { + dom_ui->RegisterMessageCallback("getShownSections", + NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); + dom_ui->RegisterMessageCallback("setShownSections", + NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); +} + +void ShownSectionsHandler::HandleGetShownSections(const Value* value) { + const int mode = dom_ui_->GetProfile()->GetPrefs()-> + GetInteger(prefs::kNTPShownSections); + FundamentalValue* mode_value = new FundamentalValue(mode); + dom_ui_->CallJavascriptFunction(L"onShownSections", *mode_value); +} + +void ShownSectionsHandler::HandleSetShownSections(const Value* value) { + if (!value->IsType(Value::TYPE_LIST)) { + NOTREACHED(); + return; + } + + const ListValue* list = static_cast<const ListValue*>(value); + std::string mode_string; + + if (list->GetSize() < 1) { + NOTREACHED() << "setShownSections called with too few arguments"; + return; + } + + bool r = list->GetString(0, &mode_string); + DCHECK(r) << "Missing value in setShownSections from the NTP Most Visited."; + + dom_ui_->GetProfile()->GetPrefs()->SetInteger( + prefs::kNTPShownSections, StringToInt(mode_string)); +} + +// static +void ShownSectionsHandler::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterIntegerPref(prefs::kNTPShownSections, + THUMB | RECENT | RECOMMENDATIONS); +} + diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h new file mode 100644 index 0000000..d70ba1c --- /dev/null +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -0,0 +1,40 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOM_UI_SHOWN_SECTIONS_HANDLER_H_ +#define CHROME_BROWSER_DOM_UI_SHOWN_SECTIONS_HANDLER_H_ + +#include "chrome/browser/dom_ui/dom_ui.h" + +class DOMUI; +class Value; +class PrefService; + +// Use for the shown sections bitmask. +enum Section { + THUMB = 1, + LIST = 2, + RECENT = 4, + RECOMMENDATIONS = 8 +}; + +class ShownSectionsHandler : public DOMMessageHandler { + public: + explicit ShownSectionsHandler(DOMUI* dom_ui); + + // Callback for "getShownSections" message. + void HandleGetShownSections(const Value* value); + + // Callback for "setShownSections" message. + void HandleSetShownSections(const Value* value); + + static void RegisterUserPrefs(PrefService* prefs); + + private: + DOMUI* dom_ui_; + + DISALLOW_COPY_AND_ASSIGN(ShownSectionsHandler); +}; + +#endif // CHROME_BROWSER_DOM_UI_SHOWN_SECTIONS_HANDLER_H_ |