| 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/ui/webui/options/font_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/font_settings_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_tab_util.h" | 23 #include "chrome/browser/extensions/extension_tab_util.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/webui/options/font_settings_utils.h" | 26 #include "chrome/browser/ui/webui/settings_utils.h" |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 29 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
| 30 #include "content/public/browser/font_list_async.h" | 30 #include "content/public/browser/font_list_async.h" |
| 31 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
| 34 #include "extensions/browser/extension_registry.h" | 34 #include "extensions/browser/extension_registry.h" |
| 35 #include "extensions/browser/extension_system.h" | 35 #include "extensions/browser/extension_system.h" |
| 36 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 SetUpSerifFontSample(); | 109 SetUpSerifFontSample(); |
| 110 SetUpSansSerifFontSample(); | 110 SetUpSansSerifFontSample(); |
| 111 SetUpFixedFontSample(); | 111 SetUpFixedFontSample(); |
| 112 SetUpMinimumFontSample(); | 112 SetUpMinimumFontSample(); |
| 113 NotifyAdvancedFontSettingsAvailability(); | 113 NotifyAdvancedFontSettingsAvailability(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void FontSettingsHandler::RegisterMessages() { | 116 void FontSettingsHandler::RegisterMessages() { |
| 117 // Perform validation for saved fonts. | 117 // Perform validation for saved fonts. |
| 118 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 118 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 119 FontSettingsUtilities::ValidateSavedFonts(pref_service); | 119 #if defined(OS_MACOSX) |
| 120 settings_utils::ValidateSavedFonts(pref_service); |
| 121 #endif |
| 120 | 122 |
| 121 // Register for preferences that we need to observe manually. | 123 // Register for preferences that we need to observe manually. |
| 122 standard_font_.Init(prefs::kWebKitStandardFontFamily, | 124 standard_font_.Init(prefs::kWebKitStandardFontFamily, |
| 123 pref_service, | 125 pref_service, |
| 124 base::Bind(&FontSettingsHandler::SetUpStandardFontSample, | 126 base::Bind(&FontSettingsHandler::SetUpStandardFontSample, |
| 125 base::Unretained(this))); | 127 base::Unretained(this))); |
| 126 serif_font_.Init(prefs::kWebKitSerifFontFamily, | 128 serif_font_.Init(prefs::kWebKitSerifFontFamily, |
| 127 pref_service, | 129 pref_service, |
| 128 base::Bind(&FontSettingsHandler::SetUpSerifFontSample, | 130 base::Bind(&FontSettingsHandler::SetUpSerifFontSample, |
| 129 base::Unretained(this))); | 131 base::Unretained(this))); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool has_font = list->GetList(i, &font); | 187 bool has_font = list->GetList(i, &font); |
| 186 DCHECK(has_font); | 188 DCHECK(has_font); |
| 187 base::string16 value; | 189 base::string16 value; |
| 188 bool has_value = font->GetString(1, &value); | 190 bool has_value = font->GetString(1, &value); |
| 189 DCHECK(has_value); | 191 DCHECK(has_value); |
| 190 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); | 192 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); |
| 191 font->AppendString(has_rtl_chars ? "rtl" : "ltr"); | 193 font->AppendString(has_rtl_chars ? "rtl" : "ltr"); |
| 192 } | 194 } |
| 193 | 195 |
| 194 base::ListValue selected_values; | 196 base::ListValue selected_values; |
| 195 selected_values.AppendString(FontSettingsUtilities::MaybeGetLocalizedFontName( | |
| 196 standard_font_.GetValue())); | |
| 197 selected_values.AppendString( | 197 selected_values.AppendString( |
| 198 FontSettingsUtilities::MaybeGetLocalizedFontName(serif_font_.GetValue())); | 198 settings_utils::MaybeGetLocalizedFontName(standard_font_.GetValue())); |
| 199 selected_values.AppendString(FontSettingsUtilities::MaybeGetLocalizedFontName( | |
| 200 sans_serif_font_.GetValue())); | |
| 201 selected_values.AppendString( | 199 selected_values.AppendString( |
| 202 FontSettingsUtilities::MaybeGetLocalizedFontName(fixed_font_.GetValue())); | 200 settings_utils::MaybeGetLocalizedFontName(serif_font_.GetValue())); |
| 201 selected_values.AppendString( |
| 202 settings_utils::MaybeGetLocalizedFontName(sans_serif_font_.GetValue())); |
| 203 selected_values.AppendString( |
| 204 settings_utils::MaybeGetLocalizedFontName(fixed_font_.GetValue())); |
| 203 | 205 |
| 204 web_ui()->CallJavascriptFunctionUnsafe( | 206 web_ui()->CallJavascriptFunctionUnsafe( |
| 205 "FontSettings.setFontsData", *list.get(), selected_values); | 207 "FontSettings.setFontsData", *list.get(), selected_values); |
| 206 } | 208 } |
| 207 | 209 |
| 208 void FontSettingsHandler::SetUpStandardFontSample() { | 210 void FontSettingsHandler::SetUpStandardFontSample() { |
| 209 base::Value font_value( | 211 base::Value font_value( |
| 210 FontSettingsUtilities::ResolveFontList(standard_font_.GetValue())); | 212 settings_utils::ResolveFontList(standard_font_.GetValue())); |
| 211 base::Value size_value(default_font_size_.GetValue()); | 213 base::Value size_value(default_font_size_.GetValue()); |
| 212 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", | 214 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", |
| 213 font_value, size_value); | 215 font_value, size_value); |
| 214 } | 216 } |
| 215 | 217 |
| 216 void FontSettingsHandler::SetUpSerifFontSample() { | 218 void FontSettingsHandler::SetUpSerifFontSample() { |
| 217 base::Value font_value( | 219 base::Value font_value( |
| 218 FontSettingsUtilities::ResolveFontList(serif_font_.GetValue())); | 220 settings_utils::ResolveFontList(serif_font_.GetValue())); |
| 219 base::Value size_value(default_font_size_.GetValue()); | 221 base::Value size_value(default_font_size_.GetValue()); |
| 220 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample", | 222 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample", |
| 221 font_value, size_value); | 223 font_value, size_value); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void FontSettingsHandler::SetUpSansSerifFontSample() { | 226 void FontSettingsHandler::SetUpSansSerifFontSample() { |
| 225 base::Value font_value( | 227 base::Value font_value( |
| 226 FontSettingsUtilities::ResolveFontList(sans_serif_font_.GetValue())); | 228 settings_utils::ResolveFontList(sans_serif_font_.GetValue())); |
| 227 base::Value size_value(default_font_size_.GetValue()); | 229 base::Value size_value(default_font_size_.GetValue()); |
| 228 web_ui()->CallJavascriptFunctionUnsafe( | 230 web_ui()->CallJavascriptFunctionUnsafe( |
| 229 "FontSettings.setUpSansSerifFontSample", font_value, size_value); | 231 "FontSettings.setUpSansSerifFontSample", font_value, size_value); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void FontSettingsHandler::SetUpFixedFontSample() { | 234 void FontSettingsHandler::SetUpFixedFontSample() { |
| 233 base::Value font_value( | 235 base::Value font_value( |
| 234 FontSettingsUtilities::ResolveFontList(fixed_font_.GetValue())); | 236 settings_utils::ResolveFontList(fixed_font_.GetValue())); |
| 235 base::Value size_value(default_fixed_font_size_.GetValue()); | 237 base::Value size_value(default_fixed_font_size_.GetValue()); |
| 236 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample", | 238 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample", |
| 237 font_value, size_value); | 239 font_value, size_value); |
| 238 } | 240 } |
| 239 | 241 |
| 240 void FontSettingsHandler::SetUpMinimumFontSample() { | 242 void FontSettingsHandler::SetUpMinimumFontSample() { |
| 241 base::Value size_value(minimum_font_size_.GetValue()); | 243 base::Value size_value(minimum_font_size_.GetValue()); |
| 242 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample", | 244 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample", |
| 243 size_value); | 245 size_value); |
| 244 } | 246 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 268 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); | 270 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); |
| 269 } | 271 } |
| 270 | 272 |
| 271 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { | 273 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { |
| 272 SetUpStandardFontSample(); | 274 SetUpStandardFontSample(); |
| 273 SetUpSerifFontSample(); | 275 SetUpSerifFontSample(); |
| 274 SetUpSansSerifFontSample(); | 276 SetUpSansSerifFontSample(); |
| 275 } | 277 } |
| 276 | 278 |
| 277 } // namespace options | 279 } // namespace options |
| OLD | NEW |