OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "remoting/host/curtain_mode_mac.h" |
| 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <Security/Security.h> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/mac/scoped_cftyperef.h" |
| 12 |
| 13 namespace { |
| 14 const char* kCGSessionPath = |
| 15 "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/" |
| 16 "CGSession"; |
| 17 } |
| 18 |
| 19 namespace remoting { |
| 20 |
| 21 CurtainMode::CurtainMode() : event_handler_(NULL) { |
| 22 } |
| 23 |
| 24 CurtainMode::~CurtainMode() { |
| 25 if (event_handler_) { |
| 26 RemoveEventHandler(event_handler_); |
| 27 } |
| 28 } |
| 29 |
| 30 bool CurtainMode::Init(const base::Closure& on_session_activate) { |
| 31 DCHECK(on_session_activate_.is_null()); |
| 32 on_session_activate_ = on_session_activate; |
| 33 EventTypeSpec event; |
| 34 event.eventClass = kEventClassSystem; |
| 35 event.eventKind = kEventSystemUserSessionActivated; |
| 36 OSStatus result = InstallApplicationEventHandler( |
| 37 NewEventHandlerUPP(SessionActivateHandler), 1, &event, this, |
| 38 &event_handler_); |
| 39 return result == noErr; |
| 40 } |
| 41 |
| 42 void CurtainMode::OnClientAuthenticated(const std::string& jid) { |
| 43 // If the current session is attached to the console and is not showing |
| 44 // the logon screen then switch it out to ensure privacy. |
| 45 base::mac::ScopedCFTypeRef<CFDictionaryRef> session( |
| 46 CGSessionCopyCurrentDictionary()); |
| 47 const void* on_console = CFDictionaryGetValue(session, |
| 48 kCGSessionOnConsoleKey); |
| 49 const void* logged_in = CFDictionaryGetValue(session, kCGSessionLoginDoneKey); |
| 50 if (logged_in == kCFBooleanTrue && on_console == kCFBooleanTrue) { |
| 51 pid_t child = fork(); |
| 52 if (child == 0) { |
| 53 execl(kCGSessionPath, kCGSessionPath, "-suspend", NULL); |
| 54 _exit(1); |
| 55 } else if (child > 0) { |
| 56 int status = 0; |
| 57 waitpid(child, &status, 0); |
| 58 } |
| 59 } |
| 60 } |
| 61 |
| 62 OSStatus CurtainMode::SessionActivateHandler(EventHandlerCallRef handler, |
| 63 EventRef event, |
| 64 void* user_data) { |
| 65 CurtainMode* self = static_cast<CurtainMode*>(user_data); |
| 66 self->OnSessionActivate(); |
| 67 return noErr; |
| 68 } |
| 69 |
| 70 void CurtainMode::OnSessionActivate() { |
| 71 if (!on_session_activate_.is_null()) { |
| 72 on_session_activate_.Run(); |
| 73 } |
| 74 } |
| 75 |
| 76 } // namespace remoting |
OLD | NEW |