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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 static base::LazyInstance<BrowserContextKeyedAPIFactory<FontSettingsAPI> > | 214 static base::LazyInstance<BrowserContextKeyedAPIFactory<FontSettingsAPI> > |
215 g_factory = LAZY_INSTANCE_INITIALIZER; | 215 g_factory = LAZY_INSTANCE_INITIALIZER; |
216 | 216 |
217 // static | 217 // static |
218 BrowserContextKeyedAPIFactory<FontSettingsAPI>* | 218 BrowserContextKeyedAPIFactory<FontSettingsAPI>* |
219 FontSettingsAPI::GetFactoryInstance() { | 219 FontSettingsAPI::GetFactoryInstance() { |
220 return g_factory.Pointer(); | 220 return g_factory.Pointer(); |
221 } | 221 } |
222 | 222 |
223 bool FontSettingsClearFontFunction::RunImpl() { | 223 bool FontSettingsClearFontFunction::RunSync() { |
224 if (GetProfile()->IsOffTheRecord()) { | 224 if (GetProfile()->IsOffTheRecord()) { |
225 error_ = kSetFromIncognitoError; | 225 error_ = kSetFromIncognitoError; |
226 return false; | 226 return false; |
227 } | 227 } |
228 | 228 |
229 scoped_ptr<fonts::ClearFont::Params> params( | 229 scoped_ptr<fonts::ClearFont::Params> params( |
230 fonts::ClearFont::Params::Create(*args_)); | 230 fonts::ClearFont::Params::Create(*args_)); |
231 EXTENSION_FUNCTION_VALIDATE(params.get()); | 231 EXTENSION_FUNCTION_VALIDATE(params.get()); |
232 | 232 |
233 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 233 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
234 params->details.script); | 234 params->details.script); |
235 | 235 |
236 // Ensure |pref_path| really is for a registered per-script font pref. | 236 // Ensure |pref_path| really is for a registered per-script font pref. |
237 EXTENSION_FUNCTION_VALIDATE( | 237 EXTENSION_FUNCTION_VALIDATE( |
238 GetProfile()->GetPrefs()->FindPreference(pref_path.c_str())); | 238 GetProfile()->GetPrefs()->FindPreference(pref_path.c_str())); |
239 | 239 |
240 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( | 240 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( |
241 extension_id(), pref_path.c_str(), kExtensionPrefsScopeRegular); | 241 extension_id(), pref_path.c_str(), kExtensionPrefsScopeRegular); |
242 return true; | 242 return true; |
243 } | 243 } |
244 | 244 |
245 bool FontSettingsGetFontFunction::RunImpl() { | 245 bool FontSettingsGetFontFunction::RunSync() { |
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 = GetProfile()->GetPrefs(); | 253 PrefService* prefs = GetProfile()->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 10 matching lines...) Expand all Loading... |
266 extensions::preference_helpers::GetLevelOfControl( | 266 extensions::preference_helpers::GetLevelOfControl( |
267 GetProfile(), extension_id(), pref_path, kIncognito); | 267 GetProfile(), extension_id(), pref_path, kIncognito); |
268 | 268 |
269 base::DictionaryValue* result = new base::DictionaryValue(); | 269 base::DictionaryValue* result = new base::DictionaryValue(); |
270 result->SetString(kFontIdKey, font_name); | 270 result->SetString(kFontIdKey, font_name); |
271 result->SetString(kLevelOfControlKey, level_of_control); | 271 result->SetString(kLevelOfControlKey, level_of_control); |
272 SetResult(result); | 272 SetResult(result); |
273 return true; | 273 return true; |
274 } | 274 } |
275 | 275 |
276 bool FontSettingsSetFontFunction::RunImpl() { | 276 bool FontSettingsSetFontFunction::RunSync() { |
277 if (GetProfile()->IsOffTheRecord()) { | 277 if (GetProfile()->IsOffTheRecord()) { |
278 error_ = kSetFromIncognitoError; | 278 error_ = kSetFromIncognitoError; |
279 return false; | 279 return false; |
280 } | 280 } |
281 | 281 |
282 scoped_ptr<fonts::SetFont::Params> params( | 282 scoped_ptr<fonts::SetFont::Params> params( |
283 fonts::SetFont::Params::Create(*args_)); | 283 fonts::SetFont::Params::Create(*args_)); |
284 EXTENSION_FUNCTION_VALIDATE(params.get()); | 284 EXTENSION_FUNCTION_VALIDATE(params.get()); |
285 | 285 |
286 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 286 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 base::DictionaryValue* font_name = new base::DictionaryValue(); | 336 base::DictionaryValue* font_name = new base::DictionaryValue(); |
337 font_name->Set(kFontIdKey, new base::StringValue(name)); | 337 font_name->Set(kFontIdKey, new base::StringValue(name)); |
338 font_name->Set(kDisplayNameKey, new base::StringValue(localized_name)); | 338 font_name->Set(kDisplayNameKey, new base::StringValue(localized_name)); |
339 result->Append(font_name); | 339 result->Append(font_name); |
340 } | 340 } |
341 | 341 |
342 SetResult(result.release()); | 342 SetResult(result.release()); |
343 return true; | 343 return true; |
344 } | 344 } |
345 | 345 |
346 bool ClearFontPrefExtensionFunction::RunImpl() { | 346 bool ClearFontPrefExtensionFunction::RunSync() { |
347 if (GetProfile()->IsOffTheRecord()) { | 347 if (GetProfile()->IsOffTheRecord()) { |
348 error_ = kSetFromIncognitoError; | 348 error_ = kSetFromIncognitoError; |
349 return false; | 349 return false; |
350 } | 350 } |
351 | 351 |
352 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( | 352 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( |
353 extension_id(), GetPrefName(), kExtensionPrefsScopeRegular); | 353 extension_id(), GetPrefName(), kExtensionPrefsScopeRegular); |
354 return true; | 354 return true; |
355 } | 355 } |
356 | 356 |
357 bool GetFontPrefExtensionFunction::RunImpl() { | 357 bool GetFontPrefExtensionFunction::RunSync() { |
358 PrefService* prefs = GetProfile()->GetPrefs(); | 358 PrefService* prefs = GetProfile()->GetPrefs(); |
359 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName()); | 359 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName()); |
360 EXTENSION_FUNCTION_VALIDATE(pref); | 360 EXTENSION_FUNCTION_VALIDATE(pref); |
361 | 361 |
362 // We don't support incognito-specific font prefs, so don't consider them when | 362 // We don't support incognito-specific font prefs, so don't consider them when |
363 // getting level of control. | 363 // getting level of control. |
364 const bool kIncognito = false; | 364 const bool kIncognito = false; |
365 | 365 |
366 std::string level_of_control = | 366 std::string level_of_control = |
367 extensions::preference_helpers::GetLevelOfControl( | 367 extensions::preference_helpers::GetLevelOfControl( |
368 GetProfile(), extension_id(), GetPrefName(), kIncognito); | 368 GetProfile(), extension_id(), GetPrefName(), kIncognito); |
369 | 369 |
370 base::DictionaryValue* result = new base::DictionaryValue(); | 370 base::DictionaryValue* result = new base::DictionaryValue(); |
371 result->Set(GetKey(), pref->GetValue()->DeepCopy()); | 371 result->Set(GetKey(), pref->GetValue()->DeepCopy()); |
372 result->SetString(kLevelOfControlKey, level_of_control); | 372 result->SetString(kLevelOfControlKey, level_of_control); |
373 SetResult(result); | 373 SetResult(result); |
374 return true; | 374 return true; |
375 } | 375 } |
376 | 376 |
377 bool SetFontPrefExtensionFunction::RunImpl() { | 377 bool SetFontPrefExtensionFunction::RunSync() { |
378 if (GetProfile()->IsOffTheRecord()) { | 378 if (GetProfile()->IsOffTheRecord()) { |
379 error_ = kSetFromIncognitoError; | 379 error_ = kSetFromIncognitoError; |
380 return false; | 380 return false; |
381 } | 381 } |
382 | 382 |
383 base::DictionaryValue* details = NULL; | 383 base::DictionaryValue* details = NULL; |
384 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 384 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
385 | 385 |
386 base::Value* value; | 386 base::Value* value; |
387 EXTENSION_FUNCTION_VALIDATE(details->Get(GetKey(), &value)); | 387 EXTENSION_FUNCTION_VALIDATE(details->Get(GetKey(), &value)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 448 |
449 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { | 449 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { |
450 return prefs::kWebKitMinimumFontSize; | 450 return prefs::kWebKitMinimumFontSize; |
451 } | 451 } |
452 | 452 |
453 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { | 453 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { |
454 return kPixelSizeKey; | 454 return kPixelSizeKey; |
455 } | 455 } |
456 | 456 |
457 } // namespace extensions | 457 } // namespace extensions |
OLD | NEW |