Chromium Code Reviews| 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> | 11 #include <memory> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
|
jdoerrie
2017/04/06 14:25:50
#include "base/memory/ptr_util.h"
vabr (Chromium)
2017/04/07 20:40:40
Done.
| |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 25 #include "chrome/browser/extensions/api/preference/preference_api.h" | 25 #include "chrome/browser/extensions/api/preference/preference_api.h" |
| 26 #include "chrome/browser/extensions/api/preference/preference_helpers.h" | 26 #include "chrome/browser/extensions/api/preference/preference_helpers.h" |
| 27 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 events::HistogramValue histogram_value, | 179 events::HistogramValue histogram_value, |
| 180 const std::string& event_name, | 180 const std::string& event_name, |
| 181 const std::string& key, | 181 const std::string& key, |
| 182 const std::string& pref_name) { | 182 const std::string& pref_name) { |
| 183 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( | 183 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( |
| 184 pref_name); | 184 pref_name); |
| 185 CHECK(pref); | 185 CHECK(pref); |
| 186 | 186 |
| 187 base::ListValue args; | 187 base::ListValue args; |
| 188 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 188 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 189 dict->Set(key, pref->GetValue()->DeepCopy()); | 189 dict->Set(key, pref->GetValue()->CreateDeepCopy()); |
| 190 args.Append(std::move(dict)); | 190 args.Append(std::move(dict)); |
| 191 | 191 |
| 192 extensions::preference_helpers::DispatchEventToExtensions( | 192 extensions::preference_helpers::DispatchEventToExtensions( |
| 193 profile_, histogram_value, event_name, &args, | 193 profile_, histogram_value, event_name, &args, |
| 194 APIPermission::kFontSettings, false, pref_name); | 194 APIPermission::kFontSettings, false, pref_name); |
| 195 } | 195 } |
| 196 | 196 |
| 197 FontSettingsAPI::FontSettingsAPI(content::BrowserContext* context) | 197 FontSettingsAPI::FontSettingsAPI(content::BrowserContext* context) |
| 198 : font_settings_event_router_( | 198 : font_settings_event_router_( |
| 199 new FontSettingsEventRouter(Profile::FromBrowserContext(context))) {} | 199 new FontSettingsEventRouter(Profile::FromBrowserContext(context))) {} |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 } | 312 } |
| 313 | 313 |
| 314 std::string localized_name; | 314 std::string localized_name; |
| 315 if (!font_list_value->GetString(1, &localized_name)) { | 315 if (!font_list_value->GetString(1, &localized_name)) { |
| 316 NOTREACHED(); | 316 NOTREACHED(); |
| 317 return false; | 317 return false; |
| 318 } | 318 } |
| 319 | 319 |
| 320 std::unique_ptr<base::DictionaryValue> font_name( | 320 std::unique_ptr<base::DictionaryValue> font_name( |
| 321 new base::DictionaryValue()); | 321 new base::DictionaryValue()); |
| 322 font_name->Set(kFontIdKey, new base::Value(name)); | 322 font_name->Set(kFontIdKey, base::MakeUnique<base::Value>(name)); |
| 323 font_name->Set(kDisplayNameKey, new base::Value(localized_name)); | 323 font_name->Set(kDisplayNameKey, |
| 324 base::MakeUnique<base::Value>(localized_name)); | |
| 324 result->Append(std::move(font_name)); | 325 result->Append(std::move(font_name)); |
| 325 } | 326 } |
| 326 | 327 |
| 327 SetResult(std::move(result)); | 328 SetResult(std::move(result)); |
| 328 return true; | 329 return true; |
| 329 } | 330 } |
| 330 | 331 |
| 331 ExtensionFunction::ResponseAction ClearFontPrefExtensionFunction::Run() { | 332 ExtensionFunction::ResponseAction ClearFontPrefExtensionFunction::Run() { |
| 332 Profile* profile = Profile::FromBrowserContext(browser_context()); | 333 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 333 if (profile->IsOffTheRecord()) | 334 if (profile->IsOffTheRecord()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 346 | 347 |
| 347 // We don't support incognito-specific font prefs, so don't consider them when | 348 // We don't support incognito-specific font prefs, so don't consider them when |
| 348 // getting level of control. | 349 // getting level of control. |
| 349 const bool kIncognito = false; | 350 const bool kIncognito = false; |
| 350 | 351 |
| 351 std::string level_of_control = | 352 std::string level_of_control = |
| 352 extensions::preference_helpers::GetLevelOfControl( | 353 extensions::preference_helpers::GetLevelOfControl( |
| 353 profile, extension_id(), GetPrefName(), kIncognito); | 354 profile, extension_id(), GetPrefName(), kIncognito); |
| 354 | 355 |
| 355 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 356 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 356 result->Set(GetKey(), pref->GetValue()->DeepCopy()); | 357 result->Set(GetKey(), pref->GetValue()->CreateDeepCopy()); |
| 357 result->SetString(kLevelOfControlKey, level_of_control); | 358 result->SetString(kLevelOfControlKey, level_of_control); |
| 358 return RespondNow(OneArgument(std::move(result))); | 359 return RespondNow(OneArgument(std::move(result))); |
| 359 } | 360 } |
| 360 | 361 |
| 361 ExtensionFunction::ResponseAction SetFontPrefExtensionFunction::Run() { | 362 ExtensionFunction::ResponseAction SetFontPrefExtensionFunction::Run() { |
| 362 Profile* profile = Profile::FromBrowserContext(browser_context()); | 363 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 363 if (profile->IsOffTheRecord()) | 364 if (profile->IsOffTheRecord()) |
| 364 return RespondNow(Error(kSetFromIncognitoError)); | 365 return RespondNow(Error(kSetFromIncognitoError)); |
| 365 | 366 |
| 366 base::DictionaryValue* details = NULL; | 367 base::DictionaryValue* details = NULL; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 430 |
| 430 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { | 431 const char* FontSettingsSetMinimumFontSizeFunction::GetPrefName() { |
| 431 return prefs::kWebKitMinimumFontSize; | 432 return prefs::kWebKitMinimumFontSize; |
| 432 } | 433 } |
| 433 | 434 |
| 434 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { | 435 const char* FontSettingsSetMinimumFontSizeFunction::GetKey() { |
| 435 return kPixelSizeKey; | 436 return kPixelSizeKey; |
| 436 } | 437 } |
| 437 | 438 |
| 438 } // namespace extensions | 439 } // namespace extensions |
| OLD | NEW |