| 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 | 10 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( | 245 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 246 standard_font_.GetValue()))); | 246 standard_font_.GetValue()))); |
| 247 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( | 247 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 248 serif_font_.GetValue()))); | 248 serif_font_.GetValue()))); |
| 249 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( | 249 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 250 sans_serif_font_.GetValue()))); | 250 sans_serif_font_.GetValue()))); |
| 251 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( | 251 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 252 fixed_font_.GetValue()))); | 252 fixed_font_.GetValue()))); |
| 253 selected_values.Append(new base::StringValue(font_encoding_.GetValue())); | 253 selected_values.Append(new base::StringValue(font_encoding_.GetValue())); |
| 254 | 254 |
| 255 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", | 255 web_ui()->CallJavascriptFunctionUnsafe( |
| 256 *list.get(), encoding_list, | 256 "FontSettings.setFontsData", *list.get(), encoding_list, selected_values); |
| 257 selected_values); | |
| 258 } | 257 } |
| 259 | 258 |
| 260 void FontSettingsHandler::SetUpStandardFontSample() { | 259 void FontSettingsHandler::SetUpStandardFontSample() { |
| 261 base::StringValue font_value(standard_font_.GetValue()); | 260 base::StringValue font_value(standard_font_.GetValue()); |
| 262 base::FundamentalValue size_value(default_font_size_.GetValue()); | 261 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 263 web_ui()->CallJavascriptFunction( | 262 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", |
| 264 "FontSettings.setUpStandardFontSample", font_value, size_value); | 263 font_value, size_value); |
| 265 } | 264 } |
| 266 | 265 |
| 267 void FontSettingsHandler::SetUpSerifFontSample() { | 266 void FontSettingsHandler::SetUpSerifFontSample() { |
| 268 base::StringValue font_value(serif_font_.GetValue()); | 267 base::StringValue font_value(serif_font_.GetValue()); |
| 269 base::FundamentalValue size_value(default_font_size_.GetValue()); | 268 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 270 web_ui()->CallJavascriptFunction( | 269 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample", |
| 271 "FontSettings.setUpSerifFontSample", font_value, size_value); | 270 font_value, size_value); |
| 272 } | 271 } |
| 273 | 272 |
| 274 void FontSettingsHandler::SetUpSansSerifFontSample() { | 273 void FontSettingsHandler::SetUpSansSerifFontSample() { |
| 275 base::StringValue font_value(sans_serif_font_.GetValue()); | 274 base::StringValue font_value(sans_serif_font_.GetValue()); |
| 276 base::FundamentalValue size_value(default_font_size_.GetValue()); | 275 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 277 web_ui()->CallJavascriptFunction( | 276 web_ui()->CallJavascriptFunctionUnsafe( |
| 278 "FontSettings.setUpSansSerifFontSample", font_value, size_value); | 277 "FontSettings.setUpSansSerifFontSample", font_value, size_value); |
| 279 } | 278 } |
| 280 | 279 |
| 281 void FontSettingsHandler::SetUpFixedFontSample() { | 280 void FontSettingsHandler::SetUpFixedFontSample() { |
| 282 base::StringValue font_value(fixed_font_.GetValue()); | 281 base::StringValue font_value(fixed_font_.GetValue()); |
| 283 base::FundamentalValue size_value(default_fixed_font_size_.GetValue()); | 282 base::FundamentalValue size_value(default_fixed_font_size_.GetValue()); |
| 284 web_ui()->CallJavascriptFunction( | 283 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample", |
| 285 "FontSettings.setUpFixedFontSample", font_value, size_value); | 284 font_value, size_value); |
| 286 } | 285 } |
| 287 | 286 |
| 288 void FontSettingsHandler::SetUpMinimumFontSample() { | 287 void FontSettingsHandler::SetUpMinimumFontSample() { |
| 289 base::FundamentalValue size_value(minimum_font_size_.GetValue()); | 288 base::FundamentalValue size_value(minimum_font_size_.GetValue()); |
| 290 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", | 289 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample", |
| 291 size_value); | 290 size_value); |
| 292 } | 291 } |
| 293 | 292 |
| 294 const extensions::Extension* | 293 const extensions::Extension* |
| 295 FontSettingsHandler::GetAdvancedFontSettingsExtension() { | 294 FontSettingsHandler::GetAdvancedFontSettingsExtension() { |
| 296 Profile* profile = Profile::FromWebUI(web_ui()); | 295 Profile* profile = Profile::FromWebUI(web_ui()); |
| 297 ExtensionService* service = | 296 ExtensionService* service = |
| 298 extensions::ExtensionSystem::Get(profile)->extension_service(); | 297 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 299 if (!service->IsExtensionEnabled(kAdvancedFontSettingsExtensionId)) | 298 if (!service->IsExtensionEnabled(kAdvancedFontSettingsExtensionId)) |
| 300 return NULL; | 299 return NULL; |
| 301 return service->GetInstalledExtension(kAdvancedFontSettingsExtensionId); | 300 return service->GetInstalledExtension(kAdvancedFontSettingsExtensionId); |
| 302 } | 301 } |
| 303 | 302 |
| 304 void FontSettingsHandler::NotifyAdvancedFontSettingsAvailability() { | 303 void FontSettingsHandler::NotifyAdvancedFontSettingsAvailability() { |
| 305 web_ui()->CallJavascriptFunction( | 304 web_ui()->CallJavascriptFunctionUnsafe( |
| 306 "FontSettings.notifyAdvancedFontSettingsAvailability", | 305 "FontSettings.notifyAdvancedFontSettingsAvailability", |
| 307 base::FundamentalValue(GetAdvancedFontSettingsExtension() != NULL)); | 306 base::FundamentalValue(GetAdvancedFontSettingsExtension() != NULL)); |
| 308 } | 307 } |
| 309 | 308 |
| 310 void FontSettingsHandler::HandleOpenAdvancedFontSettingsOptions( | 309 void FontSettingsHandler::HandleOpenAdvancedFontSettingsOptions( |
| 311 const base::ListValue* args) { | 310 const base::ListValue* args) { |
| 312 const extensions::Extension* extension = GetAdvancedFontSettingsExtension(); | 311 const extensions::Extension* extension = GetAdvancedFontSettingsExtension(); |
| 313 if (!extension) | 312 if (!extension) |
| 314 return; | 313 return; |
| 315 extensions::ExtensionTabUtil::OpenOptionsPage(extension, | 314 extensions::ExtensionTabUtil::OpenOptionsPage(extension, |
| 316 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); | 315 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); |
| 317 } | 316 } |
| 318 | 317 |
| 319 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { | 318 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { |
| 320 SetUpStandardFontSample(); | 319 SetUpStandardFontSample(); |
| 321 SetUpSerifFontSample(); | 320 SetUpSerifFontSample(); |
| 322 SetUpSansSerifFontSample(); | 321 SetUpSansSerifFontSample(); |
| 323 } | 322 } |
| 324 | 323 |
| 325 } // namespace options | 324 } // namespace options |
| OLD | NEW |