• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/me2me_desktop_environment.h"
6 
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"
20 
21 #if defined(OS_POSIX)
22 #include <sys/types.h>
23 #include <unistd.h>
24 #endif  // defined(OS_POSIX)
25 
26 const char kRateLimitResizeRequests[] = "rateLimitResizeRequests";
27 
28 namespace remoting {
29 
~Me2MeDesktopEnvironment()30 Me2MeDesktopEnvironment::~Me2MeDesktopEnvironment() {
31   DCHECK(caller_task_runner()->BelongsToCurrentThread());
32 }
33 
CreateScreenControls()34 scoped_ptr<ScreenControls> Me2MeDesktopEnvironment::CreateScreenControls() {
35   DCHECK(caller_task_runner()->BelongsToCurrentThread());
36 
37   return scoped_ptr<ScreenControls>(
38       new ResizingHostObserver(DesktopResizer::Create()));
39 }
40 
41 scoped_ptr<webrtc::ScreenCapturer>
CreateVideoCapturer()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));
49 }
50 
GetCapabilities() const51 std::string Me2MeDesktopEnvironment::GetCapabilities() const {
52   return kRateLimitResizeRequests;
53 }
54 
Me2MeDesktopEnvironment(scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)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,
60                               input_task_runner,
61                               ui_task_runner) {
62   DCHECK(caller_task_runner->BelongsToCurrentThread());
63 }
64 
InitializeSecurity(base::WeakPtr<ClientSessionControl> client_session_control,bool curtain_enabled)65 bool Me2MeDesktopEnvironment::InitializeSecurity(
66     base::WeakPtr<ClientSessionControl> client_session_control,
67     bool curtain_enabled) {
68   DCHECK(caller_task_runner()->BelongsToCurrentThread());
69 
70   // Detach the session from the local console if the caller requested.
71   if (curtain_enabled) {
72     curtain_ = CurtainMode::Create(caller_task_runner(),
73                                    ui_task_runner(),
74                                    client_session_control);
75     bool active = curtain_->Activate();
76     if (!active)
77       LOG(ERROR) << "Failed to activate the curtain mode.";
78     return active;
79   }
80 
81   // Otherwise, if the session is shared with the local user start monitoring
82   // the local input and create the in-session UI.
83 
84 #if defined(OS_LINUX)
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).
90 
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;
95 #elif defined(OS_WIN)
96   bool want_user_interface = true;
97 #endif  // defined(OS_WIN)
98 
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(),
103                                                      input_task_runner(),
104                                                      ui_task_runner(),
105                                                      client_session_control);
106 
107     disconnect_window_ = HostWindow::CreateDisconnectWindow();
108     disconnect_window_.reset(new HostWindowProxy(
109         caller_task_runner(),
110         ui_task_runner(),
111         disconnect_window_.Pass()));
112     disconnect_window_->Start(client_session_control);
113   }
114 
115   return true;
116 }
117 
Me2MeDesktopEnvironmentFactory(scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)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,
123                                      input_task_runner,
124                                      ui_task_runner),
125       curtain_enabled_(false) {
126 }
127 
~Me2MeDesktopEnvironmentFactory()128 Me2MeDesktopEnvironmentFactory::~Me2MeDesktopEnvironmentFactory() {
129 }
130 
Create(base::WeakPtr<ClientSessionControl> client_session_control)131 scoped_ptr<DesktopEnvironment> Me2MeDesktopEnvironmentFactory::Create(
132     base::WeakPtr<ClientSessionControl> client_session_control) {
133   DCHECK(caller_task_runner()->BelongsToCurrentThread());
134 
135   scoped_ptr<Me2MeDesktopEnvironment> desktop_environment(
136       new Me2MeDesktopEnvironment(caller_task_runner(),
137                                   input_task_runner(),
138                                   ui_task_runner()));
139   if (!desktop_environment->InitializeSecurity(client_session_control,
140                                                curtain_enabled_)) {
141     return scoped_ptr<DesktopEnvironment>();
142   }
143 
144   return desktop_environment.PassAs<DesktopEnvironment>();
145 }
146 
SetEnableCurtaining(bool enable)147 void Me2MeDesktopEnvironmentFactory::SetEnableCurtaining(bool enable) {
148   DCHECK(caller_task_runner()->BelongsToCurrentThread());
149 
150   curtain_enabled_ = enable;
151 }
152 
153 }  // namespace remoting
154