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

Side by Side Diff: chrome/browser/ui/tab_contents/tab_contents_wrapper.cc

Issue 8508002: Observe per-script font preferences so WebKit settings are updated when they change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: formatting Created 9 years, 1 month 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 | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tab_contents/tab_contents_wrapper.h" 5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const char* kPrefsToObserve[] = { 71 const char* kPrefsToObserve[] = {
72 prefs::kAlternateErrorPagesEnabled, 72 prefs::kAlternateErrorPagesEnabled,
73 prefs::kDefaultCharset, 73 prefs::kDefaultCharset,
74 prefs::kDefaultZoomLevel, 74 prefs::kDefaultZoomLevel,
75 prefs::kEnableReferrers, 75 prefs::kEnableReferrers,
76 #if defined (ENABLE_SAFE_BROWSING) 76 #if defined (ENABLE_SAFE_BROWSING)
77 prefs::kSafeBrowsingEnabled, 77 prefs::kSafeBrowsingEnabled,
78 #endif 78 #endif
79 prefs::kWebKitAllowDisplayingInsecureContent, 79 prefs::kWebKitAllowDisplayingInsecureContent,
80 prefs::kWebKitAllowRunningInsecureContent, 80 prefs::kWebKitAllowRunningInsecureContent,
81 prefs::kWebKitCursiveFontFamily,
81 prefs::kWebKitDefaultFixedFontSize, 82 prefs::kWebKitDefaultFixedFontSize,
82 prefs::kWebKitDefaultFontSize, 83 prefs::kWebKitDefaultFontSize,
84 prefs::kWebKitFantasyFontFamily,
83 prefs::kWebKitFixedFontFamily, 85 prefs::kWebKitFixedFontFamily,
84 prefs::kWebKitJavaEnabled, 86 prefs::kWebKitJavaEnabled,
85 prefs::kWebKitJavascriptEnabled, 87 prefs::kWebKitJavascriptEnabled,
86 prefs::kWebKitLoadsImagesAutomatically, 88 prefs::kWebKitLoadsImagesAutomatically,
87 prefs::kWebKitMinimumFontSize, 89 prefs::kWebKitMinimumFontSize,
88 prefs::kWebKitMinimumLogicalFontSize, 90 prefs::kWebKitMinimumLogicalFontSize,
89 prefs::kWebKitPluginsEnabled, 91 prefs::kWebKitPluginsEnabled,
90 prefs::kWebKitSansSerifFontFamily, 92 prefs::kWebKitSansSerifFontFamily,
91 prefs::kWebKitSerifFontFamily, 93 prefs::kWebKitSerifFontFamily,
92 prefs::kWebKitStandardFontFamily, 94 prefs::kWebKitStandardFontFamily,
93 prefs::kWebkitTabsToLinks, 95 prefs::kWebkitTabsToLinks,
94 prefs::kWebKitUsesUniversalDetector 96 prefs::kWebKitUsesUniversalDetector
95 }; 97 };
96 98
97 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); 99 const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
98 100
99 // Registers a preference under the path |map_name| for each script used for 101 // Registers a preference under the path |map_name| for each script used for
100 // per-script font prefs. For example, if |map_name| is "fonts.serif", then 102 // per-script font prefs. For example, if |map_name| is "fonts.serif", then
101 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered. 103 // "fonts.serif.Arab", "fonts.serif.Hang", etc. are registered.
102 void RegisterFontFamilyMap(PrefService* prefs, const char* map_name) { 104 void RegisterFontFamilyMap(PrefService* prefs, const char* map_name) {
103 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 105 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
104 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 106 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
105 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script); 107 std::string pref_name_str = base::StringPrintf("%s.%s", map_name, script);
106 const char* pref_name = pref_name_str.c_str(); 108 const char* pref_name = pref_name_str.c_str();
107 if (!prefs->FindPreference(pref_name)) 109 if (!prefs->FindPreference(pref_name))
108 prefs->RegisterStringPref(pref_name, "", PrefService::UNSYNCABLE_PREF); 110 prefs->RegisterStringPref(pref_name, "", PrefService::UNSYNCABLE_PREF);
109 } 111 }
110 } 112 }
111 113
114 // Registers |obs| to observe per-script font prefs under the path |map_name|.
115 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar,
116 const char* map_name,
117 content::NotificationObserver* obs) {
118 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
119 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
120 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
121 registrar->Add(pref_name.c_str(), obs);
122 }
123 }
124
112 struct PerScriptFontDefault { 125 struct PerScriptFontDefault {
113 const char* pref_name; 126 const char* pref_name;
114 int resource_id; 127 int resource_id;
115 const char* native_locale; 128 const char* native_locale;
116 }; 129 };
117 130
118 // Per-script font pref defaults. The prefs that have defaults vary by 131 // Per-script font pref defaults. The prefs that have defaults vary by
119 // platform, since not all platforms have fonts for all scripts for all generic 132 // platform, since not all platforms have fonts for all scripts for all generic
120 // families. 133 // families.
121 // TODO(falken): add proper defaults when possible for all 134 // TODO(falken): add proper defaults when possible for all
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 content::Source<ThemeService>( 325 content::Source<ThemeService>(
313 ThemeServiceFactory::GetForProfile(profile()))); 326 ThemeServiceFactory::GetForProfile(profile())));
314 #endif 327 #endif
315 328
316 // Register for notifications about all interested prefs change. 329 // Register for notifications about all interested prefs change.
317 PrefService* prefs = profile()->GetPrefs(); 330 PrefService* prefs = profile()->GetPrefs();
318 pref_change_registrar_.Init(prefs); 331 pref_change_registrar_.Init(prefs);
319 if (prefs) { 332 if (prefs) {
320 for (int i = 0; i < kPrefsToObserveLength; ++i) 333 for (int i = 0; i < kPrefsToObserveLength; ++i)
321 pref_change_registrar_.Add(kPrefsToObserve[i], this); 334 pref_change_registrar_.Add(kPrefsToObserve[i], this);
335
336 RegisterFontFamilyMapObserver(&pref_change_registrar_,
337 prefs::kWebKitStandardFontFamilyMap, this);
338 RegisterFontFamilyMapObserver(&pref_change_registrar_,
339 prefs::kWebKitFixedFontFamilyMap, this);
340 RegisterFontFamilyMapObserver(&pref_change_registrar_,
341 prefs::kWebKitSerifFontFamilyMap, this);
342 RegisterFontFamilyMapObserver(&pref_change_registrar_,
343 prefs::kWebKitSansSerifFontFamilyMap, this);
344 RegisterFontFamilyMapObserver(&pref_change_registrar_,
345 prefs::kWebKitCursiveFontFamilyMap, this);
346 RegisterFontFamilyMapObserver(&pref_change_registrar_,
347 prefs::kWebKitFantasyFontFamilyMap, this);
322 } 348 }
323 349
324 renderer_preferences_util::UpdateFromSystemSettings( 350 renderer_preferences_util::UpdateFromSystemSettings(
325 tab_contents()->GetMutableRendererPrefs(), profile()); 351 tab_contents()->GetMutableRendererPrefs(), profile());
326 } 352 }
327 353
328 TabContentsWrapper::~TabContentsWrapper() { 354 TabContentsWrapper::~TabContentsWrapper() {
329 in_destructor_ = true; 355 in_destructor_ = true;
330 356
331 // Need to tear down infobars before the TabContents goes away. 357 // Need to tear down infobars before the TabContents goes away.
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 render_view_host()->Send( 711 render_view_host()->Send(
686 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(), 712 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(),
687 safe_browsing)); 713 safe_browsing));
688 #endif 714 #endif
689 } 715 }
690 716
691 void TabContentsWrapper::ExitFullscreenMode() { 717 void TabContentsWrapper::ExitFullscreenMode() {
692 if (tab_contents() && render_view_host()) 718 if (tab_contents() && render_view_host())
693 tab_contents()->render_view_host()->ExitFullscreen(); 719 tab_contents()->render_view_host()->ExitFullscreen();
694 } 720 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698