OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/webui/settings/font_handler.h" | 5 #include "chrome/browser/ui/webui/settings/font_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 29 matching lines...) Expand all Loading... |
40 void FontHandler::HandleFetchFontsData(const base::ListValue* args) { | 40 void FontHandler::HandleFetchFontsData(const base::ListValue* args) { |
41 CHECK_EQ(1U, args->GetSize()); | 41 CHECK_EQ(1U, args->GetSize()); |
42 std::string callback_id; | 42 std::string callback_id; |
43 CHECK(args->GetString(0, &callback_id)); | 43 CHECK(args->GetString(0, &callback_id)); |
44 | 44 |
45 content::GetFontListAsync(base::Bind(&FontHandler::FontListHasLoaded, | 45 content::GetFontListAsync(base::Bind(&FontHandler::FontListHasLoaded, |
46 weak_ptr_factory_.GetWeakPtr(), | 46 weak_ptr_factory_.GetWeakPtr(), |
47 callback_id)); | 47 callback_id)); |
48 } | 48 } |
49 | 49 |
50 void FontHandler::FontListHasLoaded( | 50 void FontHandler::FontListHasLoaded(std::string callback_id, |
51 std::string callback_id, | 51 std::unique_ptr<base::ListValue> list) { |
52 scoped_ptr<base::ListValue> list) { | |
53 // Font list. Selects the directionality for the fonts in the given list. | 52 // Font list. Selects the directionality for the fonts in the given list. |
54 for (size_t i = 0; i < list->GetSize(); i++) { | 53 for (size_t i = 0; i < list->GetSize(); i++) { |
55 base::ListValue* font; | 54 base::ListValue* font; |
56 bool has_font = list->GetList(i, &font); | 55 bool has_font = list->GetList(i, &font); |
57 DCHECK(has_font); | 56 DCHECK(has_font); |
58 | 57 |
59 base::string16 value; | 58 base::string16 value; |
60 bool has_value = font->GetString(1, &value); | 59 bool has_value = font->GetString(1, &value); |
61 DCHECK(has_value); | 60 DCHECK(has_value); |
62 | 61 |
63 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); | 62 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); |
64 font->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr")); | 63 font->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr")); |
65 } | 64 } |
66 | 65 |
67 // Character encoding list. | 66 // Character encoding list. |
68 const std::vector<CharacterEncoding::EncodingInfo>* encodings; | 67 const std::vector<CharacterEncoding::EncodingInfo>* encodings; |
69 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 68 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
70 encodings = CharacterEncoding::GetCurrentDisplayEncodings( | 69 encodings = CharacterEncoding::GetCurrentDisplayEncodings( |
71 g_browser_process->GetApplicationLocale(), | 70 g_browser_process->GetApplicationLocale(), |
72 pref_service->GetString(prefs::kStaticEncodings), | 71 pref_service->GetString(prefs::kStaticEncodings), |
73 pref_service->GetString(prefs::kRecentlySelectedEncoding)); | 72 pref_service->GetString(prefs::kRecentlySelectedEncoding)); |
74 DCHECK(!encodings->empty()); | 73 DCHECK(!encodings->empty()); |
75 | 74 |
76 scoped_ptr<base::ListValue> encoding_list(new base::ListValue()); | 75 std::unique_ptr<base::ListValue> encoding_list(new base::ListValue()); |
77 for (const auto& it : *encodings) { | 76 for (const auto& it : *encodings) { |
78 scoped_ptr<base::ListValue> option(new base::ListValue()); | 77 std::unique_ptr<base::ListValue> option(new base::ListValue()); |
79 if (it.encoding_id) { | 78 if (it.encoding_id) { |
80 option->AppendString( | 79 option->AppendString( |
81 CharacterEncoding::GetCanonicalEncodingNameByCommandId( | 80 CharacterEncoding::GetCanonicalEncodingNameByCommandId( |
82 it.encoding_id)); | 81 it.encoding_id)); |
83 option->AppendString(it.encoding_display_name); | 82 option->AppendString(it.encoding_display_name); |
84 option->AppendString( | 83 option->AppendString( |
85 base::i18n::StringContainsStrongRTLChars(it.encoding_display_name) | 84 base::i18n::StringContainsStrongRTLChars(it.encoding_display_name) |
86 ? "rtl" | 85 ? "rtl" |
87 : "ltr"); | 86 : "ltr"); |
88 } else { | 87 } else { |
89 // Add empty value to indicate a separator item. | 88 // Add empty value to indicate a separator item. |
90 option->AppendString(std::string()); | 89 option->AppendString(std::string()); |
91 } | 90 } |
92 encoding_list->Append(std::move(option)); | 91 encoding_list->Append(std::move(option)); |
93 } | 92 } |
94 | 93 |
95 base::DictionaryValue response; | 94 base::DictionaryValue response; |
96 response.Set("fontList", std::move(list)); | 95 response.Set("fontList", std::move(list)); |
97 response.Set("encodingList", std::move(encoding_list)); | 96 response.Set("encodingList", std::move(encoding_list)); |
98 | 97 |
99 ResolveJavascriptCallback(base::StringValue(callback_id), response); | 98 ResolveJavascriptCallback(base::StringValue(callback_id), response); |
100 } | 99 } |
101 | 100 |
102 } // namespace settings | 101 } // namespace settings |
OLD | NEW |