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

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: Sort order 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
« no previous file with comments | « no previous file | chrome/common/pref_font_script_names-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 prefs::kWebKitLoadsImagesAutomatically, 113 prefs::kWebKitLoadsImagesAutomatically,
113 prefs::kWebKitMinimumFontSize, 114 prefs::kWebKitMinimumFontSize,
114 prefs::kWebKitMinimumLogicalFontSize, 115 prefs::kWebKitMinimumLogicalFontSize,
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 |pref_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.
125 // For example, for WEBKIT_WEBPREFS_FONTS_SERIF ("fonts.serif"):
124 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. 126 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered.
125 void RegisterFontFamilyMap(PrefRegistrySyncable* registry, 127 // |fonts_with_defaults| contains all |pref_names| already registered since they
126 const char* map_name, 128 // have a specified default value.
127 const std::set<std::string>& fonts_with_defaults) { 129 void RegisterFontFamilyPrefs(PrefRegistrySyncable* registry,
128 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 130 const std::set<std::string>& fonts_with_defaults) {
129 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 131
130 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script); 132 // Expand the font concatenated with script name so this stays at RO memory
131 const char* pref_name = pref_name_str.c_str(); 133 // rather than allocated in heap.
134 static const char* const kFontFamilyMap[] = {
135 #define EXPAND_SCRIPT_FONT(map_name, script_name) map_name "." script_name,
136
137 #include "chrome/common/pref_font_script_names-inl.h"
138 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_CURSIVE)
139 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_FANTASY)
140 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_FIXED)
141 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_PICTOGRAPH)
142 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_SANSERIF)
143 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_SERIF)
144 ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_STANDARD)
145
146 #undef EXPAND_SCRIPT_FONT
147 };
148
149 for (size_t i = 0; i < arraysize(kFontFamilyMap); ++i) {
150 const char* pref_name = kFontFamilyMap[i];
132 if (fonts_with_defaults.find(pref_name) == fonts_with_defaults.end()) { 151 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 152 // We haven't already set a default value for this font preference, so set
134 // an empty string as the default. 153 // an empty string as the default.
135 registry->RegisterStringPref( 154 registry->RegisterStringPref(
136 pref_name, "", PrefRegistrySyncable::UNSYNCABLE_PREF); 155 pref_name, "", PrefRegistrySyncable::UNSYNCABLE_PREF);
137 } 156 }
138 } 157 }
139 } 158 }
140 159
141 #if !defined(OS_ANDROID) 160 #if !defined(OS_ANDROID)
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 if (browser_script != pref_script) { 558 if (browser_script != pref_script) {
540 registry->RegisterLocalizedStringPref( 559 registry->RegisterLocalizedStringPref(
541 pref.pref_name, 560 pref.pref_name,
542 pref.resource_id, 561 pref.resource_id,
543 PrefRegistrySyncable::UNSYNCABLE_PREF); 562 PrefRegistrySyncable::UNSYNCABLE_PREF);
544 fonts_with_defaults.insert(pref.pref_name); 563 fonts_with_defaults.insert(pref.pref_name);
545 } 564 }
546 } 565 }
547 566
548 // Register font prefs that don't have defaults. 567 // Register font prefs that don't have defaults.
549 RegisterFontFamilyMap(registry, prefs::kWebKitStandardFontFamilyMap, 568 RegisterFontFamilyPrefs(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 569
564 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, 570 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
565 IDS_DEFAULT_FONT_SIZE, 571 IDS_DEFAULT_FONT_SIZE,
566 PrefRegistrySyncable::UNSYNCABLE_PREF); 572 PrefRegistrySyncable::UNSYNCABLE_PREF);
567 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, 573 registry->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
568 IDS_DEFAULT_FIXED_FONT_SIZE, 574 IDS_DEFAULT_FIXED_FONT_SIZE,
569 PrefRegistrySyncable::UNSYNCABLE_PREF); 575 PrefRegistrySyncable::UNSYNCABLE_PREF);
570 registry->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, 576 registry->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
571 IDS_MINIMUM_FONT_SIZE, 577 IDS_MINIMUM_FONT_SIZE,
572 PrefRegistrySyncable::UNSYNCABLE_PREF); 578 PrefRegistrySyncable::UNSYNCABLE_PREF);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 WebPreferences web_prefs = 667 WebPreferences web_prefs =
662 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); 668 web_contents_->GetRenderViewHost()->GetWebkitPreferences();
663 OverrideFontFamily(&web_prefs, generic_family, script, ""); 669 OverrideFontFamily(&web_prefs, generic_family, script, "");
664 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); 670 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs);
665 return; 671 return;
666 } 672 }
667 } 673 }
668 674
669 UpdateWebPreferences(); 675 UpdateWebPreferences();
670 } 676 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/pref_font_script_names-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698