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/host/client_session_control.h"
10 #include "remoting/host/curtain_mode.h"
11 #include "remoting/host/desktop_resizer.h"
12 #include "remoting/host/host_window.h"
13 #include "remoting/host/host_window.h"
14 #include "remoting/host/host_window_proxy.h"
15 #include "remoting/host/local_input_monitor.h"
16 #include "remoting/host/resizing_host_observer.h"
17 #include "remoting/host/screen_controls.h"
18 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
19 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
22 #include <sys/types.h>
24 #endif // defined(OS_POSIX)
26 const char kRateLimitResizeRequests
[] = "rateLimitResizeRequests";
30 Me2MeDesktopEnvironment::~Me2MeDesktopEnvironment() {
31 DCHECK(caller_task_runner()->BelongsToCurrentThread());
34 scoped_ptr
<ScreenControls
> Me2MeDesktopEnvironment::CreateScreenControls() {
35 DCHECK(caller_task_runner()->BelongsToCurrentThread());
37 return scoped_ptr
<ScreenControls
>(
38 new ResizingHostObserver(DesktopResizer::Create()));
41 scoped_ptr
<webrtc::ScreenCapturer
>
42 Me2MeDesktopEnvironment::CreateVideoCapturer() {
43 DCHECK(caller_task_runner()->BelongsToCurrentThread());
44 webrtc::DesktopCaptureOptions options
=
45 webrtc::DesktopCaptureOptions::CreateDefault();
46 options
.set_use_update_notifications(true);
47 return scoped_ptr
<webrtc::ScreenCapturer
>(
48 webrtc::ScreenCapturer::Create(options
));
51 std::string
Me2MeDesktopEnvironment::GetCapabilities() const {
52 return kRateLimitResizeRequests
;
55 Me2MeDesktopEnvironment::Me2MeDesktopEnvironment(
56 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
57 scoped_refptr
<base::SingleThreadTaskRunner
> input_task_runner
,
58 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
)
59 : BasicDesktopEnvironment(caller_task_runner
,
62 DCHECK(caller_task_runner
->BelongsToCurrentThread());
65 bool Me2MeDesktopEnvironment::InitializeSecurity(
66 base::WeakPtr
<ClientSessionControl
> client_session_control
,
67 bool curtain_enabled
) {
68 DCHECK(caller_task_runner()->BelongsToCurrentThread());
70 // Detach the session from the local console if the caller requested.
71 if (curtain_enabled
) {
72 curtain_
= CurtainMode::Create(caller_task_runner(),
74 client_session_control
);
75 bool active
= curtain_
->Activate();
77 LOG(ERROR
) << "Failed to activate the curtain mode.";
81 // Otherwise, if the session is shared with the local user start monitoring
82 // the local input and create the in-session UI.
85 bool want_user_interface
= false;
86 #elif defined(OS_MACOSX)
87 // Don't try to display any UI on top of the system's login screen as this
88 // is rejected by the Window Server on OS X 10.7.4, and prevents the
89 // capturer from working (http://crbug.com/140984).
91 // TODO(lambroslambrou): Use a better technique of detecting whether we're
92 // running in the LoginWindow context, and refactor this into a separate
93 // function to be used here and in CurtainMode::ActivateCurtain().
94 bool want_user_interface
= getuid() != 0;
96 bool want_user_interface
= true;
97 #endif // defined(OS_WIN)
99 // Create the disconnect window.
100 if (want_user_interface
) {
101 // Create the local input monitor.
102 local_input_monitor_
= LocalInputMonitor::Create(caller_task_runner(),
105 client_session_control
);
107 disconnect_window_
= HostWindow::CreateDisconnectWindow();
108 disconnect_window_
.reset(new HostWindowProxy(
109 caller_task_runner(),
111 disconnect_window_
.Pass()));
112 disconnect_window_
->Start(client_session_control
);
118 Me2MeDesktopEnvironmentFactory::Me2MeDesktopEnvironmentFactory(
119 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
120 scoped_refptr
<base::SingleThreadTaskRunner
> input_task_runner
,
121 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
)
122 : BasicDesktopEnvironmentFactory(caller_task_runner
,
125 curtain_enabled_(false) {
128 Me2MeDesktopEnvironmentFactory::~Me2MeDesktopEnvironmentFactory() {
131 scoped_ptr
<DesktopEnvironment
> Me2MeDesktopEnvironmentFactory::Create(
132 base::WeakPtr
<ClientSessionControl
> client_session_control
) {
133 DCHECK(caller_task_runner()->BelongsToCurrentThread());
135 scoped_ptr
<Me2MeDesktopEnvironment
> desktop_environment(
136 new Me2MeDesktopEnvironment(caller_task_runner(),
139 if (!desktop_environment
->InitializeSecurity(client_session_control
,
141 return scoped_ptr
<DesktopEnvironment
>();
144 return desktop_environment
.PassAs
<DesktopEnvironment
>();
147 void Me2MeDesktopEnvironmentFactory::SetEnableCurtaining(bool enable
) {
148 DCHECK(caller_task_runner()->BelongsToCurrentThread());
150 curtain_enabled_
= enable
;
153 } // namespace remoting