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

Unified Diff: chrome/browser/extensions/extension_font_settings_api.cc

Issue 9576001: Add getFontList() to Font Settings Extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_font_settings_api.cc
diff --git a/chrome/browser/extensions/extension_font_settings_api.cc b/chrome/browser/extensions/extension_font_settings_api.cc
index 4622d5418495744fa8380c2fff5e772c427daf00..9f00e0466cc814b2d9c66cd55c0863f26d1b9279 100644
--- a/chrome/browser/extensions/extension_font_settings_api.cc
+++ b/chrome/browser/extensions/extension_font_settings_api.cc
@@ -12,11 +12,13 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_error_utils.h"
+#include "content/public/browser/font_list_async.h"
namespace {
const char kGenericFamilyKey[] = "genericFamily";
const char kFontNameKey[] = "fontName";
+const char kLocalizedNameKey[] = "localizedName";
const char kScriptKey[] = "script";
// Format for per-script font preference keys.
@@ -43,11 +45,11 @@ bool GetFontNamePrefPath(DictionaryValue* details, std::string* pref_path)
std::string script;
if (!details->GetString(kScriptKey, &script))
return false;
- *pref_path = base::StringPrintf(kWebKitPerScriptFontPrefFormat,
+ *pref_path = StringPrintf(kWebKitPerScriptFontPrefFormat,
generic_family.c_str(),
script.c_str());
} else {
- *pref_path = base::StringPrintf(kWebKitGlobalFontPrefFormat,
+ *pref_path = StringPrintf(kWebKitGlobalFontPrefFormat,
generic_family.c_str());
}
@@ -93,6 +95,49 @@ bool SetFontNameFunction::RunImpl() {
ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
prefs->SetExtensionControlledPref(extension_id(), pref_path.c_str(),
kExtensionPrefsScopeRegular,
- base::Value::CreateStringValue(font_name));
+ Value::CreateStringValue(font_name));
+ return true;
+}
+
+bool GetFontListFunction::RunImpl() {
+ content::GetFontListAsync(
+ Bind(&GetFontListFunction::FontListHasLoaded, this));
+ return true;
+}
+
+void GetFontListFunction::FontListHasLoaded(scoped_ptr<ListValue> list) {
+ bool success = CopyFontsToResult(list.get());
+ SendResponse(success);
+}
+
+bool GetFontListFunction::CopyFontsToResult(ListValue* fonts)
+{
+ ListValue* result = new ListValue();
Matt Perry 2012/03/01 22:57:29 Use a scoped_ptr to avoid leaking result.
falken 2012/03/01 23:30:52 Done.
+ for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) {
+ ListValue *fontListValue;
Matt Perry 2012/03/01 22:57:29 ListValue* font_list_value
falken 2012/03/01 23:30:52 Done.
+ if (!(*it)->GetAsList(&fontListValue)) {
+ NOTREACHED();
+ return false;
+ }
+
+ std::string name;
+ if (!fontListValue->GetString(0, &name)) {
+ NOTREACHED();
+ return false;
+ }
+
+ std::string localizedName;
Matt Perry 2012/03/01 22:57:29 naming style
falken 2012/03/01 23:30:52 Done.
+ if (!fontListValue->GetString(1, &localizedName)) {
+ NOTREACHED();
+ return false;
+ }
+
+ DictionaryValue* fontName = new DictionaryValue();
Matt Perry 2012/03/01 22:57:29 ditto
falken 2012/03/01 23:30:52 Done.
+ fontName->Set(kFontNameKey, Value::CreateStringValue(name));
+ fontName->Set(kLocalizedNameKey, Value::CreateStringValue(localizedName));
+ result->Append(fontName);
+ }
+
+ result_.reset(result);
return true;
}
« no previous file with comments | « chrome/browser/extensions/extension_font_settings_api.h ('k') | chrome/browser/extensions/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698