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