Index: remoting/host/curtain_mode_mac.cc |
diff --git a/remoting/host/curtain_mode_mac.cc b/remoting/host/curtain_mode_mac.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b2ffcea8f08d2a684b0bb300e43d84ea38b39f3d |
--- /dev/null |
+++ b/remoting/host/curtain_mode_mac.cc |
@@ -0,0 +1,76 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/host/curtain_mode_mac.h" |
+ |
+#include <ApplicationServices/ApplicationServices.h> |
+#include <Security/Security.h> |
+ |
+#include "base/logging.h" |
+#include "base/mac/scoped_cftyperef.h" |
+ |
+namespace { |
+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.
|
+ "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/" |
+ "CGSession"; |
+} |
+ |
+namespace remoting { |
+ |
+CurtainMode::CurtainMode() : event_handler_(NULL) { |
+} |
+ |
+CurtainMode::~CurtainMode() { |
+ if (event_handler_) { |
+ RemoveEventHandler(event_handler_); |
+ } |
+} |
+ |
+bool CurtainMode::Init(const base::Closure& on_session_activate) { |
+ DCHECK(on_session_activate_.is_null()); |
+ on_session_activate_ = on_session_activate; |
+ EventTypeSpec event; |
+ event.eventClass = kEventClassSystem; |
+ event.eventKind = kEventSystemUserSessionActivated; |
+ OSStatus result = InstallApplicationEventHandler( |
+ NewEventHandlerUPP(SessionActivateHandler), 1, &event, this, |
+ &event_handler_); |
+ return result == noErr; |
+} |
+ |
+void CurtainMode::OnClientAuthenticated(const std::string& jid) { |
+ // If the current session is attached to the console and is not showing |
+ // the logon screen then switch it out to ensure privacy. |
+ base::mac::ScopedCFTypeRef<CFDictionaryRef> session( |
+ CGSessionCopyCurrentDictionary()); |
+ const void* on_console = CFDictionaryGetValue(session, |
+ kCGSessionOnConsoleKey); |
+ const void* logged_in = CFDictionaryGetValue(session, kCGSessionLoginDoneKey); |
+ if (logged_in == kCFBooleanTrue && on_console == kCFBooleanTrue) { |
+ pid_t child = fork(); |
+ if (child == 0) { |
+ 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
|
+ 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.
|
+ } else if (child > 0) { |
+ int status = 0; |
+ waitpid(child, &status, 0); |
+ } |
+ } |
+} |
+ |
+OSStatus CurtainMode::SessionActivateHandler(EventHandlerCallRef handler, |
+ EventRef event, |
+ void* user_data) { |
+ 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.
|
+ self->OnSessionActivate(); |
+ return noErr; |
+} |
+ |
+void CurtainMode::OnSessionActivate() { |
+ if (!on_session_activate_.is_null()) { |
+ on_session_activate_.Run(); |
+ } |
+} |
+ |
+} |
Lambros
2012/08/08 00:48:29
nit: // namespace remoting
Jamie
2012/08/08 01:39:43
Done.
|