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 static const char* kCGSessionPath = | |
Lambros
2012/08/08 00:48:29
nit: don't need static in anon namespace
Jamie
2012/08/08 01:39:43
Done.
| |
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); | |
Lambros
2012/08/08 00:48:29
Is there a C API equivalent of this command-line t
Jamie
2012/08/08 01:39:43
I couldn't find one last time I looked, but I agre
| |
54 exit(1); | |
Lambros
2012/08/08 00:48:29
Use _exit instead of exit (after a fork with faile
Jamie
2012/08/08 01:39:43
Done.
| |
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 = reinterpret_cast<CurtainMode*>(user_data); | |
Lambros
2012/08/08 00:48:29
nit: Use static_cast<> ?
Jamie
2012/08/08 01:39:43
Done.
| |
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 } | |
Lambros
2012/08/08 00:48:29
nit: // namespace remoting
Jamie
2012/08/08 01:39:43
Done.
| |
OLD | NEW |