| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/character_encoding.h" | 16 #include "chrome/browser/character_encoding.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/webui/options/font_settings_utils.h" | 19 #include "chrome/browser/ui/webui/options/font_settings_utils.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "content/browser/tab_contents/tab_contents.h" |
| 22 #include "content/common/notification_details.h" | 23 #include "content/common/notification_details.h" |
| 23 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 | 27 |
| 27 FontSettingsHandler::FontSettingsHandler() { | 28 FontSettingsHandler::FontSettingsHandler() { |
| 28 } | 29 } |
| 29 | 30 |
| 30 FontSettingsHandler::~FontSettingsHandler() { | 31 FontSettingsHandler::~FontSettingsHandler() { |
| 31 } | 32 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 SetUpFixedFontSample(); | 72 SetUpFixedFontSample(); |
| 72 SetUpMinimumFontSample(); | 73 SetUpMinimumFontSample(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 WebUIMessageHandler* FontSettingsHandler::Attach(WebUI* web_ui) { | 76 WebUIMessageHandler* FontSettingsHandler::Attach(WebUI* web_ui) { |
| 76 // Call through to superclass. | 77 // Call through to superclass. |
| 77 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); | 78 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); |
| 78 | 79 |
| 79 // Perform validation for saved fonts. | 80 // Perform validation for saved fonts. |
| 80 DCHECK(web_ui_); | 81 DCHECK(web_ui_); |
| 81 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 82 Profile* profile = |
| 83 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 84 PrefService* pref_service = profile->GetPrefs(); |
| 82 FontSettingsUtilities::ValidateSavedFonts(pref_service); | 85 FontSettingsUtilities::ValidateSavedFonts(pref_service); |
| 83 | 86 |
| 84 // Register for preferences that we need to observe manually. | 87 // Register for preferences that we need to observe manually. |
| 85 standard_font_.Init(prefs::kWebKitStandardFontFamily, pref_service, this); | 88 standard_font_.Init(prefs::kWebKitStandardFontFamily, pref_service, this); |
| 86 serif_font_.Init(prefs::kWebKitSerifFontFamily, pref_service, this); | 89 serif_font_.Init(prefs::kWebKitSerifFontFamily, pref_service, this); |
| 87 sans_serif_font_.Init(prefs::kWebKitSansSerifFontFamily, pref_service, this); | 90 sans_serif_font_.Init(prefs::kWebKitSansSerifFontFamily, pref_service, this); |
| 88 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, this); | 91 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, this); |
| 89 font_encoding_.Init(prefs::kDefaultCharset, pref_service, this); | 92 font_encoding_.Init(prefs::kDefaultCharset, pref_service, this); |
| 90 default_font_size_.Init(prefs::kWebKitDefaultFontSize, pref_service, this); | 93 default_font_size_.Init(prefs::kWebKitDefaultFontSize, pref_service, this); |
| 91 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, | 94 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 | 106 |
| 104 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { | 107 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { |
| 105 content::GetFontListAsync( | 108 content::GetFontListAsync( |
| 106 base::Bind(&FontSettingsHandler::FontsListHasLoaded, AsWeakPtr())); | 109 base::Bind(&FontSettingsHandler::FontsListHasLoaded, AsWeakPtr())); |
| 107 } | 110 } |
| 108 | 111 |
| 109 void FontSettingsHandler::FontsListHasLoaded( | 112 void FontSettingsHandler::FontsListHasLoaded( |
| 110 scoped_refptr<content::FontListResult> list) { | 113 scoped_refptr<content::FontListResult> list) { |
| 111 ListValue encoding_list; | 114 ListValue encoding_list; |
| 112 const std::vector<CharacterEncoding::EncodingInfo>* encodings; | 115 const std::vector<CharacterEncoding::EncodingInfo>* encodings; |
| 113 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 116 Profile* profile = |
| 117 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 118 PrefService* pref_service = profile->GetPrefs(); |
| 114 encodings = CharacterEncoding::GetCurrentDisplayEncodings( | 119 encodings = CharacterEncoding::GetCurrentDisplayEncodings( |
| 115 g_browser_process->GetApplicationLocale(), | 120 g_browser_process->GetApplicationLocale(), |
| 116 pref_service->GetString(prefs::kStaticEncodings), | 121 pref_service->GetString(prefs::kStaticEncodings), |
| 117 pref_service->GetString(prefs::kRecentlySelectedEncoding)); | 122 pref_service->GetString(prefs::kRecentlySelectedEncoding)); |
| 118 DCHECK(encodings); | 123 DCHECK(encodings); |
| 119 DCHECK(!encodings->empty()); | 124 DCHECK(!encodings->empty()); |
| 120 | 125 |
| 121 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; | 126 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; |
| 122 for (it = encodings->begin(); it != encodings->end(); ++it) { | 127 for (it = encodings->begin(); it != encodings->end(); ++it) { |
| 123 ListValue* option = new ListValue(); | 128 ListValue* option = new ListValue(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 FundamentalValue size_value(default_fixed_font_size_.GetValue()); | 204 FundamentalValue size_value(default_fixed_font_size_.GetValue()); |
| 200 web_ui_->CallJavascriptFunction( | 205 web_ui_->CallJavascriptFunction( |
| 201 "FontSettings.setUpFixedFontSample", font_value, size_value); | 206 "FontSettings.setUpFixedFontSample", font_value, size_value); |
| 202 } | 207 } |
| 203 | 208 |
| 204 void FontSettingsHandler::SetUpMinimumFontSample() { | 209 void FontSettingsHandler::SetUpMinimumFontSample() { |
| 205 FundamentalValue size_value(minimum_font_size_.GetValue()); | 210 FundamentalValue size_value(minimum_font_size_.GetValue()); |
| 206 web_ui_->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", | 211 web_ui_->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", |
| 207 size_value); | 212 size_value); |
| 208 } | 213 } |
| OLD | NEW |