Chromium Code Reviews| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 prefs::kWebKitLoadsImagesAutomatically, | 131 prefs::kWebKitLoadsImagesAutomatically, |
| 132 prefs::kWebKitMinimumFontSize, | 132 prefs::kWebKitMinimumFontSize, |
| 133 prefs::kWebKitMinimumLogicalFontSize, | 133 prefs::kWebKitMinimumLogicalFontSize, |
| 134 prefs::kWebKitPluginsEnabled, | 134 prefs::kWebKitPluginsEnabled, |
| 135 prefs::kWebkitTabsToLinks, | 135 prefs::kWebkitTabsToLinks, |
| 136 prefs::kWebKitUsesUniversalDetector | 136 prefs::kWebKitUsesUniversalDetector |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); | 139 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 140 | 140 |
| 141 #if !defined(OS_ANDROID) | |
| 141 // Registers a preference under the path |pref_name| for each script used for | 142 // Registers a preference under the path |pref_name| for each script used for |
| 142 // per-script font prefs. | 143 // per-script font prefs. |
| 143 // For example, for WEBKIT_WEBPREFS_FONTS_SERIF ("fonts.serif"): | 144 // For example, for WEBKIT_WEBPREFS_FONTS_SERIF ("fonts.serif"): |
| 144 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. | 145 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. |
| 145 // |fonts_with_defaults| contains all |pref_names| already registered since they | 146 // |fonts_with_defaults| contains all |pref_names| already registered since they |
| 146 // have a specified default value. | 147 // have a specified default value. |
| 148 // On Android there are no default values for these properties and there is no | |
| 149 // way to set them, so we can avoid registering them altogether. | |
|
falken
2013/10/17 12:23:29
Maybe mention that the way to set them on other pl
ppi
2013/10/17 16:49:04
Done.
| |
| 147 void RegisterFontFamilyPrefs(user_prefs::PrefRegistrySyncable* registry, | 150 void RegisterFontFamilyPrefs(user_prefs::PrefRegistrySyncable* registry, |
| 148 const std::set<std::string>& fonts_with_defaults) { | 151 const std::set<std::string>& fonts_with_defaults) { |
| 149 | 152 |
| 150 // Expand the font concatenated with script name so this stays at RO memory | 153 // Expand the font concatenated with script name so this stays at RO memory |
| 151 // rather than allocated in heap. | 154 // rather than allocated in heap. |
| 152 static const char* const kFontFamilyMap[] = { | 155 static const char* const kFontFamilyMap[] = { |
| 153 #define EXPAND_SCRIPT_FONT(map_name, script_name) map_name "." script_name, | 156 #define EXPAND_SCRIPT_FONT(map_name, script_name) map_name "." script_name, |
| 154 | 157 |
| 155 #include "chrome/common/pref_font_script_names-inl.h" | 158 #include "chrome/common/pref_font_script_names-inl.h" |
| 156 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_CURSIVE) | 159 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_CURSIVE) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 170 // We haven't already set a default value for this font preference, so set | 173 // We haven't already set a default value for this font preference, so set |
| 171 // an empty string as the default. | 174 // an empty string as the default. |
| 172 registry->RegisterStringPref( | 175 registry->RegisterStringPref( |
| 173 pref_name, | 176 pref_name, |
| 174 std::string(), | 177 std::string(), |
| 175 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 178 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 176 } | 179 } |
| 177 } | 180 } |
| 178 } | 181 } |
| 179 | 182 |
| 180 #if !defined(OS_ANDROID) | |
| 181 // Registers |obs| to observe per-script font prefs under the path |map_name|. | 183 // Registers |obs| to observe per-script font prefs under the path |map_name|. |
| 182 // On android, there's no exposed way to change these prefs, so we can save | 184 // On android, there's no exposed way to change these prefs, so we can save |
| 183 // ~715KB of heap and some startup cycles by avoiding observing these prefs | 185 // ~715KB of heap and some startup cycles by avoiding observing these prefs |
| 184 // since they will never change. | 186 // since they will never change. |
| 185 void RegisterFontFamilyMapObserver( | 187 void RegisterFontFamilyMapObserver( |
| 186 PrefChangeRegistrar* registrar, | 188 PrefChangeRegistrar* registrar, |
| 187 const char* map_name, | 189 const char* map_name, |
| 188 const PrefChangeRegistrar::NamedChangeCallback& obs) { | 190 const PrefChangeRegistrar::NamedChangeCallback& obs) { |
| 189 DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true)); | 191 DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true)); |
| 190 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { | 192 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 // not be really critical after all. | 607 // not be really critical after all. |
| 606 if (browser_script != pref_script) { | 608 if (browser_script != pref_script) { |
| 607 registry->RegisterLocalizedStringPref( | 609 registry->RegisterLocalizedStringPref( |
| 608 pref.pref_name, | 610 pref.pref_name, |
| 609 pref.resource_id, | 611 pref.resource_id, |
| 610 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 612 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 611 fonts_with_defaults.insert(pref.pref_name); | 613 fonts_with_defaults.insert(pref.pref_name); |
| 612 } | 614 } |
| 613 } | 615 } |
| 614 | 616 |
| 615 // Register font prefs that don't have defaults. | 617 // Register per-script font prefs that don't have defaults. |
| 618 #if !defined(OS_ANDROID) | |
| 616 RegisterFontFamilyPrefs(registry, fonts_with_defaults); | 619 RegisterFontFamilyPrefs(registry, fonts_with_defaults); |
| 620 #endif | |
| 617 | 621 |
| 618 registry->RegisterLocalizedIntegerPref( | 622 registry->RegisterLocalizedIntegerPref( |
| 619 prefs::kWebKitDefaultFontSize, | 623 prefs::kWebKitDefaultFontSize, |
| 620 IDS_DEFAULT_FONT_SIZE, | 624 IDS_DEFAULT_FONT_SIZE, |
| 621 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 625 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 622 registry->RegisterLocalizedIntegerPref( | 626 registry->RegisterLocalizedIntegerPref( |
| 623 prefs::kWebKitDefaultFixedFontSize, | 627 prefs::kWebKitDefaultFixedFontSize, |
| 624 IDS_DEFAULT_FIXED_FONT_SIZE, | 628 IDS_DEFAULT_FIXED_FONT_SIZE, |
| 625 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 629 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 626 registry->RegisterLocalizedIntegerPref( | 630 registry->RegisterLocalizedIntegerPref( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 WebPreferences web_prefs = | 721 WebPreferences web_prefs = |
| 718 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); | 722 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); |
| 719 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); | 723 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); |
| 720 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); | 724 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); |
| 721 return; | 725 return; |
| 722 } | 726 } |
| 723 } | 727 } |
| 724 | 728 |
| 725 UpdateWebPreferences(); | 729 UpdateWebPreferences(); |
| 726 } | 730 } |
| OLD | NEW |