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

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: rtcPrivate fix 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 = fonts::ToString(script_enum);
65 if (script.empty())
66 script = prefs::kWebKitCommonScript;
67 std::string generic_family = fonts::ToString(generic_family_enum);
64 return StringPrintf(kWebKitFontPrefFormat, 68 return StringPrintf(kWebKitFontPrefFormat,
65 generic_family.c_str(), 69 generic_family.c_str(),
66 script ? script->c_str() : prefs::kWebKitCommonScript); 70 script.c_str());
67 } 71 }
68 72
69 // Extracts the generic family and script from font name pref path |pref_path|. 73 // Extracts the generic family and script from font name pref path |pref_path|.
70 bool ParseFontNamePrefPath(std::string pref_path, 74 bool ParseFontNamePrefPath(std::string pref_path,
71 std::string* generic_family, 75 std::string* generic_family,
72 std::string* script) { 76 std::string* script) {
73 if (!StartsWithASCII(pref_path, kWebKitFontPrefPrefix, true)) 77 if (!StartsWithASCII(pref_path, kWebKitFontPrefPrefix, true))
74 return false; 78 return false;
75 79
76 size_t start = strlen(kWebKitFontPrefPrefix); 80 size_t start = strlen(kWebKitFontPrefPrefix);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (profile_->IsOffTheRecord()) { 248 if (profile_->IsOffTheRecord()) {
245 error_ = kSetFromIncognitoError; 249 error_ = kSetFromIncognitoError;
246 return false; 250 return false;
247 } 251 }
248 252
249 scoped_ptr<fonts::ClearFont::Params> params( 253 scoped_ptr<fonts::ClearFont::Params> params(
250 fonts::ClearFont::Params::Create(*args_)); 254 fonts::ClearFont::Params::Create(*args_));
251 EXTENSION_FUNCTION_VALIDATE(params.get()); 255 EXTENSION_FUNCTION_VALIDATE(params.get());
252 256
253 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, 257 std::string pref_path = GetFontNamePrefPath(params->details.generic_family,
254 params->details.script.get()); 258 params->details.script);
255 259
256 // Ensure |pref_path| really is for a registered per-script font pref. 260 // Ensure |pref_path| really is for a registered per-script font pref.
257 EXTENSION_FUNCTION_VALIDATE( 261 EXTENSION_FUNCTION_VALIDATE(
258 profile_->GetPrefs()->FindPreference(pref_path.c_str())); 262 profile_->GetPrefs()->FindPreference(pref_path.c_str()));
259 263
260 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 264 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
261 prefs->RemoveExtensionControlledPref(extension_id(), 265 prefs->RemoveExtensionControlledPref(extension_id(),
262 pref_path.c_str(), 266 pref_path.c_str(),
263 kExtensionPrefsScopeRegular); 267 kExtensionPrefsScopeRegular);
264 return true; 268 return true;
265 } 269 }
266 270
267 bool GetFontFunction::RunImpl() { 271 bool GetFontFunction::RunImpl() {
268 scoped_ptr<fonts::GetFont::Params> params( 272 scoped_ptr<fonts::GetFont::Params> params(
269 fonts::GetFont::Params::Create(*args_)); 273 fonts::GetFont::Params::Create(*args_));
270 EXTENSION_FUNCTION_VALIDATE(params.get()); 274 EXTENSION_FUNCTION_VALIDATE(params.get());
271 275
272 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, 276 std::string pref_path = GetFontNamePrefPath(params->details.generic_family,
273 params->details.script.get()); 277 params->details.script);
278
274 PrefService* prefs = profile_->GetPrefs(); 279 PrefService* prefs = profile_->GetPrefs();
275 const PrefService::Preference* pref = 280 const PrefService::Preference* pref =
276 prefs->FindPreference(pref_path.c_str()); 281 prefs->FindPreference(pref_path.c_str());
277 282
278 std::string font_name; 283 std::string font_name;
279 EXTENSION_FUNCTION_VALIDATE( 284 EXTENSION_FUNCTION_VALIDATE(
280 pref && pref->GetValue()->GetAsString(&font_name)); 285 pref && pref->GetValue()->GetAsString(&font_name));
281 font_name = MaybeGetLocalizedFontName(font_name); 286 font_name = MaybeGetLocalizedFontName(font_name);
282 287
283 // We don't support incognito-specific font prefs, so don't consider them when 288 // We don't support incognito-specific font prefs, so don't consider them when
(...skipping 16 matching lines...) Expand all
300 if (profile_->IsOffTheRecord()) { 305 if (profile_->IsOffTheRecord()) {
301 error_ = kSetFromIncognitoError; 306 error_ = kSetFromIncognitoError;
302 return false; 307 return false;
303 } 308 }
304 309
305 scoped_ptr<fonts::SetFont::Params> params( 310 scoped_ptr<fonts::SetFont::Params> params(
306 fonts::SetFont::Params::Create(*args_)); 311 fonts::SetFont::Params::Create(*args_));
307 EXTENSION_FUNCTION_VALIDATE(params.get()); 312 EXTENSION_FUNCTION_VALIDATE(params.get());
308 313
309 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, 314 std::string pref_path = GetFontNamePrefPath(params->details.generic_family,
310 params->details.script.get()); 315 params->details.script);
316
311 // Ensure |pref_path| really is for a registered font pref. 317 // Ensure |pref_path| really is for a registered font pref.
312 EXTENSION_FUNCTION_VALIDATE( 318 EXTENSION_FUNCTION_VALIDATE(
313 profile_->GetPrefs()->FindPreference(pref_path.c_str())); 319 profile_->GetPrefs()->FindPreference(pref_path.c_str()));
314 320
315 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); 321 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
316 prefs->SetExtensionControlledPref( 322 prefs->SetExtensionControlledPref(
317 extension_id(), 323 extension_id(),
318 pref_path.c_str(), 324 pref_path.c_str(),
319 kExtensionPrefsScopeRegular, 325 kExtensionPrefsScopeRegular,
320 Value::CreateStringValue(params->details.font_id)); 326 Value::CreateStringValue(params->details.font_id));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 478
473 const char* SetMinimumFontSizeFunction::GetPrefName() { 479 const char* SetMinimumFontSizeFunction::GetPrefName() {
474 return prefs::kWebKitMinimumFontSize; 480 return prefs::kWebKitMinimumFontSize;
475 } 481 }
476 482
477 const char* SetMinimumFontSizeFunction::GetKey() { 483 const char* SetMinimumFontSizeFunction::GetKey() {
478 return kPixelSizeKey; 484 return kPixelSizeKey;
479 } 485 }
480 486
481 } // namespace extensions 487 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698