| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 map = &prefs->cursive_font_family_map; | 317 map = &prefs->cursive_font_family_map; |
| 318 else if (generic_family == "fantasy") | 318 else if (generic_family == "fantasy") |
| 319 map = &prefs->fantasy_font_family_map; | 319 map = &prefs->fantasy_font_family_map; |
| 320 else if (generic_family == "pictograph") | 320 else if (generic_family == "pictograph") |
| 321 map = &prefs->pictograph_font_family_map; | 321 map = &prefs->pictograph_font_family_map; |
| 322 else | 322 else |
| 323 NOTREACHED() << "Unknown generic font family: " << generic_family; | 323 NOTREACHED() << "Unknown generic font family: " << generic_family; |
| 324 (*map)[script] = base::UTF8ToUTF16(pref_value); | 324 (*map)[script] = base::UTF8ToUTF16(pref_value); |
| 325 } | 325 } |
| 326 | 326 |
| 327 #if !defined(OS_ANDROID) |
| 327 void RegisterLocalizedFontPref(user_prefs::PrefRegistrySyncable* registry, | 328 void RegisterLocalizedFontPref(user_prefs::PrefRegistrySyncable* registry, |
| 328 const char* path, | 329 const char* path, |
| 329 int default_message_id) { | 330 int default_message_id) { |
| 330 int val = 0; | 331 int val = 0; |
| 331 bool success = base::StringToInt(l10n_util::GetStringUTF8( | 332 bool success = base::StringToInt(l10n_util::GetStringUTF8( |
| 332 default_message_id), &val); | 333 default_message_id), &val); |
| 333 DCHECK(success); | 334 DCHECK(success); |
| 334 registry->RegisterIntegerPref(path, val); | 335 registry->RegisterIntegerPref(path, val); |
| 335 } | 336 } |
| 337 #endif |
| 336 | 338 |
| 337 } // namespace | 339 } // namespace |
| 338 | 340 |
| 339 // Watching all these settings per tab is slow when a user has a lot of tabs and | 341 // Watching all these settings per tab is slow when a user has a lot of tabs and |
| 340 // and they use session restore. So watch them once per profile. | 342 // and they use session restore. So watch them once per profile. |
| 341 // http://crbug.com/452693 | 343 // http://crbug.com/452693 |
| 342 class PrefWatcher : public KeyedService { | 344 class PrefWatcher : public KeyedService { |
| 343 public: | 345 public: |
| 344 explicit PrefWatcher(Profile* profile) : profile_(profile) { | 346 explicit PrefWatcher(Profile* profile) : profile_(profile) { |
| 345 pref_change_registrar_.Init(profile_->GetPrefs()); | 347 pref_change_registrar_.Init(profile_->GetPrefs()); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 // can possibly be removed later if users can easily access per-script font | 580 // can possibly be removed later if users can easily access per-script font |
| 579 // prefs (e.g., via the extensions workflow), or the problem turns out to | 581 // prefs (e.g., via the extensions workflow), or the problem turns out to |
| 580 // not be really critical after all. | 582 // not be really critical after all. |
| 581 if (browser_script != pref_script) { | 583 if (browser_script != pref_script) { |
| 582 registry->RegisterStringPref(pref.pref_name, | 584 registry->RegisterStringPref(pref.pref_name, |
| 583 l10n_util::GetStringUTF8(pref.resource_id)); | 585 l10n_util::GetStringUTF8(pref.resource_id)); |
| 584 fonts_with_defaults.insert(pref.pref_name); | 586 fonts_with_defaults.insert(pref.pref_name); |
| 585 } | 587 } |
| 586 } | 588 } |
| 587 | 589 |
| 588 // Register per-script font prefs that don't have defaults. | 590 // Register font prefs. This is only configurable on desktop Chrome. |
| 589 #if !defined(OS_ANDROID) | 591 #if !defined(OS_ANDROID) |
| 590 RegisterFontFamilyPrefs(registry, fonts_with_defaults); | 592 RegisterFontFamilyPrefs(registry, fonts_with_defaults); |
| 591 #endif | |
| 592 | 593 |
| 593 RegisterLocalizedFontPref(registry, prefs::kWebKitDefaultFontSize, | 594 RegisterLocalizedFontPref(registry, prefs::kWebKitDefaultFontSize, |
| 594 IDS_DEFAULT_FONT_SIZE); | 595 IDS_DEFAULT_FONT_SIZE); |
| 595 RegisterLocalizedFontPref(registry, prefs::kWebKitDefaultFixedFontSize, | 596 RegisterLocalizedFontPref(registry, prefs::kWebKitDefaultFixedFontSize, |
| 596 IDS_DEFAULT_FIXED_FONT_SIZE); | 597 IDS_DEFAULT_FIXED_FONT_SIZE); |
| 597 RegisterLocalizedFontPref(registry, prefs::kWebKitMinimumFontSize, | 598 RegisterLocalizedFontPref(registry, prefs::kWebKitMinimumFontSize, |
| 598 IDS_MINIMUM_FONT_SIZE); | 599 IDS_MINIMUM_FONT_SIZE); |
| 599 RegisterLocalizedFontPref(registry, prefs::kWebKitMinimumLogicalFontSize, | 600 RegisterLocalizedFontPref(registry, prefs::kWebKitMinimumLogicalFontSize, |
| 600 IDS_MINIMUM_LOGICAL_FONT_SIZE); | 601 IDS_MINIMUM_LOGICAL_FONT_SIZE); |
| 602 #endif |
| 601 } | 603 } |
| 602 | 604 |
| 603 // static | 605 // static |
| 604 void PrefsTabHelper::GetServiceInstance() { | 606 void PrefsTabHelper::GetServiceInstance() { |
| 605 PrefWatcherFactory::GetInstance(); | 607 PrefWatcherFactory::GetInstance(); |
| 606 } | 608 } |
| 607 | 609 |
| 608 void PrefsTabHelper::Observe(int type, | 610 void PrefsTabHelper::Observe(int type, |
| 609 const content::NotificationSource& source, | 611 const content::NotificationSource& source, |
| 610 const content::NotificationDetails& details) { | 612 const content::NotificationDetails& details) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 } | 679 } |
| 678 | 680 |
| 679 void PrefsTabHelper::NotifyWebkitPreferencesChanged( | 681 void PrefsTabHelper::NotifyWebkitPreferencesChanged( |
| 680 const std::string& pref_name) { | 682 const std::string& pref_name) { |
| 681 #if !defined(OS_ANDROID) | 683 #if !defined(OS_ANDROID) |
| 682 OnFontFamilyPrefChanged(pref_name); | 684 OnFontFamilyPrefChanged(pref_name); |
| 683 #endif | 685 #endif |
| 684 | 686 |
| 685 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); | 687 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 686 } | 688 } |
| OLD | NEW |