| 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/prefs/prefs_tab_helper.h" | 5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/prefs/overlay_user_pref_store.h" | 9 #include "base/prefs/overlay_user_pref_store.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 #endif // !defined(OS_ANDROID) | 124 #endif // !defined(OS_ANDROID) |
| 125 | 125 |
| 126 // Registers |obs| to observe per-script font prefs under the path |map_name|. | 126 // Registers |obs| to observe per-script font prefs under the path |map_name|. |
| 127 // On android, there's no exposed way to change these prefs, so we can save | 127 // On android, there's no exposed way to change these prefs, so we can save |
| 128 // ~715KB of heap and some startup cycles by avoiding observing these prefs | 128 // ~715KB of heap and some startup cycles by avoiding observing these prefs |
| 129 // since they will never change. | 129 // since they will never change. |
| 130 void RegisterFontFamilyMapObserver( | 130 void RegisterFontFamilyMapObserver( |
| 131 PrefChangeRegistrar* registrar, | 131 PrefChangeRegistrar* registrar, |
| 132 const char* map_name, | 132 const char* map_name, |
| 133 const PrefChangeRegistrar::NamedChangeCallback& obs) { | 133 const PrefChangeRegistrar::NamedChangeCallback& obs) { |
| 134 bool result = StartsWithASCII(map_name, "webkit.webprefs.", true); | 134 DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true)); |
| 135 DCHECK(result); | 135 |
| 136 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { | 136 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 137 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; | 137 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 138 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); | 138 registrar->Add(base::StringPrintf("%s.%s", map_name, script), obs); |
| 139 registrar->Add(pref_name.c_str(), obs); | |
| 140 } | 139 } |
| 141 } | 140 } |
| 142 | 141 |
| 143 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
| 144 // On Windows with antialising we want to use an alternate fixed font like | 143 // On Windows with antialising we want to use an alternate fixed font like |
| 145 // Consolas, which looks much better than Courier New. | 144 // Consolas, which looks much better than Courier New. |
| 146 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) { | 145 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) { |
| 147 if (!StartsWithASCII(script, "courier", false)) | 146 if (!StartsWithASCII(script, "courier", false)) |
| 148 return false; | 147 return false; |
| 149 UINT smooth_type = 0; | 148 UINT smooth_type = 0; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 // is normally okay since WebKit does the desired fallback behavior regardless | 624 // is normally okay since WebKit does the desired fallback behavior regardless |
| 626 // of whether the empty string is passed or the pref is not passed at all. But | 625 // of whether the empty string is passed or the pref is not passed at all. But |
| 627 // if the pref has changed from non-empty to the empty string, we must let | 626 // if the pref has changed from non-empty to the empty string, we must let |
| 628 // WebKit know. | 627 // WebKit know. |
| 629 std::string generic_family; | 628 std::string generic_family; |
| 630 std::string script; | 629 std::string script; |
| 631 if (pref_names_util::ParseFontNamePrefPath(pref_name, | 630 if (pref_names_util::ParseFontNamePrefPath(pref_name, |
| 632 &generic_family, | 631 &generic_family, |
| 633 &script)) { | 632 &script)) { |
| 634 PrefService* prefs = GetProfile()->GetPrefs(); | 633 PrefService* prefs = GetProfile()->GetPrefs(); |
| 635 std::string pref_value = prefs->GetString(pref_name.c_str()); | 634 std::string pref_value = prefs->GetString(pref_name); |
| 636 if (pref_value.empty()) { | 635 if (pref_value.empty()) { |
| 637 WebPreferences web_prefs = | 636 WebPreferences web_prefs = |
| 638 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); | 637 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); |
| 639 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); | 638 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); |
| 640 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); | 639 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); |
| 641 return; | 640 return; |
| 642 } | 641 } |
| 643 } | 642 } |
| 644 } | 643 } |
| 645 | 644 |
| 646 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { | 645 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { |
| 647 #if !defined(OS_ANDROID) | 646 #if !defined(OS_ANDROID) |
| 648 OnFontFamilyPrefChanged(pref_name); | 647 OnFontFamilyPrefChanged(pref_name); |
| 649 #endif | 648 #endif |
| 650 | 649 |
| 651 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); | 650 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 652 } | 651 } |
| OLD | NEW |