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

Side by Side Diff: chrome/browser/browser_theme_provider.cc

Issue 1117008: Set the details field of the BROWSER_THEME_CHANGED notification to (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « chrome/browser/browser_theme_provider.h ('k') | chrome/browser/gtk/gtk_theme_provider.h » ('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/browser_theme_provider.h" 5 #include "chrome/browser/browser_theme_provider.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/thread.h" 11 #include "base/thread.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/browser_theme_pack.h" 15 #include "chrome/browser/browser_theme_pack.h"
16 #include "chrome/browser/browser_window.h" 16 #include "chrome/browser/browser_window.h"
17 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
18 #include "chrome/browser/metrics/user_metrics.h" 18 #include "chrome/browser/metrics/user_metrics.h"
19 #include "chrome/browser/pref_service.h" 19 #include "chrome/browser/pref_service.h"
20 #include "chrome/browser/profile.h" 20 #include "chrome/browser/profile.h"
21 #include "chrome/browser/theme_resources_util.h" 21 #include "chrome/browser/theme_resources_util.h"
22 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
23 #include "chrome/common/extensions/extension.h" 23 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/notification_details.h"
24 #include "chrome/common/notification_service.h" 25 #include "chrome/common/notification_service.h"
26 #include "chrome/common/notification_source.h"
25 #include "chrome/common/notification_type.h" 27 #include "chrome/common/notification_type.h"
26 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
27 #include "gfx/codec/png_codec.h" 29 #include "gfx/codec/png_codec.h"
28 #include "gfx/skbitmap_operations.h" 30 #include "gfx/skbitmap_operations.h"
29 #include "grit/app_resources.h" 31 #include "grit/app_resources.h"
30 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
31 #include "net/base/file_stream.h" 33 #include "net/base/file_stream.h"
32 #include "net/base/net_errors.h" 34 #include "net/base/net_errors.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 35 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "third_party/skia/include/core/SkCanvas.h" 36 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 void BrowserThemeProvider::SetTheme(Extension* extension) { 287 void BrowserThemeProvider::SetTheme(Extension* extension) {
286 // Clear our image cache. 288 // Clear our image cache.
287 FreePlatformCaches(); 289 FreePlatformCaches();
288 290
289 DCHECK(extension); 291 DCHECK(extension);
290 DCHECK(extension->IsTheme()); 292 DCHECK(extension->IsTheme());
291 293
292 BuildFromExtension(extension); 294 BuildFromExtension(extension);
293 SaveThemeID(extension->id()); 295 SaveThemeID(extension->id());
294 296
295 NotifyThemeChanged(); 297 NotifyThemeChanged(extension);
296 UserMetrics::RecordAction("Themes_Installed", profile_); 298 UserMetrics::RecordAction("Themes_Installed", profile_);
297 } 299 }
298 300
299 void BrowserThemeProvider::RemoveUnusedThemes() { 301 void BrowserThemeProvider::RemoveUnusedThemes() {
300 if (!profile_) 302 if (!profile_)
301 return; 303 return;
302 ExtensionsService* service = profile_->GetExtensionsService(); 304 ExtensionsService* service = profile_->GetExtensionsService();
303 if (!service) 305 if (!service)
304 return; 306 return;
305 std::string current_theme = GetThemeID(); 307 std::string current_theme = GetThemeID();
306 std::vector<std::string> remove_list; 308 std::vector<std::string> remove_list;
307 const ExtensionList* extensions = service->extensions(); 309 const ExtensionList* extensions = service->extensions();
308 for (ExtensionList::const_iterator it = extensions->begin(); 310 for (ExtensionList::const_iterator it = extensions->begin();
309 it != extensions->end(); ++it) { 311 it != extensions->end(); ++it) {
310 if ((*it)->IsTheme() && (*it)->id() != current_theme) { 312 if ((*it)->IsTheme() && (*it)->id() != current_theme) {
311 remove_list.push_back((*it)->id()); 313 remove_list.push_back((*it)->id());
312 } 314 }
313 } 315 }
314 for (size_t i = 0; i < remove_list.size(); ++i) 316 for (size_t i = 0; i < remove_list.size(); ++i)
315 service->UninstallExtension(remove_list[i], false); 317 service->UninstallExtension(remove_list[i], false);
316 } 318 }
317 319
318 void BrowserThemeProvider::UseDefaultTheme() { 320 void BrowserThemeProvider::UseDefaultTheme() {
319 ClearAllThemeData(); 321 ClearAllThemeData();
320 NotifyThemeChanged(); 322 NotifyThemeChanged(NULL);
321 UserMetrics::RecordAction("Themes_Reset", profile_); 323 UserMetrics::RecordAction("Themes_Reset", profile_);
322 } 324 }
323 325
324 std::string BrowserThemeProvider::GetThemeID() const { 326 std::string BrowserThemeProvider::GetThemeID() const {
325 std::wstring id = profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); 327 std::wstring id = profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
326 return WideToUTF8(id); 328 return WideToUTF8(id);
327 } 329 }
328 330
329 // static 331 // static
330 std::string BrowserThemeProvider::AlignmentToString(int alignment) { 332 std::string BrowserThemeProvider::AlignmentToString(int alignment) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } else { 556 } else {
555 DLOG(ERROR) << "Theme is mysteriously gone."; 557 DLOG(ERROR) << "Theme is mysteriously gone.";
556 ClearAllThemeData(); 558 ClearAllThemeData();
557 UserMetrics::RecordAction("Themes.Gone", profile_); 559 UserMetrics::RecordAction("Themes.Gone", profile_);
558 } 560 }
559 } 561 }
560 } 562 }
561 } 563 }
562 } 564 }
563 565
564 void BrowserThemeProvider::NotifyThemeChanged() { 566 void BrowserThemeProvider::NotifyThemeChanged(Extension* extension) {
565 // Redraw! 567 // Redraw!
566 NotificationService* service = NotificationService::current(); 568 NotificationService* service = NotificationService::current();
567 service->Notify(NotificationType::BROWSER_THEME_CHANGED, 569 service->Notify(NotificationType::BROWSER_THEME_CHANGED,
568 Source<BrowserThemeProvider>(this), 570 Source<BrowserThemeProvider>(this),
569 NotificationService::NoDetails()); 571 Details<Extension>(extension));
570 #if defined(OS_MACOSX) 572 #if defined(OS_MACOSX)
571 NotifyPlatformThemeChanged(); 573 NotifyPlatformThemeChanged();
572 #endif // OS_MACOSX 574 #endif // OS_MACOSX
573 } 575 }
574 576
575 #if defined(OS_WIN) 577 #if defined(OS_WIN)
576 void BrowserThemeProvider::FreePlatformCaches() { 578 void BrowserThemeProvider::FreePlatformCaches() {
577 // Views (Skia) has no platform image cache to clear. 579 // Views (Skia) has no platform image cache to clear.
578 } 580 }
579 #endif 581 #endif
(...skipping 29 matching lines...) Expand all
609 void BrowserThemeProvider::OnInfobarDisplayed() { 611 void BrowserThemeProvider::OnInfobarDisplayed() {
610 number_of_infobars_++; 612 number_of_infobars_++;
611 } 613 }
612 614
613 void BrowserThemeProvider::OnInfobarDestroyed() { 615 void BrowserThemeProvider::OnInfobarDestroyed() {
614 number_of_infobars_--; 616 number_of_infobars_--;
615 617
616 if (number_of_infobars_ == 0) 618 if (number_of_infobars_ == 0)
617 RemoveUnusedThemes(); 619 RemoveUnusedThemes();
618 } 620 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_theme_provider.h ('k') | chrome/browser/gtk/gtk_theme_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698