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