summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordschuyler <dschuyler@chromium.org>2015-10-26 15:05:32 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-26 22:06:19 +0000
commita02f4993a13bc0d82c406aa136f1b8fd1fd6114a (patch)
tree3312a45b4263d4fb9c67433076650916456230cb /chrome
parent98cfcb3459daafc954b2c11ab1f5a3e4572b402f (diff)
downloadchromium_src-a02f4993a13bc0d82c406aa136f1b8fd1fd6114a.zip
chromium_src-a02f4993a13bc0d82c406aa136f1b8fd1fd6114a.tar.gz
chromium_src-a02f4993a13bc0d82c406aa136f1b8fd1fd6114a.tar.bz2
[MD settings] adding c++ side of font settings
This CL handles the requests for OS font lists and character encoding lists. It will be used by the WebContent settings. BUG=538372 Review URL: https://codereview.chromium.org/1405453002 Cr-Commit-Position: refs/heads/master@{#356139}
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/webui/settings/font_handler.cc88
-rw-r--r--chrome/browser/ui/webui/settings/font_handler.h46
-rw-r--r--chrome/browser/ui/webui/settings/md_settings_ui.cc2
-rw-r--r--chrome/chrome_browser_ui.gypi2
4 files changed, 138 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/settings/font_handler.cc b/chrome/browser/ui/webui/settings/font_handler.cc
new file mode 100644
index 0000000..5fb93cc
--- /dev/null
+++ b/chrome/browser/ui/webui/settings/font_handler.cc
@@ -0,0 +1,88 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/settings/font_handler.h"
+
+#include "base/bind_helpers.h"
+#include "base/i18n/rtl.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/character_encoding.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/webui/options/font_settings_utils.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/font_list_async.h"
+#include "content/public/browser/web_ui.h"
+
+namespace settings {
+
+FontHandler::FontHandler(content::WebUI* webui)
+ : weak_ptr_factory_(this) {
+ // Perform validation for saved fonts.
+ PrefService* pref_service = Profile::FromWebUI(webui)->GetPrefs();
+ options::FontSettingsUtilities::ValidateSavedFonts(pref_service);
+}
+
+FontHandler::~FontHandler() {}
+
+void FontHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "fetchFontsData", base::Bind(&FontHandler::HandleFetchFontsData,
+ base::Unretained(this)));
+}
+
+void FontHandler::HandleFetchFontsData(
+ const base::ListValue* /*args*/) {
+ content::GetFontListAsync(base::Bind(&FontHandler::FontListHasLoaded,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void FontHandler::FontListHasLoaded(scoped_ptr<base::ListValue> list) {
+ // Font list. Selects the directionality for the fonts in the given list.
+ for (size_t i = 0; i < list->GetSize(); i++) {
+ base::ListValue* font;
+ bool has_font = list->GetList(i, &font);
+ DCHECK(has_font);
+
+ base::string16 value;
+ bool has_value = font->GetString(1, &value);
+ DCHECK(has_value);
+
+ bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value);
+ font->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr"));
+ }
+
+ // Character encoding list.
+ const std::vector<CharacterEncoding::EncodingInfo>* encodings;
+ PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
+ encodings = CharacterEncoding::GetCurrentDisplayEncodings(
+ g_browser_process->GetApplicationLocale(),
+ pref_service->GetString(prefs::kStaticEncodings),
+ pref_service->GetString(prefs::kRecentlySelectedEncoding));
+ DCHECK(!encodings->empty());
+
+ base::ListValue encoding_list;
+ for (const auto& it : *encodings) {
+ scoped_ptr<base::ListValue> option(new base::ListValue());
+ if (it.encoding_id) {
+ option->AppendString(
+ CharacterEncoding::GetCanonicalEncodingNameByCommandId(
+ it.encoding_id));
+ option->AppendString(it.encoding_display_name);
+ option->AppendString(
+ base::i18n::StringContainsStrongRTLChars(it.encoding_display_name)
+ ? "rtl"
+ : "ltr");
+ } else {
+ // Add empty value to indicate a separator item.
+ option->AppendString(std::string());
+ }
+ encoding_list.Append(option.Pass());
+ }
+
+ web_ui()->CallJavascriptFunction("Settings.setFontsData", *list,
+ encoding_list);
+}
+
+} // namespace settings
diff --git a/chrome/browser/ui/webui/settings/font_handler.h b/chrome/browser/ui/webui/settings/font_handler.h
new file mode 100644
index 0000000..6da85cb
--- /dev/null
+++ b/chrome/browser/ui/webui/settings/font_handler.h
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_FONT_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_SETTINGS_FONT_HANDLER_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/ui/webui/settings/md_settings_ui.h"
+
+namespace base {
+class ListValue;
+}
+
+namespace content {
+class WebUI;
+}
+
+namespace settings {
+
+// Handle OS font list, font preference settings and character encoding.
+class FontHandler : public SettingsPageUIHandler {
+ public:
+ explicit FontHandler(content::WebUI* webui);
+ ~FontHandler() override;
+
+ // SettingsPageUIHandler implementation.
+ void RegisterMessages() override;
+
+ private:
+ // Handler for script asking for font information.
+ void HandleFetchFontsData(const base::ListValue* args);
+
+ // Callback to handle fonts loading.
+ void FontListHasLoaded(scoped_ptr<base::ListValue> list);
+
+ base::WeakPtrFactory<FontHandler> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FontHandler);
+};
+
+} // namespace settings
+
+#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_FONT_HANDLER_H_
diff --git a/chrome/browser/ui/webui/settings/md_settings_ui.cc b/chrome/browser/ui/webui/settings/md_settings_ui.cc
index cfacee5..909afe7 100644
--- a/chrome/browser/ui/webui/settings/md_settings_ui.cc
+++ b/chrome/browser/ui/webui/settings/md_settings_ui.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/ui/webui/options/sync_setup_handler.h"
#include "chrome/browser/ui/webui/settings/appearance_handler.h"
#include "chrome/browser/ui/webui/settings/downloads_handler.h"
+#include "chrome/browser/ui/webui/settings/font_handler.h"
#include "chrome/browser/ui/webui/settings/languages_handler.h"
#include "chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.h"
#include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.h"
@@ -36,6 +37,7 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui)
AddSettingsPageUIHandler(new ClearBrowsingDataHandler(web_ui));
AddSettingsPageUIHandler(new DefaultBrowserHandler(web_ui));
AddSettingsPageUIHandler(new DownloadsHandler());
+ AddSettingsPageUIHandler(new FontHandler(web_ui));
AddSettingsPageUIHandler(new LanguagesHandler(web_ui));
AddSettingsPageUIHandler(new StartupPagesHandler(web_ui));
AddSettingsPageUIHandler(new SyncSetupHandler());
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 5c92057..9ac4512 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1934,6 +1934,8 @@
'browser/ui/webui/settings/appearance_handler.h',
'browser/ui/webui/settings/downloads_handler.cc',
'browser/ui/webui/settings/downloads_handler.h',
+ 'browser/ui/webui/settings/font_handler.cc',
+ 'browser/ui/webui/settings/font_handler.h',
'browser/ui/webui/settings/languages_handler.cc',
'browser/ui/webui/settings/languages_handler.h',
'browser/ui/webui/settings/md_settings_localized_strings_provider.cc',