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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/signin/easy_unlock_service.h" |
10 #include "chrome/common/extensions/api/screenlock_private.h" | 11 #include "chrome/common/extensions/api/screenlock_private.h" |
11 #include "extensions/browser/event_router.h" | 12 #include "extensions/browser/event_router.h" |
12 | 13 |
13 namespace screenlock = extensions::api::screenlock_private; | 14 namespace screenlock = extensions::api::screenlock_private; |
14 | 15 |
15 namespace extensions { | 16 namespace extensions { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const char kNotLockedError[] = "Screen is not currently locked."; | |
20 | |
21 screenlock::AuthType FromLockHandlerAuthType( | 20 screenlock::AuthType FromLockHandlerAuthType( |
22 ScreenlockBridge::LockHandler::AuthType auth_type) { | 21 ScreenlockBridge::LockHandler::AuthType auth_type) { |
23 switch (auth_type) { | 22 switch (auth_type) { |
24 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: | 23 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: |
25 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; | 24 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; |
26 case ScreenlockBridge::LockHandler::NUMERIC_PIN: | 25 case ScreenlockBridge::LockHandler::NUMERIC_PIN: |
27 return screenlock::AUTH_TYPE_NUMERICPIN; | 26 return screenlock::AUTH_TYPE_NUMERICPIN; |
28 case ScreenlockBridge::LockHandler::USER_CLICK: | 27 case ScreenlockBridge::LockHandler::USER_CLICK: |
29 return screenlock::AUTH_TYPE_USERCLICK; | 28 return screenlock::AUTH_TYPE_USERCLICK; |
30 case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN: | 29 case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 SendResponse(error_.empty()); | 68 SendResponse(error_.empty()); |
70 return true; | 69 return true; |
71 } | 70 } |
72 | 71 |
73 ScreenlockPrivateAcceptAuthAttemptFunction:: | 72 ScreenlockPrivateAcceptAuthAttemptFunction:: |
74 ScreenlockPrivateAcceptAuthAttemptFunction() {} | 73 ScreenlockPrivateAcceptAuthAttemptFunction() {} |
75 | 74 |
76 ScreenlockPrivateAcceptAuthAttemptFunction:: | 75 ScreenlockPrivateAcceptAuthAttemptFunction:: |
77 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} | 76 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} |
78 | 77 |
79 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunAsync() { | 78 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() { |
80 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( | 79 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( |
81 screenlock::AcceptAuthAttempt::Params::Create(*args_)); | 80 screenlock::AcceptAuthAttempt::Params::Create(*args_)); |
82 EXTENSION_FUNCTION_VALIDATE(params.get()); | 81 EXTENSION_FUNCTION_VALIDATE(params.get()); |
83 | 82 |
84 ScreenlockBridge::LockHandler* locker = | 83 Profile* profile = Profile::FromBrowserContext(browser_context()); |
85 ScreenlockBridge::Get()->lock_handler(); | 84 EasyUnlockService::Get(profile)->FinalizeUnlock(params->accept); |
86 if (locker) { | |
87 if (params->accept) { | |
88 locker->Unlock(ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile())); | |
89 } else { | |
90 locker->EnableInput(); | |
91 } | |
92 } else { | |
93 SetError(kNotLockedError); | |
94 } | |
95 SendResponse(error_.empty()); | |
96 return true; | 85 return true; |
97 } | 86 } |
98 | 87 |
99 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( | 88 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( |
100 content::BrowserContext* context) | 89 content::BrowserContext* context) |
101 : browser_context_(context) { | 90 : browser_context_(context) { |
102 ScreenlockBridge::Get()->AddObserver(this); | 91 ScreenlockBridge::Get()->AddObserver(this); |
103 } | 92 } |
104 | 93 |
105 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} | 94 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} |
(...skipping 29 matching lines...) Expand all Loading... |
135 // static | 124 // static |
136 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* | 125 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* |
137 ScreenlockPrivateEventRouter::GetFactoryInstance() { | 126 ScreenlockPrivateEventRouter::GetFactoryInstance() { |
138 return g_factory.Pointer(); | 127 return g_factory.Pointer(); |
139 } | 128 } |
140 | 129 |
141 void ScreenlockPrivateEventRouter::Shutdown() { | 130 void ScreenlockPrivateEventRouter::Shutdown() { |
142 ScreenlockBridge::Get()->RemoveObserver(this); | 131 ScreenlockBridge::Get()->RemoveObserver(this); |
143 } | 132 } |
144 | 133 |
145 void ScreenlockPrivateEventRouter::OnAuthAttempted( | 134 bool ScreenlockPrivateEventRouter::OnAuthAttempted( |
146 ScreenlockBridge::LockHandler::AuthType auth_type, | 135 ScreenlockBridge::LockHandler::AuthType auth_type, |
147 const std::string& value) { | 136 const std::string& value) { |
| 137 extensions::EventRouter* router = |
| 138 extensions::EventRouter::Get(browser_context_); |
| 139 if (!router->HasEventListener(screenlock::OnAuthAttempted::kEventName)) |
| 140 return false; |
| 141 |
148 scoped_ptr<base::ListValue> args(new base::ListValue()); | 142 scoped_ptr<base::ListValue> args(new base::ListValue()); |
149 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); | 143 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); |
150 args->AppendString(value); | 144 args->AppendString(value); |
151 | 145 |
152 scoped_ptr<extensions::Event> event(new extensions::Event( | 146 scoped_ptr<extensions::Event> event(new extensions::Event( |
153 screenlock::OnAuthAttempted::kEventName, args.Pass())); | 147 screenlock::OnAuthAttempted::kEventName, args.Pass())); |
154 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 148 router->BroadcastEvent(event.Pass()); |
| 149 return true; |
155 } | 150 } |
156 | 151 |
157 } // namespace extensions | 152 } // namespace extensions |
OLD | NEW |