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

Side by Side Diff: chrome/browser/dom_ui/dom_ui_theme_source.cc

Issue 164002: Apply theme to incognito NTP.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.h ('k') | chrome/browser/dom_ui/new_tab_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/dom_ui/dom_ui_theme_source.h" 5 #include "chrome/browser/dom_ui/dom_ui_theme_source.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/theme_provider.h" 9 #include "app/theme_provider.h"
10 #include "base/gfx/png_encoder.h" 10 #include "base/gfx/png_encoder.h"
(...skipping 10 matching lines...) Expand all
21 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
23 23
24 #if defined(OS_WIN) 24 #if defined(OS_WIN)
25 #include "chrome/browser/views/bookmark_bar_view.h" 25 #include "chrome/browser/views/bookmark_bar_view.h"
26 #endif 26 #endif
27 27
28 // Path for the New Tab CSS. When we get more than a few of these, we should 28 // Path for the New Tab CSS. When we get more than a few of these, we should
29 // use a resource map rather than hard-coded strings. 29 // use a resource map rather than hard-coded strings.
30 static const char* kNewTabCSSPath = "css/newtab.css"; 30 static const char* kNewTabCSSPath = "css/newtab.css";
31 static const char* kNewIncognitoTabCSSPath = "css/newincognitotab.css";
31 32
32 static string16 SkColorToRGBAString(SkColor color) { 33 static string16 SkColorToRGBAString(SkColor color) {
33 return WideToUTF16(l10n_util::GetStringF(IDS_RGBA_CSS_FORMAT_STRING, 34 return WideToUTF16(l10n_util::GetStringF(IDS_RGBA_CSS_FORMAT_STRING,
34 IntToWString(SkColorGetR(color)), 35 IntToWString(SkColorGetR(color)),
35 IntToWString(SkColorGetG(color)), 36 IntToWString(SkColorGetG(color)),
36 IntToWString(SkColorGetB(color)), 37 IntToWString(SkColorGetB(color)),
37 DoubleToWString(SkColorGetA(color) / 255.0))); 38 DoubleToWString(SkColorGetA(color) / 255.0)));
38 } 39 }
39 40
40 static std::string StripQueryParams(const std::string& path) { 41 static std::string StripQueryParams(const std::string& path) {
(...skipping 11 matching lines...) Expand all
52 } 53 }
53 54
54 void DOMUIThemeSource::StartDataRequest(const std::string& path, 55 void DOMUIThemeSource::StartDataRequest(const std::string& path,
55 int request_id) { 56 int request_id) {
56 // Our path may include cachebuster arguments, so trim them off. 57 // Our path may include cachebuster arguments, so trim them off.
57 std::string uncached_path = StripQueryParams(path); 58 std::string uncached_path = StripQueryParams(path);
58 59
59 if (strcmp(uncached_path.c_str(), kNewTabCSSPath) == 0) { 60 if (strcmp(uncached_path.c_str(), kNewTabCSSPath) == 0) {
60 SendNewTabCSS(request_id); 61 SendNewTabCSS(request_id);
61 return; 62 return;
63 } else if (strcmp(uncached_path.c_str(), kNewIncognitoTabCSSPath) == 0) {
64 SendNewIncognitoTabCSS(request_id);
65 return;
62 } else { 66 } else {
63 int resource_id = ThemeResourcesUtil::GetId(uncached_path); 67 int resource_id = ThemeResourcesUtil::GetId(uncached_path);
64 if (resource_id != -1) { 68 if (resource_id != -1) {
65 SendThemeBitmap(request_id, resource_id); 69 SendThemeBitmap(request_id, resource_id);
66 return; 70 return;
67 } 71 }
68 } 72 }
69 // We don't have any data to send back. 73 // We don't have any data to send back.
70 SendResponse(request_id, NULL); 74 SendResponse(request_id, NULL);
71 } 75 }
72 76
73 std::string DOMUIThemeSource::GetMimeType(const std::string& path) const { 77 std::string DOMUIThemeSource::GetMimeType(const std::string& path) const {
74 std::string uncached_path = StripQueryParams(path); 78 std::string uncached_path = StripQueryParams(path);
75 79
76 if (strcmp(uncached_path.c_str(), kNewTabCSSPath) == 0) 80 if (strcmp(uncached_path.c_str(), kNewTabCSSPath) == 0 ||
81 strcmp(uncached_path.c_str(), kNewIncognitoTabCSSPath) == 0)
77 return "text/css"; 82 return "text/css";
78 return "image/png"; 83 return "image/png";
79 } 84 }
80 85
81 void DOMUIThemeSource::SendResponse(int request_id, RefCountedBytes* data) { 86 void DOMUIThemeSource::SendResponse(int request_id, RefCountedBytes* data) {
82 ChromeURLDataManager::DataSource::SendResponse(request_id, data); 87 ChromeURLDataManager::DataSource::SendResponse(request_id, data);
83 } 88 }
84 89
85 //////////////////////////////////////////////////////////////////////////////// 90 ////////////////////////////////////////////////////////////////////////////////
86 // DOMUIThemeSource, private: 91 // DOMUIThemeSource, private:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 150
146 // Convert to a format appropriate for sending. 151 // Convert to a format appropriate for sending.
147 scoped_refptr<RefCountedBytes> css_bytes(new RefCountedBytes); 152 scoped_refptr<RefCountedBytes> css_bytes(new RefCountedBytes);
148 css_bytes->data.resize(css_string2.size()); 153 css_bytes->data.resize(css_string2.size());
149 std::copy(css_string2.begin(), css_string2.end(), css_bytes->data.begin()); 154 std::copy(css_string2.begin(), css_string2.end(), css_bytes->data.begin());
150 155
151 // Send. 156 // Send.
152 SendResponse(request_id, css_bytes); 157 SendResponse(request_id, css_bytes);
153 } 158 }
154 159
160 void DOMUIThemeSource::SendNewIncognitoTabCSS(int request_id) {
161 ThemeProvider* tp = profile_->GetThemeProvider();
162 DCHECK(tp);
163
164 // Get our theme colors
165 SkColor color_background =
166 tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND);
167
168 // Generate the replacements.
169 std::vector<string16> subst;
170
171 // Cache-buster for background.
172 subst.push_back(WideToUTF16(
173 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID))); // $1
174
175 // Colors.
176 subst.push_back(SkColorToRGBAString(color_background)); // $2
177 subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(false))); // $3
178 subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(true))); // $4
179 subst.push_back(UTF8ToUTF16(GetNewTabBackgroundTilingCSS())); // $5
180
181 // Get our template.
182 static const StringPiece new_tab_theme_css(
183 ResourceBundle::GetSharedInstance().GetRawDataResource(
184 IDR_NEW_INCOGNITO_TAB_THEME_CSS));
185
186 // Create the string from our template and the replacements.
187 string16 format_string = ASCIIToUTF16(new_tab_theme_css.as_string());
188 const std::string css_string = UTF16ToASCII(ReplaceStringPlaceholders(
189 format_string, subst, NULL));
190
191 // Convert to a format appropriate for sending.
192 scoped_refptr<RefCountedBytes> css_bytes(new RefCountedBytes);
193 css_bytes->data.resize(css_string.size());
194 std::copy(css_string.begin(), css_string.end(), css_bytes->data.begin());
195
196 // Send.
197 SendResponse(request_id, css_bytes);
198 }
199
155 void DOMUIThemeSource::SendThemeBitmap(int request_id, int resource_id) { 200 void DOMUIThemeSource::SendThemeBitmap(int request_id, int resource_id) {
156 ThemeProvider* tp = profile_->GetThemeProvider(); 201 ThemeProvider* tp = profile_->GetThemeProvider();
157 DCHECK(tp); 202 DCHECK(tp);
158 203
159 std::vector<unsigned char> png_bytes; 204 std::vector<unsigned char> png_bytes;
160 if (tp->GetRawData(resource_id, &png_bytes)) { 205 if (tp->GetRawData(resource_id, &png_bytes)) {
161 scoped_refptr<RefCountedBytes> image_data = 206 scoped_refptr<RefCountedBytes> image_data =
162 new RefCountedBytes(png_bytes); 207 new RefCountedBytes(png_bytes);
163 SendResponse(request_id, image_data); 208 SendResponse(request_id, image_data);
164 } else { 209 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return BrowserThemeProvider::AlignmentToString(alignment); 245 return BrowserThemeProvider::AlignmentToString(alignment);
201 } 246 }
202 247
203 std::string DOMUIThemeSource::GetNewTabBackgroundTilingCSS() { 248 std::string DOMUIThemeSource::GetNewTabBackgroundTilingCSS() {
204 int repeat_mode; 249 int repeat_mode;
205 profile_->GetThemeProvider()->GetDisplayProperty( 250 profile_->GetThemeProvider()->GetDisplayProperty(
206 BrowserThemeProvider::NTP_BACKGROUND_TILING, &repeat_mode); 251 BrowserThemeProvider::NTP_BACKGROUND_TILING, &repeat_mode);
207 return BrowserThemeProvider::TilingToString(repeat_mode); 252 return BrowserThemeProvider::TilingToString(repeat_mode);
208 } 253 }
209 254
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.h ('k') | chrome/browser/dom_ui/new_tab_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698