| 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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 prefs::kWebKitPluginsEnabled, | 115 prefs::kWebKitPluginsEnabled, |
| 116 prefs::kWebkitTabsToLinks, | 116 prefs::kWebkitTabsToLinks, |
| 117 prefs::kWebKitUsesUniversalDetector | 117 prefs::kWebKitUsesUniversalDetector |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); | 120 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 121 | 121 |
| 122 // Registers a preference under the path |map_name| for each script used for | 122 // Registers a preference under the path |map_name| for each script used for |
| 123 // per-script font prefs. For example, if |map_name| is "fonts.serif", then | 123 // per-script font prefs. For example, if |map_name| is "fonts.serif", then |
| 124 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. | 124 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. |
| 125 void RegisterFontFamilyMap(PrefService* prefs, const char* map_name) { | 125 void RegisterFontFamilyMap(PrefService* prefs, |
| 126 const char* map_name, |
| 127 const std::set<std::string>& fonts_with_defaults) { |
| 126 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { | 128 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 127 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; | 129 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 128 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script); | 130 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script); |
| 129 const char* pref_name = pref_name_str.c_str(); | 131 const char* pref_name = pref_name_str.c_str(); |
| 130 if (!prefs->FindPreference(pref_name)) | 132 if (fonts_with_defaults.find(pref_name) == fonts_with_defaults.end()) { |
| 133 // We haven't already set a default value for this font preference, so set |
| 134 // an empty string as the default. |
| 131 prefs->RegisterStringPref(pref_name, "", PrefService::UNSYNCABLE_PREF); | 135 prefs->RegisterStringPref(pref_name, "", PrefService::UNSYNCABLE_PREF); |
| 136 } |
| 132 } | 137 } |
| 133 } | 138 } |
| 134 | 139 |
| 135 // Registers |obs| to observe per-script font prefs under the path |map_name|. | 140 // Registers |obs| to observe per-script font prefs under the path |map_name|. |
| 136 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar, | 141 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar, |
| 137 const char* map_name, | 142 const char* map_name, |
| 138 content::NotificationObserver* obs) { | 143 content::NotificationObserver* obs) { |
| 139 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { | 144 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 140 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; | 145 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 141 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); | 146 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // Not used in OSX. | 466 // Not used in OSX. |
| 462 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages, | 467 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages, |
| 463 IDS_ACCEPT_LANGUAGES, | 468 IDS_ACCEPT_LANGUAGES, |
| 464 PrefService::UNSYNCABLE_PREF); | 469 PrefService::UNSYNCABLE_PREF); |
| 465 #endif | 470 #endif |
| 466 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset, | 471 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset, |
| 467 IDS_DEFAULT_ENCODING, | 472 IDS_DEFAULT_ENCODING, |
| 468 PrefService::SYNCABLE_PREF); | 473 PrefService::SYNCABLE_PREF); |
| 469 | 474 |
| 470 // Register font prefs that have defaults. | 475 // Register font prefs that have defaults. |
| 476 std::set<std::string> fonts_with_defaults; |
| 471 UScriptCode browser_script = GetScriptOfBrowserLocale(); | 477 UScriptCode browser_script = GetScriptOfBrowserLocale(); |
| 472 for (size_t i = 0; i < kFontDefaultsLength; ++i) { | 478 for (size_t i = 0; i < kFontDefaultsLength; ++i) { |
| 473 const FontDefault& pref = kFontDefaults[i]; | 479 const FontDefault& pref = kFontDefaults[i]; |
| 474 UScriptCode pref_script = GetScriptOfFontPref(pref.pref_name); | 480 UScriptCode pref_script = GetScriptOfFontPref(pref.pref_name); |
| 475 | 481 |
| 476 // Suppress this default font pref value if it is for the primary script of | 482 // Suppress this default font pref value if it is for the primary script of |
| 477 // the browser's UI locale. For example, if the pref is for the sans-serif | 483 // the browser's UI locale. For example, if the pref is for the sans-serif |
| 478 // font for the Cyrillic script, and the browser locale is "ru" (Russian), | 484 // font for the Cyrillic script, and the browser locale is "ru" (Russian), |
| 479 // the default is suppressed. Otherwise, the default would override the | 485 // the default is suppressed. Otherwise, the default would override the |
| 480 // user's font preferences when viewing pages in their native language. | 486 // user's font preferences when viewing pages in their native language. |
| 481 // This is because users have no way yet of customizing their per-script | 487 // This is because users have no way yet of customizing their per-script |
| 482 // font preferences. The font prefs accessible in the options UI are for | 488 // font preferences. The font prefs accessible in the options UI are for |
| 483 // the default, unknown script; these prefs have less priority than the | 489 // the default, unknown script; these prefs have less priority than the |
| 484 // per-script font prefs when the script of the content is known. This code | 490 // per-script font prefs when the script of the content is known. This code |
| 485 // can possibly be removed later if users can easily access per-script font | 491 // can possibly be removed later if users can easily access per-script font |
| 486 // prefs (e.g., via the extensions workflow), or the problem turns out to | 492 // prefs (e.g., via the extensions workflow), or the problem turns out to |
| 487 // not be really critical after all. | 493 // not be really critical after all. |
| 488 if (browser_script != pref_script) { | 494 if (browser_script != pref_script) { |
| 489 prefs->RegisterLocalizedStringPref(pref.pref_name, | 495 prefs->RegisterLocalizedStringPref(pref.pref_name, |
| 490 pref.resource_id, | 496 pref.resource_id, |
| 491 PrefService::UNSYNCABLE_PREF); | 497 PrefService::UNSYNCABLE_PREF); |
| 498 fonts_with_defaults.insert(pref.pref_name); |
| 492 } | 499 } |
| 493 } | 500 } |
| 494 | 501 |
| 495 // Register font prefs that don't have defaults. | 502 // Register font prefs that don't have defaults. |
| 496 RegisterFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap); | 503 RegisterFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, |
| 497 RegisterFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap); | 504 fonts_with_defaults); |
| 498 RegisterFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap); | 505 RegisterFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, |
| 499 RegisterFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap); | 506 fonts_with_defaults); |
| 500 RegisterFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap); | 507 RegisterFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, |
| 501 RegisterFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap); | 508 fonts_with_defaults); |
| 502 RegisterFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap); | 509 RegisterFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, |
| 510 fonts_with_defaults); |
| 511 RegisterFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, |
| 512 fonts_with_defaults); |
| 513 RegisterFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, |
| 514 fonts_with_defaults); |
| 515 RegisterFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap, |
| 516 fonts_with_defaults); |
| 503 | 517 |
| 504 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, | 518 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, |
| 505 IDS_DEFAULT_FONT_SIZE, | 519 IDS_DEFAULT_FONT_SIZE, |
| 506 PrefService::UNSYNCABLE_PREF); | 520 PrefService::UNSYNCABLE_PREF); |
| 507 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, | 521 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, |
| 508 IDS_DEFAULT_FIXED_FONT_SIZE, | 522 IDS_DEFAULT_FIXED_FONT_SIZE, |
| 509 PrefService::UNSYNCABLE_PREF); | 523 PrefService::UNSYNCABLE_PREF); |
| 510 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, | 524 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, |
| 511 IDS_MINIMUM_FONT_SIZE, | 525 IDS_MINIMUM_FONT_SIZE, |
| 512 PrefService::UNSYNCABLE_PREF); | 526 PrefService::UNSYNCABLE_PREF); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 | 581 |
| 568 void PrefsTabHelper::UpdateRendererPreferences() { | 582 void PrefsTabHelper::UpdateRendererPreferences() { |
| 569 renderer_preferences_util::UpdateFromSystemSettings( | 583 renderer_preferences_util::UpdateFromSystemSettings( |
| 570 web_contents_->GetMutableRendererPrefs(), GetProfile()); | 584 web_contents_->GetMutableRendererPrefs(), GetProfile()); |
| 571 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 585 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
| 572 } | 586 } |
| 573 | 587 |
| 574 Profile* PrefsTabHelper::GetProfile() { | 588 Profile* PrefsTabHelper::GetProfile() { |
| 575 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 589 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 576 } | 590 } |
| OLD | NEW |