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.
5 #include "remoting/host/me2me_desktop_environment.h"
7 #include "base/logging.h"
8 #include "base/single_thread_task_runner.h"
9 #include "remoting/base/logging.h"
10 #include "remoting/host/client_session_control.h"
11 #include "remoting/host/curtain_mode.h"
12 #include "remoting/host/desktop_resizer.h"
13 #include "remoting/host/gnubby_auth_handler.h"
14 #include "remoting/host/host_window.h"
15 #include "remoting/host/host_window.h"
16 #include "remoting/host/host_window_proxy.h"
17 #include "remoting/host/local_input_monitor.h"
18 #include "remoting/host/resizing_host_observer.h"
19 #include "remoting/host/screen_controls.h"
20 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
21 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
24 #include <sys/types.h>
26 #endif // defined(OS_POSIX)
28 const char kRateLimitResizeRequests
[] = "rateLimitResizeRequests";
32 Me2MeDesktopEnvironment::~Me2MeDesktopEnvironment() {
33 DCHECK(caller_task_runner()->BelongsToCurrentThread());
36 scoped_ptr
<ScreenControls
> Me2MeDesktopEnvironment::CreateScreenControls() {
37 DCHECK(caller_task_runner()->BelongsToCurrentThread());
39 return make_scoped_ptr(new ResizingHostObserver(DesktopResizer::Create()));
42 std::string
Me2MeDesktopEnvironment::GetCapabilities() const {
43 return kRateLimitResizeRequests
;
46 Me2MeDesktopEnvironment::Me2MeDesktopEnvironment(
47 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
48 scoped_refptr
<base::SingleThreadTaskRunner
> input_task_runner
,
49 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
)
50 : BasicDesktopEnvironment(caller_task_runner
,
53 gnubby_auth_enabled_(false) {
54 DCHECK(caller_task_runner
->BelongsToCurrentThread());
55 desktop_capture_options()->set_use_update_notifications(true);
58 scoped_ptr
<GnubbyAuthHandler
> Me2MeDesktopEnvironment::CreateGnubbyAuthHandler(
59 protocol::ClientStub
* client_stub
) {
60 DCHECK(caller_task_runner()->BelongsToCurrentThread());
62 if (gnubby_auth_enabled_
)
63 return GnubbyAuthHandler::Create(client_stub
);
65 HOST_LOG
<< "gnubby auth is not enabled";
69 bool Me2MeDesktopEnvironment::InitializeSecurity(
70 base::WeakPtr
<ClientSessionControl
> client_session_control
,
71 bool curtain_enabled
) {
72 DCHECK(caller_task_runner()->BelongsToCurrentThread());
74 // Detach the session from the local console if the caller requested.
75 if (curtain_enabled
) {
76 curtain_
= CurtainMode::Create(caller_task_runner(),
78 client_session_control
);
79 bool active
= curtain_
->Activate();
81 LOG(ERROR
) << "Failed to activate the curtain mode.";
85 // Otherwise, if the session is shared with the local user start monitoring
86 // the local input and create the in-session UI.
89 bool want_user_interface
= false;
90 #elif defined(OS_MACOSX)
91 // Don't try to display any UI on top of the system's login screen as this
92 // is rejected by the Window Server on OS X 10.7.4, and prevents the
93 // capturer from working (http://crbug.com/140984).
95 // TODO(lambroslambrou): Use a better technique of detecting whether we're
96 // running in the LoginWindow context, and refactor this into a separate
97 // function to be used here and in CurtainMode::ActivateCurtain().
98 bool want_user_interface
= getuid() != 0;
100 bool want_user_interface
= true;
101 #endif // defined(OS_WIN)
103 // Create the disconnect window.
104 if (want_user_interface
) {
105 // Create the local input monitor.
106 local_input_monitor_
= LocalInputMonitor::Create(caller_task_runner(),
109 client_session_control
);
111 disconnect_window_
= HostWindow::CreateDisconnectWindow();
112 disconnect_window_
.reset(new HostWindowProxy(
113 caller_task_runner(),
115 disconnect_window_
.Pass()));
116 disconnect_window_
->Start(client_session_control
);
122 void Me2MeDesktopEnvironment::SetEnableGnubbyAuth(bool gnubby_auth_enabled
) {
123 gnubby_auth_enabled_
= gnubby_auth_enabled
;
126 Me2MeDesktopEnvironmentFactory::Me2MeDesktopEnvironmentFactory(
127 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
128 scoped_refptr
<base::SingleThreadTaskRunner
> input_task_runner
,
129 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
)
130 : BasicDesktopEnvironmentFactory(caller_task_runner
,
133 curtain_enabled_(false) {
136 Me2MeDesktopEnvironmentFactory::~Me2MeDesktopEnvironmentFactory() {
139 scoped_ptr
<DesktopEnvironment
> Me2MeDesktopEnvironmentFactory::Create(
140 base::WeakPtr
<ClientSessionControl
> client_session_control
) {
141 DCHECK(caller_task_runner()->BelongsToCurrentThread());
143 scoped_ptr
<Me2MeDesktopEnvironment
> desktop_environment(
144 new Me2MeDesktopEnvironment(caller_task_runner(),
147 if (!desktop_environment
->InitializeSecurity(client_session_control
,
151 desktop_environment
->SetEnableGnubbyAuth(gnubby_auth_enabled_
);
153 return desktop_environment
.Pass();
156 void Me2MeDesktopEnvironmentFactory::SetEnableCurtaining(bool enable
) {
157 DCHECK(caller_task_runner()->BelongsToCurrentThread());
159 curtain_enabled_
= enable
;
162 void Me2MeDesktopEnvironmentFactory::SetEnableGnubbyAuth(
163 bool gnubby_auth_enabled
) {
164 gnubby_auth_enabled_
= gnubby_auth_enabled
;
167 } // namespace remoting