Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: chrome/browser/chromeos/base/locale_util.cc

Issue 133273032: Guest Mode: input method should default to the underlying latin keyboard layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Use EnableInputMethod instead of EnableInputMethods. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/base/locale_util.h" 5 #include "chrome/browser/chromeos/base/locale_util.h"
6 6
7 #include <vector>
8
7 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/input_method/input_method_util.h" 10 #include "chrome/browser/chromeos/input_method/input_method_util.h"
9 #include "chromeos/ime/input_method_manager.h" 11 #include "chromeos/ime/input_method_manager.h"
10 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
11 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/platform_font_pango.h" 14 #include "ui/gfx/platform_font_pango.h"
13 15
14 namespace chromeos { 16 namespace chromeos {
15 17
16 namespace { 18 namespace {
17 19
18 struct SwitchLanguageData { 20 struct SwitchLanguageData {
19 SwitchLanguageData(const std::string& locale, 21 SwitchLanguageData(const std::string& locale,
20 const bool enableLocaleKeyboardLayouts, 22 const bool enableLocaleKeyboardLayouts,
23 const bool login_layouts_only,
21 scoped_ptr<locale_util::SwitchLanguageCallback> callback) 24 scoped_ptr<locale_util::SwitchLanguageCallback> callback)
22 : callback(callback.Pass()), 25 : callback(callback.Pass()),
23 locale(locale), 26 locale(locale),
24 enableLocaleKeyboardLayouts(enableLocaleKeyboardLayouts), 27 enableLocaleKeyboardLayouts(enableLocaleKeyboardLayouts),
28 login_layouts_only(login_layouts_only),
25 success(false) {} 29 success(false) {}
26 30
27 scoped_ptr<locale_util::SwitchLanguageCallback> callback; 31 scoped_ptr<locale_util::SwitchLanguageCallback> callback;
28 32
29 const std::string locale; 33 const std::string locale;
30 const bool enableLocaleKeyboardLayouts; 34 const bool enableLocaleKeyboardLayouts;
35 const bool login_layouts_only;
31 std::string loaded_locale; 36 std::string loaded_locale;
32 bool success; 37 bool success;
33 }; 38 };
34 39
35 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). 40 // Runs on SequencedWorkerPool thread under PostTaskAndReply().
36 // So data is owned by "Reply" part of PostTaskAndReply() process. 41 // So data is owned by "Reply" part of PostTaskAndReply() process.
37 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { 42 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) {
38 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 43 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
39 44
40 data->loaded_locale = 45 data->loaded_locale =
(...skipping 10 matching lines...) Expand all
51 if (data->success) { 56 if (data->success) {
52 g_browser_process->SetApplicationLocale(data->loaded_locale); 57 g_browser_process->SetApplicationLocale(data->loaded_locale);
53 58
54 if (data->enableLocaleKeyboardLayouts) { 59 if (data->enableLocaleKeyboardLayouts) {
55 // If we have switched the locale, enable the keyboard layouts that 60 // If we have switched the locale, enable the keyboard layouts that
56 // are necessary for the new locale. Change the current input method 61 // are necessary for the new locale. Change the current input method
57 // to the hardware keyboard layout since the input method currently in 62 // to the hardware keyboard layout since the input method currently in
58 // use may not be supported by the new locale (3rd parameter). 63 // use may not be supported by the new locale (3rd parameter).
59 input_method::InputMethodManager* manager = 64 input_method::InputMethodManager* manager =
60 input_method::InputMethodManager::Get(); 65 input_method::InputMethodManager::Get();
61 manager->EnableLayouts( 66 manager->EnableLoginLayouts(
62 data->locale, 67 data->locale,
63 manager->GetInputMethodUtil()->GetHardwareInputMethodId()); 68 manager->GetInputMethodUtil()->GetHardwareLoginInputMethodId());
69 if (!data->login_layouts_only) {
70 // Enable all the other layouts
71 std::vector<std::string> candidates;
72 input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
73 // Add input methods associated with the language.
74 util->GetInputMethodIdsFromLanguageCode(
75 data->locale, input_method::kKeyboardLayoutsOnly, &candidates);
76 for (std::vector<std::string>::const_iterator i = candidates.begin();
77 i != candidates.end();
78 ++i)
79 manager->EnableInputMethod(*i);
80 }
64 } 81 }
65 } 82 }
66 gfx::PlatformFontPango::ReloadDefaultFont(); 83 gfx::PlatformFontPango::ReloadDefaultFont();
67 if (data->callback) 84 if (data->callback)
68 data->callback->Run(data->locale, data->loaded_locale, data->success); 85 data->callback->Run(data->locale, data->loaded_locale, data->success);
69 } 86 }
70 87
71 } // namespace 88 } // namespace
72 89
73 namespace locale_util { 90 namespace locale_util {
74 91
75 void SwitchLanguage(const std::string& locale, 92 void SwitchLanguage(const std::string& locale,
76 bool enableLocaleKeyboardLayouts, 93 const bool enableLocaleKeyboardLayouts,
94 const bool login_layouts_only,
77 scoped_ptr<SwitchLanguageCallback> callback) { 95 scoped_ptr<SwitchLanguageCallback> callback) {
78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
79 scoped_ptr<SwitchLanguageData> data(new SwitchLanguageData( 97 scoped_ptr<SwitchLanguageData> data(
80 locale, enableLocaleKeyboardLayouts, callback.Pass())); 98 new SwitchLanguageData(locale,
99 enableLocaleKeyboardLayouts,
100 login_layouts_only,
101 callback.Pass()));
81 base::Closure reloader( 102 base::Closure reloader(
82 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); 103 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get())));
83 content::BrowserThread::PostBlockingPoolTaskAndReply( 104 content::BrowserThread::PostBlockingPoolTaskAndReply(
84 FROM_HERE, 105 FROM_HERE,
85 reloader, 106 reloader,
86 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); 107 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass())));
87 } 108 }
88 109
89 } // namespace locale_util 110 } // namespace locale_util
90 } // namespace chromeos 111 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/base/locale_util.h ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698