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

Unified Diff: chrome/browser/search/local_ntp_source.cc

Issue 435723002: [New Tab Page] Add Field Trial support to the Local NTP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « chrome/browser/search/local_ntp_source.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/local_ntp_source.cc
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc
index bcda9f437e71d5f5b2fdb3b2b7e4f7cbd13daf4a..975bf3bbe62fad3cfa2ef3b0e7c4ce99af18faa5 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
@@ -30,17 +31,25 @@
namespace {
+// Constants related to the Material Design NTP field trial.
+const char kMaterialDesignNTPFieldTrialName[] = "MaterialDesignNTP";
+const char kMaterialDesignNTPFieldTrialEnabledPrefix[] = "Enabled";
+
+// Class name to be used for the new design in local resources.
+const char kMaterialDesignNTPClassName[] = "md";
+
// Signifies a locally constructed resource, i.e. not from grit/.
const int kLocalResource = -1;
const char kConfigDataFilename[] = "config.js";
+const char kLocalNTPFilename[] = "local-ntp.html";
const struct Resource{
const char* filename;
int identifier;
const char* mime_type;
} kResources[] = {
- { "local-ntp.html", IDR_LOCAL_NTP_HTML, "text/html" },
+ { kLocalNTPFilename, IDR_LOCAL_NTP_HTML, "text/html" },
{ "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" },
{ kConfigDataFilename, kLocalResource, "application/javascript" },
{ "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" },
@@ -75,6 +84,14 @@ bool DefaultSearchProviderIsGoogle(Profile* profile) {
SEARCH_ENGINE_GOOGLE);
}
+// Returns whether the user is part of a group where the Material Design NTP is
+// enabled.
+bool IsMaterialDesignEnabled() {
+ return StartsWithASCII(
+ base::FieldTrialList::FindFullName(kMaterialDesignNTPFieldTrialName),
+ kMaterialDesignNTPFieldTrialEnabledPrefix, true);
+}
+
// Adds a localized string keyed by resource id to the dictionary.
void AddString(base::DictionaryValue* dictionary,
const std::string& key,
@@ -150,6 +167,13 @@ void LocalNtpSource::StartDataRequest(
callback.Run(base::RefCountedString::TakeString(&config_data_js));
return;
}
+ if (stripped_path == kLocalNTPFilename) {
+ SendResourceWithClass(
+ IDR_LOCAL_NTP_HTML,
+ IsMaterialDesignEnabled() ? kMaterialDesignNTPClassName : "",
+ callback);
+ return;
+ }
float scale = 1.0f;
std::string filename;
webui::ParsePathAndScale(
@@ -199,3 +223,14 @@ std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const {
return base::StringPrintf("frame-src %s;",
chrome::kChromeSearchMostVisitedUrl);
}
+
+void LocalNtpSource::SendResourceWithClass(
+ int resource_id,
+ const std::string& class_name,
+ const content::URLDataSource::GotDataCallback& callback) {
+ base::StringPiece resource_data =
+ ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
+ std::string response(resource_data.as_string());
+ ReplaceFirstSubstringAfterOffset(&response, 0, "{{CLASS}}", class_name);
+ callback.Run(base::RefCountedString::TakeString(&response));
+}
« no previous file with comments | « chrome/browser/search/local_ntp_source.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698