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

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
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..7f3f920f281b8b1060475aef58b4e1faf53f49f3 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 new NTP design field trial.
+const char kNewNTPDesignFieldTrialName[] = "NewNTPDesign";
+const char kNewNTPDesignFieldTrialEnabledPrefix[] = "Enabled";
+
+// Class name to be used for the new design in local resources.
+const char kNewNTPDesignClassName[] = "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 new NTP design is
+// enabled.
+bool IsNewDesignEnabled() {
+ return StartsWithASCII(
+ base::FieldTrialList::FindFullName(kNewNTPDesignFieldTrialName),
+ kNewNTPDesignFieldTrialEnabledPrefix, true);
+}
+
// Adds a localized string keyed by resource id to the dictionary.
void AddString(base::DictionaryValue* dictionary,
const std::string& key,
@@ -150,6 +167,12 @@ void LocalNtpSource::StartDataRequest(
callback.Run(base::RefCountedString::TakeString(&config_data_js));
return;
}
+ if (stripped_path == kLocalNTPFilename) {
+ SendResourceWithClass(
+ IDR_LOCAL_NTP_HTML, IsNewDesignEnabled() ? kNewNTPDesignClassName : "",
+ callback);
+ return;
+ }
float scale = 1.0f;
std::string filename;
webui::ParsePathAndScale(
@@ -199,3 +222,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));
+}

Powered by Google App Engine
This is Rietveld 408576698