OLD | NEW |
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/extensions/screenlock_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/screenlock_private_api.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/login/screen_locker.h" | 9 #include "chrome/browser/chromeos/login/screen_locker.h" |
10 #include "chrome/browser/extensions/image_loader.h" | 10 #include "chrome/browser/extensions/image_loader.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; | 54 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} | 60 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} |
61 | 61 |
62 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} | 62 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} |
63 | 63 |
64 bool ScreenlockPrivateGetLockedFunction::RunImpl() { | 64 bool ScreenlockPrivateGetLockedFunction::RunAsync() { |
65 bool locked = false; | 65 bool locked = false; |
66 chromeos::ScreenLocker* locker = | 66 chromeos::ScreenLocker* locker = |
67 chromeos::ScreenLocker::default_screen_locker(); | 67 chromeos::ScreenLocker::default_screen_locker(); |
68 if (locker) | 68 if (locker) |
69 locked = locker->locked(); | 69 locked = locker->locked(); |
70 SetResult(new base::FundamentalValue(locked)); | 70 SetResult(new base::FundamentalValue(locked)); |
71 SendResponse(error_.empty()); | 71 SendResponse(error_.empty()); |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} | 75 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} |
76 | 76 |
77 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} | 77 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} |
78 | 78 |
79 bool ScreenlockPrivateSetLockedFunction::RunImpl() { | 79 bool ScreenlockPrivateSetLockedFunction::RunAsync() { |
80 scoped_ptr<screenlock::SetLocked::Params> params( | 80 scoped_ptr<screenlock::SetLocked::Params> params( |
81 screenlock::SetLocked::Params::Create(*args_)); | 81 screenlock::SetLocked::Params::Create(*args_)); |
82 EXTENSION_FUNCTION_VALIDATE(params.get()); | 82 EXTENSION_FUNCTION_VALIDATE(params.get()); |
83 if (params->locked) { | 83 if (params->locked) { |
84 chromeos::SessionManagerClient* session_manager = | 84 chromeos::SessionManagerClient* session_manager = |
85 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 85 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
86 session_manager->RequestLockScreen(); | 86 session_manager->RequestLockScreen(); |
87 } else { | 87 } else { |
88 chromeos::ScreenLocker* locker = | 88 chromeos::ScreenLocker* locker = |
89 chromeos::ScreenLocker::default_screen_locker(); | 89 chromeos::ScreenLocker::default_screen_locker(); |
90 if (locker) | 90 if (locker) |
91 chromeos::ScreenLocker::Hide(); | 91 chromeos::ScreenLocker::Hide(); |
92 } | 92 } |
93 SendResponse(error_.empty()); | 93 SendResponse(error_.empty()); |
94 return true; | 94 return true; |
95 } | 95 } |
96 | 96 |
97 ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {} | 97 ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {} |
98 | 98 |
99 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {} | 99 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {} |
100 | 100 |
101 bool ScreenlockPrivateShowMessageFunction::RunImpl() { | 101 bool ScreenlockPrivateShowMessageFunction::RunAsync() { |
102 scoped_ptr<screenlock::ShowMessage::Params> params( | 102 scoped_ptr<screenlock::ShowMessage::Params> params( |
103 screenlock::ShowMessage::Params::Create(*args_)); | 103 screenlock::ShowMessage::Params::Create(*args_)); |
104 EXTENSION_FUNCTION_VALIDATE(params.get()); | 104 EXTENSION_FUNCTION_VALIDATE(params.get()); |
105 chromeos::ScreenLocker* locker = | 105 chromeos::ScreenLocker* locker = |
106 chromeos::ScreenLocker::default_screen_locker(); | 106 chromeos::ScreenLocker::default_screen_locker(); |
107 if (locker) | 107 if (locker) |
108 locker->ShowBannerMessage(params->message); | 108 locker->ShowBannerMessage(params->message); |
109 SendResponse(error_.empty()); | 109 SendResponse(error_.empty()); |
110 return true; | 110 return true; |
111 } | 111 } |
112 | 112 |
113 static const int kMaxButtonIconSize = 40; | 113 static const int kMaxButtonIconSize = 40; |
114 | 114 |
115 ScreenlockPrivateShowButtonFunction:: | 115 ScreenlockPrivateShowButtonFunction:: |
116 ScreenlockPrivateShowButtonFunction() {} | 116 ScreenlockPrivateShowButtonFunction() {} |
117 | 117 |
118 ScreenlockPrivateShowButtonFunction:: | 118 ScreenlockPrivateShowButtonFunction:: |
119 ~ScreenlockPrivateShowButtonFunction() {} | 119 ~ScreenlockPrivateShowButtonFunction() {} |
120 | 120 |
121 bool ScreenlockPrivateShowButtonFunction::RunImpl() { | 121 bool ScreenlockPrivateShowButtonFunction::RunAsync() { |
122 scoped_ptr<screenlock::ShowButton::Params> params( | 122 scoped_ptr<screenlock::ShowButton::Params> params( |
123 screenlock::ShowButton::Params::Create(*args_)); | 123 screenlock::ShowButton::Params::Create(*args_)); |
124 EXTENSION_FUNCTION_VALIDATE(params.get()); | 124 EXTENSION_FUNCTION_VALIDATE(params.get()); |
125 chromeos::ScreenLocker* locker = | 125 chromeos::ScreenLocker* locker = |
126 chromeos::ScreenLocker::default_screen_locker(); | 126 chromeos::ScreenLocker::default_screen_locker(); |
127 if (!locker) { | 127 if (!locker) { |
128 SetError(kNotLockedError); | 128 SetError(kNotLockedError); |
129 SendResponse(false); | 129 SendResponse(false); |
130 return true; | 130 return true; |
131 } | 131 } |
(...skipping 18 matching lines...) Expand all Loading... |
150 image, | 150 image, |
151 base::Bind(&ScreenlockPrivateEventRouter::OnButtonClicked, | 151 base::Bind(&ScreenlockPrivateEventRouter::OnButtonClicked, |
152 base::Unretained(router))); | 152 base::Unretained(router))); |
153 SendResponse(error_.empty()); | 153 SendResponse(error_.empty()); |
154 } | 154 } |
155 | 155 |
156 ScreenlockPrivateHideButtonFunction::ScreenlockPrivateHideButtonFunction() {} | 156 ScreenlockPrivateHideButtonFunction::ScreenlockPrivateHideButtonFunction() {} |
157 | 157 |
158 ScreenlockPrivateHideButtonFunction::~ScreenlockPrivateHideButtonFunction() {} | 158 ScreenlockPrivateHideButtonFunction::~ScreenlockPrivateHideButtonFunction() {} |
159 | 159 |
160 bool ScreenlockPrivateHideButtonFunction::RunImpl() { | 160 bool ScreenlockPrivateHideButtonFunction::RunAsync() { |
161 chromeos::ScreenLocker* locker = | 161 chromeos::ScreenLocker* locker = |
162 chromeos::ScreenLocker::default_screen_locker(); | 162 chromeos::ScreenLocker::default_screen_locker(); |
163 if (locker) { | 163 if (locker) { |
164 const chromeos::User* user = | 164 const chromeos::User* user = |
165 chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); | 165 chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
166 locker->HideUserPodButton(user->email()); | 166 locker->HideUserPodButton(user->email()); |
167 } else { | 167 } else { |
168 SetError(kNotLockedError); | 168 SetError(kNotLockedError); |
169 } | 169 } |
170 SendResponse(error_.empty()); | 170 SendResponse(error_.empty()); |
171 return true; | 171 return true; |
172 } | 172 } |
173 | 173 |
174 ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {} | 174 ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {} |
175 | 175 |
176 ScreenlockPrivateSetAuthTypeFunction::~ScreenlockPrivateSetAuthTypeFunction() {} | 176 ScreenlockPrivateSetAuthTypeFunction::~ScreenlockPrivateSetAuthTypeFunction() {} |
177 | 177 |
178 bool ScreenlockPrivateSetAuthTypeFunction::RunImpl() { | 178 bool ScreenlockPrivateSetAuthTypeFunction::RunAsync() { |
179 scoped_ptr<screenlock::SetAuthType::Params> params( | 179 scoped_ptr<screenlock::SetAuthType::Params> params( |
180 screenlock::SetAuthType::Params::Create(*args_)); | 180 screenlock::SetAuthType::Params::Create(*args_)); |
181 EXTENSION_FUNCTION_VALIDATE(params.get()); | 181 EXTENSION_FUNCTION_VALIDATE(params.get()); |
182 | 182 |
183 chromeos::ScreenLocker* locker = | 183 chromeos::ScreenLocker* locker = |
184 chromeos::ScreenLocker::default_screen_locker(); | 184 chromeos::ScreenLocker::default_screen_locker(); |
185 if (locker) { | 185 if (locker) { |
186 std::string initial_value = | 186 std::string initial_value = |
187 params->initial_value.get() ? *(params->initial_value.get()) : ""; | 187 params->initial_value.get() ? *(params->initial_value.get()) : ""; |
188 const chromeos::User* user = | 188 const chromeos::User* user = |
189 chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); | 189 chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
190 locker->SetAuthType(user->email(), | 190 locker->SetAuthType(user->email(), |
191 ToLoginDisplayAuthType(params->auth_type), | 191 ToLoginDisplayAuthType(params->auth_type), |
192 initial_value); | 192 initial_value); |
193 } else { | 193 } else { |
194 SetError(kNotLockedError); | 194 SetError(kNotLockedError); |
195 } | 195 } |
196 SendResponse(error_.empty()); | 196 SendResponse(error_.empty()); |
197 return true; | 197 return true; |
198 } | 198 } |
199 | 199 |
200 ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {} | 200 ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {} |
201 | 201 |
202 ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {} | 202 ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {} |
203 | 203 |
204 bool ScreenlockPrivateGetAuthTypeFunction::RunImpl() { | 204 bool ScreenlockPrivateGetAuthTypeFunction::RunAsync() { |
205 chromeos::ScreenLocker* locker = | 205 chromeos::ScreenLocker* locker = |
206 chromeos::ScreenLocker::default_screen_locker(); | 206 chromeos::ScreenLocker::default_screen_locker(); |
207 if (locker) { | 207 if (locker) { |
208 const chromeos::User* user = | 208 const chromeos::User* user = |
209 chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); | 209 chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
210 chromeos::LoginDisplay::AuthType auth_type = | 210 chromeos::LoginDisplay::AuthType auth_type = |
211 locker->GetAuthType(user->email()); | 211 locker->GetAuthType(user->email()); |
212 std::string auth_type_name = | 212 std::string auth_type_name = |
213 screenlock::ToString(ToScreenlockPrivateAuthType(auth_type)); | 213 screenlock::ToString(ToScreenlockPrivateAuthType(auth_type)); |
214 SetResult(new base::StringValue(auth_type_name)); | 214 SetResult(new base::StringValue(auth_type_name)); |
215 } else { | 215 } else { |
216 SetError(kNotLockedError); | 216 SetError(kNotLockedError); |
217 } | 217 } |
218 SendResponse(error_.empty()); | 218 SendResponse(error_.empty()); |
219 return true; | 219 return true; |
220 } | 220 } |
221 | 221 |
222 ScreenlockPrivateAcceptAuthAttemptFunction:: | 222 ScreenlockPrivateAcceptAuthAttemptFunction:: |
223 ScreenlockPrivateAcceptAuthAttemptFunction() {} | 223 ScreenlockPrivateAcceptAuthAttemptFunction() {} |
224 | 224 |
225 ScreenlockPrivateAcceptAuthAttemptFunction:: | 225 ScreenlockPrivateAcceptAuthAttemptFunction:: |
226 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} | 226 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} |
227 | 227 |
228 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunImpl() { | 228 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunAsync() { |
229 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( | 229 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( |
230 screenlock::AcceptAuthAttempt::Params::Create(*args_)); | 230 screenlock::AcceptAuthAttempt::Params::Create(*args_)); |
231 EXTENSION_FUNCTION_VALIDATE(params.get()); | 231 EXTENSION_FUNCTION_VALIDATE(params.get()); |
232 | 232 |
233 chromeos::ScreenLocker* locker = | 233 chromeos::ScreenLocker* locker = |
234 chromeos::ScreenLocker::default_screen_locker(); | 234 chromeos::ScreenLocker::default_screen_locker(); |
235 if (locker) { | 235 if (locker) { |
236 if (params->accept) | 236 if (params->accept) |
237 chromeos::ScreenLocker::Hide(); | 237 chromeos::ScreenLocker::Hide(); |
238 else | 238 else |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 args->AppendString( | 303 args->AppendString( |
304 screenlock::ToString(ToScreenlockPrivateAuthType(auth_type))); | 304 screenlock::ToString(ToScreenlockPrivateAuthType(auth_type))); |
305 args->AppendString(value); | 305 args->AppendString(value); |
306 | 306 |
307 scoped_ptr<extensions::Event> event(new extensions::Event( | 307 scoped_ptr<extensions::Event> event(new extensions::Event( |
308 screenlock::OnAuthAttempted::kEventName, args.Pass())); | 308 screenlock::OnAuthAttempted::kEventName, args.Pass())); |
309 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 309 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
310 } | 310 } |
311 | 311 |
312 } // namespace extensions | 312 } // namespace extensions |
OLD | NEW |