Chromium Code Reviews| Index: chrome/browser/ui/webui/settings_utils_mac.mm |
| diff --git a/chrome/browser/ui/webui/settings_utils_mac.mm b/chrome/browser/ui/webui/settings_utils_mac.mm |
| index 1f68f49dae76f40078fb7fca2922d7fea7b175a3..9796d0a2eea44e886669d96968c7355eea0700f3 100644 |
| --- a/chrome/browser/ui/webui/settings_utils_mac.mm |
| +++ b/chrome/browser/ui/webui/settings_utils_mac.mm |
| @@ -9,6 +9,31 @@ |
| #include "base/logging.h" |
| #include "base/mac/mac_logging.h" |
| #include "base/mac/scoped_aedesc.h" |
| +#include "base/mac/scoped_nsautorelease_pool.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "base/values.h" |
|
Lei Zhang
2017/06/09 04:22:54
Not needed?
Dan Beam
2017/06/09 06:32:55
Done.
|
| +#include "chrome/common/pref_names.h" |
| +#include "components/prefs/pref_service.h" |
| + |
| +namespace { |
| + |
| +void ValidateFontFamily(PrefService* prefs, const char* family_pref_name) { |
| + // The native font settings dialog saved fonts by the font name, rather |
| + // than the family name. This worked for the old dialog since |
| + // -[NSFont fontWithName:size] accepted a font or family name, but the |
| + // behavior was technically wrong. Since we really need the family name for |
| + // the webui settings window, we will fix the saved preference if necessary. |
| + NSString* family_name = |
| + base::SysUTF8ToNSString(prefs->GetString(family_pref_name)); |
| + NSFont* font = [NSFont fontWithName:family_name size:[NSFont systemFontSize]]; |
| + if (font && |
| + [[font familyName] caseInsensitiveCompare:family_name] != NSOrderedSame) { |
| + std::string new_family_name = base::SysNSStringToUTF8([font familyName]); |
| + prefs->SetString(family_pref_name, new_family_name); |
| + } |
| +} |
| + |
| +} |
| namespace settings_utils { |
| @@ -41,4 +66,10 @@ void ShowManageSSLCertificates(content::WebContents* web_contents) { |
| launchIdentifier:nil]; |
| } |
| +void ValidateSavedFonts(PrefService* prefs) { |
| + ValidateFontFamily(prefs, prefs::kWebKitSerifFontFamily); |
| + ValidateFontFamily(prefs, prefs::kWebKitSansSerifFontFamily); |
| + ValidateFontFamily(prefs, prefs::kWebKitFixedFontFamily); |
| +} |
| + |
| } // namespace settings_utils |