| Index: chrome/browser/ui/prefs/prefs_tab_helper.cc
 | 
| diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc
 | 
| index 903cb9db07a159696e6323e9bb02e5fab2215af4..8074e6d0ba91edc723438f6fbc66b3c636d77b70 100644
 | 
| --- a/chrome/browser/ui/prefs/prefs_tab_helper.cc
 | 
| +++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc
 | 
| @@ -9,12 +9,14 @@
 | 
|  #include "base/prefs/overlay_user_pref_store.h"
 | 
|  #include "base/string_util.h"
 | 
|  #include "base/stringprintf.h"
 | 
| +#include "base/utf_string_conversions.h"
 | 
|  #include "chrome/browser/browser_process.h"
 | 
|  #include "chrome/browser/prefs/pref_service.h"
 | 
|  #include "chrome/browser/profiles/profile.h"
 | 
|  #include "chrome/browser/renderer_preferences_util.h"
 | 
|  #include "chrome/common/chrome_notification_types.h"
 | 
|  #include "chrome/common/pref_names.h"
 | 
| +#include "chrome/common/pref_names_util.h"
 | 
|  #include "content/public/browser/notification_details.h"
 | 
|  #include "content/public/browser/notification_service.h"
 | 
|  #include "content/public/browser/render_view_host.h"
 | 
| @@ -38,7 +40,7 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(PrefsTabHelper)
 | 
|  namespace {
 | 
|  
 | 
|  // Registers prefs only used for migration.
 | 
| -static void RegisterPrefsToMigrate(PrefService* prefs) {
 | 
| +void RegisterPrefsToMigrate(PrefService* prefs) {
 | 
|    prefs->RegisterLocalizedStringPref(prefs::kWebKitOldStandardFontFamily,
 | 
|                                       IDS_STANDARD_FONT_FAMILY,
 | 
|                                       PrefService::UNSYNCABLE_PREF);
 | 
| @@ -332,7 +334,7 @@ const struct {
 | 
|  
 | 
|  const int kPrefsToMigrateLength = ARRAYSIZE_UNSAFE(kPrefNamesToMigrate);
 | 
|  
 | 
| -static void MigratePreferences(PrefService* prefs) {
 | 
| +void MigratePreferences(PrefService* prefs) {
 | 
|    RegisterPrefsToMigrate(prefs);
 | 
|    for (int i = 0; i < kPrefsToMigrateLength; ++i) {
 | 
|      const PrefService::Preference* pref =
 | 
| @@ -346,6 +348,31 @@ static void MigratePreferences(PrefService* prefs) {
 | 
|    }
 | 
|  }
 | 
|  
 | 
| +// Sets a font family pref in |prefs| to |pref_value|.
 | 
| +void OverrideFontFamily(WebPreferences* prefs,
 | 
| +                        const std::string& generic_family,
 | 
| +                        const std::string& script,
 | 
| +                        const std::string& pref_value) {
 | 
| +  WebPreferences::ScriptFontFamilyMap* map = NULL;
 | 
| +  if (generic_family == "standard")
 | 
| +    map = &prefs->standard_font_family_map;
 | 
| +  else if (generic_family == "fixed")
 | 
| +    map = &prefs->fixed_font_family_map;
 | 
| +  else if (generic_family == "serif")
 | 
| +    map = &prefs->serif_font_family_map;
 | 
| +  else if (generic_family == "sansserif")
 | 
| +    map = &prefs->sans_serif_font_family_map;
 | 
| +  else if (generic_family == "cursive")
 | 
| +    map = &prefs->cursive_font_family_map;
 | 
| +  else if (generic_family == "fantasy")
 | 
| +    map = &prefs->fantasy_font_family_map;
 | 
| +  else if (generic_family == "pictograph")
 | 
| +    map = &prefs->pictograph_font_family_map;
 | 
| +  else
 | 
| +    NOTREACHED() << "Unknown generic font family: " << generic_family;
 | 
| +  (*map)[script] = UTF8ToUTF16(pref_value);
 | 
| +}
 | 
| +
 | 
|  }  // namespace
 | 
|  
 | 
|  PrefsTabHelper::PrefsTabHelper(WebContents* contents)
 | 
| @@ -545,7 +572,7 @@ void PrefsTabHelper::Observe(int type,
 | 
|                   GetProfile()->GetPrefs());
 | 
|        if (*pref_name_in == prefs::kDefaultCharset ||
 | 
|            StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
 | 
| -        UpdateWebPreferences();
 | 
| +        OnWebPrefChanged(*pref_name_in);
 | 
|        } else if (*pref_name_in == prefs::kDefaultZoomLevel ||
 | 
|                   *pref_name_in == prefs::kEnableReferrers ||
 | 
|                   *pref_name_in == prefs::kEnableDoNotTrack) {
 | 
| @@ -574,3 +601,35 @@ void PrefsTabHelper::UpdateRendererPreferences() {
 | 
|  Profile* PrefsTabHelper::GetProfile() {
 | 
|    return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
 | 
|  }
 | 
| +
 | 
| +void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) {
 | 
| +  // When a font family pref's value goes from non-empty to the empty string, we
 | 
| +  // must add it to the usual WebPreferences struct passed to the renderer.
 | 
| +  //
 | 
| +  // The empty string means to fall back to the pref for the Common script
 | 
| +  // ("Zyyy").  For example, if chrome.fonts.serif.Cyrl is the empty string, it
 | 
| +  // means to use chrome.fonts.serif.Zyyy for Cyrillic script. Prefs that are
 | 
| +  // the empty string are normally not passed to WebKit, since there are so many
 | 
| +  // of them that it would cause a performance regression. Not passing the pref
 | 
| +  // is normally okay since WebKit does the desired fallback behavior regardless
 | 
| +  // of whether the empty string is passed or the pref is not passed at all. But
 | 
| +  // if the pref has changed from non-empty to the empty string, we must let
 | 
| +  // WebKit know.
 | 
| +  std::string generic_family;
 | 
| +  std::string script;
 | 
| +  if (pref_names_util::ParseFontNamePrefPath(pref_name,
 | 
| +                                             &generic_family,
 | 
| +                                             &script)) {
 | 
| +    PrefService* prefs = GetProfile()->GetPrefs();
 | 
| +    std::string pref_value = prefs->GetString(pref_name.c_str());
 | 
| +    if (pref_value.empty()) {
 | 
| +      WebPreferences web_prefs =
 | 
| +          web_contents_->GetRenderViewHost()->GetWebkitPreferences();
 | 
| +      OverrideFontFamily(&web_prefs, generic_family, script, "");
 | 
| +      web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs);
 | 
| +      return;
 | 
| +    }
 | 
| +  }
 | 
| +
 | 
| +  UpdateWebPreferences();
 | 
| +}
 | 
| 
 |