OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_api.h" | 5 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <unordered_set> | 11 #include <unordered_set> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/ptr_util.h" |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_delegate.h" | 25 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_delegate.h" |
25 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_delegate_factory.h" | 26 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_delegate_factory.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 language.display_name_rtl.reset(new bool(true)); | 235 language.display_name_rtl.reset(new bool(true)); |
235 if (locale_set.count(pair.first) > 0) | 236 if (locale_set.count(pair.first) > 0) |
236 language.supports_ui.reset(new bool(true)); | 237 language.supports_ui.reset(new bool(true)); |
237 if (spellcheck_language_set.count(pair.first) > 0) | 238 if (spellcheck_language_set.count(pair.first) > 0) |
238 language.supports_spellcheck.reset(new bool(true)); | 239 language.supports_spellcheck.reset(new bool(true)); |
239 if (translate_language_set.count(pair.first) > 0) | 240 if (translate_language_set.count(pair.first) > 0) |
240 language.supports_translate.reset(new bool(true)); | 241 language.supports_translate.reset(new bool(true)); |
241 | 242 |
242 language_list->Append(language.ToValue()); | 243 language_list->Append(language.ToValue()); |
243 } | 244 } |
244 return RespondNow(OneArgument(language_list.release())); | 245 return RespondNow(OneArgument(std::move(language_list))); |
245 } | 246 } |
246 | 247 |
247 LanguageSettingsPrivateSetLanguageListFunction:: | 248 LanguageSettingsPrivateSetLanguageListFunction:: |
248 LanguageSettingsPrivateSetLanguageListFunction() | 249 LanguageSettingsPrivateSetLanguageListFunction() |
249 : chrome_details_(this) { | 250 : chrome_details_(this) { |
250 } | 251 } |
251 | 252 |
252 LanguageSettingsPrivateSetLanguageListFunction:: | 253 LanguageSettingsPrivateSetLanguageListFunction:: |
253 ~LanguageSettingsPrivateSetLanguageListFunction() { | 254 ~LanguageSettingsPrivateSetLanguageListFunction() { |
254 } | 255 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 ~LanguageSettingsPrivateGetSpellcheckWordsFunction() { | 296 ~LanguageSettingsPrivateGetSpellcheckWordsFunction() { |
296 } | 297 } |
297 | 298 |
298 ExtensionFunction::ResponseAction | 299 ExtensionFunction::ResponseAction |
299 LanguageSettingsPrivateGetSpellcheckWordsFunction::Run() { | 300 LanguageSettingsPrivateGetSpellcheckWordsFunction::Run() { |
300 SpellcheckService* service = | 301 SpellcheckService* service = |
301 SpellcheckServiceFactory::GetForContext(browser_context()); | 302 SpellcheckServiceFactory::GetForContext(browser_context()); |
302 SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary(); | 303 SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary(); |
303 | 304 |
304 if (dictionary->IsLoaded()) | 305 if (dictionary->IsLoaded()) |
305 return RespondNow(OneArgument(GetSpellcheckWords().release())); | 306 return RespondNow(OneArgument(GetSpellcheckWords())); |
306 | 307 |
307 dictionary->AddObserver(this); | 308 dictionary->AddObserver(this); |
308 AddRef(); // Balanced in OnCustomDictionaryLoaded(). | 309 AddRef(); // Balanced in OnCustomDictionaryLoaded(). |
309 return RespondLater(); | 310 return RespondLater(); |
310 } | 311 } |
311 | 312 |
312 void | 313 void |
313 LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryLoaded() { | 314 LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryLoaded() { |
314 SpellcheckService* service = | 315 SpellcheckService* service = |
315 SpellcheckServiceFactory::GetForContext(browser_context()); | 316 SpellcheckServiceFactory::GetForContext(browser_context()); |
316 service->GetCustomDictionary()->RemoveObserver(this); | 317 service->GetCustomDictionary()->RemoveObserver(this); |
317 Respond(OneArgument(GetSpellcheckWords().release())); | 318 Respond(OneArgument(GetSpellcheckWords())); |
318 Release(); | 319 Release(); |
319 } | 320 } |
320 | 321 |
321 void | 322 void |
322 LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryChanged( | 323 LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryChanged( |
323 const SpellcheckCustomDictionary::Change& dictionary_change) { | 324 const SpellcheckCustomDictionary::Change& dictionary_change) { |
324 NOTREACHED() << "SpellcheckCustomDictionary::Observer: " | 325 NOTREACHED() << "SpellcheckCustomDictionary::Observer: " |
325 "OnCustomDictionaryChanged() called before " | 326 "OnCustomDictionaryChanged() called before " |
326 "OnCustomDictionaryLoaded()"; | 327 "OnCustomDictionaryLoaded()"; |
327 } | 328 } |
(...skipping 24 matching lines...) Expand all Loading... |
352 ExtensionFunction::ResponseAction | 353 ExtensionFunction::ResponseAction |
353 LanguageSettingsPrivateAddSpellcheckWordFunction::Run() { | 354 LanguageSettingsPrivateAddSpellcheckWordFunction::Run() { |
354 std::unique_ptr<language_settings_private::AddSpellcheckWord::Params> params = | 355 std::unique_ptr<language_settings_private::AddSpellcheckWord::Params> params = |
355 language_settings_private::AddSpellcheckWord::Params::Create(*args_); | 356 language_settings_private::AddSpellcheckWord::Params::Create(*args_); |
356 EXTENSION_FUNCTION_VALIDATE(params.get()); | 357 EXTENSION_FUNCTION_VALIDATE(params.get()); |
357 | 358 |
358 SpellcheckService* service = | 359 SpellcheckService* service = |
359 SpellcheckServiceFactory::GetForContext(browser_context()); | 360 SpellcheckServiceFactory::GetForContext(browser_context()); |
360 bool success = service->GetCustomDictionary()->AddWord(params->word); | 361 bool success = service->GetCustomDictionary()->AddWord(params->word); |
361 | 362 |
362 return RespondNow(OneArgument(new base::FundamentalValue(success))); | 363 return RespondNow( |
| 364 OneArgument(base::MakeUnique<base::FundamentalValue>(success))); |
363 } | 365 } |
364 | 366 |
365 LanguageSettingsPrivateRemoveSpellcheckWordFunction:: | 367 LanguageSettingsPrivateRemoveSpellcheckWordFunction:: |
366 LanguageSettingsPrivateRemoveSpellcheckWordFunction() { | 368 LanguageSettingsPrivateRemoveSpellcheckWordFunction() { |
367 } | 369 } |
368 | 370 |
369 LanguageSettingsPrivateRemoveSpellcheckWordFunction:: | 371 LanguageSettingsPrivateRemoveSpellcheckWordFunction:: |
370 ~LanguageSettingsPrivateRemoveSpellcheckWordFunction() { | 372 ~LanguageSettingsPrivateRemoveSpellcheckWordFunction() { |
371 } | 373 } |
372 | 374 |
373 ExtensionFunction::ResponseAction | 375 ExtensionFunction::ResponseAction |
374 LanguageSettingsPrivateRemoveSpellcheckWordFunction::Run() { | 376 LanguageSettingsPrivateRemoveSpellcheckWordFunction::Run() { |
375 std::unique_ptr<language_settings_private::RemoveSpellcheckWord::Params> | 377 std::unique_ptr<language_settings_private::RemoveSpellcheckWord::Params> |
376 params = language_settings_private::RemoveSpellcheckWord::Params::Create( | 378 params = language_settings_private::RemoveSpellcheckWord::Params::Create( |
377 *args_); | 379 *args_); |
378 EXTENSION_FUNCTION_VALIDATE(params.get()); | 380 EXTENSION_FUNCTION_VALIDATE(params.get()); |
379 | 381 |
380 SpellcheckService* service = | 382 SpellcheckService* service = |
381 SpellcheckServiceFactory::GetForContext(browser_context()); | 383 SpellcheckServiceFactory::GetForContext(browser_context()); |
382 bool success = service->GetCustomDictionary()->RemoveWord(params->word); | 384 bool success = service->GetCustomDictionary()->RemoveWord(params->word); |
383 | 385 |
384 return RespondNow(OneArgument(new base::FundamentalValue(success))); | 386 return RespondNow( |
| 387 OneArgument(base::MakeUnique<base::FundamentalValue>(success))); |
385 } | 388 } |
386 | 389 |
387 LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: | 390 LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: |
388 LanguageSettingsPrivateGetTranslateTargetLanguageFunction() | 391 LanguageSettingsPrivateGetTranslateTargetLanguageFunction() |
389 : chrome_details_(this) { | 392 : chrome_details_(this) { |
390 } | 393 } |
391 | 394 |
392 LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: | 395 LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: |
393 ~LanguageSettingsPrivateGetTranslateTargetLanguageFunction() { | 396 ~LanguageSettingsPrivateGetTranslateTargetLanguageFunction() { |
394 } | 397 } |
395 | 398 |
396 ExtensionFunction::ResponseAction | 399 ExtensionFunction::ResponseAction |
397 LanguageSettingsPrivateGetTranslateTargetLanguageFunction::Run() { | 400 LanguageSettingsPrivateGetTranslateTargetLanguageFunction::Run() { |
398 return RespondNow(OneArgument(new base::StringValue( | 401 return RespondNow(OneArgument( |
399 TranslateService::GetTargetLanguage( | 402 base::MakeUnique<base::StringValue>(TranslateService::GetTargetLanguage( |
400 chrome_details_.GetProfile()->GetPrefs())))); | 403 chrome_details_.GetProfile()->GetPrefs())))); |
401 } | 404 } |
402 | 405 |
403 #if defined(OS_CHROMEOS) | 406 #if defined(OS_CHROMEOS) |
404 // Populates the vector of input methods using information in the list of | 407 // Populates the vector of input methods using information in the list of |
405 // descriptors. Used for languageSettingsPrivate.getInputMethodLists(). | 408 // descriptors. Used for languageSettingsPrivate.getInputMethodLists(). |
406 void PopulateInputMethodListFromDescriptors( | 409 void PopulateInputMethodListFromDescriptors( |
407 const InputMethodDescriptors& descriptors, | 410 const InputMethodDescriptors& descriptors, |
408 std::vector<language_settings_private::InputMethod>* input_methods) { | 411 std::vector<language_settings_private::InputMethod>* input_methods) { |
409 InputMethodManager* manager = InputMethodManager::Get(); | 412 InputMethodManager* manager = InputMethodManager::Get(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 input_method_list.end(), input_method_id); | 565 input_method_list.end(), input_method_id); |
563 if (pos != input_method_list.end()) { | 566 if (pos != input_method_list.end()) { |
564 input_method_list.erase(pos); | 567 input_method_list.erase(pos); |
565 prefs->SetString(pref_name, base::JoinString(input_method_list, ",")); | 568 prefs->SetString(pref_name, base::JoinString(input_method_list, ",")); |
566 } | 569 } |
567 #endif | 570 #endif |
568 return RespondNow(NoArguments()); | 571 return RespondNow(NoArguments()); |
569 } | 572 } |
570 | 573 |
571 } // namespace extensions | 574 } // namespace extensions |
OLD | NEW |