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/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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 pref_name); | 210 pref_name); |
211 } | 211 } |
212 | 212 |
213 FontSettingsAPI::FontSettingsAPI(Profile* profile) | 213 FontSettingsAPI::FontSettingsAPI(Profile* profile) |
214 : font_settings_event_router_(new FontSettingsEventRouter(profile)) { | 214 : font_settings_event_router_(new FontSettingsEventRouter(profile)) { |
215 } | 215 } |
216 | 216 |
217 FontSettingsAPI::~FontSettingsAPI() { | 217 FontSettingsAPI::~FontSettingsAPI() { |
218 } | 218 } |
219 | 219 |
220 bool ClearFontFunction::RunImpl() { | 220 bool FontSettingsClearFontFunction::RunImpl() { |
221 if (profile_->IsOffTheRecord()) { | 221 if (profile_->IsOffTheRecord()) { |
222 error_ = kSetFromIncognitoError; | 222 error_ = kSetFromIncognitoError; |
223 return false; | 223 return false; |
224 } | 224 } |
225 | 225 |
226 scoped_ptr<fonts::ClearFont::Params> params( | 226 scoped_ptr<fonts::ClearFont::Params> params( |
227 fonts::ClearFont::Params::Create(*args_)); | 227 fonts::ClearFont::Params::Create(*args_)); |
228 EXTENSION_FUNCTION_VALIDATE(params.get()); | 228 EXTENSION_FUNCTION_VALIDATE(params.get()); |
229 | 229 |
230 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 230 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
231 params->details.script); | 231 params->details.script); |
232 | 232 |
233 // Ensure |pref_path| really is for a registered per-script font pref. | 233 // Ensure |pref_path| really is for a registered per-script font pref. |
234 EXTENSION_FUNCTION_VALIDATE( | 234 EXTENSION_FUNCTION_VALIDATE( |
235 profile_->GetPrefs()->FindPreference(pref_path.c_str())); | 235 profile_->GetPrefs()->FindPreference(pref_path.c_str())); |
236 | 236 |
237 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> | 237 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> |
238 extension_service()->extension_prefs(); | 238 extension_service()->extension_prefs(); |
239 prefs->RemoveExtensionControlledPref(extension_id(), | 239 prefs->RemoveExtensionControlledPref(extension_id(), |
240 pref_path.c_str(), | 240 pref_path.c_str(), |
241 kExtensionPrefsScopeRegular); | 241 kExtensionPrefsScopeRegular); |
242 return true; | 242 return true; |
243 } | 243 } |
244 | 244 |
245 bool GetFontFunction::RunImpl() { | 245 bool FontSettingsGetFontFunction::RunImpl() { |
246 scoped_ptr<fonts::GetFont::Params> params( | 246 scoped_ptr<fonts::GetFont::Params> params( |
247 fonts::GetFont::Params::Create(*args_)); | 247 fonts::GetFont::Params::Create(*args_)); |
248 EXTENSION_FUNCTION_VALIDATE(params.get()); | 248 EXTENSION_FUNCTION_VALIDATE(params.get()); |
249 | 249 |
250 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 250 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
251 params->details.script); | 251 params->details.script); |
252 | 252 |
253 PrefService* prefs = profile_->GetPrefs(); | 253 PrefService* prefs = profile_->GetPrefs(); |
254 const PrefService::Preference* pref = | 254 const PrefService::Preference* pref = |
255 prefs->FindPreference(pref_path.c_str()); | 255 prefs->FindPreference(pref_path.c_str()); |
(...skipping 12 matching lines...) Expand all Loading... |
268 pref_path, | 268 pref_path, |
269 kIncognito); | 269 kIncognito); |
270 | 270 |
271 DictionaryValue* result = new DictionaryValue(); | 271 DictionaryValue* result = new DictionaryValue(); |
272 result->SetString(kFontIdKey, font_name); | 272 result->SetString(kFontIdKey, font_name); |
273 result->SetString(kLevelOfControlKey, level_of_control); | 273 result->SetString(kLevelOfControlKey, level_of_control); |
274 SetResult(result); | 274 SetResult(result); |
275 return true; | 275 return true; |
276 } | 276 } |
277 | 277 |
278 bool SetFontFunction::RunImpl() { | 278 bool FontSettingsSetFontFunction::RunImpl() { |
279 if (profile_->IsOffTheRecord()) { | 279 if (profile_->IsOffTheRecord()) { |
280 error_ = kSetFromIncognitoError; | 280 error_ = kSetFromIncognitoError; |
281 return false; | 281 return false; |
282 } | 282 } |
283 | 283 |
284 scoped_ptr<fonts::SetFont::Params> params( | 284 scoped_ptr<fonts::SetFont::Params> params( |
285 fonts::SetFont::Params::Create(*args_)); | 285 fonts::SetFont::Params::Create(*args_)); |
286 EXTENSION_FUNCTION_VALIDATE(params.get()); | 286 EXTENSION_FUNCTION_VALIDATE(params.get()); |
287 | 287 |
288 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 288 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
289 params->details.script); | 289 params->details.script); |
290 | 290 |
291 // Ensure |pref_path| really is for a registered font pref. | 291 // Ensure |pref_path| really is for a registered font pref. |
292 EXTENSION_FUNCTION_VALIDATE( | 292 EXTENSION_FUNCTION_VALIDATE( |
293 profile_->GetPrefs()->FindPreference(pref_path.c_str())); | 293 profile_->GetPrefs()->FindPreference(pref_path.c_str())); |
294 | 294 |
295 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> | 295 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> |
296 extension_service()->extension_prefs(); | 296 extension_service()->extension_prefs(); |
297 prefs->SetExtensionControlledPref( | 297 prefs->SetExtensionControlledPref( |
298 extension_id(), | 298 extension_id(), |
299 pref_path.c_str(), | 299 pref_path.c_str(), |
300 kExtensionPrefsScopeRegular, | 300 kExtensionPrefsScopeRegular, |
301 Value::CreateStringValue(params->details.font_id)); | 301 Value::CreateStringValue(params->details.font_id)); |
302 return true; | 302 return true; |
303 } | 303 } |
304 | 304 |
305 bool GetFontListFunction::RunImpl() { | 305 bool FontSettingsGetFontListFunction::RunImpl() { |
306 content::GetFontListAsync( | 306 content::GetFontListAsync( |
307 Bind(&GetFontListFunction::FontListHasLoaded, this)); | 307 Bind(&FontSettingsGetFontListFunction::FontListHasLoaded, this)); |
308 return true; | 308 return true; |
309 } | 309 } |
310 | 310 |
311 void GetFontListFunction::FontListHasLoaded(scoped_ptr<ListValue> list) { | 311 void FontSettingsGetFontListFunction::FontListHasLoaded( |
| 312 scoped_ptr<ListValue> list) { |
312 bool success = CopyFontsToResult(list.get()); | 313 bool success = CopyFontsToResult(list.get()); |
313 SendResponse(success); | 314 SendResponse(success); |
314 } | 315 } |
315 | 316 |
316 bool GetFontListFunction::CopyFontsToResult(ListValue* fonts) { | 317 bool FontSettingsGetFontListFunction::CopyFontsToResult(ListValue* fonts) { |
317 scoped_ptr<ListValue> result(new ListValue()); | 318 scoped_ptr<ListValue> result(new ListValue()); |
318 for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) { | 319 for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) { |
319 ListValue* font_list_value; | 320 ListValue* font_list_value; |
320 if (!(*it)->GetAsList(&font_list_value)) { | 321 if (!(*it)->GetAsList(&font_list_value)) { |
321 NOTREACHED(); | 322 NOTREACHED(); |
322 return false; | 323 return false; |
323 } | 324 } |
324 | 325 |
325 std::string name; | 326 std::string name; |
326 if (!font_list_value->GetString(0, &name)) { | 327 if (!font_list_value->GetString(0, &name)) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 395 |
395 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> | 396 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> |
396 extension_service()->extension_prefs(); | 397 extension_service()->extension_prefs(); |
397 prefs->SetExtensionControlledPref(extension_id(), | 398 prefs->SetExtensionControlledPref(extension_id(), |
398 GetPrefName(), | 399 GetPrefName(), |
399 kExtensionPrefsScopeRegular, | 400 kExtensionPrefsScopeRegular, |
400 value->DeepCopy()); | 401 value->DeepCopy()); |
401 return true; | 402 return true; |
402 } | 403 } |
403 | 404 |
404 const char* ClearDefaultFontSizeFunction::GetPrefName() { | 405 const char* FontSettingsClearDefaultFontSizeFunction::GetPrefName() { |
405 return prefs::kWebKitDefaultFontSize; | 406 return prefs::kWebKitDefaultFontSize; |
406 } | 407 } |
407 | 408 |
408 const char* GetDefaultFontSizeFunction::GetPrefName() { | 409 const char* FontSettingsGetDefaultFontSizeFunction::GetPrefName() { |
409 return prefs::kWebKitDefaultFontSize; | 410 return prefs::kWebKitDefaultFontSize; |
410 } | 411 } |
411 | 412 |
412 const char* GetDefaultFontSizeFunction::GetKey() { | 413 const char* FontSettingsGetDefaultFontSizeFunction::GetKey() { |
413 return kPixelSizeKey; | 414 return kPixelSizeKey; |
414 } | 415 } |
415 | 416 |
416 const char* SetDefaultFontSizeFunction::GetPrefName() { | 417 const char* FontSettingsSetDefaultFontSizeFunction::GetPrefName() { |
417 return prefs::kWebKitDefaultFontSize; | 418 return prefs::kWebKitDefaultFontSize; |
418 } | 419 } |
419 | 420 |
420 const char* SetDefaultFontSizeFunction::GetKey() { | 421 const char* FontSettingsSetDefaultFontSizeFunction::GetKey() { |
421 return kPixelSizeKey; | 422 return kPixelSizeKey; |
422 } | 423 } |
423 | 424 |
424 const char* ClearDefaultFixedFontSizeFunction::GetPrefName() { | 425 const char* FontSettingsClearDefaultFixedFontSizeFunction::GetPrefName() { |
425 return prefs::kWebKitDefaultFixedFontSize; | 426 return prefs::kWebKitDefaultFixedFontSize; |
426 } | 427 } |
427 | 428 |
428 const char* GetDefaultFixedFontSizeFunction::GetPrefName() { | 429 const char* FontSettingsGetDefaultFixedFontSizeFunction::GetPrefName() { |
429 return prefs::kWebKitDefaultFixedFontSize; | 430 return prefs::kWebKitDefaultFixedFontSize; |
430 } | 431 } |
431 | 432 |
432 const char* GetDefaultFixedFontSizeFunction::GetKey() { | 433 const char* FontSettingsGetDefaultFixedFontSizeFunction::GetKey() { |
433 return kPixelSizeKey; | 434 return kPixelSizeKey; |
434 } | 435 } |
435 | 436 |
436 const char* SetDefaultFixedFontSizeFunction::GetPrefName() { | 437 const char* FontSettingsSetDefaultFixedFontSizeFunction::GetPrefName() { |
437 return prefs::kWebKitDefaultFixedFontSize; | 438 return prefs::kWebKitDefaultFixedFontSize; |
438 } | 439 } |
439 | 440 |
440 const char* SetDefaultFixedFontSizeFunction::GetKey() { | 441 const char* FontSettingsSetDefaultFixedFontSizeFunction::GetKey() { |
441 return kPixelSizeKey; | 442 return kPixelSizeKey; |
442 } | 443 } |
443 | 444 |
444 const char* ClearMinimumFontSizeFunction::GetPrefName() { | 445 const char* FontSettingsClearMinimumFontSizeFunction::GetPrefName() { |
445 return prefs::kWebKitMinimumFontSize; | 446 return prefs::kWebKitMinimumFontSize; |
446 } | 447 } |
447 | 448 |
448 const char* GetMinimumFontSizeFunction::GetPrefName() { | 449 const char* FontSettingsGetMinimumFontSizeFunction::GetPrefName() { |
449 return prefs::kWebKitMinimumFontSize; | 450 return prefs::kWebKitMinimumFontSize; |
450 } | 451 } |
451 | 452 |
452 const char* GetMinimumFontSizeFunction::GetKey() { | 453 const char* FontSettingsGetMinimumFontSizeFunction::GetKey() { |
453 return kPixelSizeKey; | 454 return kPixelSizeKey; |
454 } | 455 } |
455 | 456 |
456 const char* SetMinimumFontSizeFunction::GetPrefName() { | 457 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { |
457 return prefs::kWebKitMinimumFontSize; | 458 return prefs::kWebKitMinimumFontSize; |
458 } | 459 } |
459 | 460 |
460 const char* SetMinimumFontSizeFunction::GetKey() { | 461 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { |
461 return kPixelSizeKey; | 462 return kPixelSizeKey; |
462 } | 463 } |
463 | 464 |
464 } // namespace extensions | 465 } // namespace extensions |
OLD | NEW |