diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-25 23:32:48 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-25 23:32:48 +0000 |
commit | 6a3d3e6c7511c586128b11901310b0475b2b982a (patch) | |
tree | f67617b0098c3fe64d7c9683cae8d1dc9858dfa8 /chrome/browser/dom_ui | |
parent | 8411ad62509db62b1bb5a1e4d4a3488e8c48f037 (diff) | |
download | chromium_src-6a3d3e6c7511c586128b11901310b0475b2b982a.zip chromium_src-6a3d3e6c7511c586128b11901310b0475b2b982a.tar.gz chromium_src-6a3d3e6c7511c586128b11901310b0475b2b982a.tar.bz2 |
Hooks backend tip service into new tab page. Also changes tip service to load tips from popgadget, at http://www.google.com/labs/popgadget/world.
BUG= http://crbug.com/14962
TEST= Enable new tab page. See welcome message. On reload afterwards (and always after that, as long as preferences file isn't removed), see browsing recommendations appear in bottom right corner.
Review URL: http://codereview.chromium.org/147109
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19306 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 82 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.h (renamed from chrome/browser/dom_ui/web_resource_handler.h) | 26 | ||||
-rw-r--r-- | chrome/browser/dom_ui/web_resource_handler.cc | 95 |
6 files changed, 100 insertions, 113 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 9f8b54d..2c4de50 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -23,7 +23,7 @@ #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/dom_ui/tips_handler.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" @@ -1421,7 +1421,7 @@ NewTabUI::NewTabUI(TabContents* contents) } if (EnableWebResources()) - AddMessageHandler(new WebResourceHandler(this)); + AddMessageHandler(new TipsHandler(this)); AddMessageHandler(new TemplateURLHandler(this)); AddMessageHandler(new MostVisitedHandler(this)); @@ -1479,7 +1479,7 @@ void NewTabUI::Observe(NotificationType type, void NewTabUI::RegisterUserPrefs(PrefService* prefs) { MostVisitedHandler::RegisterUserPrefs(prefs); if (NewTabUI::EnableWebResources()) - WebResourceHandler::RegisterUserPrefs(prefs); + TipsHandler::RegisterUserPrefs(prefs); if (NewTabUI::EnableNewNewTabPage()) ShownSectionsHandler::RegisterUserPrefs(prefs); } diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc index d9c3488..22597cb 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.cc +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -49,6 +49,6 @@ void ShownSectionsHandler::HandleSetShownSections(const Value* value) { // static void ShownSectionsHandler::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterIntegerPref(prefs::kNTPShownSections, - THUMB | RECENT | RECOMMENDATIONS); + THUMB | RECENT | TIPS); } diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h index d70ba1c..798a14f 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.h +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -16,7 +16,7 @@ enum Section { THUMB = 1, LIST = 2, RECENT = 4, - RECOMMENDATIONS = 8 + TIPS = 8 }; class ShownSectionsHandler : public DOMMessageHandler { diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc new file mode 100644 index 0000000..3df6d4a --- /dev/null +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -0,0 +1,82 @@ +// 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 "base/string_util.h" +#include "base/values.h" +#include "chrome/browser/dom_ui/tips_handler.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/web_resource/web_resource_service.h" +#include "chrome/common/web_resource/web_resource_unpacker.h" +#include "chrome/common/pref_names.h" + +namespace { + + const int kNumTipsToShow = 2; + + // TODO(mrc): l10n + // This title should only appear the very first time Chrome is run with + // web resources enabled; otherwise the cache should be populated. + static const wchar_t* kTipsTitleAtStartup = + L"Tips and recommendations to help you discover interesting websites."; +} + +TipsHandler::TipsHandler(DOMUI* dom_ui) + : DOMMessageHandler(dom_ui), + dom_ui_(dom_ui) { + dom_ui->RegisterMessageCallback("getTips", + NewCallback(this, &TipsHandler::HandleGetTips)); + + tips_cache_ = dom_ui_->GetProfile()->GetPrefs()-> + GetDictionary(prefs::kNTPTipsCache); +} + +void TipsHandler::HandleGetTips(const Value* content) { + // List containing the tips to be displayed. + ListValue list_value; + + // Holds the web resource data found in the preferences cache. + DictionaryValue* wr_dict; + + // These values hold the data for each web resource item. As the web + // resource server solidifies, these may change. + std::wstring title; + std::wstring thumb; + std::wstring source; + std::wstring snipp; + std::wstring url; + + // This should only be true on the very first Chrome run; otherwise, + // the cache should be populated. + if (tips_cache_ == NULL || tips_cache_->GetSize() < 1) { + title = kTipsTitleAtStartup; + DictionaryValue* tip_dict = new DictionaryValue(); + tip_dict->SetString(WebResourceService::kWebResourceTitle, title); + list_value.Append(tip_dict); + } else { + int tip_counter = 0; + while (tips_cache_->GetDictionary(IntToWString(tip_counter++), &wr_dict)) { + DictionaryValue* tip_dict = new DictionaryValue(); + if (wr_dict && + wr_dict->GetSize() > 0 && + wr_dict->GetString(WebResourceService::kWebResourceTitle, &title) && + wr_dict->GetString(WebResourceService::kWebResourceURL, &url)) { + tip_dict->SetString(WebResourceService::kWebResourceTitle, title); + tip_dict->SetString(WebResourceService::kWebResourceURL, url); + list_value.Append(tip_dict); + } + } + } + + // Send list of web resource items back out to the DOM. + dom_ui_->CallJavascriptFunction(L"tips", list_value); +} + +// static +void TipsHandler::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); + prefs->RegisterStringPref(prefs::kNTPTipsServer, + WebResourceService::kDefaultResourceServer); +} + + diff --git a/chrome/browser/dom_ui/web_resource_handler.h b/chrome/browser/dom_ui/tips_handler.h index 12f2386..a218e09 100644 --- a/chrome/browser/dom_ui/web_resource_handler.h +++ b/chrome/browser/dom_ui/tips_handler.h @@ -6,10 +6,10 @@ // has been stored in the user's preferences file. Used mainly // by the suggestions and tips area of the new tab page. -// Current sketch of tip cache format, hardcoded for poptart data in +// Current sketch of tip cache format, hardcoded for popgadget data in // basic text form: -// "web_resource_cache": { +// "tip_cache": { // "0": { // "index": should become time field (or not) // "snippet": the text of the item @@ -20,8 +20,8 @@ // }, // [up to number of items in kMaxWebResourceCacheSize] -#ifndef CHROME_BROWSER_DOM_UI_WEB_RESOURCE_HANDLER_H_ -#define CHROME_BROWSER_DOM_UI_WEB_RESOURCE_HANDLER_H_ +#ifndef CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ +#define CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ #include "chrome/browser/dom_ui/dom_ui.h" @@ -30,16 +30,16 @@ class DOMUI; class PrefService; class Value; -class WebResourceHandler : public DOMMessageHandler { +class TipsHandler : public DOMMessageHandler { public: - explicit WebResourceHandler(DOMUI* dom_ui); + explicit TipsHandler(DOMUI* dom_ui); - WebResourceHandler(); + TipsHandler(); - // Callback which pulls web resource data from the preferences. - void HandleGetCachedWebResource(const Value* content); + // Callback which pulls tips data from the preferences. + void HandleGetTips(const Value* content); - // Register web resource cache with pref service. + // Register tips cache with pref service. static void RegisterUserPrefs(PrefService* prefs); private: @@ -47,10 +47,10 @@ class WebResourceHandler : public DOMMessageHandler { DOMUI* dom_ui_; // Filled with data from cache in preferences. - const DictionaryValue* web_resource_cache_; + const DictionaryValue* tips_cache_; - DISALLOW_COPY_AND_ASSIGN(WebResourceHandler); + DISALLOW_COPY_AND_ASSIGN(TipsHandler); }; -#endif // CHROME_BROWSER_DOM_UI_WEB_RESOURCE_HANDLER_H_ +#endif // CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ diff --git a/chrome/browser/dom_ui/web_resource_handler.cc b/chrome/browser/dom_ui/web_resource_handler.cc deleted file mode 100644 index 4865187..0000000 --- a/chrome/browser/dom_ui/web_resource_handler.cc +++ /dev/null @@ -1,95 +0,0 @@ -// 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 "base/values.h" -#include "chrome/browser/dom_ui/web_resource_handler.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/web_resource/web_resource_service.h" -#include "chrome/common/web_resource/web_resource_unpacker.h" -#include "chrome/common/pref_names.h" - -namespace { - - const int kNumWebResourcesToShow = 2; - - // TODO(mrc): l10n - // This title should only appear the very first time Chrome is run with - // web resources enabled; otherwise the cache should be populated. - static const wchar_t* kWebResourceTitleAtStartup = - L"New: Suggestion Box!"; - - // This snipp should only appear the very first time Chrome is run with - // web resources enabled; otherwise the cache should be populated. - static const wchar_t* kWebResourceSnippetAtStartup = - L"Tips and recommendations to help you discover interesting websites."; -} - -WebResourceHandler::WebResourceHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui) { - dom_ui->RegisterMessageCallback("getNextCachedWebResource", - NewCallback(this, &WebResourceHandler::HandleGetCachedWebResource)); - - web_resource_cache_ = dom_ui_->GetProfile()->GetPrefs()-> - GetDictionary(prefs::kNTPWebResourceCache); -} - -void WebResourceHandler::HandleGetCachedWebResource(const Value* content) { - // Eventually we will feed more than one web resource datum at a time - // to the NTP; for now, this is a list containing one item: the tip - // to be displayed. - ListValue list_value; - - // Holds the web resource data found in the preferences cache. - DictionaryValue* wr_dict; - - // Dictionary which will be sent back in a Javascript call. - DictionaryValue* tip_dict = new DictionaryValue(); - - // These values hold the data for each web resource item. As the web - // resource server solidifies, these may change. - std::wstring title; - std::wstring thumb; - std::wstring source; - std::wstring snipp; - std::wstring url; - - // This should only be true on the very first Chrome run; otherwise, - // the cache should be populated. - if (web_resource_cache_ == NULL || web_resource_cache_->GetSize() < 1) { - title = kWebResourceTitleAtStartup; - snipp = kWebResourceSnippetAtStartup; - } else { - // Right now, hard-coded to simply get the first item (marked "0") in the - // resource data stored in the cache. Fail silently if data is missing. - // TODO(mrc): If data is missing, iterate through cache. - web_resource_cache_->GetDictionary(L"0", &wr_dict); - if (wr_dict && - wr_dict->GetSize() > 0 && - wr_dict->GetString(WebResourceService::kWebResourceTitle, &title) && - wr_dict->GetString(WebResourceService::kWebResourceThumb, &thumb) && - wr_dict->GetString(WebResourceService::kWebResourceSource, &source) && - wr_dict->GetString(WebResourceService::kWebResourceSnippet, &snipp) && - wr_dict->GetString(WebResourceService::kWebResourceURL, &url)) { - tip_dict->SetString(WebResourceService::kWebResourceTitle, title); - tip_dict->SetString(WebResourceService::kWebResourceThumb, thumb); - tip_dict->SetString(WebResourceService::kWebResourceSource, source); - tip_dict->SetString(WebResourceService::kWebResourceSnippet, snipp); - tip_dict->SetString(WebResourceService::kWebResourceURL, url); - } - } - - list_value.Append(tip_dict); - - // Send list of snippets back out to the DOM. - dom_ui_->CallJavascriptFunction(L"nextWebResource", list_value); -} - -// static -void WebResourceHandler::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterDictionaryPref(prefs::kNTPWebResourceCache); - prefs->RegisterStringPref(prefs::kNTPWebResourceServer, - WebResourceService::kDefaultResourceServer); -} - |