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

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: Uses pre-processor 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/pref_font_webkit_names.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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 prefs::kWebKitPluginsEnabled, 116 prefs::kWebKitPluginsEnabled,
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,
falken 2013/03/19 18:26:04 Can you update this comment and change the functio
bulach 2013/03/20 11:01:27 Done.
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
129 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 129 // Expand the font concatenated with script name so this stays at RO memory
130 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script); 130 // rather than allocated in heap.
131 const char* pref_name = pref_name_str.c_str(); 131 static const char* const kFontFamilyMap[] = {
132 #define EXPAND_SCRIPT_FONT(map_name, script_name) map_name "." script_name,
133
134 #include "chrome/common/pref_font_script_names-inl.h"
135 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_CURSIVE)
136 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_FANTASY)
137 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_FIXED)
138 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_PICTOGRAPH)
139 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_SANSERIF)
140 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_SERIF)
141 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_STANDARD)
142
143 #undef EXPAND_SCRIPT_FONT
144 };
145
146 for (size_t i = 0; i < arraysize(kFontFamilyMap); ++i) {
147 const char* pref_name = kFontFamilyMap[i];
132 if (fonts_with_defaults.find(pref_name) == fonts_with_defaults.end()) { 148 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 149 // We haven't already set a default value for this font preference, so set
134 // an empty string as the default. 150 // an empty string as the default.
135 registry->RegisterStringPref( 151 registry->RegisterStringPref(
136 pref_name, "", PrefRegistrySyncable::UNSYNCABLE_PREF); 152 pref_name, "", PrefRegistrySyncable::UNSYNCABLE_PREF);
137 } 153 }
138 } 154 }
139 } 155 }
140 156
141 #if !defined(OS_ANDROID) 157 #if !defined(OS_ANDROID)
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 if (browser_script != pref_script) { 555 if (browser_script != pref_script) {
540 registry->RegisterLocalizedStringPref( 556 registry->RegisterLocalizedStringPref(
541 pref.pref_name, 557 pref.pref_name,
542 pref.resource_id, 558 pref.resource_id,
543 PrefRegistrySyncable::UNSYNCABLE_PREF); 559 PrefRegistrySyncable::UNSYNCABLE_PREF);
544 fonts_with_defaults.insert(pref.pref_name); 560 fonts_with_defaults.insert(pref.pref_name);
545 } 561 }
546 } 562 }
547 563
548 // Register font prefs that don't have defaults. 564 // Register font prefs that don't have defaults.
549 RegisterFontFamilyMap(registry, prefs::kWebKitStandardFontFamilyMap, 565 RegisterFontFamilyMap(registry, fonts_with_defaults);
550 fonts_with_defaults);
551 RegisterFontFamilyMap(registry, prefs::kWebKitFixedFontFamilyMap,
552 fonts_with_defaults);
553 RegisterFontFamilyMap(registry, prefs::kWebKitSerifFontFamilyMap,
554 fonts_with_defaults);
555 RegisterFontFamilyMap(registry, prefs::kWebKitSansSerifFontFamilyMap,
556 fonts_with_defaults);
557 RegisterFontFamilyMap(registry, prefs::kWebKitCursiveFontFamilyMap,
558 fonts_with_defaults);
559 RegisterFontFamilyMap(registry, prefs::kWebKitFantasyFontFamilyMap,
560 fonts_with_defaults);
561 RegisterFontFamilyMap(registry, prefs::kWebKitPictographFontFamilyMap,
562 fonts_with_defaults);
563 566
564 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, 567 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
565 IDS_DEFAULT_FONT_SIZE, 568 IDS_DEFAULT_FONT_SIZE,
566 PrefRegistrySyncable::UNSYNCABLE_PREF); 569 PrefRegistrySyncable::UNSYNCABLE_PREF);
567 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, 570 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
568 IDS_DEFAULT_FIXED_FONT_SIZE, 571 IDS_DEFAULT_FIXED_FONT_SIZE,
569 PrefRegistrySyncable::UNSYNCABLE_PREF); 572 PrefRegistrySyncable::UNSYNCABLE_PREF);
570 registry->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, 573 registry->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
571 IDS_MINIMUM_FONT_SIZE, 574 IDS_MINIMUM_FONT_SIZE,
572 PrefRegistrySyncable::UNSYNCABLE_PREF); 575 PrefRegistrySyncable::UNSYNCABLE_PREF);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 WebPreferences web_prefs = 664 WebPreferences web_prefs =
662 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); 665 web_contents_->GetRenderViewHost()->GetWebkitPreferences();
663 OverrideFontFamily(&web_prefs, generic_family, script, ""); 666 OverrideFontFamily(&web_prefs, generic_family, script, "");
664 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); 667 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs);
665 return; 668 return;
666 } 669 }
667 } 670 }
668 671
669 UpdateWebPreferences(); 672 UpdateWebPreferences();
670 } 673 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/pref_font_script_names-inl.h » ('j') | chrome/common/pref_font_script_names-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698