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 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 input_method::InputMethodManager* manager = | 112 input_method::InputMethodManager* manager = |
113 input_method::InputMethodManager::Get(); | 113 input_method::InputMethodManager::Get(); |
114 // GetSupportedInputMethods() never return NULL. | 114 // GetSupportedInputMethods() never return NULL. |
115 scoped_ptr<input_method::InputMethodDescriptors> descriptors( | 115 scoped_ptr<input_method::InputMethodDescriptors> descriptors( |
116 manager->GetSupportedInputMethods()); | 116 manager->GetSupportedInputMethods()); |
117 localized_strings->Set("languageList", GetAcceptLanguageList(*descriptors)); | 117 localized_strings->Set("languageList", GetAcceptLanguageList(*descriptors)); |
118 localized_strings->Set("inputMethodList", GetInputMethodList(*descriptors)); | 118 localized_strings->Set("inputMethodList", GetInputMethodList(*descriptors)); |
119 | 119 |
120 input_method::InputMethodDescriptors ext_ime_descriptors; | 120 input_method::InputMethodDescriptors ext_ime_descriptors; |
121 manager->GetInputMethodExtensions(&ext_ime_descriptors); | 121 manager->GetInputMethodExtensions(&ext_ime_descriptors); |
122 localized_strings->Set("extensionImeList", | 122 |
123 ConvertInputMethodDescriptosToIMEList( | 123 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( |
124 ext_ime_descriptors)); | 124 ext_ime_descriptors); |
| 125 AddImeProvider(ext_ime_list); |
| 126 localized_strings->Set("extensionImeList", ext_ime_list); |
125 | 127 |
126 ComponentExtensionIMEManager* component_extension_manager = | 128 ComponentExtensionIMEManager* component_extension_manager = |
127 input_method::InputMethodManager::Get() | 129 input_method::InputMethodManager::Get() |
128 ->GetComponentExtensionIMEManager(); | 130 ->GetComponentExtensionIMEManager(); |
129 if (component_extension_manager->IsInitialized()) { | 131 if (component_extension_manager->IsInitialized()) { |
130 localized_strings->Set( | 132 localized_strings->Set( |
131 "componentExtensionImeList", | 133 "componentExtensionImeList", |
132 ConvertInputMethodDescriptosToIMEList( | 134 ConvertInputMethodDescriptorsToIMEList( |
133 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | 135 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); |
134 composition_extension_appended_ = true; | 136 composition_extension_appended_ = true; |
135 } else { | 137 } else { |
136 // If component extension IME manager is not ready for use, it will be | 138 // If component extension IME manager is not ready for use, it will be |
137 // added in |InitializePage()|. | 139 // added in |InitializePage()|. |
138 localized_strings->Set("componentExtensionImeList", | 140 localized_strings->Set("componentExtensionImeList", |
139 new base::ListValue()); | 141 new base::ListValue()); |
140 } | 142 } |
141 } | 143 } |
142 | 144 |
143 void CrosLanguageOptionsHandler::RegisterMessages() { | 145 void CrosLanguageOptionsHandler::RegisterMessages() { |
144 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); | 146 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); |
145 | 147 |
146 web_ui()->RegisterMessageCallback("inputMethodDisable", | 148 web_ui()->RegisterMessageCallback("inputMethodDisable", |
147 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, | 149 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, |
148 base::Unretained(this))); | 150 base::Unretained(this))); |
149 web_ui()->RegisterMessageCallback("inputMethodEnable", | 151 web_ui()->RegisterMessageCallback("inputMethodEnable", |
150 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, | 152 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, |
151 base::Unretained(this))); | 153 base::Unretained(this))); |
152 web_ui()->RegisterMessageCallback("inputMethodOptionsOpen", | 154 web_ui()->RegisterMessageCallback("inputMethodOptionsOpen", |
153 base::Bind(&CrosLanguageOptionsHandler::InputMethodOptionsOpenCallback, | 155 base::Bind(&CrosLanguageOptionsHandler::InputMethodOptionsOpenCallback, |
154 base::Unretained(this))); | 156 base::Unretained(this))); |
155 web_ui()->RegisterMessageCallback("uiLanguageRestart", | 157 web_ui()->RegisterMessageCallback("uiLanguageRestart", |
156 base::Bind(&CrosLanguageOptionsHandler::RestartCallback, | 158 base::Bind(&CrosLanguageOptionsHandler::RestartCallback, |
157 base::Unretained(this))); | 159 base::Unretained(this))); |
158 } | 160 } |
159 | 161 |
| 162 // static |
160 base::ListValue* CrosLanguageOptionsHandler::GetInputMethodList( | 163 base::ListValue* CrosLanguageOptionsHandler::GetInputMethodList( |
161 const input_method::InputMethodDescriptors& descriptors) { | 164 const input_method::InputMethodDescriptors& descriptors) { |
162 input_method::InputMethodManager* manager = | 165 input_method::InputMethodManager* manager = |
163 input_method::InputMethodManager::Get(); | 166 input_method::InputMethodManager::Get(); |
164 | 167 |
165 base::ListValue* input_method_list = new base::ListValue(); | 168 base::ListValue* input_method_list = new base::ListValue(); |
166 | 169 |
167 for (size_t i = 0; i < descriptors.size(); ++i) { | 170 for (size_t i = 0; i < descriptors.size(); ++i) { |
168 const input_method::InputMethodDescriptor& descriptor = | 171 const input_method::InputMethodDescriptor& descriptor = |
169 descriptors[i]; | 172 descriptors[i]; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 414 |
412 // static | 415 // static |
413 base::ListValue* CrosLanguageOptionsHandler::GetUILanguageList( | 416 base::ListValue* CrosLanguageOptionsHandler::GetUILanguageList( |
414 const input_method::InputMethodDescriptors& descriptors) { | 417 const input_method::InputMethodDescriptors& descriptors) { |
415 // Collect the language codes from the available locales. | 418 // Collect the language codes from the available locales. |
416 return GetLanguageListInternal( | 419 return GetLanguageListInternal( |
417 descriptors, l10n_util::GetAvailableLocales(), true); | 420 descriptors, l10n_util::GetAvailableLocales(), true); |
418 } | 421 } |
419 | 422 |
420 base::ListValue* | 423 base::ListValue* |
421 CrosLanguageOptionsHandler::ConvertInputMethodDescriptosToIMEList( | 424 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList( |
422 const input_method::InputMethodDescriptors& descriptors) { | 425 const input_method::InputMethodDescriptors& descriptors) { |
423 scoped_ptr<base::ListValue> ime_ids_list(new base::ListValue()); | 426 scoped_ptr<base::ListValue> ime_ids_list(new base::ListValue()); |
424 for (size_t i = 0; i < descriptors.size(); ++i) { | 427 for (size_t i = 0; i < descriptors.size(); ++i) { |
425 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; | 428 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; |
426 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); | 429 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); |
427 dictionary->SetString("id", descriptor.id()); | 430 dictionary->SetString("id", descriptor.id()); |
428 dictionary->SetString("displayName", descriptor.name()); | 431 dictionary->SetString("displayName", descriptor.name()); |
429 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); | 432 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); |
430 scoped_ptr<base::DictionaryValue> language_codes( | 433 scoped_ptr<base::DictionaryValue> language_codes( |
431 new base::DictionaryValue()); | 434 new base::DictionaryValue()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // extension IMEs will be done in InitializePage function later. | 515 // extension IMEs will be done in InitializePage function later. |
513 return; | 516 return; |
514 } | 517 } |
515 | 518 |
516 ComponentExtensionIMEManager* manager = | 519 ComponentExtensionIMEManager* manager = |
517 input_method::InputMethodManager::Get() | 520 input_method::InputMethodManager::Get() |
518 ->GetComponentExtensionIMEManager(); | 521 ->GetComponentExtensionIMEManager(); |
519 | 522 |
520 DCHECK(manager->IsInitialized()); | 523 DCHECK(manager->IsInitialized()); |
521 scoped_ptr<base::ListValue> ime_list( | 524 scoped_ptr<base::ListValue> ime_list( |
522 ConvertInputMethodDescriptosToIMEList( | 525 ConvertInputMethodDescriptorsToIMEList( |
523 manager->GetAllIMEAsInputMethodDescriptor())); | 526 manager->GetAllIMEAsInputMethodDescriptor())); |
524 web_ui()->CallJavascriptFunction( | 527 web_ui()->CallJavascriptFunction( |
525 "options.LanguageOptions.onComponentManagerInitialized", | 528 "options.LanguageOptions.onComponentManagerInitialized", |
526 *ime_list); | 529 *ime_list); |
527 composition_extension_appended_ = true; | 530 composition_extension_appended_ = true; |
528 } | 531 } |
529 | 532 |
530 void CrosLanguageOptionsHandler::InitializePage() { | 533 void CrosLanguageOptionsHandler::InitializePage() { |
531 is_page_initialized_ = true; | 534 is_page_initialized_ = true; |
532 if (composition_extension_appended_) | 535 if (composition_extension_appended_) |
533 return; | 536 return; |
534 | 537 |
535 ComponentExtensionIMEManager* component_extension_manager = | 538 ComponentExtensionIMEManager* component_extension_manager = |
536 input_method::InputMethodManager::Get() | 539 input_method::InputMethodManager::Get() |
537 ->GetComponentExtensionIMEManager(); | 540 ->GetComponentExtensionIMEManager(); |
538 if (!component_extension_manager->IsInitialized()) { | 541 if (!component_extension_manager->IsInitialized()) { |
539 // If the component extension IME manager is not available yet, append the | 542 // If the component extension IME manager is not available yet, append the |
540 // component extension list in |OnInitialized()|. | 543 // component extension list in |OnInitialized()|. |
541 return; | 544 return; |
542 } | 545 } |
543 | 546 |
544 scoped_ptr<base::ListValue> ime_list( | 547 scoped_ptr<base::ListValue> ime_list( |
545 ConvertInputMethodDescriptosToIMEList( | 548 ConvertInputMethodDescriptorsToIMEList( |
546 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | 549 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); |
547 web_ui()->CallJavascriptFunction( | 550 web_ui()->CallJavascriptFunction( |
548 "options.LanguageOptions.onComponentManagerInitialized", | 551 "options.LanguageOptions.onComponentManagerInitialized", |
549 *ime_list); | 552 *ime_list); |
550 composition_extension_appended_ = true; | 553 composition_extension_appended_ = true; |
551 } | 554 } |
552 | 555 |
| 556 void CrosLanguageOptionsHandler::AddImeProvider(base::ListValue* list) { |
| 557 Profile* profile = Profile::FromWebUI(web_ui()); |
| 558 ExtensionService* extension_service = profile->GetExtensionService(); |
| 559 for (size_t i = 0; i < list->GetSize(); i++) { |
| 560 base::DictionaryValue* entry; |
| 561 list->GetDictionary(i, &entry); |
| 562 |
| 563 std::string input_method_id; |
| 564 entry->GetString("id", &input_method_id); |
| 565 |
| 566 std::string extension_id = |
| 567 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); |
| 568 const extensions::Extension* extension = |
| 569 extension_service->GetExtensionById(extension_id, false); |
| 570 if (extension) |
| 571 entry->SetString("extensionName", extension->name()); |
| 572 } |
| 573 } |
| 574 |
553 } // namespace options | 575 } // namespace options |
554 } // namespace chromeos | 576 } // namespace chromeos |
OLD | NEW |