| 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/browser/signin/easy_unlock_service.h" |
| 11 #include "chrome/common/extensions/api/screenlock_private.h" | 11 #include "chrome/common/extensions/api/screenlock_private.h" |
| 12 #include "extensions/browser/event_router.h" | 12 #include "extensions/browser/event_router.h" |
| 13 | 13 |
| 14 namespace screenlock = extensions::api::screenlock_private; | 14 namespace screenlock = extensions::api::screenlock_private; |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 screenlock::AuthType FromLockHandlerAuthType( | 20 screenlock::AuthType FromLockHandlerAuthType( |
| 21 ScreenlockBridge::LockHandler::AuthType auth_type) { | 21 SigninScreenBridge::LockHandler::AuthType auth_type) { |
| 22 switch (auth_type) { | 22 switch (auth_type) { |
| 23 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: | 23 case SigninScreenBridge::LockHandler::OFFLINE_PASSWORD: |
| 24 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; | 24 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; |
| 25 case ScreenlockBridge::LockHandler::NUMERIC_PIN: | 25 case SigninScreenBridge::LockHandler::NUMERIC_PIN: |
| 26 return screenlock::AUTH_TYPE_NUMERICPIN; | 26 return screenlock::AUTH_TYPE_NUMERICPIN; |
| 27 case ScreenlockBridge::LockHandler::USER_CLICK: | 27 case SigninScreenBridge::LockHandler::USER_CLICK: |
| 28 return screenlock::AUTH_TYPE_USERCLICK; | 28 return screenlock::AUTH_TYPE_USERCLICK; |
| 29 case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN: | 29 case SigninScreenBridge::LockHandler::ONLINE_SIGN_IN: |
| 30 // Apps should treat forced online sign in same as system password. | 30 // Apps should treat forced online sign in same as system password. |
| 31 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; | 31 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; |
| 32 case ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK: | 32 case SigninScreenBridge::LockHandler::EXPAND_THEN_USER_CLICK: |
| 33 // This type is used for public sessions, which do not support screen | 33 // This type is used for public sessions, which do not support screen |
| 34 // locking. | 34 // locking. |
| 35 NOTREACHED(); | 35 NOTREACHED(); |
| 36 return screenlock::AUTH_TYPE_NONE; | 36 return screenlock::AUTH_TYPE_NONE; |
| 37 case ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD: | 37 case SigninScreenBridge::LockHandler::FORCE_OFFLINE_PASSWORD: |
| 38 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; | 38 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; |
| 39 } | 39 } |
| 40 NOTREACHED(); | 40 NOTREACHED(); |
| 41 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; | 41 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} | 46 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} |
| 47 | 47 |
| 48 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} | 48 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} |
| 49 | 49 |
| 50 bool ScreenlockPrivateGetLockedFunction::RunAsync() { | 50 bool ScreenlockPrivateGetLockedFunction::RunAsync() { |
| 51 SetResult(new base::FundamentalValue(ScreenlockBridge::Get()->IsLocked())); | 51 SetResult(new base::FundamentalValue(SigninScreenBridge::Get()->IsLocked())); |
| 52 SendResponse(error_.empty()); | 52 SendResponse(error_.empty()); |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} | 56 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} |
| 57 | 57 |
| 58 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} | 58 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} |
| 59 | 59 |
| 60 bool ScreenlockPrivateSetLockedFunction::RunAsync() { | 60 bool ScreenlockPrivateSetLockedFunction::RunAsync() { |
| 61 scoped_ptr<screenlock::SetLocked::Params> params( | 61 scoped_ptr<screenlock::SetLocked::Params> params( |
| 62 screenlock::SetLocked::Params::Create(*args_)); | 62 screenlock::SetLocked::Params::Create(*args_)); |
| 63 EXTENSION_FUNCTION_VALIDATE(params.get()); | 63 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 64 if (params->locked) | 64 if (params->locked) |
| 65 ScreenlockBridge::Get()->Lock(GetProfile()); | 65 SigninScreenBridge::Get()->Lock(GetProfile()); |
| 66 else | 66 else |
| 67 ScreenlockBridge::Get()->Unlock(GetProfile()); | 67 SigninScreenBridge::Get()->Unlock(GetProfile()); |
| 68 SendResponse(error_.empty()); | 68 SendResponse(error_.empty()); |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 ScreenlockPrivateAcceptAuthAttemptFunction:: | 72 ScreenlockPrivateAcceptAuthAttemptFunction:: |
| 73 ScreenlockPrivateAcceptAuthAttemptFunction() {} | 73 ScreenlockPrivateAcceptAuthAttemptFunction() {} |
| 74 | 74 |
| 75 ScreenlockPrivateAcceptAuthAttemptFunction:: | 75 ScreenlockPrivateAcceptAuthAttemptFunction:: |
| 76 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} | 76 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} |
| 77 | 77 |
| 78 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() { | 78 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() { |
| 79 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( | 79 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( |
| 80 screenlock::AcceptAuthAttempt::Params::Create(*args_)); | 80 screenlock::AcceptAuthAttempt::Params::Create(*args_)); |
| 81 EXTENSION_FUNCTION_VALIDATE(params.get()); | 81 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 82 | 82 |
| 83 Profile* profile = Profile::FromBrowserContext(browser_context()); | 83 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 84 EasyUnlockService::Get(profile)->FinalizeUnlock(params->accept); | 84 EasyUnlockService::Get(profile)->FinalizeUnlock(params->accept); |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 | 87 |
| 88 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( | 88 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( |
| 89 content::BrowserContext* context) | 89 content::BrowserContext* context) |
| 90 : browser_context_(context) { | 90 : browser_context_(context) { |
| 91 ScreenlockBridge::Get()->AddObserver(this); | 91 SigninScreenBridge::Get()->AddObserver(this); |
| 92 } | 92 } |
| 93 | 93 |
| 94 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} | 94 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} |
| 95 | 95 |
| 96 void ScreenlockPrivateEventRouter::OnScreenDidLock() { | 96 void ScreenlockPrivateEventRouter::OnScreenDidLock() { |
| 97 DispatchEvent(screenlock::OnChanged::kEventName, | 97 DispatchEvent(screenlock::OnChanged::kEventName, |
| 98 new base::FundamentalValue(true)); | 98 new base::FundamentalValue(true)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ScreenlockPrivateEventRouter::OnScreenDidUnlock() { | 101 void ScreenlockPrivateEventRouter::OnScreenDidUnlock() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 121 static base::LazyInstance<extensions::BrowserContextKeyedAPIFactory< | 121 static base::LazyInstance<extensions::BrowserContextKeyedAPIFactory< |
| 122 ScreenlockPrivateEventRouter> > g_factory = LAZY_INSTANCE_INITIALIZER; | 122 ScreenlockPrivateEventRouter> > g_factory = LAZY_INSTANCE_INITIALIZER; |
| 123 | 123 |
| 124 // static | 124 // static |
| 125 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* | 125 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* |
| 126 ScreenlockPrivateEventRouter::GetFactoryInstance() { | 126 ScreenlockPrivateEventRouter::GetFactoryInstance() { |
| 127 return g_factory.Pointer(); | 127 return g_factory.Pointer(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void ScreenlockPrivateEventRouter::Shutdown() { | 130 void ScreenlockPrivateEventRouter::Shutdown() { |
| 131 ScreenlockBridge::Get()->RemoveObserver(this); | 131 SigninScreenBridge::Get()->RemoveObserver(this); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool ScreenlockPrivateEventRouter::OnAuthAttempted( | 134 bool ScreenlockPrivateEventRouter::OnAuthAttempted( |
| 135 ScreenlockBridge::LockHandler::AuthType auth_type, | 135 SigninScreenBridge::LockHandler::AuthType auth_type, |
| 136 const std::string& value) { | 136 const std::string& value) { |
| 137 extensions::EventRouter* router = | 137 extensions::EventRouter* router = |
| 138 extensions::EventRouter::Get(browser_context_); | 138 extensions::EventRouter::Get(browser_context_); |
| 139 if (!router->HasEventListener(screenlock::OnAuthAttempted::kEventName)) | 139 if (!router->HasEventListener(screenlock::OnAuthAttempted::kEventName)) |
| 140 return false; | 140 return false; |
| 141 | 141 |
| 142 scoped_ptr<base::ListValue> args(new base::ListValue()); | 142 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 143 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); | 143 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); |
| 144 args->AppendString(value); | 144 args->AppendString(value); |
| 145 | 145 |
| 146 scoped_ptr<extensions::Event> event(new extensions::Event( | 146 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 147 screenlock::OnAuthAttempted::kEventName, args.Pass())); | 147 screenlock::OnAuthAttempted::kEventName, args.Pass())); |
| 148 router->BroadcastEvent(event.Pass()); | 148 router->BroadcastEvent(event.Pass()); |
| 149 return true; | 149 return true; |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace extensions | 152 } // namespace extensions |
| OLD | NEW |