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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache.cc

Issue 1440113002: [MD] Change appearance of incognito NTP to MD spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/ntp/ntp_resource_cache.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if (should_show_apps_page != should_show_apps_page_) { 220 if (should_show_apps_page != should_show_apps_page_) {
221 should_show_apps_page_ = should_show_apps_page; 221 should_show_apps_page_ = should_show_apps_page;
222 return true; 222 return true;
223 } 223 }
224 return false; 224 return false;
225 } 225 }
226 226
227 NTPResourceCache::WindowType NTPResourceCache::GetWindowType( 227 NTPResourceCache::WindowType NTPResourceCache::GetWindowType(
228 Profile* profile, content::RenderProcessHost* render_host) { 228 Profile* profile, content::RenderProcessHost* render_host) {
229 if (profile->IsGuestSession()) { 229 if (profile->IsGuestSession()) {
230 return NTPResourceCache::GUEST; 230 return GUEST;
231 } else if (render_host) { 231 } else if (render_host) {
232 // Sometimes the |profile| is the parent (non-incognito) version of the user 232 // Sometimes the |profile| is the parent (non-incognito) version of the user
233 // so we check the |render_host| if it is provided. 233 // so we check the |render_host| if it is provided.
234 if (render_host->GetBrowserContext()->IsOffTheRecord()) 234 if (render_host->GetBrowserContext()->IsOffTheRecord())
235 return NTPResourceCache::INCOGNITO; 235 return INCOGNITO;
236 } else if (profile->IsOffTheRecord()) { 236 } else if (profile->IsOffTheRecord()) {
237 return NTPResourceCache::INCOGNITO; 237 return INCOGNITO;
238 } 238 }
239 return NTPResourceCache::NORMAL; 239 return NORMAL;
240 } 240 }
241 241
242 base::RefCountedMemory* NTPResourceCache::GetNewTabHTML(WindowType win_type) { 242 base::RefCountedMemory* NTPResourceCache::GetNewTabHTML(WindowType win_type) {
243 DCHECK_CURRENTLY_ON(BrowserThread::UI); 243 DCHECK_CURRENTLY_ON(BrowserThread::UI);
244 if (win_type == GUEST) { 244 if (win_type == GUEST) {
245 if (!new_tab_guest_html_.get()) 245 if (!new_tab_guest_html_)
246 CreateNewTabGuestHTML(); 246 CreateNewTabGuestHTML();
247 return new_tab_guest_html_.get(); 247 return new_tab_guest_html_.get();
248 } else if (win_type == INCOGNITO) { 248 } else if (win_type == INCOGNITO) {
249 if (!new_tab_incognito_html_.get()) 249 if (!new_tab_incognito_html_)
250 CreateNewTabIncognitoHTML(); 250 CreateNewTabIncognitoHTML();
251 return new_tab_incognito_html_.get(); 251 return new_tab_incognito_html_.get();
252 } else { 252 } else {
253 // Refresh the cached HTML if necessary. 253 // Refresh the cached HTML if necessary.
254 // NOTE: NewTabCacheNeedsRefresh() must be called every time the new tab 254 // NOTE: NewTabCacheNeedsRefresh() must be called every time the new tab
255 // HTML is fetched, because it needs to initialize cached values. 255 // HTML is fetched, because it needs to initialize cached values.
256 if (NewTabCacheNeedsRefresh() || !new_tab_html_.get()) 256 if (NewTabCacheNeedsRefresh() || !new_tab_html_)
257 CreateNewTabHTML(); 257 CreateNewTabHTML();
258 return new_tab_html_.get(); 258 return new_tab_html_.get();
259 } 259 }
260 } 260 }
261 261
262 base::RefCountedMemory* NTPResourceCache::GetNewTabCSS(WindowType win_type) { 262 base::RefCountedMemory* NTPResourceCache::GetNewTabCSS(WindowType win_type) {
263 DCHECK_CURRENTLY_ON(BrowserThread::UI); 263 DCHECK_CURRENTLY_ON(BrowserThread::UI);
264 if (win_type == GUEST) { 264
265 if (!new_tab_guest_css_.get()) 265 // Guest mode doesn't have theme-related CSS.
266 CreateNewTabGuestCSS(); 266 if (win_type == GUEST)
267 return new_tab_guest_css_.get(); 267 return nullptr;
268 } else if (win_type == INCOGNITO) { 268
269 if (!new_tab_incognito_css_.get()) 269 if (win_type == INCOGNITO) {
270 if (!new_tab_incognito_css_)
270 CreateNewTabIncognitoCSS(); 271 CreateNewTabIncognitoCSS();
271 return new_tab_incognito_css_.get(); 272 return new_tab_incognito_css_.get();
272 } else {
273 if (!new_tab_css_.get())
274 CreateNewTabCSS();
275 return new_tab_css_.get();
276 } 273 }
274
275 if (!new_tab_css_)
276 CreateNewTabCSS();
277 return new_tab_css_.get();
277 } 278 }
278 279
279 void NTPResourceCache::Observe(int type, 280 void NTPResourceCache::Observe(int type,
280 const content::NotificationSource& source, 281 const content::NotificationSource& source,
281 const content::NotificationDetails& details) { 282 const content::NotificationDetails& details) {
282 // Invalidate the cache. 283 // Invalidate the cache.
283 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type || 284 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type ||
284 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) { 285 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) {
285 Invalidate(); 286 Invalidate();
286 } else { 287 } else {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 331 }
331 332
332 localized_strings.SetString("learnMore", 333 localized_strings.SetString("learnMore",
333 l10n_util::GetStringUTF16(new_tab_link_ids)); 334 l10n_util::GetStringUTF16(new_tab_link_ids));
334 localized_strings.SetString("learnMoreLink", new_tab_link); 335 localized_strings.SetString("learnMoreLink", new_tab_link);
335 336
336 bool bookmark_bar_attached = 337 bool bookmark_bar_attached =
337 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); 338 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar);
338 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached); 339 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached);
339 340
341 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
342 localized_strings.SetBoolean("hasCustomBackground",
343 tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND));
344
340 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 345 const std::string& app_locale = g_browser_process->GetApplicationLocale();
341 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); 346 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings);
342 347
343 static const base::StringPiece incognito_tab_html( 348 static const base::StringPiece incognito_tab_html(
344 ResourceBundle::GetSharedInstance().GetRawDataResource( 349 ResourceBundle::GetSharedInstance().GetRawDataResource(
345 new_tab_html_idr)); 350 new_tab_html_idr));
346 351
347 std::string full_html = webui::GetI18nTemplateHtml( 352 std::string full_html = webui::GetI18nTemplateHtml(
348 incognito_tab_html, &localized_strings); 353 incognito_tab_html, &localized_strings);
349 354
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 webui::GetI18nTemplateHtml(new_tab_html, &load_time_data); 537 webui::GetI18nTemplateHtml(new_tab_html, &load_time_data);
533 new_tab_html_ = base::RefCountedString::TakeString(&full_html); 538 new_tab_html_ = base::RefCountedString::TakeString(&full_html);
534 } 539 }
535 540
536 void NTPResourceCache::CreateNewTabIncognitoCSS() { 541 void NTPResourceCache::CreateNewTabIncognitoCSS() {
537 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 542 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
538 DCHECK(tp); 543 DCHECK(tp);
539 544
540 // Get our theme colors 545 // Get our theme colors
541 SkColor color_background = 546 SkColor color_background =
542 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); 547 tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)
548 ? GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND)
549 : SkColorSetRGB(0x32, 0x32, 0x32);
543 550
544 // Generate the replacements. 551 // Generate the replacements.
545 std::map<base::StringPiece, std::string> substitutions; 552 std::map<base::StringPiece, std::string> substitutions;
546 553
547 // Cache-buster for background. 554 // Cache-buster for background.
548 substitutions["themeId"] = 555 substitutions["themeId"] =
549 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); 556 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
550 557
551 // Colors. 558 // Colors.
552 substitutions["colorBackground"] = SkColorToRGBAString(color_background); 559 substitutions["colorBackground"] = SkColorToRGBAString(color_background);
553 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); 560 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false);
554 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); 561 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true);
555 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); 562 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp);
556 563
557 // Get our template. 564 // Get our template.
558 static const base::StringPiece new_tab_theme_css( 565 static const base::StringPiece new_tab_theme_css(
559 ResourceBundle::GetSharedInstance().GetRawDataResource( 566 ResourceBundle::GetSharedInstance().GetRawDataResource(
560 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); 567 IDR_NEW_INCOGNITO_TAB_THEME_CSS));
561 568
562 // Create the string from our template and the replacements. 569 // Create the string from our template and the replacements.
563 std::string full_css = 570 std::string full_css =
564 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); 571 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
565 572
566 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); 573 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css);
567 } 574 }
568 575
569 void NTPResourceCache::CreateNewTabGuestCSS() {
570 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
571 DCHECK(tp);
572
573 // Get our theme colors
574 SkColor color_background =
575 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND);
576
577 // Generate the replacements.
578 std::map<base::StringPiece, std::string> substitutions;
579
580 // Cache-buster for background.
581 substitutions["themeId"] =
582 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
583
584 // Colors.
585 substitutions["colorBackground"] = SkColorToRGBAString(color_background);
586 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false);
587 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true);
588 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp);
589
590 // Get our template.
591 static const base::StringPiece new_tab_theme_css(
592 ResourceBundle::GetSharedInstance().GetRawDataResource(
593 IDR_NEW_INCOGNITO_TAB_THEME_CSS));
594
595 // Create the string from our template and the replacements.
596 std::string full_css =
597 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
598
599 new_tab_guest_css_ = base::RefCountedString::TakeString(&full_css);
600 }
601
602 void NTPResourceCache::CreateNewTabCSS() { 576 void NTPResourceCache::CreateNewTabCSS() {
603 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 577 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
604 DCHECK(tp); 578 DCHECK(tp);
605 579
606 // Get our theme colors 580 // Get our theme colors
607 SkColor color_background = 581 SkColor color_background =
608 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); 582 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND);
609 SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT); 583 SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT);
610 SkColor color_text_light = 584 SkColor color_text_light =
611 GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT); 585 GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // Get our template. 640 // Get our template.
667 static const base::StringPiece new_tab_theme_css( 641 static const base::StringPiece new_tab_theme_css(
668 ResourceBundle::GetSharedInstance().GetRawDataResource( 642 ResourceBundle::GetSharedInstance().GetRawDataResource(
669 IDR_NEW_TAB_4_THEME_CSS)); 643 IDR_NEW_TAB_4_THEME_CSS));
670 644
671 // Create the string from our template and the replacements. 645 // Create the string from our template and the replacements.
672 std::string css_string = 646 std::string css_string =
673 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); 647 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
674 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 648 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
675 } 649 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_resource_cache.h ('k') | chrome/browser/ui/webui/theme_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698