| OLD | NEW |
| 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/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/themes/browser_theme_pack.h" | 15 #include "chrome/browser/themes/browser_theme_pack.h" |
| 16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/user_metrics.h" | 20 #include "content/public/browser/user_metrics.h" |
| 21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 22 #include "grit/theme_resources_standard.h" | 22 #include "grit/theme_resources_standard.h" |
| 23 #include "grit/ui_resources.h" | 23 #include "grit/ui_resources.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/image/image_skia.h" |
| 25 | 26 |
| 26 #if defined(OS_WIN) && !defined(USE_AURA) | 27 #if defined(OS_WIN) && !defined(USE_AURA) |
| 27 #include "ui/views/widget/native_widget_win.h" | 28 #include "ui/views/widget/native_widget_win.h" |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| 31 using content::UserMetricsAction; | 32 using content::UserMetricsAction; |
| 32 using ui::ResourceBundle; | 33 using ui::ResourceBundle; |
| 33 | 34 |
| 34 // Strings used in alignment properties. | 35 // Strings used in alignment properties. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (theme_pack_.get()) | 238 if (theme_pack_.get()) |
| 238 image = theme_pack_->GetImageNamed(id); | 239 image = theme_pack_->GetImageNamed(id); |
| 239 | 240 |
| 240 if (!image) | 241 if (!image) |
| 241 image = &rb_.GetNativeImageNamed(id); | 242 image = &rb_.GetNativeImageNamed(id); |
| 242 | 243 |
| 243 return image; | 244 return image; |
| 244 } | 245 } |
| 245 | 246 |
| 246 SkBitmap* ThemeService::GetBitmapNamed(int id) const { | 247 SkBitmap* ThemeService::GetBitmapNamed(int id) const { |
| 247 DCHECK(CalledOnValidThread()); | 248 const gfx::Image* image = GetImageNamed(id); |
| 249 if (!image) |
| 250 return NULL; |
| 248 | 251 |
| 249 SkBitmap* bitmap = NULL; | 252 return const_cast<SkBitmap*>(image->ToSkBitmap()); |
| 253 } |
| 250 | 254 |
| 251 if (theme_pack_.get()) | 255 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
| 252 bitmap = theme_pack_->GetBitmapNamed(id); | 256 const gfx::Image* image = GetImageNamed(id); |
| 253 | 257 if (!image) |
| 254 if (!bitmap) | 258 return NULL; |
| 255 bitmap = rb_.GetBitmapNamed(id); | 259 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
| 256 | 260 // its images const. GetImageSkiaNamed() also should but has many callsites. |
| 257 return bitmap; | 261 return const_cast<gfx::ImageSkia*>(image->ToImageSkia()); |
| 258 } | 262 } |
| 259 | 263 |
| 260 SkColor ThemeService::GetColor(int id) const { | 264 SkColor ThemeService::GetColor(int id) const { |
| 261 DCHECK(CalledOnValidThread()); | 265 DCHECK(CalledOnValidThread()); |
| 262 | 266 |
| 263 SkColor color; | 267 SkColor color; |
| 264 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) | 268 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) |
| 265 return color; | 269 return color; |
| 266 | 270 |
| 267 // For backward compat with older themes, some newer colors are generated from | 271 // For backward compat with older themes, some newer colors are generated from |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 void ThemeService::OnInfobarDisplayed() { | 680 void ThemeService::OnInfobarDisplayed() { |
| 677 number_of_infobars_++; | 681 number_of_infobars_++; |
| 678 } | 682 } |
| 679 | 683 |
| 680 void ThemeService::OnInfobarDestroyed() { | 684 void ThemeService::OnInfobarDestroyed() { |
| 681 number_of_infobars_--; | 685 number_of_infobars_--; |
| 682 | 686 |
| 683 if (number_of_infobars_ == 0) | 687 if (number_of_infobars_ == 0) |
| 684 RemoveUnusedThemes(); | 688 RemoveUnusedThemes(); |
| 685 } | 689 } |
| OLD | NEW |