Commit 2b8290de authored by mathp@chromium.org's avatar mathp@chromium.org

[New Tab Page] Add Field Trial support to the Local NTP

This will allow development of the new design in parallel with the current implementation. The plan is to put new styles in local-ntp.css, which will be selected according to the class of the containing div.

This CL also adds a command-line flag, which will be tied to the Field trial from the server.

BUG=399388
TEST=using force-fieldtrials, confirmed that it works.

Review URL: https://codereview.chromium.org/435723002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287131 0039d316-1c4b-4281-b951-d872f2087c98
parent 38703dd7
...@@ -6228,6 +6228,12 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -6228,6 +6228,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_ENABLE_SYNC_APP_LIST_DESCRIPTION" desc="Description for the flag to enable syncing the app list."> <message name="IDS_FLAGS_ENABLE_SYNC_APP_LIST_DESCRIPTION" desc="Description for the flag to enable syncing the app list.">
Enable App Launcher sync. This also enables Folders where available (non OSX). Enable App Launcher sync. This also enables Folders where available (non OSX).
</message> </message>
<message name="IDS_FLAGS_ENABLE_MATERIAL_DESIGN_NTP_NAME" desc="Name of the flag to enable the Material Design New Tab Page (NTP).">
Enable Material Design NTP.
</message>
<message name="IDS_FLAGS_ENABLE_MATERIAL_DESIGN_NTP_DESCRIPTION" desc="Description for the flag to enable the Material Design New Tab Page (NTP).">
Enable the Material Design New Tab Page.
</message>
<if expr="is_macosx"> <if expr="is_macosx">
<message name="IDS_FLAGS_ENABLE_AVFOUNDATION_NAME" desc="Name of the flag to enable Mac AVFoundation."> <message name="IDS_FLAGS_ENABLE_AVFOUNDATION_NAME" desc="Name of the flag to enable Mac AVFoundation.">
Enable use of Mac OS X AVFoundation APIs, instead of QTKit. Enable use of Mac OS X AVFoundation APIs, instead of QTKit.
......
...@@ -893,6 +893,14 @@ const Experiment kExperiments[] = { ...@@ -893,6 +893,14 @@ const Experiment kExperiments[] = {
kOsDesktop, kOsDesktop,
SINGLE_VALUE_TYPE(switches::kDisableNTPOtherSessionsMenu) SINGLE_VALUE_TYPE(switches::kDisableNTPOtherSessionsMenu)
}, },
{
"enable-material-design-ntp",
IDS_FLAGS_ENABLE_MATERIAL_DESIGN_NTP_NAME,
IDS_FLAGS_ENABLE_MATERIAL_DESIGN_NTP_DESCRIPTION,
kOsDesktop,
ENABLE_DISABLE_VALUE_TYPE(switches::kEnableMaterialDesignNTP,
switches::kDisableMaterialDesignNTP)
},
{ {
"enable-devtools-experiments", "enable-devtools-experiments",
IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_NAME, IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_NAME,
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<meta name="google" value="notranslate"> <meta name="google" value="notranslate">
</head> </head>
<body> <body>
<div id="ntp-contents"> <div id="ntp-contents" class="{{CLASS}}">
<div id="most-visited"> <div id="most-visited">
<div id="mv-tiles"></div> <div id="mv-tiles"></div>
<!-- Notification shown when a tile is blacklisted. --> <!-- Notification shown when a tile is blacklisted. -->
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
...@@ -30,17 +31,25 @@ ...@@ -30,17 +31,25 @@
namespace { 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/. // Signifies a locally constructed resource, i.e. not from grit/.
const int kLocalResource = -1; const int kLocalResource = -1;
const char kConfigDataFilename[] = "config.js"; const char kConfigDataFilename[] = "config.js";
const char kLocalNTPFilename[] = "local-ntp.html";
const struct Resource{ const struct Resource{
const char* filename; const char* filename;
int identifier; int identifier;
const char* mime_type; const char* mime_type;
} kResources[] = { } 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" }, { "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" },
{ "local-ntp-util.js", IDR_LOCAL_NTP_UTIL_JS, "application/javascript" }, { "local-ntp-util.js", IDR_LOCAL_NTP_UTIL_JS, "application/javascript" },
{ kConfigDataFilename, kLocalResource, "application/javascript" }, { kConfigDataFilename, kLocalResource, "application/javascript" },
...@@ -76,6 +85,14 @@ bool DefaultSearchProviderIsGoogle(Profile* profile) { ...@@ -76,6 +85,14 @@ bool DefaultSearchProviderIsGoogle(Profile* profile) {
SEARCH_ENGINE_GOOGLE); 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. // Adds a localized string keyed by resource id to the dictionary.
void AddString(base::DictionaryValue* dictionary, void AddString(base::DictionaryValue* dictionary,
const std::string& key, const std::string& key,
...@@ -151,6 +168,13 @@ void LocalNtpSource::StartDataRequest( ...@@ -151,6 +168,13 @@ void LocalNtpSource::StartDataRequest(
callback.Run(base::RefCountedString::TakeString(&config_data_js)); callback.Run(base::RefCountedString::TakeString(&config_data_js));
return; return;
} }
if (stripped_path == kLocalNTPFilename) {
SendResourceWithClass(
IDR_LOCAL_NTP_HTML,
IsMaterialDesignEnabled() ? kMaterialDesignNTPClassName : "",
callback);
return;
}
float scale = 1.0f; float scale = 1.0f;
std::string filename; std::string filename;
webui::ParsePathAndScale( webui::ParsePathAndScale(
...@@ -200,3 +224,14 @@ std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { ...@@ -200,3 +224,14 @@ std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const {
return base::StringPrintf("frame-src %s;", return base::StringPrintf("frame-src %s;",
chrome::kChromeSearchMostVisitedUrl); 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));
}
...@@ -32,6 +32,12 @@ class LocalNtpSource : public content::URLDataSource { ...@@ -32,6 +32,12 @@ class LocalNtpSource : public content::URLDataSource {
const net::URLRequest* request) const OVERRIDE; const net::URLRequest* request) const OVERRIDE;
virtual std::string GetContentSecurityPolicyFrameSrc() const OVERRIDE; virtual std::string GetContentSecurityPolicyFrameSrc() const OVERRIDE;
// Sends a local resource with a specific |class_name| substituted.
void SendResourceWithClass(
int resource_id,
const std::string& class_name,
const content::URLDataSource::GotDataCallback& callback);
Profile* profile_; Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(LocalNtpSource); DISALLOW_COPY_AND_ASSIGN(LocalNtpSource);
......
...@@ -274,6 +274,9 @@ const char kDisableMinimizeOnSecondLauncherItemClick[] = ...@@ -274,6 +274,9 @@ const char kDisableMinimizeOnSecondLauncherItemClick[] =
// Disables the menu on the NTP for accessing sessions from other devices. // Disables the menu on the NTP for accessing sessions from other devices.
const char kDisableNTPOtherSessionsMenu[] = "disable-ntp-other-sessions-menu"; const char kDisableNTPOtherSessionsMenu[] = "disable-ntp-other-sessions-menu";
// Disables the Material Design NTP.
const char kDisableMaterialDesignNTP[] = "disable-material-design-ntp";
// Disable auto-reload of error pages if offline. // Disable auto-reload of error pages if offline.
const char kDisableOfflineAutoReload[] = "disable-offline-auto-reload"; const char kDisableOfflineAutoReload[] = "disable-offline-auto-reload";
...@@ -482,6 +485,9 @@ const char kEnableNaCl[] = "enable-nacl"; ...@@ -482,6 +485,9 @@ const char kEnableNaCl[] = "enable-nacl";
// Enables the network-related benchmarking extensions. // Enables the network-related benchmarking extensions.
const char kEnableNetBenchmarking[] = "enable-net-benchmarking"; const char kEnableNetBenchmarking[] = "enable-net-benchmarking";
// Enables the Material Design NTP.
const char kEnableMaterialDesignNTP[] = "enable-material-design-ntp";
// Enables NPN with HTTP. It means NPN is enabled but SPDY won't be used. // Enables NPN with HTTP. It means NPN is enabled but SPDY won't be used.
// HTTP is still used for all requests. // HTTP is still used for all requests.
const char kEnableNpnHttpOnly[] = "enable-npn-http"; const char kEnableNpnHttpOnly[] = "enable-npn-http";
......
...@@ -86,6 +86,7 @@ extern const char kDisableExtensionsHttpThrottling[]; ...@@ -86,6 +86,7 @@ extern const char kDisableExtensionsHttpThrottling[];
extern const char kDisableExtensions[]; extern const char kDisableExtensions[];
extern const char kDisableIPv6[]; extern const char kDisableIPv6[];
extern const char kDisableMinimizeOnSecondLauncherItemClick[]; extern const char kDisableMinimizeOnSecondLauncherItemClick[];
extern const char kDisableMaterialDesignNTP[];
extern const char kDisableNTPOtherSessionsMenu[]; extern const char kDisableNTPOtherSessionsMenu[];
extern const char kDisableOfflineAutoReload[]; extern const char kDisableOfflineAutoReload[];
extern const char kDisableOfflineAutoReloadVisibleOnly[]; extern const char kDisableOfflineAutoReloadVisibleOnly[];
...@@ -145,6 +146,7 @@ extern const char kEnableIPv6[]; ...@@ -145,6 +146,7 @@ extern const char kEnableIPv6[];
extern const char kEnableLinkableEphemeralApps[]; extern const char kEnableLinkableEphemeralApps[];
extern const char kEnableNaCl[]; extern const char kEnableNaCl[];
extern const char kEnableNetBenchmarking[]; extern const char kEnableNetBenchmarking[];
extern const char kEnableMaterialDesignNTP[];
extern const char kEnableNpnHttpOnly[]; extern const char kEnableNpnHttpOnly[];
extern const char kEnableOfflineAutoReload[]; extern const char kEnableOfflineAutoReload[];
extern const char kEnableOfflineAutoReloadVisibleOnly[]; extern const char kEnableOfflineAutoReloadVisibleOnly[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment