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

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

Issue 1400423002: Adds a new theme.css endpoint for NTP that sets the background of NTP to the current theme backgrou… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 944f29de6e952a3eb0ccdb1a74d24c5de34a0fad..9bef385588032b46589a5b3d316cc0f82bbe2d1e 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -18,6 +18,9 @@
#include "chrome/browser/search/local_files_ntp_source.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/themes/theme_service.h"
+#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
@@ -26,6 +29,7 @@
#include "grit/browser_resources.h"
#include "grit/theme_resources.h"
#include "net/url_request/url_request.h"
+#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
@@ -40,6 +44,7 @@ namespace {
const int kLocalResource = -1;
const char kConfigDataFilename[] = "config.js";
+const char kThemeCSSFilename[] = "theme.css";
const struct Resource{
const char* filename;
@@ -49,6 +54,7 @@ const struct Resource{
{ "local-ntp.html", IDR_LOCAL_NTP_HTML, "text/html" },
{ "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" },
{ kConfigDataFilename, kLocalResource, "application/javascript" },
+ { kThemeCSSFilename, kLocalResource, "text/css" },
{ "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" },
{ "images/close_2.png", IDR_CLOSE_2, "image/png" },
{ "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" },
@@ -157,6 +163,17 @@ std::string GetConfigData(Profile* profile) {
return config_data_js;
}
+std::string GetThemeCSS(Profile* profile) {
+ ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
+ SkColor background_color =
+ theme_service->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND);
+
+ return base::StringPrintf("body { background-color: #%02X%02X%02X; }",
+ SkColorGetR(background_color),
Mathieu 2015/10/14 20:53:03 can you run "git cl format" I'm thinking the inden
fserb 2015/10/20 18:48:16 Done.
+ SkColorGetG(background_color),
+ SkColorGetB(background_color));
+}
+
std::string GetLocalNtpPath() {
return std::string(chrome::kChromeSearchScheme) + "://" +
std::string(chrome::kChromeSearchLocalNtpHost) + "/";
@@ -185,6 +202,11 @@ void LocalNtpSource::StartDataRequest(
callback.Run(base::RefCountedString::TakeString(&config_data_js));
return;
}
+ if (stripped_path == kThemeCSSFilename) {
+ std::string theme_css = GetThemeCSS(profile_);
+ callback.Run(base::RefCountedString::TakeString(&theme_css));
+ return;
+ }
#if !defined(GOOGLE_CHROME_BUILD)
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();

Powered by Google App Engine
This is Rietveld 408576698