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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
34 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
35 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
37 | 37 |
38 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
39 | 39 |
40 namespace chromeos { | 40 namespace chromeos { |
41 namespace options { | 41 namespace options { |
42 | 42 |
43 CrosLanguageOptionsHandler::CrosLanguageOptionsHandler() | 43 CrosLanguageOptionsHandler::CrosLanguageOptionsHandler() { |
44 : composition_extension_appended_(false), | |
45 is_page_initialized_(false) { | |
46 input_method::InputMethodManager::Get()->GetComponentExtensionIMEManager()-> | |
47 AddObserver(this); | |
48 } | 44 } |
49 | 45 |
50 CrosLanguageOptionsHandler::~CrosLanguageOptionsHandler() { | 46 CrosLanguageOptionsHandler::~CrosLanguageOptionsHandler() { |
51 input_method::InputMethodManager::Get()->GetComponentExtensionIMEManager()-> | |
52 RemoveObserver(this); | |
53 } | 47 } |
54 | 48 |
55 void CrosLanguageOptionsHandler::GetLocalizedValues( | 49 void CrosLanguageOptionsHandler::GetLocalizedValues( |
56 base::DictionaryValue* localized_strings) { | 50 base::DictionaryValue* localized_strings) { |
57 ::options::LanguageOptionsHandlerCommon::GetLocalizedValues( | 51 ::options::LanguageOptionsHandlerCommon::GetLocalizedValues( |
58 localized_strings); | 52 localized_strings); |
59 | 53 |
60 RegisterTitle(localized_strings, "languagePage", | 54 RegisterTitle(localized_strings, "languagePage", |
61 IDS_OPTIONS_SETTINGS_LANGUAGES_AND_INPUT_DIALOG_TITLE); | 55 IDS_OPTIONS_SETTINGS_LANGUAGES_AND_INPUT_DIALOG_TITLE); |
62 localized_strings->SetString("okButton", l10n_util::GetStringUTF16(IDS_OK)); | 56 localized_strings->SetString("okButton", l10n_util::GetStringUTF16(IDS_OK)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 manager->GetInputMethodExtensions(&ext_ime_descriptors); | 93 manager->GetInputMethodExtensions(&ext_ime_descriptors); |
100 | 94 |
101 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( | 95 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( |
102 ext_ime_descriptors); | 96 ext_ime_descriptors); |
103 AddImeProvider(ext_ime_list); | 97 AddImeProvider(ext_ime_list); |
104 localized_strings->Set("extensionImeList", ext_ime_list); | 98 localized_strings->Set("extensionImeList", ext_ime_list); |
105 | 99 |
106 ComponentExtensionIMEManager* component_extension_manager = | 100 ComponentExtensionIMEManager* component_extension_manager = |
107 input_method::InputMethodManager::Get() | 101 input_method::InputMethodManager::Get() |
108 ->GetComponentExtensionIMEManager(); | 102 ->GetComponentExtensionIMEManager(); |
109 if (component_extension_manager->IsInitialized()) { | 103 localized_strings->Set( |
110 localized_strings->Set( | 104 "componentExtensionImeList", |
111 "componentExtensionImeList", | 105 ConvertInputMethodDescriptorsToIMEList( |
112 ConvertInputMethodDescriptorsToIMEList( | 106 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); |
113 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | |
114 composition_extension_appended_ = true; | |
115 } else { | |
116 // If component extension IME manager is not ready for use, it will be | |
117 // added in |InitializePage()|. | |
118 localized_strings->Set("componentExtensionImeList", | |
119 new base::ListValue()); | |
120 } | |
121 } | 107 } |
122 | 108 |
123 void CrosLanguageOptionsHandler::RegisterMessages() { | 109 void CrosLanguageOptionsHandler::RegisterMessages() { |
124 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); | 110 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); |
125 | 111 |
126 web_ui()->RegisterMessageCallback("inputMethodDisable", | 112 web_ui()->RegisterMessageCallback("inputMethodDisable", |
127 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, | 113 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, |
128 base::Unretained(this))); | 114 base::Unretained(this))); |
129 web_ui()->RegisterMessageCallback("inputMethodEnable", | 115 web_ui()->RegisterMessageCallback("inputMethodEnable", |
130 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, | 116 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 SINGLETON_TAB, | 241 SINGLETON_TAB, |
256 content::PAGE_TRANSITION_LINK, | 242 content::PAGE_TRANSITION_LINK, |
257 false); | 243 false); |
258 browser->OpenURL(params); | 244 browser->OpenURL(params); |
259 browser->window()->Show(); | 245 browser->window()->Show(); |
260 content::WebContents* web_contents = | 246 content::WebContents* web_contents = |
261 browser->tab_strip_model()->GetActiveWebContents(); | 247 browser->tab_strip_model()->GetActiveWebContents(); |
262 web_contents->GetDelegate()->ActivateContents(web_contents); | 248 web_contents->GetDelegate()->ActivateContents(web_contents); |
263 } | 249 } |
264 | 250 |
265 void CrosLanguageOptionsHandler::OnImeComponentExtensionInitialized() { | |
266 if (composition_extension_appended_ || !is_page_initialized_) { | |
267 // If an option page is not ready to call JavaScript, appending component | |
268 // extension IMEs will be done in InitializePage function later. | |
269 return; | |
270 } | |
271 | |
272 ComponentExtensionIMEManager* manager = | |
273 input_method::InputMethodManager::Get() | |
274 ->GetComponentExtensionIMEManager(); | |
275 | |
276 DCHECK(manager->IsInitialized()); | |
277 scoped_ptr<base::ListValue> ime_list( | |
278 ConvertInputMethodDescriptorsToIMEList( | |
279 manager->GetAllIMEAsInputMethodDescriptor())); | |
280 web_ui()->CallJavascriptFunction( | |
281 "options.LanguageOptions.onComponentManagerInitialized", | |
282 *ime_list); | |
283 composition_extension_appended_ = true; | |
284 } | |
285 | |
286 void CrosLanguageOptionsHandler::InitializePage() { | |
287 is_page_initialized_ = true; | |
288 if (composition_extension_appended_) | |
289 return; | |
290 | |
291 ComponentExtensionIMEManager* component_extension_manager = | |
292 input_method::InputMethodManager::Get() | |
293 ->GetComponentExtensionIMEManager(); | |
294 if (!component_extension_manager->IsInitialized()) { | |
295 // If the component extension IME manager is not available yet, append the | |
296 // component extension list in |OnInitialized()|. | |
297 return; | |
298 } | |
299 | |
300 scoped_ptr<base::ListValue> ime_list( | |
301 ConvertInputMethodDescriptorsToIMEList( | |
302 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | |
303 web_ui()->CallJavascriptFunction( | |
304 "options.LanguageOptions.onComponentManagerInitialized", | |
305 *ime_list); | |
306 composition_extension_appended_ = true; | |
307 } | |
308 | |
309 void CrosLanguageOptionsHandler::AddImeProvider(base::ListValue* list) { | 251 void CrosLanguageOptionsHandler::AddImeProvider(base::ListValue* list) { |
310 Profile* profile = Profile::FromWebUI(web_ui()); | 252 Profile* profile = Profile::FromWebUI(web_ui()); |
311 const extensions::ExtensionSet& enabled_extensions = | 253 const extensions::ExtensionSet& enabled_extensions = |
312 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 254 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
313 for (size_t i = 0; i < list->GetSize(); ++i) { | 255 for (size_t i = 0; i < list->GetSize(); ++i) { |
314 base::DictionaryValue* entry; | 256 base::DictionaryValue* entry; |
315 list->GetDictionary(i, &entry); | 257 list->GetDictionary(i, &entry); |
316 | 258 |
317 std::string input_method_id; | 259 std::string input_method_id; |
318 entry->GetString("id", &input_method_id); | 260 entry->GetString("id", &input_method_id); |
319 | 261 |
320 std::string extension_id = | 262 std::string extension_id = |
321 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); | 263 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); |
322 const extensions::Extension* extension = | 264 const extensions::Extension* extension = |
323 enabled_extensions.GetByID(extension_id); | 265 enabled_extensions.GetByID(extension_id); |
324 if (extension) | 266 if (extension) |
325 entry->SetString("extensionName", extension->name()); | 267 entry->SetString("extensionName", extension->name()); |
326 } | 268 } |
327 } | 269 } |
328 | 270 |
329 } // namespace options | 271 } // namespace options |
330 } // namespace chromeos | 272 } // namespace chromeos |
OLD | NEW |