Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/ui/prefs/prefs_tab_helper.cc

Issue 12902021: Auto-generates the font family scripts at build time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/renderer_preferences_util.h" 16 #include "chrome/browser/renderer_preferences_util.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/font_family_scripts.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chrome/common/pref_names_util.h" 20 #include "chrome/common/pref_names_util.h"
20 #include "components/user_prefs/pref_registry_syncable.h" 21 #include "components/user_prefs/pref_registry_syncable.h"
21 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "grit/locale_settings.h" 26 #include "grit/locale_settings.h"
26 #include "grit/platform_locale_settings.h" 27 #include "grit/platform_locale_settings.h"
27 #include "third_party/icu/public/common/unicode/uchar.h" 28 #include "third_party/icu/public/common/unicode/uchar.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 prefs::kWebkitTabsToLinks, 117 prefs::kWebkitTabsToLinks,
117 prefs::kWebKitUsesUniversalDetector 118 prefs::kWebKitUsesUniversalDetector
118 }; 119 };
119 120
120 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); 121 const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
121 122
122 // Registers a preference under the path |map_name| for each script used for 123 // 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 124 // per-script font prefs. For example, if |map_name| is "fonts.serif", then
124 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. 125 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered.
125 void RegisterFontFamilyMap(PrefRegistrySyncable* registry, 126 void RegisterFontFamilyMap(PrefRegistrySyncable* registry,
126 const char* map_name,
127 const std::set<std::string>& fonts_with_defaults) { 127 const std::set<std::string>& fonts_with_defaults) {
128 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 128 // kFontFamilyScripts is auto-generated at build time in order to
129 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 129 // have all the data in the static RO segment rather than heap allocated.
130 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script); 130 for (size_t i = 0; i < arraysize(kFontFamilyScripts); ++i) {
131 const char* pref_name = pref_name_str.c_str(); 131 const char* pref_name = kFontFamilyScripts[i];
132 if (fonts_with_defaults.find(pref_name) == fonts_with_defaults.end()) { 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 133 // We haven't already set a default value for this font preference, so set
134 // an empty string as the default. 134 // an empty string as the default.
135 registry->RegisterStringPref( 135 registry->RegisterStringPref(
136 pref_name, "", PrefRegistrySyncable::UNSYNCABLE_PREF); 136 pref_name, "", PrefRegistrySyncable::UNSYNCABLE_PREF);
137 } 137 }
138 } 138 }
139 } 139 }
140 140
141 // Registers |obs| to observe per-script font prefs under the path |map_name|. 141 // Registers |obs| to observe per-script font prefs under the path |map_name|.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (browser_script != pref_script) { 532 if (browser_script != pref_script) {
533 registry->RegisterLocalizedStringPref( 533 registry->RegisterLocalizedStringPref(
534 pref.pref_name, 534 pref.pref_name,
535 pref.resource_id, 535 pref.resource_id,
536 PrefRegistrySyncable::UNSYNCABLE_PREF); 536 PrefRegistrySyncable::UNSYNCABLE_PREF);
537 fonts_with_defaults.insert(pref.pref_name); 537 fonts_with_defaults.insert(pref.pref_name);
538 } 538 }
539 } 539 }
540 540
541 // Register font prefs that don't have defaults. 541 // Register font prefs that don't have defaults.
542 RegisterFontFamilyMap(registry, prefs::kWebKitStandardFontFamilyMap, 542 RegisterFontFamilyMap(registry, fonts_with_defaults);
543 fonts_with_defaults);
544 RegisterFontFamilyMap(registry, prefs::kWebKitFixedFontFamilyMap,
545 fonts_with_defaults);
546 RegisterFontFamilyMap(registry, prefs::kWebKitSerifFontFamilyMap,
547 fonts_with_defaults);
548 RegisterFontFamilyMap(registry, prefs::kWebKitSansSerifFontFamilyMap,
549 fonts_with_defaults);
550 RegisterFontFamilyMap(registry, prefs::kWebKitCursiveFontFamilyMap,
551 fonts_with_defaults);
552 RegisterFontFamilyMap(registry, prefs::kWebKitFantasyFontFamilyMap,
553 fonts_with_defaults);
554 RegisterFontFamilyMap(registry, prefs::kWebKitPictographFontFamilyMap,
555 fonts_with_defaults);
556 543
557 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, 544 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
558 IDS_DEFAULT_FONT_SIZE, 545 IDS_DEFAULT_FONT_SIZE,
559 PrefRegistrySyncable::UNSYNCABLE_PREF); 546 PrefRegistrySyncable::UNSYNCABLE_PREF);
560 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, 547 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
561 IDS_DEFAULT_FIXED_FONT_SIZE, 548 IDS_DEFAULT_FIXED_FONT_SIZE,
562 PrefRegistrySyncable::UNSYNCABLE_PREF); 549 PrefRegistrySyncable::UNSYNCABLE_PREF);
563 registry->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, 550 registry->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
564 IDS_MINIMUM_FONT_SIZE, 551 IDS_MINIMUM_FONT_SIZE,
565 PrefRegistrySyncable::UNSYNCABLE_PREF); 552 PrefRegistrySyncable::UNSYNCABLE_PREF);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 WebPreferences web_prefs = 641 WebPreferences web_prefs =
655 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); 642 web_contents_->GetRenderViewHost()->GetWebkitPreferences();
656 OverrideFontFamily(&web_prefs, generic_family, script, ""); 643 OverrideFontFamily(&web_prefs, generic_family, script, "");
657 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); 644 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs);
658 return; 645 return;
659 } 646 }
660 } 647 }
661 648
662 UpdateWebPreferences(); 649 UpdateWebPreferences();
663 } 650 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_browser_ui.gypi » ('j') | chrome/common/font_family_scripts_generator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698