Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / theme_handler.cc
blob4112d2bdd959523ae7bb472320c026b81da07e8a
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 base::FundamentalValue attribution(
43 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage(
44 IDR_THEME_NTP_ATTRIBUTION));
45 web_ui()->CallJavascriptFunction("ntp.themeChanged", attribution);
48 void ThemeHandler::InitializeCSSCaches() {
49 Profile* profile = GetProfile();
50 ThemeSource* theme = new ThemeSource(profile);
51 content::URLDataSource::Add(profile, theme);
54 Profile* ThemeHandler::GetProfile() const {
55 return Profile::FromWebUI(web_ui());