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

Side by Side Diff: chrome/browser/ui/webui/settings/font_handler.cc

Issue 1405453002: [MD settings] adding c++ side of font settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 'review changes' Created 5 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/settings/font_handler.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/i18n/rtl.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/character_encoding.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/webui/options/font_settings_utils.h"
14 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/font_list_async.h"
16 #include "content/public/browser/web_ui.h"
17
18 namespace settings {
19
20 FontHandler::FontHandler(content::WebUI* webui)
21 : weak_ptr_factory_(this) {
22 // Perform validation for saved fonts.
23 PrefService* pref_service = Profile::FromWebUI(webui)->GetPrefs();
24 options::FontSettingsUtilities::ValidateSavedFonts(pref_service);
25 }
26
27 FontHandler::~FontHandler() {}
28
29 void FontHandler::RegisterMessages() {
30 web_ui()->RegisterMessageCallback(
31 "fetchFontsData", base::Bind(&FontHandler::HandleFetchFontsData,
32 base::Unretained(this)));
33 }
34
35 void FontHandler::HandleFetchFontsData(
36 const base::ListValue* /*args*/) {
37 content::GetFontListAsync(base::Bind(&FontHandler::FontListHasLoaded,
38 weak_ptr_factory_.GetWeakPtr()));
39 }
40
41 void FontHandler::FontListHasLoaded(scoped_ptr<base::ListValue> list) {
42 // Font list. Selects the directionality for the fonts in the given list.
43 for (size_t i = 0; i < list->GetSize(); i++) {
44 base::ListValue* font;
45 bool has_font = list->GetList(i, &font);
46 DCHECK(has_font);
47
48 base::string16 value;
49 bool has_value = font->GetString(1, &value);
50 DCHECK(has_value);
51
52 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value);
53 font->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr"));
54 }
55
56 // Character encoding list.
57 const std::vector<CharacterEncoding::EncodingInfo>* encodings;
58 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
59 encodings = CharacterEncoding::GetCurrentDisplayEncodings(
60 g_browser_process->GetApplicationLocale(),
61 pref_service->GetString(prefs::kStaticEncodings),
62 pref_service->GetString(prefs::kRecentlySelectedEncoding));
63 DCHECK(!encodings->empty());
64
65 base::ListValue encoding_list;
66 for (const auto& it : *encodings) {
67 scoped_ptr<base::ListValue> option(new base::ListValue());
68 if (it.encoding_id) {
69 option->AppendString(
70 CharacterEncoding::GetCanonicalEncodingNameByCommandId(
71 it.encoding_id));
72 option->AppendString(it.encoding_display_name);
73 option->AppendString(
74 base::i18n::StringContainsStrongRTLChars(it.encoding_display_name)
75 ? "rtl"
76 : "ltr");
77 } else {
78 // Add empty value to indicate a separator item.
79 option->AppendString(std::string());
80 }
81 encoding_list.Append(option.Pass());
82 }
83
84 web_ui()->CallJavascriptFunction("Settings.setFontsData", *list,
85 encoding_list);
86 }
87
88 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/font_handler.h ('k') | chrome/browser/ui/webui/settings/md_settings_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698