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 <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 FontSettingsAPI::GetFactoryInstance() { | 223 FontSettingsAPI::GetFactoryInstance() { |
224 return g_factory.Pointer(); | 224 return g_factory.Pointer(); |
225 } | 225 } |
226 | 226 |
227 bool FontSettingsClearFontFunction::RunSync() { | 227 bool FontSettingsClearFontFunction::RunSync() { |
228 if (GetProfile()->IsOffTheRecord()) { | 228 if (GetProfile()->IsOffTheRecord()) { |
229 error_ = kSetFromIncognitoError; | 229 error_ = kSetFromIncognitoError; |
230 return false; | 230 return false; |
231 } | 231 } |
232 | 232 |
233 scoped_ptr<fonts::ClearFont::Params> params( | 233 std::unique_ptr<fonts::ClearFont::Params> params( |
234 fonts::ClearFont::Params::Create(*args_)); | 234 fonts::ClearFont::Params::Create(*args_)); |
235 EXTENSION_FUNCTION_VALIDATE(params.get()); | 235 EXTENSION_FUNCTION_VALIDATE(params.get()); |
236 | 236 |
237 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 237 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
238 params->details.script); | 238 params->details.script); |
239 | 239 |
240 // Ensure |pref_path| really is for a registered per-script font pref. | 240 // Ensure |pref_path| really is for a registered per-script font pref. |
241 EXTENSION_FUNCTION_VALIDATE( | 241 EXTENSION_FUNCTION_VALIDATE( |
242 GetProfile()->GetPrefs()->FindPreference(pref_path)); | 242 GetProfile()->GetPrefs()->FindPreference(pref_path)); |
243 | 243 |
244 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( | 244 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( |
245 extension_id(), pref_path, kExtensionPrefsScopeRegular); | 245 extension_id(), pref_path, kExtensionPrefsScopeRegular); |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 bool FontSettingsGetFontFunction::RunSync() { | 249 bool FontSettingsGetFontFunction::RunSync() { |
250 scoped_ptr<fonts::GetFont::Params> params( | 250 std::unique_ptr<fonts::GetFont::Params> params( |
251 fonts::GetFont::Params::Create(*args_)); | 251 fonts::GetFont::Params::Create(*args_)); |
252 EXTENSION_FUNCTION_VALIDATE(params.get()); | 252 EXTENSION_FUNCTION_VALIDATE(params.get()); |
253 | 253 |
254 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 254 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
255 params->details.script); | 255 params->details.script); |
256 | 256 |
257 PrefService* prefs = GetProfile()->GetPrefs(); | 257 PrefService* prefs = GetProfile()->GetPrefs(); |
258 const PrefService::Preference* pref = | 258 const PrefService::Preference* pref = |
259 prefs->FindPreference(pref_path); | 259 prefs->FindPreference(pref_path); |
260 | 260 |
(...skipping 15 matching lines...) Expand all Loading... |
276 SetResult(result); | 276 SetResult(result); |
277 return true; | 277 return true; |
278 } | 278 } |
279 | 279 |
280 bool FontSettingsSetFontFunction::RunSync() { | 280 bool FontSettingsSetFontFunction::RunSync() { |
281 if (GetProfile()->IsOffTheRecord()) { | 281 if (GetProfile()->IsOffTheRecord()) { |
282 error_ = kSetFromIncognitoError; | 282 error_ = kSetFromIncognitoError; |
283 return false; | 283 return false; |
284 } | 284 } |
285 | 285 |
286 scoped_ptr<fonts::SetFont::Params> params( | 286 std::unique_ptr<fonts::SetFont::Params> params( |
287 fonts::SetFont::Params::Create(*args_)); | 287 fonts::SetFont::Params::Create(*args_)); |
288 EXTENSION_FUNCTION_VALIDATE(params.get()); | 288 EXTENSION_FUNCTION_VALIDATE(params.get()); |
289 | 289 |
290 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, | 290 std::string pref_path = GetFontNamePrefPath(params->details.generic_family, |
291 params->details.script); | 291 params->details.script); |
292 | 292 |
293 // Ensure |pref_path| really is for a registered font pref. | 293 // Ensure |pref_path| really is for a registered font pref. |
294 EXTENSION_FUNCTION_VALIDATE( | 294 EXTENSION_FUNCTION_VALIDATE( |
295 GetProfile()->GetPrefs()->FindPreference(pref_path)); | 295 GetProfile()->GetPrefs()->FindPreference(pref_path)); |
296 | 296 |
297 PreferenceAPI::Get(GetProfile())->SetExtensionControlledPref( | 297 PreferenceAPI::Get(GetProfile())->SetExtensionControlledPref( |
298 extension_id(), | 298 extension_id(), |
299 pref_path, | 299 pref_path, |
300 kExtensionPrefsScopeRegular, | 300 kExtensionPrefsScopeRegular, |
301 new base::StringValue(params->details.font_id)); | 301 new base::StringValue(params->details.font_id)); |
302 return true; | 302 return true; |
303 } | 303 } |
304 | 304 |
305 bool FontSettingsGetFontListFunction::RunAsync() { | 305 bool FontSettingsGetFontListFunction::RunAsync() { |
306 content::GetFontListAsync( | 306 content::GetFontListAsync( |
307 Bind(&FontSettingsGetFontListFunction::FontListHasLoaded, this)); | 307 Bind(&FontSettingsGetFontListFunction::FontListHasLoaded, this)); |
308 return true; | 308 return true; |
309 } | 309 } |
310 | 310 |
311 void FontSettingsGetFontListFunction::FontListHasLoaded( | 311 void FontSettingsGetFontListFunction::FontListHasLoaded( |
312 scoped_ptr<base::ListValue> list) { | 312 std::unique_ptr<base::ListValue> list) { |
313 bool success = CopyFontsToResult(list.get()); | 313 bool success = CopyFontsToResult(list.get()); |
314 SendResponse(success); | 314 SendResponse(success); |
315 } | 315 } |
316 | 316 |
317 bool FontSettingsGetFontListFunction::CopyFontsToResult( | 317 bool FontSettingsGetFontListFunction::CopyFontsToResult( |
318 base::ListValue* fonts) { | 318 base::ListValue* fonts) { |
319 scoped_ptr<base::ListValue> result(new base::ListValue()); | 319 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
320 for (base::ListValue::iterator it = fonts->begin(); | 320 for (base::ListValue::iterator it = fonts->begin(); |
321 it != fonts->end(); ++it) { | 321 it != fonts->end(); ++it) { |
322 base::ListValue* font_list_value; | 322 base::ListValue* font_list_value; |
323 if (!(*it)->GetAsList(&font_list_value)) { | 323 if (!(*it)->GetAsList(&font_list_value)) { |
324 NOTREACHED(); | 324 NOTREACHED(); |
325 return false; | 325 return false; |
326 } | 326 } |
327 | 327 |
328 std::string name; | 328 std::string name; |
329 if (!font_list_value->GetString(0, &name)) { | 329 if (!font_list_value->GetString(0, &name)) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 452 |
453 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { | 453 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { |
454 return prefs::kWebKitMinimumFontSize; | 454 return prefs::kWebKitMinimumFontSize; |
455 } | 455 } |
456 | 456 |
457 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { | 457 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { |
458 return kPixelSizeKey; | 458 return kPixelSizeKey; |
459 } | 459 } |
460 | 460 |
461 } // namespace extensions | 461 } // namespace extensions |
OLD | NEW |