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

Side by Side Diff: chrome/browser/extensions/extension_font_settings_api.cc

Issue 10108007: Font Settings Extension API: Rename get/setFontName to get/setFont. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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 #include "chrome/browser/extensions/extension_font_settings_api.h" 5 #include "chrome/browser/extensions/extension_font_settings_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 16 matching lines...) Expand all
27 #endif 27 #endif
28 28
29 namespace { 29 namespace {
30 30
31 const char kGenericFamilyKey[] = "genericFamily"; 31 const char kGenericFamilyKey[] = "genericFamily";
32 const char kFontNameKey[] = "fontName"; 32 const char kFontNameKey[] = "fontName";
33 const char kLocalizedNameKey[] = "localizedName"; 33 const char kLocalizedNameKey[] = "localizedName";
34 const char kPixelSizeKey[] = "pixelSize"; 34 const char kPixelSizeKey[] = "pixelSize";
35 const char kScriptKey[] = "script"; 35 const char kScriptKey[] = "script";
36 36
37 const char kOnFontNameChanged[] = 37 const char kOnFontChanged[] = "experimental.fontSettings.onFontChanged";
38 "experimental.fontSettings.onFontNameChanged";
39 38
40 // Format for per-script font preference keys. 39 // Format for per-script font preference keys.
41 // E.g., "webkit.webprefs.fonts.standard.Hrkt" 40 // E.g., "webkit.webprefs.fonts.standard.Hrkt"
42 const char kWebKitPerScriptFontPrefFormat[] = "webkit.webprefs.fonts.%s.%s"; 41 const char kWebKitPerScriptFontPrefFormat[] = "webkit.webprefs.fonts.%s.%s";
43 const char kWebKitPerScriptFontPrefPrefix[] = "webkit.webprefs.fonts."; 42 const char kWebKitPerScriptFontPrefPrefix[] = "webkit.webprefs.fonts.";
44 43
45 // Format for global (non per-script) font preference keys. 44 // Format for global (non per-script) font preference keys.
46 // E.g., "webkit.webprefs.global.fixed_font_family" 45 // E.g., "webkit.webprefs.global.fixed_font_family"
47 // Note: there are two meanings of "global" here. The "Global" in the const name 46 // Note: there are two meanings of "global" here. The "Global" in the const name
48 // means "not per-script". The "global" in the key itself means "not per-tab" 47 // means "not per-script". The "global" in the key itself means "not per-tab"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 ListValue args; 188 ListValue args;
190 DictionaryValue* dict = new DictionaryValue(); 189 DictionaryValue* dict = new DictionaryValue();
191 args.Append(dict); 190 args.Append(dict);
192 dict->SetString(kFontNameKey, font_name); 191 dict->SetString(kFontNameKey, font_name);
193 dict->SetString(kGenericFamilyKey, generic_family); 192 dict->SetString(kGenericFamilyKey, generic_family);
194 if (!script.empty()) 193 if (!script.empty())
195 dict->SetString(kScriptKey, script); 194 dict->SetString(kScriptKey, script);
196 195
197 extension_preference_helpers::DispatchEventToExtensions( 196 extension_preference_helpers::DispatchEventToExtensions(
198 profile_, 197 profile_,
199 kOnFontNameChanged, 198 kOnFontChanged,
200 &args, 199 &args,
201 ExtensionAPIPermission::kExperimental, 200 ExtensionAPIPermission::kExperimental,
202 incognito, 201 incognito,
203 *pref_key); 202 *pref_key);
204 } 203 }
205 204
206 bool GetFontNameFunction::RunImpl() { 205 bool GetFontFunction::RunImpl() {
207 DictionaryValue* details = NULL; 206 DictionaryValue* details = NULL;
208 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 207 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
209 208
210 std::string pref_path; 209 std::string pref_path;
211 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path)); 210 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path));
212 211
213 PrefService* prefs = profile_->GetPrefs(); 212 PrefService* prefs = profile_->GetPrefs();
214 const PrefService::Preference* pref = 213 const PrefService::Preference* pref =
215 prefs->FindPreference(pref_path.c_str()); 214 prefs->FindPreference(pref_path.c_str());
216 std::string font_name; 215 std::string font_name;
217 EXTENSION_FUNCTION_VALIDATE( 216 EXTENSION_FUNCTION_VALIDATE(
218 pref && pref->GetValue()->GetAsString(&font_name)); 217 pref && pref->GetValue()->GetAsString(&font_name));
219 218
220 font_name = MaybeGetLocalizedFontName(font_name); 219 font_name = MaybeGetLocalizedFontName(font_name);
221 220
222 DictionaryValue* result = new DictionaryValue(); 221 DictionaryValue* result = new DictionaryValue();
223 result->SetString(kFontNameKey, font_name); 222 result->SetString(kFontNameKey, font_name);
224 result_.reset(result); 223 result_.reset(result);
225 return true; 224 return true;
226 } 225 }
227 226
228 bool SetFontNameFunction::RunImpl() { 227 bool SetFontFunction::RunImpl() {
229 DictionaryValue* details = NULL; 228 DictionaryValue* details = NULL;
230 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 229 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
231 230
232 std::string pref_path; 231 std::string pref_path;
233 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path)); 232 EXTENSION_FUNCTION_VALIDATE(GetFontNamePrefPath(details, &pref_path));
234 233
235 std::string font_name; 234 std::string font_name;
236 EXTENSION_FUNCTION_VALIDATE(details->GetString(kFontNameKey, &font_name)); 235 EXTENSION_FUNCTION_VALIDATE(details->GetString(kFontNameKey, &font_name));
237 236
238 // Ensure |pref_path| really is for a registered per-script font pref. 237 // Ensure |pref_path| really is for a registered per-script font pref.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 return prefs::kWebKitGlobalDefaultFixedFontSize; 328 return prefs::kWebKitGlobalDefaultFixedFontSize;
330 } 329 }
331 330
332 const char* GetMinimumFontSizeFunction::GetPrefName() { 331 const char* GetMinimumFontSizeFunction::GetPrefName() {
333 return prefs::kWebKitGlobalMinimumFontSize; 332 return prefs::kWebKitGlobalMinimumFontSize;
334 } 333 }
335 334
336 const char* SetMinimumFontSizeFunction::GetPrefName() { 335 const char* SetMinimumFontSizeFunction::GetPrefName() {
337 return prefs::kWebKitGlobalMinimumFontSize; 336 return prefs::kWebKitGlobalMinimumFontSize;
338 } 337 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_font_settings_api.h ('k') | chrome/browser/extensions/extension_function_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698