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 |
| 11 #include <memory> |
| 12 #include <utility> |
| 13 |
11 #include "base/bind.h" | 14 #include "base/bind.h" |
12 #include "base/command_line.h" | 15 #include "base/command_line.h" |
13 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
14 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
15 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
16 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
18 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
19 #include "base/values.h" | 22 #include "base/values.h" |
20 #include "build/build_config.h" | 23 #include "build/build_config.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 pref && pref->GetValue()->GetAsString(&font_name)); | 266 pref && pref->GetValue()->GetAsString(&font_name)); |
264 font_name = MaybeGetLocalizedFontName(font_name); | 267 font_name = MaybeGetLocalizedFontName(font_name); |
265 | 268 |
266 // We don't support incognito-specific font prefs, so don't consider them when | 269 // We don't support incognito-specific font prefs, so don't consider them when |
267 // getting level of control. | 270 // getting level of control. |
268 const bool kIncognito = false; | 271 const bool kIncognito = false; |
269 std::string level_of_control = | 272 std::string level_of_control = |
270 extensions::preference_helpers::GetLevelOfControl( | 273 extensions::preference_helpers::GetLevelOfControl( |
271 GetProfile(), extension_id(), pref_path, kIncognito); | 274 GetProfile(), extension_id(), pref_path, kIncognito); |
272 | 275 |
273 base::DictionaryValue* result = new base::DictionaryValue(); | 276 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
274 result->SetString(kFontIdKey, font_name); | 277 result->SetString(kFontIdKey, font_name); |
275 result->SetString(kLevelOfControlKey, level_of_control); | 278 result->SetString(kLevelOfControlKey, level_of_control); |
276 SetResult(result); | 279 SetResult(std::move(result)); |
277 return true; | 280 return true; |
278 } | 281 } |
279 | 282 |
280 bool FontSettingsSetFontFunction::RunSync() { | 283 bool FontSettingsSetFontFunction::RunSync() { |
281 if (GetProfile()->IsOffTheRecord()) { | 284 if (GetProfile()->IsOffTheRecord()) { |
282 error_ = kSetFromIncognitoError; | 285 error_ = kSetFromIncognitoError; |
283 return false; | 286 return false; |
284 } | 287 } |
285 | 288 |
286 std::unique_ptr<fonts::SetFont::Params> params( | 289 std::unique_ptr<fonts::SetFont::Params> params( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 NOTREACHED(); | 339 NOTREACHED(); |
337 return false; | 340 return false; |
338 } | 341 } |
339 | 342 |
340 base::DictionaryValue* font_name = new base::DictionaryValue(); | 343 base::DictionaryValue* font_name = new base::DictionaryValue(); |
341 font_name->Set(kFontIdKey, new base::StringValue(name)); | 344 font_name->Set(kFontIdKey, new base::StringValue(name)); |
342 font_name->Set(kDisplayNameKey, new base::StringValue(localized_name)); | 345 font_name->Set(kDisplayNameKey, new base::StringValue(localized_name)); |
343 result->Append(font_name); | 346 result->Append(font_name); |
344 } | 347 } |
345 | 348 |
346 SetResult(result.release()); | 349 SetResult(std::move(result)); |
347 return true; | 350 return true; |
348 } | 351 } |
349 | 352 |
350 bool ClearFontPrefExtensionFunction::RunSync() { | 353 bool ClearFontPrefExtensionFunction::RunSync() { |
351 if (GetProfile()->IsOffTheRecord()) { | 354 if (GetProfile()->IsOffTheRecord()) { |
352 error_ = kSetFromIncognitoError; | 355 error_ = kSetFromIncognitoError; |
353 return false; | 356 return false; |
354 } | 357 } |
355 | 358 |
356 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( | 359 PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( |
357 extension_id(), GetPrefName(), kExtensionPrefsScopeRegular); | 360 extension_id(), GetPrefName(), kExtensionPrefsScopeRegular); |
358 return true; | 361 return true; |
359 } | 362 } |
360 | 363 |
361 bool GetFontPrefExtensionFunction::RunSync() { | 364 bool GetFontPrefExtensionFunction::RunSync() { |
362 PrefService* prefs = GetProfile()->GetPrefs(); | 365 PrefService* prefs = GetProfile()->GetPrefs(); |
363 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName()); | 366 const PrefService::Preference* pref = prefs->FindPreference(GetPrefName()); |
364 EXTENSION_FUNCTION_VALIDATE(pref); | 367 EXTENSION_FUNCTION_VALIDATE(pref); |
365 | 368 |
366 // We don't support incognito-specific font prefs, so don't consider them when | 369 // We don't support incognito-specific font prefs, so don't consider them when |
367 // getting level of control. | 370 // getting level of control. |
368 const bool kIncognito = false; | 371 const bool kIncognito = false; |
369 | 372 |
370 std::string level_of_control = | 373 std::string level_of_control = |
371 extensions::preference_helpers::GetLevelOfControl( | 374 extensions::preference_helpers::GetLevelOfControl( |
372 GetProfile(), extension_id(), GetPrefName(), kIncognito); | 375 GetProfile(), extension_id(), GetPrefName(), kIncognito); |
373 | 376 |
374 base::DictionaryValue* result = new base::DictionaryValue(); | 377 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
375 result->Set(GetKey(), pref->GetValue()->DeepCopy()); | 378 result->Set(GetKey(), pref->GetValue()->DeepCopy()); |
376 result->SetString(kLevelOfControlKey, level_of_control); | 379 result->SetString(kLevelOfControlKey, level_of_control); |
377 SetResult(result); | 380 SetResult(std::move(result)); |
378 return true; | 381 return true; |
379 } | 382 } |
380 | 383 |
381 bool SetFontPrefExtensionFunction::RunSync() { | 384 bool SetFontPrefExtensionFunction::RunSync() { |
382 if (GetProfile()->IsOffTheRecord()) { | 385 if (GetProfile()->IsOffTheRecord()) { |
383 error_ = kSetFromIncognitoError; | 386 error_ = kSetFromIncognitoError; |
384 return false; | 387 return false; |
385 } | 388 } |
386 | 389 |
387 base::DictionaryValue* details = NULL; | 390 base::DictionaryValue* details = NULL; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 455 |
453 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { | 456 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { |
454 return prefs::kWebKitMinimumFontSize; | 457 return prefs::kWebKitMinimumFontSize; |
455 } | 458 } |
456 | 459 |
457 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { | 460 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { |
458 return kPixelSizeKey; | 461 return kPixelSizeKey; |
459 } | 462 } |
460 | 463 |
461 } // namespace extensions | 464 } // namespace extensions |
OLD | NEW |