OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ntp_resource_cache.h" | 5 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "app/theme_provider.h" | |
13 #include "base/command_line.h" | 12 #include "base/command_line.h" |
14 #include "base/file_util.h" | 13 #include "base/file_util.h" |
15 #include "base/ref_counted_memory.h" | 14 #include "base/ref_counted_memory.h" |
16 #include "base/string16.h" | 15 #include "base/string16.h" |
17 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
18 #include "base/time.h" | 17 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 19 #include "base/values.h" |
21 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
22 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 21 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
(...skipping 11 matching lines...) Expand all Loading... |
34 #include "chrome/common/notification_type.h" | 33 #include "chrome/common/notification_type.h" |
35 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
37 #include "gfx/color_utils.h" | 36 #include "gfx/color_utils.h" |
38 #include "grit/browser_resources.h" | 37 #include "grit/browser_resources.h" |
39 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
40 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
41 #include "grit/locale_settings.h" | 40 #include "grit/locale_settings.h" |
42 #include "grit/theme_resources.h" | 41 #include "grit/theme_resources.h" |
43 #include "ui/base/animation/animation.h" | 42 #include "ui/base/animation/animation.h" |
| 43 #include "ui/base/theme_provider.h" |
44 | 44 |
45 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) | 45 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) |
46 #include "chrome/browser/ui/views/bookmark_bar_view.h" | 46 #include "chrome/browser/ui/views/bookmark_bar_view.h" |
47 #elif defined(OS_MACOSX) | 47 #elif defined(OS_MACOSX) |
48 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 48 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
49 #elif defined(OS_POSIX) | 49 #elif defined(OS_POSIX) |
50 #include "chrome/browser/gtk/bookmark_bar_gtk.h" | 50 #include "chrome/browser/gtk/bookmark_bar_gtk.h" |
51 #endif | 51 #endif |
52 | 52 |
53 using base::Time; | 53 using base::Time; |
(...skipping 27 matching lines...) Expand all Loading... |
81 std::string SkColorToRGBAString(SkColor color) { | 81 std::string SkColorToRGBAString(SkColor color) { |
82 // We convert the alpha using DoubleToString because StringPrintf will use | 82 // We convert the alpha using DoubleToString because StringPrintf will use |
83 // locale specific formatters (e.g., use , instead of . in German). | 83 // locale specific formatters (e.g., use , instead of . in German). |
84 return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color), | 84 return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color), |
85 SkColorGetG(color), SkColorGetB(color), | 85 SkColorGetG(color), SkColorGetB(color), |
86 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); | 86 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); |
87 } | 87 } |
88 | 88 |
89 // Get the CSS string for the background position on the new tab page for the | 89 // Get the CSS string for the background position on the new tab page for the |
90 // states when the bar is attached or detached. | 90 // states when the bar is attached or detached. |
91 std::string GetNewTabBackgroundCSS(const ThemeProvider* theme_provider, | 91 std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, |
92 bool bar_attached) { | 92 bool bar_attached) { |
93 int alignment; | 93 int alignment; |
94 theme_provider->GetDisplayProperty( | 94 theme_provider->GetDisplayProperty( |
95 BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, &alignment); | 95 BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, &alignment); |
96 | 96 |
97 // TODO(glen): This is a quick workaround to hide the notused.png image when | 97 // TODO(glen): This is a quick workaround to hide the notused.png image when |
98 // no image is provided - we don't have time right now to figure out why | 98 // no image is provided - we don't have time right now to figure out why |
99 // this is painting as white. | 99 // this is painting as white. |
100 // http://crbug.com/17593 | 100 // http://crbug.com/17593 |
101 if (!theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { | 101 if (!theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { |
(...skipping 20 matching lines...) Expand all Loading... |
122 return "0% " + base::IntToString(-offset) + "px"; | 122 return "0% " + base::IntToString(-offset) + "px"; |
123 else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) | 123 else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) |
124 return "100% " + base::IntToString(-offset) + "px"; | 124 return "100% " + base::IntToString(-offset) + "px"; |
125 return "center " + base::IntToString(-offset) + "px"; | 125 return "center " + base::IntToString(-offset) + "px"; |
126 } | 126 } |
127 return BrowserThemeProvider::AlignmentToString(alignment); | 127 return BrowserThemeProvider::AlignmentToString(alignment); |
128 } | 128 } |
129 | 129 |
130 // How the background image on the new tab page should be tiled (see tiling | 130 // How the background image on the new tab page should be tiled (see tiling |
131 // masks in browser_theme_provider.h). | 131 // masks in browser_theme_provider.h). |
132 std::string GetNewTabBackgroundTilingCSS(const ThemeProvider* theme_provider) { | 132 std::string GetNewTabBackgroundTilingCSS( |
| 133 const ui::ThemeProvider* theme_provider) { |
133 int repeat_mode; | 134 int repeat_mode; |
134 theme_provider->GetDisplayProperty( | 135 theme_provider->GetDisplayProperty( |
135 BrowserThemeProvider::NTP_BACKGROUND_TILING, &repeat_mode); | 136 BrowserThemeProvider::NTP_BACKGROUND_TILING, &repeat_mode); |
136 return BrowserThemeProvider::TilingToString(repeat_mode); | 137 return BrowserThemeProvider::TilingToString(repeat_mode); |
137 } | 138 } |
138 | 139 |
139 // Is the current time within a given date range? | 140 // Is the current time within a given date range? |
140 bool InDateRange(double begin, double end) { | 141 bool InDateRange(double begin, double end) { |
141 Time start_time = Time::FromDoubleT(begin); | 142 Time start_time = Time::FromDoubleT(begin); |
142 Time end_time = Time::FromDoubleT(end); | 143 Time end_time = Time::FromDoubleT(end); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 NOTREACHED(); | 409 NOTREACHED(); |
409 full_html.assign(new_tab_html.data(), new_tab_html.size()); | 410 full_html.assign(new_tab_html.data(), new_tab_html.size()); |
410 } | 411 } |
411 | 412 |
412 new_tab_html_ = new RefCountedBytes; | 413 new_tab_html_ = new RefCountedBytes; |
413 new_tab_html_->data.resize(full_html.size()); | 414 new_tab_html_->data.resize(full_html.size()); |
414 std::copy(full_html.begin(), full_html.end(), new_tab_html_->data.begin()); | 415 std::copy(full_html.begin(), full_html.end(), new_tab_html_->data.begin()); |
415 } | 416 } |
416 | 417 |
417 void NTPResourceCache::CreateNewTabIncognitoCSS() { | 418 void NTPResourceCache::CreateNewTabIncognitoCSS() { |
418 ThemeProvider* tp = profile_->GetThemeProvider(); | 419 ui::ThemeProvider* tp = profile_->GetThemeProvider(); |
419 DCHECK(tp); | 420 DCHECK(tp); |
420 | 421 |
421 // Get our theme colors | 422 // Get our theme colors |
422 SkColor color_background = | 423 SkColor color_background = |
423 tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND); | 424 tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND); |
424 | 425 |
425 // Generate the replacements. | 426 // Generate the replacements. |
426 std::vector<std::string> subst; | 427 std::vector<std::string> subst; |
427 | 428 |
428 // Cache-buster for background. | 429 // Cache-buster for background. |
(...skipping 15 matching lines...) Expand all Loading... |
444 std::string full_css = ReplaceStringPlaceholders( | 445 std::string full_css = ReplaceStringPlaceholders( |
445 new_tab_theme_css, subst, NULL); | 446 new_tab_theme_css, subst, NULL); |
446 | 447 |
447 new_tab_incognito_css_ = new RefCountedBytes; | 448 new_tab_incognito_css_ = new RefCountedBytes; |
448 new_tab_incognito_css_->data.resize(full_css.size()); | 449 new_tab_incognito_css_->data.resize(full_css.size()); |
449 std::copy(full_css.begin(), full_css.end(), | 450 std::copy(full_css.begin(), full_css.end(), |
450 new_tab_incognito_css_->data.begin()); | 451 new_tab_incognito_css_->data.begin()); |
451 } | 452 } |
452 | 453 |
453 void NTPResourceCache::CreateNewTabCSS() { | 454 void NTPResourceCache::CreateNewTabCSS() { |
454 ThemeProvider* tp = profile_->GetThemeProvider(); | 455 ui::ThemeProvider* tp = profile_->GetThemeProvider(); |
455 DCHECK(tp); | 456 DCHECK(tp); |
456 | 457 |
457 // Get our theme colors | 458 // Get our theme colors |
458 SkColor color_background = | 459 SkColor color_background = |
459 tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND); | 460 tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND); |
460 SkColor color_text = tp->GetColor(BrowserThemeProvider::COLOR_NTP_TEXT); | 461 SkColor color_text = tp->GetColor(BrowserThemeProvider::COLOR_NTP_TEXT); |
461 SkColor color_link = tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK); | 462 SkColor color_link = tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK); |
462 SkColor color_link_underline = | 463 SkColor color_link_underline = |
463 tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK_UNDERLINE); | 464 tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK_UNDERLINE); |
464 | 465 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 std::string css_string; | 548 std::string css_string; |
548 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 549 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
549 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); | 550 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); |
550 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); | 551 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); |
551 | 552 |
552 new_tab_css_ = new RefCountedBytes; | 553 new_tab_css_ = new RefCountedBytes; |
553 new_tab_css_->data.resize(css_string.size()); | 554 new_tab_css_->data.resize(css_string.size()); |
554 std::copy(css_string.begin(), css_string.end(), | 555 std::copy(css_string.begin(), css_string.end(), |
555 new_tab_css_->data.begin()); | 556 new_tab_css_->data.begin()); |
556 } | 557 } |
OLD | NEW |