Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1443)

Unified Diff: chrome/browser/ui/webui/ntp/new_tab_ui.cc

Issue 9358031: Added new adaptive "Suggest" tab on the New Tab Page, behing the flag, for the experiments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed bug in card_slider.js which prevented correct card be selected in dome cases Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/new_tab_ui.cc
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
index fe80f87cd8011e89ddd40a72a1eb23d945fdd3fc..ebe71fee041c9b2547ffe9c5d4fd1d0799d5b113 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
@@ -38,6 +38,7 @@
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
#include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
+#include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
#include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
@@ -50,6 +51,7 @@
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
+#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -108,6 +110,8 @@ NewTabUI::NewTabUI(content::WebUI* web_ui)
if (!GetProfile()->IsOffTheRecord()) {
web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
web_ui->AddMessageHandler(new MostVisitedHandler());
+ if (NewTabUI::IsSuggestionsPageEnabled())
+ web_ui->AddMessageHandler(new SuggestionsHandler());
web_ui->AddMessageHandler(new RecentlyClosedTabsHandler());
web_ui->AddMessageHandler(new MetricsHandler());
if (GetProfile()->IsSyncAccessible())
@@ -132,6 +136,13 @@ NewTabUI::NewTabUI(content::WebUI* web_ui)
NewTabHTMLSource* html_source =
new NewTabHTMLSource(GetProfile()->GetOriginalProfile());
GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source);
+ // These two resources should be loaded only if suggestions NTP is enabled.
+ html_source->AddResource("suggestions_page.css", "text/css",
+ NewTabUI::IsSuggestionsPageEnabled() ? IDR_SUGGESTIONS_PAGE_CSS : 0);
+ if (NewTabUI::IsSuggestionsPageEnabled()) {
+ html_source->AddResource("suggestions_page.js", "text/javascript",
Dan Beam 2012/02/28 20:14:24 nit: should this be application/javascript? if yo
GeorgeY 2012/02/28 21:17:42 sure
+ IDR_SUGGESTIONS_PAGE_JS);
+ }
// Listen for theme installation.
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
@@ -227,6 +238,8 @@ void NewTabUI::RegisterUserPrefs(PrefService* prefs) {
NewTabPageHandler::RegisterUserPrefs(prefs);
AppLauncherHandler::RegisterUserPrefs(prefs);
MostVisitedHandler::RegisterUserPrefs(prefs);
+ if (NewTabUI::IsSuggestionsPageEnabled())
+ SuggestionsHandler::RegisterUserPrefs(prefs);
}
// static
@@ -260,6 +273,12 @@ bool NewTabUI::ShouldShowAppInstallHint() {
}
// static
+bool NewTabUI::IsSuggestionsPageEnabled() {
+ return CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSuggestionsTabPage);
+}
+
+// static
void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary,
const string16& title,
const GURL& gurl) {
@@ -319,6 +338,18 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path,
int request_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ std::map<std::string, std::pair<std::string, int> >::iterator it =
+ resource_map_.find(path);
+ if (it != resource_map_.end()) {
+ scoped_refptr<RefCountedStaticMemory> resource_bytes(
Dan Beam 2012/02/28 20:14:24 nit: indent is weird
GeorgeY 2012/02/28 21:17:42 Four spaces - what is the problem?
Dan Beam 2012/02/28 22:30:12 It's fine.
+ it->second.second ?
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
+ it->second.second) :
+ new RefCountedStaticMemory);
+ SendResponse(request_id, resource_bytes);
+ return;
+ }
+
if (!path.empty() && path[0] != '#') {
// A path under new-tab was requested; it's likely a bad relative
// URL from the new tab page, but in any case it's an error.
@@ -333,10 +364,24 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path,
SendResponse(request_id, html_bytes);
}
-std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const {
+std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& s)
Dan Beam 2012/02/28 20:14:24 can you rename |s| to something more descriptive?
GeorgeY 2012/02/28 21:17:42 Done.
+ const {
+ std::map<std::string, std::pair<std::string, int> >::const_iterator it =
+ resource_map_.find(s);
+ if (it != resource_map_.end())
+ return it->second.first;
return "text/html";
}
bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
return false;
}
+
+void NewTabUI::NewTabHTMLSource::AddResource(const char* resource,
+ const char* mime_type,
+ int resource_id) {
+ DCHECK(resource);
+ DCHECK(mime_type);
+ resource_map_[std::string(resource)] =
+ std::make_pair(std::string(mime_type), resource_id);
+}

Powered by Google App Engine
This is Rietveld 408576698