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

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

Issue 10907151: Extensions Docs Server: Enum values do not show up if enum is a type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add back braces Created 8 years, 3 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 // 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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const char kOnFontChanged[] = "fontSettings.onFontChanged"; 52 const char kOnFontChanged[] = "fontSettings.onFontChanged";
53 const char kOnMinimumFontSizeChanged[] = 53 const char kOnMinimumFontSizeChanged[] =
54 "fontSettings.onMinimumFontSizeChanged"; 54 "fontSettings.onMinimumFontSizeChanged";
55 55
56 // Format for font name preference paths. 56 // Format for font name preference paths.
57 const char kWebKitFontPrefFormat[] = "webkit.webprefs.fonts.%s.%s"; 57 const char kWebKitFontPrefFormat[] = "webkit.webprefs.fonts.%s.%s";
58 const char kWebKitFontPrefPrefix[] = "webkit.webprefs.fonts."; 58 const char kWebKitFontPrefPrefix[] = "webkit.webprefs.fonts.";
59 59
60 // Gets the font name preference path for |generic_family| and |script|. If 60 // Gets the font name preference path for |generic_family| and |script|. If
61 // |script| is NULL, uses prefs::kWebKitCommonScript. 61 // |script| is NULL, uses prefs::kWebKitCommonScript.
62 std::string GetFontNamePrefPath(const std::string& generic_family, 62 std::string GetFontNamePrefPath(fonts::GenericFamily generic_family_enum,
63 const std::string* script) { 63 fonts::ScriptCode script_enum) {
64 std::string script;
65 scoped_ptr<Value> script_value = fonts::CreateEnumValue(script_enum);
66 if (script_value.get())
67 script_value->GetAsString(&script);
not at google - send to devlin 2012/09/14 01:44:51 etc
cduvall 2012/09/17 22:07:46 Done.
68 else
69 script = prefs::kWebKitCommonScript;
70 std::string generic_family;
71 fonts::CreateEnumValue(generic_family_enum)->GetAsString(&generic_family);
64 return StringPrintf(kWebKitFontPrefFormat, 72 return StringPrintf(kWebKitFontPrefFormat,
65 generic_family.c_str(), 73 generic_family.c_str(),
66 script ? script->c_str() : prefs::kWebKitCommonScript); 74 script.c_str());
67 } 75 }
68 76
69 // Extracts the generic family and script from font name pref path |pref_path|. 77 // Extracts the generic family and script from font name pref path |pref_path|.
70 bool ParseFontNamePrefPath(std::string pref_path, 78 bool ParseFontNamePrefPath(std::string pref_path,
71 std::string* generic_family, 79 std::string* generic_family,
72 std::string* script) { 80 std::string* script) {
73 if (!StartsWithASCII(pref_path, kWebKitFontPrefPrefix, true)) 81 if (!StartsWithASCII(pref_path, kWebKitFontPrefPrefix, true))
74 return false; 82 return false;
75 83
76 size_t start = strlen(kWebKitFontPrefPrefix); 84 size_t start = strlen(kWebKitFontPrefPrefix);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (profile_->IsOffTheRecord()) { 252 if (profile_->IsOffTheRecord()) {
245 error_ = kSetFromIncognitoError; 253 error_ = kSetFromIncognitoError;
246 return false; 254 return false;
247 } 255 }
248 256
249 scoped_ptr<fonts::ClearFont::Params> params( 257 scoped_ptr<fonts::ClearFont::Params> params(
250 fonts::ClearFont::Params::Create(*args_)); 258 fonts::ClearFont::Params::Create(*args_));
251 EXTENSION_FUNCTION_VALIDATE(params.get()); 259 EXTENSION_FUNCTION_VALIDATE(params.get());
252 260
253 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, 261 std::string pref_path = GetFontNamePrefPath(params->details.generic_family,
254 params->details.script.get()); 262 params->details.script);
255 263
256 // Ensure |pref_path| really is for a registered per-script font pref. 264 // Ensure |pref_path| really is for a registered per-script font pref.
257 EXTENSION_FUNCTION_VALIDATE( 265 EXTENSION_FUNCTION_VALIDATE(
258 profile_->GetPrefs()->FindPreference(pref_path.c_str())); 266 profile_->GetPrefs()->FindPreference(pref_path.c_str()));
259 267
260 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 268 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
261 prefs->RemoveExtensionControlledPref(extension_id(), 269 prefs->RemoveExtensionControlledPref(extension_id(),
262 pref_path.c_str(), 270 pref_path.c_str(),
263 kExtensionPrefsScopeRegular); 271 kExtensionPrefsScopeRegular);
264 return true; 272 return true;
265 } 273 }
266 274
267 bool GetFontFunction::RunImpl() { 275 bool GetFontFunction::RunImpl() {
268 scoped_ptr<fonts::GetFont::Params> params( 276 scoped_ptr<fonts::GetFont::Params> params(
269 fonts::GetFont::Params::Create(*args_)); 277 fonts::GetFont::Params::Create(*args_));
270 EXTENSION_FUNCTION_VALIDATE(params.get()); 278 EXTENSION_FUNCTION_VALIDATE(params.get());
271 279
272 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, 280 std::string pref_path = GetFontNamePrefPath(params->details.generic_family,
273 params->details.script.get()); 281 params->details.script);
282
274 PrefService* prefs = profile_->GetPrefs(); 283 PrefService* prefs = profile_->GetPrefs();
275 const PrefService::Preference* pref = 284 const PrefService::Preference* pref =
276 prefs->FindPreference(pref_path.c_str()); 285 prefs->FindPreference(pref_path.c_str());
277 286
278 std::string font_name; 287 std::string font_name;
279 EXTENSION_FUNCTION_VALIDATE( 288 EXTENSION_FUNCTION_VALIDATE(
280 pref && pref->GetValue()->GetAsString(&font_name)); 289 pref && pref->GetValue()->GetAsString(&font_name));
281 font_name = MaybeGetLocalizedFontName(font_name); 290 font_name = MaybeGetLocalizedFontName(font_name);
282 291
283 // We don't support incognito-specific font prefs, so don't consider them when 292 // We don't support incognito-specific font prefs, so don't consider them when
(...skipping 16 matching lines...) Expand all
300 if (profile_->IsOffTheRecord()) { 309 if (profile_->IsOffTheRecord()) {
301 error_ = kSetFromIncognitoError; 310 error_ = kSetFromIncognitoError;
302 return false; 311 return false;
303 } 312 }
304 313
305 scoped_ptr<fonts::SetFont::Params> params( 314 scoped_ptr<fonts::SetFont::Params> params(
306 fonts::SetFont::Params::Create(*args_)); 315 fonts::SetFont::Params::Create(*args_));
307 EXTENSION_FUNCTION_VALIDATE(params.get()); 316 EXTENSION_FUNCTION_VALIDATE(params.get());
308 317
309 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, 318 std::string pref_path = GetFontNamePrefPath(params->details.generic_family,
310 params->details.script.get()); 319 params->details.script);
320
311 // Ensure |pref_path| really is for a registered font pref. 321 // Ensure |pref_path| really is for a registered font pref.
312 EXTENSION_FUNCTION_VALIDATE( 322 EXTENSION_FUNCTION_VALIDATE(
313 profile_->GetPrefs()->FindPreference(pref_path.c_str())); 323 profile_->GetPrefs()->FindPreference(pref_path.c_str()));
314 324
315 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 325 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
316 prefs->SetExtensionControlledPref( 326 prefs->SetExtensionControlledPref(
317 extension_id(), 327 extension_id(),
318 pref_path.c_str(), 328 pref_path.c_str(),
319 kExtensionPrefsScopeRegular, 329 kExtensionPrefsScopeRegular,
320 Value::CreateStringValue(params->details.font_id)); 330 Value::CreateStringValue(params->details.font_id));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 482
473 const char* SetMinimumFontSizeFunction::GetPrefName() { 483 const char* SetMinimumFontSizeFunction::GetPrefName() {
474 return prefs::kWebKitMinimumFontSize; 484 return prefs::kWebKitMinimumFontSize;
475 } 485 }
476 486
477 const char* SetMinimumFontSizeFunction::GetKey() { 487 const char* SetMinimumFontSizeFunction::GetKey() {
478 return kPixelSizeKey; 488 return kPixelSizeKey;
479 } 489 }
480 490
481 } // namespace extensions 491 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698