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 FontSettingsClearFontFunction::RunImpl() { | 220 bool ClearFontFunction::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 FontSettingsGetFontFunction::RunImpl() { | 245 bool GetFontFunction::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 FontSettingsSetFontFunction::RunImpl() { | 278 bool SetFontFunction::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 FontSettingsGetFontListFunction::RunImpl() { | 305 bool GetFontListFunction::RunImpl() { |
306 content::GetFontListAsync( | 306 content::GetFontListAsync( |
307 Bind(&FontSettingsGetFontListFunction::FontListHasLoaded, this)); | 307 Bind(&GetFontListFunction::FontListHasLoaded, this)); |
308 return true; | 308 return true; |
309 } | 309 } |
310 | 310 |
311 void FontSettingsGetFontListFunction::FontListHasLoaded( | 311 void GetFontListFunction::FontListHasLoaded(scoped_ptr<ListValue> list) { |
312 scoped_ptr<ListValue> list) { | |
313 bool success = CopyFontsToResult(list.get()); | 312 bool success = CopyFontsToResult(list.get()); |
314 SendResponse(success); | 313 SendResponse(success); |
315 } | 314 } |
316 | 315 |
317 bool FontSettingsGetFontListFunction::CopyFontsToResult(ListValue* fonts) { | 316 bool GetFontListFunction::CopyFontsToResult(ListValue* fonts) { |
318 scoped_ptr<ListValue> result(new ListValue()); | 317 scoped_ptr<ListValue> result(new ListValue()); |
319 for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) { | 318 for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) { |
320 ListValue* font_list_value; | 319 ListValue* font_list_value; |
321 if (!(*it)->GetAsList(&font_list_value)) { | 320 if (!(*it)->GetAsList(&font_list_value)) { |
322 NOTREACHED(); | 321 NOTREACHED(); |
323 return false; | 322 return false; |
324 } | 323 } |
325 | 324 |
326 std::string name; | 325 std::string name; |
327 if (!font_list_value->GetString(0, &name)) { | 326 if (!font_list_value->GetString(0, &name)) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 394 |
396 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> | 395 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> |
397 extension_service()->extension_prefs(); | 396 extension_service()->extension_prefs(); |
398 prefs->SetExtensionControlledPref(extension_id(), | 397 prefs->SetExtensionControlledPref(extension_id(), |
399 GetPrefName(), | 398 GetPrefName(), |
400 kExtensionPrefsScopeRegular, | 399 kExtensionPrefsScopeRegular, |
401 value->DeepCopy()); | 400 value->DeepCopy()); |
402 return true; | 401 return true; |
403 } | 402 } |
404 | 403 |
405 const char* FontSettingsClearDefaultFontSizeFunction::GetPrefName() { | 404 const char* ClearDefaultFontSizeFunction::GetPrefName() { |
406 return prefs::kWebKitDefaultFontSize; | 405 return prefs::kWebKitDefaultFontSize; |
407 } | 406 } |
408 | 407 |
409 const char* FontSettingsGetDefaultFontSizeFunction::GetPrefName() { | 408 const char* GetDefaultFontSizeFunction::GetPrefName() { |
410 return prefs::kWebKitDefaultFontSize; | 409 return prefs::kWebKitDefaultFontSize; |
411 } | 410 } |
412 | 411 |
413 const char* FontSettingsGetDefaultFontSizeFunction::GetKey() { | 412 const char* GetDefaultFontSizeFunction::GetKey() { |
414 return kPixelSizeKey; | 413 return kPixelSizeKey; |
415 } | 414 } |
416 | 415 |
417 const char* FontSettingsSetDefaultFontSizeFunction::GetPrefName() { | 416 const char* SetDefaultFontSizeFunction::GetPrefName() { |
418 return prefs::kWebKitDefaultFontSize; | 417 return prefs::kWebKitDefaultFontSize; |
419 } | 418 } |
420 | 419 |
421 const char* FontSettingsSetDefaultFontSizeFunction::GetKey() { | 420 const char* SetDefaultFontSizeFunction::GetKey() { |
422 return kPixelSizeKey; | 421 return kPixelSizeKey; |
423 } | 422 } |
424 | 423 |
425 const char* FontSettingsClearDefaultFixedFontSizeFunction::GetPrefName() { | 424 const char* ClearDefaultFixedFontSizeFunction::GetPrefName() { |
426 return prefs::kWebKitDefaultFixedFontSize; | 425 return prefs::kWebKitDefaultFixedFontSize; |
427 } | 426 } |
428 | 427 |
429 const char* FontSettingsGetDefaultFixedFontSizeFunction::GetPrefName() { | 428 const char* GetDefaultFixedFontSizeFunction::GetPrefName() { |
430 return prefs::kWebKitDefaultFixedFontSize; | 429 return prefs::kWebKitDefaultFixedFontSize; |
431 } | 430 } |
432 | 431 |
433 const char* FontSettingsGetDefaultFixedFontSizeFunction::GetKey() { | 432 const char* GetDefaultFixedFontSizeFunction::GetKey() { |
434 return kPixelSizeKey; | 433 return kPixelSizeKey; |
435 } | 434 } |
436 | 435 |
437 const char* FontSettingsSetDefaultFixedFontSizeFunction::GetPrefName() { | 436 const char* SetDefaultFixedFontSizeFunction::GetPrefName() { |
438 return prefs::kWebKitDefaultFixedFontSize; | 437 return prefs::kWebKitDefaultFixedFontSize; |
439 } | 438 } |
440 | 439 |
441 const char* FontSettingsSetDefaultFixedFontSizeFunction::GetKey() { | 440 const char* SetDefaultFixedFontSizeFunction::GetKey() { |
442 return kPixelSizeKey; | 441 return kPixelSizeKey; |
443 } | 442 } |
444 | 443 |
445 const char* FontSettingsClearMinimumFontSizeFunction::GetPrefName() { | 444 const char* ClearMinimumFontSizeFunction::GetPrefName() { |
446 return prefs::kWebKitMinimumFontSize; | 445 return prefs::kWebKitMinimumFontSize; |
447 } | 446 } |
448 | 447 |
449 const char* FontSettingsGetMinimumFontSizeFunction::GetPrefName() { | 448 const char* GetMinimumFontSizeFunction::GetPrefName() { |
450 return prefs::kWebKitMinimumFontSize; | 449 return prefs::kWebKitMinimumFontSize; |
451 } | 450 } |
452 | 451 |
453 const char* FontSettingsGetMinimumFontSizeFunction::GetKey() { | 452 const char* GetMinimumFontSizeFunction::GetKey() { |
454 return kPixelSizeKey; | 453 return kPixelSizeKey; |
455 } | 454 } |
456 | 455 |
457 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { | 456 const char* SetMinimumFontSizeFunction::GetPrefName() { |
458 return prefs::kWebKitMinimumFontSize; | 457 return prefs::kWebKitMinimumFontSize; |
459 } | 458 } |
460 | 459 |
461 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { | 460 const char* SetMinimumFontSizeFunction::GetKey() { |
462 return kPixelSizeKey; | 461 return kPixelSizeKey; |
463 } | 462 } |
464 | 463 |
465 } // namespace extensions | 464 } // namespace extensions |
OLD | NEW |