OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/login/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/screen_locker.h" |
6 | 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
7 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
9 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
10 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_list.h" | 16 #include "chrome/browser/browser_list.h" |
| 17 #include "chrome/browser/chromeos/cros/language_library.h" |
13 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 18 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
| 19 #include "chrome/browser/chromeos/language_preferences.h" |
14 #include "chrome/browser/chromeos/login/authenticator.h" | 20 #include "chrome/browser/chromeos/login/authenticator.h" |
15 #include "chrome/browser/chromeos/login/background_view.h" | 21 #include "chrome/browser/chromeos/login/background_view.h" |
16 #include "chrome/browser/chromeos/login/login_utils.h" | 22 #include "chrome/browser/chromeos/login/login_utils.h" |
17 #include "chrome/browser/chromeos/login/message_bubble.h" | 23 #include "chrome/browser/chromeos/login/message_bubble.h" |
18 #include "chrome/browser/chromeos/login/screen_lock_view.h" | 24 #include "chrome/browser/chromeos/login/screen_lock_view.h" |
19 #include "chrome/browser/metrics/user_metrics.h" | 25 #include "chrome/browser/metrics/user_metrics.h" |
20 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
21 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
23 #include "views/screen.h" | 29 #include "views/screen.h" |
24 #include "views/widget/root_view.h" | 30 #include "views/widget/root_view.h" |
25 #include "views/widget/widget_gtk.h" | 31 #include "views/widget/widget_gtk.h" |
26 | 32 |
27 #include "chrome/browser/chromeos/wm_ipc.h" | 33 #include "chrome/browser/chromeos/wm_ipc.h" |
28 #include "third_party/cros/chromeos_wm_ipc_enums.h" | 34 #include "third_party/cros/chromeos_wm_ipc_enums.h" |
29 | 35 |
30 namespace { | 36 namespace { |
31 // The maxium times that the screen locker should try to grab input, | 37 // The maxium times that the screen locker should try to grab input, |
32 // and its interval. It has to be able to grab all inputs in 30 seconds, | 38 // and its interval. It has to be able to grab all inputs in 30 seconds, |
33 // otherwise chromium process fails and the session is terminated. | 39 // otherwise chromium process fails and the session is terminated. |
34 const int64 kRetryGrabIntervalMs = 500; | 40 const int64 kRetryGrabIntervalMs = 500; |
35 const int kGrabFailureLimit = 60; | 41 const int kGrabFailureLimit = 60; |
| 42 // Each keyboard layout has a dummy input method ID which starts with "xkb:". |
| 43 const char kValidInputMethodPrefix[] = "xkb:"; |
36 | 44 |
37 // Observer to start ScreenLocker when the screen lock | 45 // Observer to start ScreenLocker when the screen lock |
38 class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, | 46 class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, |
39 public NotificationObserver { | 47 public NotificationObserver { |
40 public: | 48 public: |
41 ScreenLockObserver() { | 49 ScreenLockObserver() { |
42 registrar_.Add(this, NotificationType::LOGIN_USER_CHANGED, | 50 registrar_.Add(this, NotificationType::LOGIN_USER_CHANGED, |
43 NotificationService::AllSources()); | 51 NotificationService::AllSources()); |
44 } | 52 } |
45 | 53 |
46 // NotificationObserver overrides: | 54 // NotificationObserver overrides: |
47 virtual void Observe(NotificationType type, | 55 virtual void Observe(NotificationType type, |
48 const NotificationSource& source, | 56 const NotificationSource& source, |
49 const NotificationDetails& details) { | 57 const NotificationDetails& details) { |
50 if (type == NotificationType::LOGIN_USER_CHANGED) { | 58 if (type == NotificationType::LOGIN_USER_CHANGED) { |
51 // Register Screen Lock after login screen to make sure | 59 // Register Screen Lock after login screen to make sure |
52 // we don't show the screen lock on top of the login screen by accident. | 60 // we don't show the screen lock on top of the login screen by accident. |
53 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) | 61 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) |
54 chromeos::CrosLibrary::Get()->GetScreenLockLibrary()->AddObserver(this); | 62 chromeos::CrosLibrary::Get()->GetScreenLockLibrary()->AddObserver(this); |
55 } | 63 } |
56 } | 64 } |
57 | 65 |
58 virtual void LockScreen(chromeos::ScreenLockLibrary* obj) { | 66 virtual void LockScreen(chromeos::ScreenLockLibrary* obj) { |
| 67 SetupInputMethodsForScreenLocker(); |
59 chromeos::ScreenLocker::Show(); | 68 chromeos::ScreenLocker::Show(); |
60 } | 69 } |
61 | 70 |
62 virtual void UnlockScreen(chromeos::ScreenLockLibrary* obj) { | 71 virtual void UnlockScreen(chromeos::ScreenLockLibrary* obj) { |
| 72 RestoreInputMethods(); |
63 chromeos::ScreenLocker::Hide(); | 73 chromeos::ScreenLocker::Hide(); |
64 } | 74 } |
65 | 75 |
66 virtual void UnlockScreenFailed(chromeos::ScreenLockLibrary* obj) { | 76 virtual void UnlockScreenFailed(chromeos::ScreenLockLibrary* obj) { |
67 chromeos::ScreenLocker::UnlockScreenFailed(); | 77 chromeos::ScreenLocker::UnlockScreenFailed(); |
68 } | 78 } |
69 | 79 |
70 private: | 80 private: |
| 81 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) |
| 82 // since they are not necessary to input a login password. Users are still |
| 83 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, |
| 84 // French). |
| 85 void SetupInputMethodsForScreenLocker() { |
| 86 if (chromeos::CrosLibrary::Get()->EnsureLoaded() && |
| 87 // The LockScreen function is also called when the OS is suspended, and |
| 88 // in that case |saved_active_input_method_list_| might be non-empty. |
| 89 saved_active_input_method_list_.empty()) { |
| 90 chromeos::LanguageLibrary* language = |
| 91 chromeos::CrosLibrary::Get()->GetLanguageLibrary(); |
| 92 saved_current_input_method_id_ = language->current_input_method().id; |
| 93 // TODO(yusukes): save/restore previous input method ID. |
| 94 scoped_ptr<chromeos::InputMethodDescriptors> active_input_method_list( |
| 95 language->GetActiveInputMethods()); |
| 96 |
| 97 chromeos::ImeConfigValue value; |
| 98 value.type = chromeos::ImeConfigValue::kValueTypeStringList; |
| 99 for (size_t i = 0; i < active_input_method_list->size(); ++i) { |
| 100 const std::string& input_method_id = active_input_method_list->at(i).id; |
| 101 saved_active_input_method_list_.push_back(input_method_id); |
| 102 // |active_input_method_list| contains both input method descriptions |
| 103 // and keyboard layout descriptions. |
| 104 if (!StartsWithASCII(input_method_id, kValidInputMethodPrefix, true)) |
| 105 continue; |
| 106 value.string_list_value.push_back(input_method_id); |
| 107 } |
| 108 if (value.string_list_value.empty()) { |
| 109 value.string_list_value.push_back(kFallbackInputMethodId); // US qwerty |
| 110 } |
| 111 language->SetImeConfig(chromeos::kGeneralSectionName, |
| 112 chromeos::kPreloadEnginesConfigName, |
| 113 value); |
| 114 } |
| 115 } |
| 116 |
| 117 void RestoreInputMethods() { |
| 118 if (chromeos::CrosLibrary::Get()->EnsureLoaded() && |
| 119 !saved_active_input_method_list_.empty()) { |
| 120 chromeos::LanguageLibrary* language = |
| 121 chromeos::CrosLibrary::Get()->GetLanguageLibrary(); |
| 122 |
| 123 chromeos::ImeConfigValue value; |
| 124 value.type = chromeos::ImeConfigValue::kValueTypeStringList; |
| 125 value.string_list_value = saved_active_input_method_list_; |
| 126 language->SetImeConfig(chromeos::kGeneralSectionName, |
| 127 chromeos::kPreloadEnginesConfigName, |
| 128 value); |
| 129 language->ChangeInputMethod(saved_current_input_method_id_); |
| 130 |
| 131 saved_current_input_method_id_.clear(); |
| 132 saved_active_input_method_list_.clear(); |
| 133 } |
| 134 } |
| 135 |
71 NotificationRegistrar registrar_; | 136 NotificationRegistrar registrar_; |
| 137 std::string saved_current_input_method_id_; |
| 138 std::vector<std::string> saved_active_input_method_list_; |
72 | 139 |
73 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); | 140 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); |
74 }; | 141 }; |
75 | 142 |
76 // A child widget that grabs both keyboard and pointer input. | 143 // A child widget that grabs both keyboard and pointer input. |
77 // TODO(oshima): catch grab-broke event and quit if it ever happenes. | 144 // TODO(oshima): catch grab-broke event and quit if it ever happenes. |
78 class GrabWidget : public views::WidgetGtk { | 145 class GrabWidget : public views::WidgetGtk { |
79 public: | 146 public: |
80 explicit GrabWidget(chromeos::ScreenLocker* screen_locker) | 147 explicit GrabWidget(chromeos::ScreenLocker* screen_locker) |
81 : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), | 148 : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 LOG(INFO) << "Screen is unlocked"; | 482 LOG(INFO) << "Screen is unlocked"; |
416 } | 483 } |
417 } | 484 } |
418 | 485 |
419 // static | 486 // static |
420 void ScreenLocker::InitClass() { | 487 void ScreenLocker::InitClass() { |
421 Singleton<ScreenLockObserver>::get(); | 488 Singleton<ScreenLockObserver>::get(); |
422 } | 489 } |
423 | 490 |
424 } // namespace chromeos | 491 } // namespace chromeos |
OLD | NEW |