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

Side by Side Diff: chrome/browser/extensions/api/font_settings/font_settings_api.cc

Issue 2927273002: Move code for old, deprecated Options UI to only ChromeOS (Closed)
Patch Set: check_gn_headers Created 3 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Font Settings Extension API implementation. 5 // Font Settings Extension API implementation.
6 6
7 #include "chrome/browser/extensions/api/font_settings/font_settings_api.h" 7 #include "chrome/browser/extensions/api/font_settings/font_settings_api.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/extensions/api/preference/preference_api.h" 26 #include "chrome/browser/extensions/api/preference/preference_api.h"
27 #include "chrome/browser/extensions/api/preference/preference_helpers.h" 27 #include "chrome/browser/extensions/api/preference/preference_helpers.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/webui/options/font_settings_utils.h" 30 #include "chrome/browser/ui/webui/settings_utils.h"
31 #include "chrome/common/extensions/api/font_settings.h" 31 #include "chrome/common/extensions/api/font_settings.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "chrome/common/pref_names_util.h" 33 #include "chrome/common/pref_names_util.h"
34 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "content/public/browser/font_list_async.h" 35 #include "content/public/browser/font_list_async.h"
36 #include "content/public/browser/notification_details.h" 36 #include "content/public/browser/notification_details.h"
37 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
38 #include "extensions/browser/extension_system.h" 38 #include "extensions/browser/extension_system.h"
39 #include "extensions/common/error_utils.h" 39 #include "extensions/common/error_utils.h"
40 40
41 namespace extensions { 41 namespace extensions {
42 42
43 namespace fonts = api::font_settings; 43 namespace fonts = api::font_settings;
44 using options::FontSettingsUtilities;
45 44
46 namespace { 45 namespace {
47 46
48 const char kFontIdKey[] = "fontId"; 47 const char kFontIdKey[] = "fontId";
49 const char kGenericFamilyKey[] = "genericFamily"; 48 const char kGenericFamilyKey[] = "genericFamily";
50 const char kLevelOfControlKey[] = "levelOfControl"; 49 const char kLevelOfControlKey[] = "levelOfControl";
51 const char kDisplayNameKey[] = "displayName"; 50 const char kDisplayNameKey[] = "displayName";
52 const char kPixelSizeKey[] = "pixelSize"; 51 const char kPixelSizeKey[] = "pixelSize";
53 const char kScriptKey[] = "script"; 52 const char kScriptKey[] = "script";
54 53
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const std::string& script) { 153 const std::string& script) {
155 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( 154 const PrefService::Preference* pref = registrar_.prefs()->FindPreference(
156 pref_name); 155 pref_name);
157 CHECK(pref); 156 CHECK(pref);
158 157
159 std::string font_name; 158 std::string font_name;
160 if (!pref->GetValue()->GetAsString(&font_name)) { 159 if (!pref->GetValue()->GetAsString(&font_name)) {
161 NOTREACHED(); 160 NOTREACHED();
162 return; 161 return;
163 } 162 }
164 font_name = FontSettingsUtilities::MaybeGetLocalizedFontName(font_name); 163 font_name = settings_utils::MaybeGetLocalizedFontName(font_name);
165 164
166 base::ListValue args; 165 base::ListValue args;
167 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 166 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
168 dict->SetString(kFontIdKey, font_name); 167 dict->SetString(kFontIdKey, font_name);
169 dict->SetString(kGenericFamilyKey, generic_family); 168 dict->SetString(kGenericFamilyKey, generic_family);
170 dict->SetString(kScriptKey, script); 169 dict->SetString(kScriptKey, script);
171 args.Append(std::move(dict)); 170 args.Append(std::move(dict));
172 171
173 extensions::preference_helpers::DispatchEventToExtensions( 172 extensions::preference_helpers::DispatchEventToExtensions(
174 profile_, events::FONT_SETTINGS_ON_FONT_CHANGED, 173 profile_, events::FONT_SETTINGS_ON_FONT_CHANGED,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 params->details.script); 239 params->details.script);
241 240
242 Profile* profile = Profile::FromBrowserContext(browser_context()); 241 Profile* profile = Profile::FromBrowserContext(browser_context());
243 PrefService* prefs = profile->GetPrefs(); 242 PrefService* prefs = profile->GetPrefs();
244 const PrefService::Preference* pref = 243 const PrefService::Preference* pref =
245 prefs->FindPreference(pref_path); 244 prefs->FindPreference(pref_path);
246 245
247 std::string font_name; 246 std::string font_name;
248 EXTENSION_FUNCTION_VALIDATE( 247 EXTENSION_FUNCTION_VALIDATE(
249 pref && pref->GetValue()->GetAsString(&font_name)); 248 pref && pref->GetValue()->GetAsString(&font_name));
250 font_name = FontSettingsUtilities::MaybeGetLocalizedFontName(font_name); 249 font_name = settings_utils::MaybeGetLocalizedFontName(font_name);
251 250
252 // We don't support incognito-specific font prefs, so don't consider them when 251 // We don't support incognito-specific font prefs, so don't consider them when
253 // getting level of control. 252 // getting level of control.
254 const bool kIncognito = false; 253 const bool kIncognito = false;
255 std::string level_of_control = 254 std::string level_of_control =
256 extensions::preference_helpers::GetLevelOfControl(profile, extension_id(), 255 extensions::preference_helpers::GetLevelOfControl(profile, extension_id(),
257 pref_path, kIncognito); 256 pref_path, kIncognito);
258 257
259 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 258 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
260 result->SetString(kFontIdKey, font_name); 259 result->SetString(kFontIdKey, font_name);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 430
432 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { 431 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() {
433 return prefs::kWebKitMinimumFontSize; 432 return prefs::kWebKitMinimumFontSize;
434 } 433 }
435 434
436 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { 435 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() {
437 return kPixelSizeKey; 436 return kPixelSizeKey;
438 } 437 }
439 438
440 } // namespace extensions 439 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698