| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/extensions/screenlock_private_api.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 9 #include "chrome/browser/extensions/event_router.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/common/extensions/api/screenlock_private.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 |
| 14 using chromeos::ScreenLocker; |
| 15 |
| 16 namespace screenlock = extensions::api::screenlock_private; |
| 17 |
| 18 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} |
| 19 |
| 20 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} |
| 21 |
| 22 bool ScreenlockPrivateGetLockedFunction::RunImpl() { |
| 23 bool locked = false; |
| 24 ScreenLocker* locker = ScreenLocker::default_screen_locker(); |
| 25 if (locker) |
| 26 locked = locker->locked(); |
| 27 SetResult(new base::FundamentalValue(locked)); |
| 28 SendResponse(error_.empty()); |
| 29 return true; |
| 30 } |
| 31 |
| 32 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} |
| 33 |
| 34 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} |
| 35 |
| 36 bool ScreenlockPrivateSetLockedFunction::RunImpl() { |
| 37 scoped_ptr<screenlock::SetLocked::Params> params( |
| 38 screenlock::SetLocked::Params::Create(*args_)); |
| 39 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 40 if (params->locked) { |
| 41 ScreenLocker::Show(); |
| 42 } else { |
| 43 ScreenLocker* locker = ScreenLocker::default_screen_locker(); |
| 44 if (locker) |
| 45 ScreenLocker::Hide(); |
| 46 } |
| 47 SendResponse(error_.empty()); |
| 48 return true; |
| 49 } |
| 50 |
| 51 ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {} |
| 52 |
| 53 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {} |
| 54 |
| 55 bool ScreenlockPrivateShowMessageFunction::RunImpl() { |
| 56 scoped_ptr<screenlock::SetLocked::Params> params( |
| 57 screenlock::SetLocked::Params::Create(*args_)); |
| 58 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 59 ScreenLocker* locker = ScreenLocker::default_screen_locker(); |
| 60 if (!locker) { |
| 61 SendResponse(error_.empty()); |
| 62 return true; |
| 63 } |
| 64 // TODO locker->ShowMessage(params->message); |
| 65 SendResponse(error_.empty()); |
| 66 return true; |
| 67 } |
| 68 |
| 69 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(Profile* profile) |
| 70 : profile_(profile) { |
| 71 chromeos::SessionManagerClient* session_manager = |
| 72 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| 73 if (!session_manager->HasObserver(this)) |
| 74 session_manager->AddObserver(this); |
| 75 } |
| 76 |
| 77 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} |
| 78 |
| 79 void ScreenlockPrivateEventRouter::ScreenIsLocked() { |
| 80 DispatchEvent(screenlock::OnChange::kEventName, |
| 81 new base::FundamentalValue(true)); |
| 82 } |
| 83 |
| 84 void ScreenlockPrivateEventRouter::ScreenIsUnlocked() { |
| 85 DispatchEvent(screenlock::OnChange::kEventName, |
| 86 new base::FundamentalValue(false)); |
| 87 } |
| 88 |
| 89 void ScreenlockPrivateEventRouter::DispatchEvent( |
| 90 const std::string& event_name, |
| 91 base::Value* arg) { |
| 92 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 93 args->Append(arg); |
| 94 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 95 event_name, args.Pass())); |
| 96 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 97 BroadcastEvent(event.Pass()); |
| 98 } |
| OLD | NEW |