OLD | NEW |
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/extension_font_settings_api.h" | 7 #include "chrome/browser/extensions/extension_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 18 matching lines...) Expand all Loading... |
29 #include "ui/gfx/font.h" | 29 #include "ui/gfx/font.h" |
30 #include "ui/gfx/platform_font_win.h" | 30 #include "ui/gfx/platform_font_win.h" |
31 #endif | 31 #endif |
32 | 32 |
33 using extensions::APIPermission; | 33 using extensions::APIPermission; |
34 | 34 |
35 namespace fonts = extensions::api::experimental_font_settings; | 35 namespace fonts = extensions::api::experimental_font_settings; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const char kFontNameKey[] = "fontName"; | 39 const char kFontIdKey[] = "fontId"; |
40 const char kGenericFamilyKey[] = "genericFamily"; | 40 const char kGenericFamilyKey[] = "genericFamily"; |
41 const char kLevelOfControlKey[] = "levelOfControl"; | 41 const char kLevelOfControlKey[] = "levelOfControl"; |
42 const char kLocalizedNameKey[] = "localizedName"; | 42 const char kDisplayNameKey[] = "displayName"; |
43 const char kPixelSizeKey[] = "pixelSize"; | 43 const char kPixelSizeKey[] = "pixelSize"; |
44 const char kScriptKey[] = "script"; | 44 const char kScriptKey[] = "script"; |
45 | 45 |
46 const char kSetFromIncognitoError[] = | 46 const char kSetFromIncognitoError[] = |
47 "Can't modify regular settings from an incognito context."; | 47 "Can't modify regular settings from an incognito context."; |
48 | 48 |
49 const char kOnDefaultFixedFontSizeChanged[] = | 49 const char kOnDefaultFixedFontSizeChanged[] = |
50 "experimental.fontSettings.onDefaultFixedFontSizeChanged"; | 50 "experimental.fontSettings.onDefaultFixedFontSizeChanged"; |
51 const char kOnDefaultFontSizeChanged[] = | 51 const char kOnDefaultFontSizeChanged[] = |
52 "experimental.fontSettings.onDefaultFontSizeChanged"; | 52 "experimental.fontSettings.onDefaultFontSizeChanged"; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 std::string font_name; | 197 std::string font_name; |
198 if (!pref->GetValue()->GetAsString(&font_name)) { | 198 if (!pref->GetValue()->GetAsString(&font_name)) { |
199 NOTREACHED(); | 199 NOTREACHED(); |
200 return; | 200 return; |
201 } | 201 } |
202 font_name = MaybeGetLocalizedFontName(font_name); | 202 font_name = MaybeGetLocalizedFontName(font_name); |
203 | 203 |
204 ListValue args; | 204 ListValue args; |
205 DictionaryValue* dict = new DictionaryValue(); | 205 DictionaryValue* dict = new DictionaryValue(); |
206 args.Append(dict); | 206 args.Append(dict); |
207 dict->SetString(kFontNameKey, font_name); | 207 dict->SetString(kFontIdKey, font_name); |
208 dict->SetString(kGenericFamilyKey, generic_family); | 208 dict->SetString(kGenericFamilyKey, generic_family); |
209 dict->SetString(kScriptKey, script); | 209 dict->SetString(kScriptKey, script); |
210 | 210 |
211 extension_preference_helpers::DispatchEventToExtensions( | 211 extension_preference_helpers::DispatchEventToExtensions( |
212 profile_, | 212 profile_, |
213 kOnFontChanged, | 213 kOnFontChanged, |
214 &args, | 214 &args, |
215 APIPermission::kExperimental, | 215 APIPermission::kExperimental, |
216 incognito, | 216 incognito, |
217 pref_name); | 217 pref_name); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // We don't support incognito-specific font prefs, so don't consider them when | 285 // We don't support incognito-specific font prefs, so don't consider them when |
286 // getting level of control. | 286 // getting level of control. |
287 const bool kIncognito = false; | 287 const bool kIncognito = false; |
288 std::string level_of_control = | 288 std::string level_of_control = |
289 extension_preference_helpers::GetLevelOfControl(profile_, | 289 extension_preference_helpers::GetLevelOfControl(profile_, |
290 extension_id(), | 290 extension_id(), |
291 pref_path, | 291 pref_path, |
292 kIncognito); | 292 kIncognito); |
293 | 293 |
294 DictionaryValue* result = new DictionaryValue(); | 294 DictionaryValue* result = new DictionaryValue(); |
295 result->SetString(kFontNameKey, font_name); | 295 result->SetString(kFontIdKey, font_name); |
296 result->SetString(kLevelOfControlKey, level_of_control); | 296 result->SetString(kLevelOfControlKey, level_of_control); |
297 result_.reset(result); | 297 result_.reset(result); |
298 return true; | 298 return true; |
299 } | 299 } |
300 | 300 |
301 bool SetFontFunction::RunImpl() { | 301 bool SetFontFunction::RunImpl() { |
302 if (profile_->IsOffTheRecord()) { | 302 if (profile_->IsOffTheRecord()) { |
303 error_ = kSetFromIncognitoError; | 303 error_ = kSetFromIncognitoError; |
304 return false; | 304 return false; |
305 } | 305 } |
306 | 306 |
307 scoped_ptr<fonts::SetFont::Params> params( | 307 scoped_ptr<fonts::SetFont::Params> params( |
308 fonts::SetFont::Params::Create(*args_)); | 308 fonts::SetFont::Params::Create(*args_)); |
309 EXTENSION_FUNCTION_VALIDATE(params.get()); | 309 EXTENSION_FUNCTION_VALIDATE(params.get()); |
310 | 310 |
311 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 311 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
312 params->details.script.get()); | 312 params->details.script.get()); |
313 // Ensure |pref_path| really is for a registered font pref. | 313 // Ensure |pref_path| really is for a registered font pref. |
314 EXTENSION_FUNCTION_VALIDATE( | 314 EXTENSION_FUNCTION_VALIDATE( |
315 profile_->GetPrefs()->FindPreference(pref_path.c_str())); | 315 profile_->GetPrefs()->FindPreference(pref_path.c_str())); |
316 | 316 |
317 extensions::ExtensionPrefs* prefs = | 317 extensions::ExtensionPrefs* prefs = |
318 profile_->GetExtensionService()->extension_prefs(); | 318 profile_->GetExtensionService()->extension_prefs(); |
319 prefs->SetExtensionControlledPref( | 319 prefs->SetExtensionControlledPref( |
320 extension_id(), | 320 extension_id(), |
321 pref_path.c_str(), | 321 pref_path.c_str(), |
322 extensions::kExtensionPrefsScopeRegular, | 322 extensions::kExtensionPrefsScopeRegular, |
323 Value::CreateStringValue(params->details.font_name)); | 323 Value::CreateStringValue(params->details.font_id)); |
324 return true; | 324 return true; |
325 } | 325 } |
326 | 326 |
327 bool GetFontListFunction::RunImpl() { | 327 bool GetFontListFunction::RunImpl() { |
328 content::GetFontListAsync( | 328 content::GetFontListAsync( |
329 Bind(&GetFontListFunction::FontListHasLoaded, this)); | 329 Bind(&GetFontListFunction::FontListHasLoaded, this)); |
330 return true; | 330 return true; |
331 } | 331 } |
332 | 332 |
333 void GetFontListFunction::FontListHasLoaded(scoped_ptr<ListValue> list) { | 333 void GetFontListFunction::FontListHasLoaded(scoped_ptr<ListValue> list) { |
(...skipping 16 matching lines...) Expand all Loading... |
350 return false; | 350 return false; |
351 } | 351 } |
352 | 352 |
353 std::string localized_name; | 353 std::string localized_name; |
354 if (!font_list_value->GetString(1, &localized_name)) { | 354 if (!font_list_value->GetString(1, &localized_name)) { |
355 NOTREACHED(); | 355 NOTREACHED(); |
356 return false; | 356 return false; |
357 } | 357 } |
358 | 358 |
359 DictionaryValue* font_name = new DictionaryValue(); | 359 DictionaryValue* font_name = new DictionaryValue(); |
360 font_name->Set(kFontNameKey, Value::CreateStringValue(name)); | 360 font_name->Set(kFontIdKey, Value::CreateStringValue(name)); |
361 font_name->Set(kLocalizedNameKey, Value::CreateStringValue(localized_name)); | 361 font_name->Set(kDisplayNameKey, Value::CreateStringValue(localized_name)); |
362 result->Append(font_name); | 362 result->Append(font_name); |
363 } | 363 } |
364 | 364 |
365 result_.reset(result.release()); | 365 result_.reset(result.release()); |
366 return true; | 366 return true; |
367 } | 367 } |
368 | 368 |
369 bool ClearFontPrefExtensionFunction::RunImpl() { | 369 bool ClearFontPrefExtensionFunction::RunImpl() { |
370 if (profile_->IsOffTheRecord()) { | 370 if (profile_->IsOffTheRecord()) { |
371 error_ = kSetFromIncognitoError; | 371 error_ = kSetFromIncognitoError; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 return kPixelSizeKey; | 475 return kPixelSizeKey; |
476 } | 476 } |
477 | 477 |
478 const char* SetMinimumFontSizeFunction::GetPrefName() { | 478 const char* SetMinimumFontSizeFunction::GetPrefName() { |
479 return prefs::kWebKitMinimumFontSize; | 479 return prefs::kWebKitMinimumFontSize; |
480 } | 480 } |
481 | 481 |
482 const char* SetMinimumFontSizeFunction::GetKey() { | 482 const char* SetMinimumFontSizeFunction::GetKey() { |
483 return kPixelSizeKey; | 483 return kPixelSizeKey; |
484 } | 484 } |
OLD | NEW |