Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / webui / theme_handler.cc
blob7759fa1d855379d49472d592a8ab53b3db31ad8e
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/theme_handler.h"
7 #include "base/values.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/themes/theme_service.h"
11 #include "chrome/browser/themes/theme_service_factory.h"
12 #include "chrome/browser/ui/webui/theme_source.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/web_ui.h"
15 #include "grit/theme_resources.h"
17 ///////////////////////////////////////////////////////////////////////////////
18 // ThemeHandler
20 ThemeHandler::ThemeHandler() {
23 ThemeHandler::~ThemeHandler() {
26 void ThemeHandler::RegisterMessages() {
27 // These are not actual message registrations, but can't be done in the
28 // constructor since they need the web_ui value to be set, which is done
29 // post-construction, but before registering messages.
30 InitializeCSSCaches();
31 // Listen for theme installation.
32 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
33 content::Source<ThemeService>(
34 ThemeServiceFactory::GetForProfile(GetProfile())));
37 void ThemeHandler::Observe(int type,
38 const content::NotificationSource& source,
39 const content::NotificationDetails& details) {
40 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
41 InitializeCSSCaches();
42 web_ui()->CallJavascriptFunction("ntp.themeChanged");
45 void ThemeHandler::InitializeCSSCaches() {
46 Profile* profile = GetProfile();
47 ThemeSource* theme = new ThemeSource(profile);
48 content::URLDataSource::Add(profile, theme);
51 Profile* ThemeHandler::GetProfile() const {
52 return Profile::FromWebUI(web_ui());