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