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/extensions/api/screenlock_private/screenlock_private_ap
i.h" | 5 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/extensions/api/screenlock_private.h" | 13 #include "chrome/common/extensions/api/screenlock_private.h" |
13 #include "extensions/browser/event_router.h" | 14 #include "extensions/browser/event_router.h" |
14 #include "extensions/browser/image_loader.h" | 15 #include "extensions/browser/image_loader.h" |
15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
16 | 17 |
17 namespace screenlock = extensions::api::screenlock_private; | 18 namespace screenlock = extensions::api::screenlock_private; |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {} | 95 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {} |
95 | 96 |
96 bool ScreenlockPrivateShowMessageFunction::RunAsync() { | 97 bool ScreenlockPrivateShowMessageFunction::RunAsync() { |
97 scoped_ptr<screenlock::ShowMessage::Params> params( | 98 scoped_ptr<screenlock::ShowMessage::Params> params( |
98 screenlock::ShowMessage::Params::Create(*args_)); | 99 screenlock::ShowMessage::Params::Create(*args_)); |
99 EXTENSION_FUNCTION_VALIDATE(params.get()); | 100 EXTENSION_FUNCTION_VALIDATE(params.get()); |
100 ScreenlockBridge::LockHandler* locker = | 101 ScreenlockBridge::LockHandler* locker = |
101 ScreenlockBridge::Get()->lock_handler(); | 102 ScreenlockBridge::Get()->lock_handler(); |
102 if (locker) | 103 if (locker) |
103 locker->ShowBannerMessage(params->message); | 104 locker->ShowBannerMessage(base::UTF8ToUTF16(params->message)); |
104 SendResponse(error_.empty()); | 105 SendResponse(error_.empty()); |
105 return true; | 106 return true; |
106 } | 107 } |
107 | 108 |
108 ScreenlockPrivateShowCustomIconFunction:: | 109 ScreenlockPrivateShowCustomIconFunction:: |
109 ScreenlockPrivateShowCustomIconFunction() {} | 110 ScreenlockPrivateShowCustomIconFunction() {} |
110 | 111 |
111 ScreenlockPrivateShowCustomIconFunction:: | 112 ScreenlockPrivateShowCustomIconFunction:: |
112 ~ScreenlockPrivateShowCustomIconFunction() {} | 113 ~ScreenlockPrivateShowCustomIconFunction() {} |
113 | 114 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 icon_info, | 162 icon_info, |
162 base::Bind(&ScreenlockPrivateShowCustomIconFunction::OnImageLoaded, | 163 base::Bind(&ScreenlockPrivateShowCustomIconFunction::OnImageLoaded, |
163 this)); | 164 this)); |
164 return true; | 165 return true; |
165 } | 166 } |
166 | 167 |
167 void ScreenlockPrivateShowCustomIconFunction::OnImageLoaded( | 168 void ScreenlockPrivateShowCustomIconFunction::OnImageLoaded( |
168 const gfx::Image& image) { | 169 const gfx::Image& image) { |
169 ScreenlockBridge::LockHandler* locker = | 170 ScreenlockBridge::LockHandler* locker = |
170 ScreenlockBridge::Get()->lock_handler(); | 171 ScreenlockBridge::Get()->lock_handler(); |
| 172 if (!locker) { |
| 173 SetError(kNotLockedError); |
| 174 SendResponse(false); |
| 175 return; |
| 176 } |
| 177 |
| 178 ScreenlockBridge::UserPodCustomIconOptions icon; |
| 179 icon.SetIconAsImage(image); |
171 locker->ShowUserPodCustomIcon( | 180 locker->ShowUserPodCustomIcon( |
172 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()), | 181 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()), |
173 image); | 182 icon); |
174 SendResponse(error_.empty()); | 183 SendResponse(error_.empty()); |
175 } | 184 } |
176 | 185 |
177 ScreenlockPrivateHideCustomIconFunction:: | 186 ScreenlockPrivateHideCustomIconFunction:: |
178 ScreenlockPrivateHideCustomIconFunction() { | 187 ScreenlockPrivateHideCustomIconFunction() { |
179 } | 188 } |
180 | 189 |
181 ScreenlockPrivateHideCustomIconFunction:: | 190 ScreenlockPrivateHideCustomIconFunction:: |
182 ~ScreenlockPrivateHideCustomIconFunction() { | 191 ~ScreenlockPrivateHideCustomIconFunction() { |
183 } | 192 } |
(...skipping 21 matching lines...) Expand all Loading... |
205 EXTENSION_FUNCTION_VALIDATE(params.get()); | 214 EXTENSION_FUNCTION_VALIDATE(params.get()); |
206 | 215 |
207 ScreenlockBridge::LockHandler* locker = | 216 ScreenlockBridge::LockHandler* locker = |
208 ScreenlockBridge::Get()->lock_handler(); | 217 ScreenlockBridge::Get()->lock_handler(); |
209 if (locker) { | 218 if (locker) { |
210 std::string initial_value = | 219 std::string initial_value = |
211 params->initial_value.get() ? *(params->initial_value.get()) : ""; | 220 params->initial_value.get() ? *(params->initial_value.get()) : ""; |
212 locker->SetAuthType( | 221 locker->SetAuthType( |
213 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()), | 222 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()), |
214 ToLockHandlerAuthType(params->auth_type), | 223 ToLockHandlerAuthType(params->auth_type), |
215 initial_value); | 224 base::UTF8ToUTF16(initial_value)); |
216 } else { | 225 } else { |
217 SetError(kNotLockedError); | 226 SetError(kNotLockedError); |
218 } | 227 } |
219 SendResponse(error_.empty()); | 228 SendResponse(error_.empty()); |
220 return true; | 229 return true; |
221 } | 230 } |
222 | 231 |
223 ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {} | 232 ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {} |
224 | 233 |
225 ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {} | 234 ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {} |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 scoped_ptr<base::ListValue> args(new base::ListValue()); | 323 scoped_ptr<base::ListValue> args(new base::ListValue()); |
315 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); | 324 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); |
316 args->AppendString(value); | 325 args->AppendString(value); |
317 | 326 |
318 scoped_ptr<extensions::Event> event(new extensions::Event( | 327 scoped_ptr<extensions::Event> event(new extensions::Event( |
319 screenlock::OnAuthAttempted::kEventName, args.Pass())); | 328 screenlock::OnAuthAttempted::kEventName, args.Pass())); |
320 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 329 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
321 } | 330 } |
322 | 331 |
323 } // namespace extensions | 332 } // namespace extensions |
OLD | NEW |