| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 namespace chromeos { | 57 namespace chromeos { |
| 58 namespace options { | 58 namespace options { |
| 59 | 59 |
| 60 const char kVendorOtherLanguagesListDivider[] = | 60 const char kVendorOtherLanguagesListDivider[] = |
| 61 "VENDOR_OTHER_LANGUAGES_LIST_DIVIDER"; | 61 "VENDOR_OTHER_LANGUAGES_LIST_DIVIDER"; |
| 62 | 62 |
| 63 CrosLanguageOptionsHandler::CrosLanguageOptionsHandler() | 63 CrosLanguageOptionsHandler::CrosLanguageOptionsHandler() { |
| 64 : composition_extension_appended_(false), | |
| 65 is_page_initialized_(false) { | |
| 66 input_method::InputMethodManager::Get()->GetComponentExtensionIMEManager()-> | |
| 67 AddObserver(this); | |
| 68 } | 64 } |
| 69 | 65 |
| 70 CrosLanguageOptionsHandler::~CrosLanguageOptionsHandler() { | 66 CrosLanguageOptionsHandler::~CrosLanguageOptionsHandler() { |
| 71 input_method::InputMethodManager::Get()->GetComponentExtensionIMEManager()-> | |
| 72 RemoveObserver(this); | |
| 73 } | 67 } |
| 74 | 68 |
| 75 void CrosLanguageOptionsHandler::GetLocalizedValues( | 69 void CrosLanguageOptionsHandler::GetLocalizedValues( |
| 76 base::DictionaryValue* localized_strings) { | 70 base::DictionaryValue* localized_strings) { |
| 77 ::options::LanguageOptionsHandlerCommon::GetLocalizedValues( | 71 ::options::LanguageOptionsHandlerCommon::GetLocalizedValues( |
| 78 localized_strings); | 72 localized_strings); |
| 79 | 73 |
| 80 RegisterTitle(localized_strings, "languagePage", | 74 RegisterTitle(localized_strings, "languagePage", |
| 81 IDS_OPTIONS_SETTINGS_LANGUAGES_AND_INPUT_DIALOG_TITLE); | 75 IDS_OPTIONS_SETTINGS_LANGUAGES_AND_INPUT_DIALOG_TITLE); |
| 82 localized_strings->SetString("okButton", l10n_util::GetStringUTF16(IDS_OK)); | 76 localized_strings->SetString("okButton", l10n_util::GetStringUTF16(IDS_OK)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 manager->GetInputMethodExtensions(&ext_ime_descriptors); | 115 manager->GetInputMethodExtensions(&ext_ime_descriptors); |
| 122 | 116 |
| 123 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( | 117 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( |
| 124 ext_ime_descriptors); | 118 ext_ime_descriptors); |
| 125 AddImeProvider(ext_ime_list); | 119 AddImeProvider(ext_ime_list); |
| 126 localized_strings->Set("extensionImeList", ext_ime_list); | 120 localized_strings->Set("extensionImeList", ext_ime_list); |
| 127 | 121 |
| 128 ComponentExtensionIMEManager* component_extension_manager = | 122 ComponentExtensionIMEManager* component_extension_manager = |
| 129 input_method::InputMethodManager::Get() | 123 input_method::InputMethodManager::Get() |
| 130 ->GetComponentExtensionIMEManager(); | 124 ->GetComponentExtensionIMEManager(); |
| 131 if (component_extension_manager->IsInitialized()) { | 125 localized_strings->Set( |
| 132 localized_strings->Set( | 126 "componentExtensionImeList", |
| 133 "componentExtensionImeList", | 127 ConvertInputMethodDescriptorsToIMEList( |
| 134 ConvertInputMethodDescriptorsToIMEList( | 128 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); |
| 135 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | |
| 136 composition_extension_appended_ = true; | |
| 137 } else { | |
| 138 // If component extension IME manager is not ready for use, it will be | |
| 139 // added in |InitializePage()|. | |
| 140 localized_strings->Set("componentExtensionImeList", | |
| 141 new base::ListValue()); | |
| 142 } | |
| 143 } | 129 } |
| 144 | 130 |
| 145 void CrosLanguageOptionsHandler::RegisterMessages() { | 131 void CrosLanguageOptionsHandler::RegisterMessages() { |
| 146 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); | 132 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); |
| 147 | 133 |
| 148 web_ui()->RegisterMessageCallback("inputMethodDisable", | 134 web_ui()->RegisterMessageCallback("inputMethodDisable", |
| 149 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, | 135 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, |
| 150 base::Unretained(this))); | 136 base::Unretained(this))); |
| 151 web_ui()->RegisterMessageCallback("inputMethodEnable", | 137 web_ui()->RegisterMessageCallback("inputMethodEnable", |
| 152 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, | 138 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 SINGLETON_TAB, | 488 SINGLETON_TAB, |
| 503 content::PAGE_TRANSITION_LINK, | 489 content::PAGE_TRANSITION_LINK, |
| 504 false); | 490 false); |
| 505 browser->OpenURL(params); | 491 browser->OpenURL(params); |
| 506 browser->window()->Show(); | 492 browser->window()->Show(); |
| 507 content::WebContents* web_contents = | 493 content::WebContents* web_contents = |
| 508 browser->tab_strip_model()->GetActiveWebContents(); | 494 browser->tab_strip_model()->GetActiveWebContents(); |
| 509 web_contents->GetDelegate()->ActivateContents(web_contents); | 495 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 510 } | 496 } |
| 511 | 497 |
| 512 void CrosLanguageOptionsHandler::OnImeComponentExtensionInitialized() { | |
| 513 if (composition_extension_appended_ || !is_page_initialized_) { | |
| 514 // If an option page is not ready to call JavaScript, appending component | |
| 515 // extension IMEs will be done in InitializePage function later. | |
| 516 return; | |
| 517 } | |
| 518 | |
| 519 ComponentExtensionIMEManager* manager = | |
| 520 input_method::InputMethodManager::Get() | |
| 521 ->GetComponentExtensionIMEManager(); | |
| 522 | |
| 523 DCHECK(manager->IsInitialized()); | |
| 524 scoped_ptr<base::ListValue> ime_list( | |
| 525 ConvertInputMethodDescriptorsToIMEList( | |
| 526 manager->GetAllIMEAsInputMethodDescriptor())); | |
| 527 web_ui()->CallJavascriptFunction( | |
| 528 "options.LanguageOptions.onComponentManagerInitialized", | |
| 529 *ime_list); | |
| 530 composition_extension_appended_ = true; | |
| 531 } | |
| 532 | |
| 533 void CrosLanguageOptionsHandler::InitializePage() { | |
| 534 is_page_initialized_ = true; | |
| 535 if (composition_extension_appended_) | |
| 536 return; | |
| 537 | |
| 538 ComponentExtensionIMEManager* component_extension_manager = | |
| 539 input_method::InputMethodManager::Get() | |
| 540 ->GetComponentExtensionIMEManager(); | |
| 541 if (!component_extension_manager->IsInitialized()) { | |
| 542 // If the component extension IME manager is not available yet, append the | |
| 543 // component extension list in |OnInitialized()|. | |
| 544 return; | |
| 545 } | |
| 546 | |
| 547 scoped_ptr<base::ListValue> ime_list( | |
| 548 ConvertInputMethodDescriptorsToIMEList( | |
| 549 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | |
| 550 web_ui()->CallJavascriptFunction( | |
| 551 "options.LanguageOptions.onComponentManagerInitialized", | |
| 552 *ime_list); | |
| 553 composition_extension_appended_ = true; | |
| 554 } | |
| 555 | |
| 556 void CrosLanguageOptionsHandler::AddImeProvider(base::ListValue* list) { | 498 void CrosLanguageOptionsHandler::AddImeProvider(base::ListValue* list) { |
| 557 Profile* profile = Profile::FromWebUI(web_ui()); | 499 Profile* profile = Profile::FromWebUI(web_ui()); |
| 558 const extensions::ExtensionSet& enabled_extensions = | 500 const extensions::ExtensionSet& enabled_extensions = |
| 559 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 501 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
| 560 for (size_t i = 0; i < list->GetSize(); ++i) { | 502 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 561 base::DictionaryValue* entry; | 503 base::DictionaryValue* entry; |
| 562 list->GetDictionary(i, &entry); | 504 list->GetDictionary(i, &entry); |
| 563 | 505 |
| 564 std::string input_method_id; | 506 std::string input_method_id; |
| 565 entry->GetString("id", &input_method_id); | 507 entry->GetString("id", &input_method_id); |
| 566 | 508 |
| 567 std::string extension_id = | 509 std::string extension_id = |
| 568 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); | 510 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); |
| 569 const extensions::Extension* extension = | 511 const extensions::Extension* extension = |
| 570 enabled_extensions.GetByID(extension_id); | 512 enabled_extensions.GetByID(extension_id); |
| 571 if (extension) | 513 if (extension) |
| 572 entry->SetString("extensionName", extension->name()); | 514 entry->SetString("extensionName", extension->name()); |
| 573 } | 515 } |
| 574 } | 516 } |
| 575 | 517 |
| 576 } // namespace options | 518 } // namespace options |
| 577 } // namespace chromeos | 519 } // namespace chromeos |
| OLD | NEW |