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

Side by Side Diff: chrome/browser/search/local_ntp_source.cc

Issue 473583002: [Local NTP] Implementing Material Design styling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing Roboto; fixing theme compatibility; using .mv-mask for borders. Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/search/local_ntp_source.h" 5 #include "chrome/browser/search/local_ntp_source.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 #include "ui/base/webui/jstemplate_builder.h" 29 #include "ui/base/webui/jstemplate_builder.h"
30 #include "ui/base/webui/web_ui_util.h" 30 #include "ui/base/webui/web_ui_util.h"
31 #include "url/gurl.h" 31 #include "url/gurl.h"
32 32
33 namespace { 33 namespace {
34 34
35 // Constants related to the Material Design NTP field trial. 35 // Constants related to the Material Design NTP field trial.
36 const char kMaterialDesignNTPFieldTrialName[] = "MaterialDesignNTP"; 36 const char kMaterialDesignNTPFieldTrialName[] = "MaterialDesignNTP";
37 const char kMaterialDesignNTPFieldTrialEnabledPrefix[] = "Enabled"; 37 const char kMaterialDesignNTPFieldTrialEnabledPrefix[] = "Enabled";
38 38
39 // Name to be used for the new design in local resources. 39 // Name to be used for the new design in local resources.
Mathieu 2014/08/14 15:05:39 update comment
huangs 2014/08/14 15:50:21 Done.
40 const char kClassicalNTPName[] = "classical";
40 const char kMaterialDesignNTPName[] = "md"; 41 const char kMaterialDesignNTPName[] = "md";
41 42
42 // Signifies a locally constructed resource, i.e. not from grit/. 43 // Signifies a locally constructed resource, i.e. not from grit/.
43 const int kLocalResource = -1; 44 const int kLocalResource = -1;
44 45
45 const char kConfigDataFilename[] = "config.js"; 46 const char kConfigDataFilename[] = "config.js";
46 const char kLocalNTPFilename[] = "local-ntp.html"; 47 const char kLocalNTPFilename[] = "local-ntp.html";
47 48
48 const struct Resource{ 49 const struct Resource{
49 const char* filename; 50 const char* filename;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 const content::URLDataSource::GotDataCallback& callback) { 182 const content::URLDataSource::GotDataCallback& callback) {
182 const std::string stripped_path = StripParameters(path); 183 const std::string stripped_path = StripParameters(path);
183 if (stripped_path == kConfigDataFilename) { 184 if (stripped_path == kConfigDataFilename) {
184 std::string config_data_js = GetConfigData(profile_); 185 std::string config_data_js = GetConfigData(profile_);
185 callback.Run(base::RefCountedString::TakeString(&config_data_js)); 186 callback.Run(base::RefCountedString::TakeString(&config_data_js));
186 return; 187 return;
187 } 188 }
188 if (stripped_path == kLocalNTPFilename) { 189 if (stripped_path == kLocalNTPFilename) {
189 SendResourceWithClass( 190 SendResourceWithClass(
190 IDR_LOCAL_NTP_HTML, 191 IDR_LOCAL_NTP_HTML,
191 IsMaterialDesignEnabled() ? kMaterialDesignNTPName : "", 192 IsMaterialDesignEnabled() ? kMaterialDesignNTPName : kClassicalNTPName,
192 callback); 193 callback);
193 return; 194 return;
194 } 195 }
195 float scale = 1.0f; 196 float scale = 1.0f;
196 std::string filename; 197 std::string filename;
197 webui::ParsePathAndScale( 198 webui::ParsePathAndScale(
198 GURL(GetLocalNtpPath() + stripped_path), &filename, &scale); 199 GURL(GetLocalNtpPath() + stripped_path), &filename, &scale);
199 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); 200 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale);
200 for (size_t i = 0; i < arraysize(kResources); ++i) { 201 for (size_t i = 0; i < arraysize(kResources); ++i) {
201 if (filename == kResources[i].filename) { 202 if (filename == kResources[i].filename) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void LocalNtpSource::SendResourceWithClass( 246 void LocalNtpSource::SendResourceWithClass(
246 int resource_id, 247 int resource_id,
247 const std::string& class_name, 248 const std::string& class_name,
248 const content::URLDataSource::GotDataCallback& callback) { 249 const content::URLDataSource::GotDataCallback& callback) {
249 base::StringPiece resource_data = 250 base::StringPiece resource_data =
250 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); 251 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
251 std::string response(resource_data.as_string()); 252 std::string response(resource_data.as_string());
252 ReplaceFirstSubstringAfterOffset(&response, 0, "{{CLASS}}", class_name); 253 ReplaceFirstSubstringAfterOffset(&response, 0, "{{CLASS}}", class_name);
253 callback.Run(base::RefCountedString::TakeString(&response)); 254 callback.Run(base::RefCountedString::TakeString(&response));
254 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698