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

Side by Side Diff: chrome/browser/ui/webui/options/font_settings_handler.cc

Issue 399603002: Replace usage of NOTIFICATION_EXTENSION_UNLOADED with ExtensionRegistryObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_handler.h ('k') | no next file » | 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) 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/ui/webui/options/font_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/font_settings_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/character_encoding.h" 19 #include "chrome/browser/character_encoding.h"
20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_tab_util.h" 21 #include "chrome/browser/extensions/extension_tab_util.h"
23 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/webui/options/font_settings_utils.h" 24 #include "chrome/browser/ui/webui/options/font_settings_utils.h"
26 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
27 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/font_list_async.h" 27 #include "content/public/browser/font_list_async.h"
29 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
30 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/web_ui.h" 30 #include "content/public/browser/web_ui.h"
31 #include "extensions/browser/extension_registry.h"
32 #include "extensions/browser/extension_system.h" 32 #include "extensions/browser/extension_system.h"
33 #include "extensions/common/extension.h" 33 #include "extensions/common/extension.h"
34 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "url/gurl.h" 37 #include "url/gurl.h"
38 38
39 #if defined(OS_WIN) 39 #if defined(OS_WIN)
40 #include "ui/gfx/font.h" 40 #include "ui/gfx/font.h"
41 #include "ui/gfx/platform_font_win.h" 41 #include "ui/gfx/platform_font_win.h"
(...skipping 15 matching lines...) Expand all
57 } 57 }
58 58
59 const char kAdvancedFontSettingsExtensionId[] = 59 const char kAdvancedFontSettingsExtensionId[] =
60 "caclkomlalccbpcdllchkeecicepbmbm"; 60 "caclkomlalccbpcdllchkeecicepbmbm";
61 61
62 } // namespace 62 } // namespace
63 63
64 64
65 namespace options { 65 namespace options {
66 66
67 FontSettingsHandler::FontSettingsHandler() { 67 FontSettingsHandler::FontSettingsHandler()
68 : extension_registry_observer_(this) {
68 } 69 }
69 70
70 FontSettingsHandler::~FontSettingsHandler() { 71 FontSettingsHandler::~FontSettingsHandler() {
71 } 72 }
72 73
73 void FontSettingsHandler::GetLocalizedValues( 74 void FontSettingsHandler::GetLocalizedValues(
74 base::DictionaryValue* localized_strings) { 75 base::DictionaryValue* localized_strings) {
75 DCHECK(localized_strings); 76 DCHECK(localized_strings);
76 77
77 static OptionsStringResource resources[] = { 78 static OptionsStringResource resources[] = {
(...skipping 28 matching lines...) Expand all
106 107
107 GURL install_url(extension_urls::GetWebstoreItemDetailURLPrefix()); 108 GURL install_url(extension_urls::GetWebstoreItemDetailURLPrefix());
108 localized_strings->SetString("advancedFontSettingsInstall", 109 localized_strings->SetString("advancedFontSettingsInstall",
109 l10n_util::GetStringFUTF16( 110 l10n_util::GetStringFUTF16(
110 IDS_FONT_LANGUAGE_SETTING_ADVANCED_FONT_SETTINGS_INSTALL, 111 IDS_FONT_LANGUAGE_SETTING_ADVANCED_FONT_SETTINGS_INSTALL,
111 base::UTF8ToUTF16( 112 base::UTF8ToUTF16(
112 install_url.Resolve(kAdvancedFontSettingsExtensionId).spec()))); 113 install_url.Resolve(kAdvancedFontSettingsExtensionId).spec())));
113 } 114 }
114 115
115 void FontSettingsHandler::InitializeHandler() { 116 void FontSettingsHandler::InitializeHandler() {
116 registrar_.Add(this, 117 Profile* profile = Profile::FromWebUI(web_ui());
117 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 118 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
118 content::NotificationService::AllSources());
119 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
120 content::NotificationService::AllSources());
121 } 119 }
122 120
123 void FontSettingsHandler::InitializePage() { 121 void FontSettingsHandler::InitializePage() {
124 DCHECK(web_ui()); 122 DCHECK(web_ui());
125 SetUpStandardFontSample(); 123 SetUpStandardFontSample();
126 SetUpSerifFontSample(); 124 SetUpSerifFontSample();
127 SetUpSansSerifFontSample(); 125 SetUpSansSerifFontSample();
128 SetUpFixedFontSample(); 126 SetUpFixedFontSample();
129 SetUpMinimumFontSample(); 127 SetUpMinimumFontSample();
130 NotifyAdvancedFontSettingsAvailability(); 128 NotifyAdvancedFontSettingsAvailability();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 base::Unretained(this))); 168 base::Unretained(this)));
171 169
172 web_ui()->RegisterMessageCallback("fetchFontsData", 170 web_ui()->RegisterMessageCallback("fetchFontsData",
173 base::Bind(&FontSettingsHandler::HandleFetchFontsData, 171 base::Bind(&FontSettingsHandler::HandleFetchFontsData,
174 base::Unretained(this))); 172 base::Unretained(this)));
175 web_ui()->RegisterMessageCallback("openAdvancedFontSettingsOptions", 173 web_ui()->RegisterMessageCallback("openAdvancedFontSettingsOptions",
176 base::Bind(&FontSettingsHandler::HandleOpenAdvancedFontSettingsOptions, 174 base::Bind(&FontSettingsHandler::HandleOpenAdvancedFontSettingsOptions,
177 base::Unretained(this))); 175 base::Unretained(this)));
178 } 176 }
179 177
180 void FontSettingsHandler::Observe(int type, 178 void FontSettingsHandler::OnExtensionLoaded(
181 const content::NotificationSource& source, 179 content::BrowserContext* browser_context,
182 const content::NotificationDetails& details) { 180 const extensions::Extension* extension) {
183 DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED ||
184 type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
185 NotifyAdvancedFontSettingsAvailability(); 181 NotifyAdvancedFontSettingsAvailability();
186 } 182 }
187 183
184 void FontSettingsHandler::OnExtensionUnloaded(
185 content::BrowserContext* browser_context,
186 const extensions::Extension* extension,
187 extensions::UnloadedExtensionInfo::Reason reason) {
188 NotifyAdvancedFontSettingsAvailability();
189 }
190
188 void FontSettingsHandler::HandleFetchFontsData(const base::ListValue* args) { 191 void FontSettingsHandler::HandleFetchFontsData(const base::ListValue* args) {
189 content::GetFontListAsync( 192 content::GetFontListAsync(
190 base::Bind(&FontSettingsHandler::FontsListHasLoaded, 193 base::Bind(&FontSettingsHandler::FontsListHasLoaded,
191 base::Unretained(this))); 194 base::Unretained(this)));
192 } 195 }
193 196
194 void FontSettingsHandler::FontsListHasLoaded( 197 void FontSettingsHandler::FontsListHasLoaded(
195 scoped_ptr<base::ListValue> list) { 198 scoped_ptr<base::ListValue> list) {
196 // Selects the directionality for the fonts in the given list. 199 // Selects the directionality for the fonts in the given list.
197 for (size_t i = 0; i < list->GetSize(); i++) { 200 for (size_t i = 0; i < list->GetSize(); i++) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); 313 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()));
311 } 314 }
312 315
313 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { 316 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() {
314 SetUpStandardFontSample(); 317 SetUpStandardFontSample();
315 SetUpSerifFontSample(); 318 SetUpSerifFontSample();
316 SetUpSansSerifFontSample(); 319 SetUpSansSerifFontSample();
317 } 320 }
318 321
319 } // namespace options 322 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698