Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / remoting / host / me2me_desktop_environment.cc
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/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"
22
23 #if defined(OS_POSIX)
24 #include <sys/types.h>
25 #include <unistd.h>
26 #endif  // defined(OS_POSIX)
27
28 const char kRateLimitResizeRequests[] = "rateLimitResizeRequests";
29
30 namespace remoting {
31
32 Me2MeDesktopEnvironment::~Me2MeDesktopEnvironment() {
33   DCHECK(caller_task_runner()->BelongsToCurrentThread());
34 }
35
36 scoped_ptr<ScreenControls> Me2MeDesktopEnvironment::CreateScreenControls() {
37   DCHECK(caller_task_runner()->BelongsToCurrentThread());
38
39   return scoped_ptr<ScreenControls>(
40       new ResizingHostObserver(DesktopResizer::Create()));
41 }
42
43 scoped_ptr<webrtc::ScreenCapturer>
44 Me2MeDesktopEnvironment::CreateVideoCapturer() {
45   DCHECK(caller_task_runner()->BelongsToCurrentThread());
46   webrtc::DesktopCaptureOptions options =
47       webrtc::DesktopCaptureOptions::CreateDefault();
48   options.set_use_update_notifications(true);
49   return scoped_ptr<webrtc::ScreenCapturer>(
50       webrtc::ScreenCapturer::Create(options));
51 }
52
53 std::string Me2MeDesktopEnvironment::GetCapabilities() const {
54   return kRateLimitResizeRequests;
55 }
56
57 Me2MeDesktopEnvironment::Me2MeDesktopEnvironment(
58     scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
59     scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
60     scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
61     : BasicDesktopEnvironment(caller_task_runner,
62                               input_task_runner,
63                               ui_task_runner),
64       gnubby_auth_enabled_(false) {
65   DCHECK(caller_task_runner->BelongsToCurrentThread());
66 }
67
68 scoped_ptr<GnubbyAuthHandler> Me2MeDesktopEnvironment::CreateGnubbyAuthHandler(
69     protocol::ClientStub* client_stub) {
70   DCHECK(caller_task_runner()->BelongsToCurrentThread());
71
72   if (gnubby_auth_enabled_)
73     return scoped_ptr<GnubbyAuthHandler>(
74         GnubbyAuthHandler::Create(client_stub));
75
76   HOST_LOG << "gnubby auth is not enabled";
77   return scoped_ptr<GnubbyAuthHandler>();
78 }
79
80 bool Me2MeDesktopEnvironment::InitializeSecurity(
81     base::WeakPtr<ClientSessionControl> client_session_control,
82     bool curtain_enabled) {
83   DCHECK(caller_task_runner()->BelongsToCurrentThread());
84
85   // Detach the session from the local console if the caller requested.
86   if (curtain_enabled) {
87     curtain_ = CurtainMode::Create(caller_task_runner(),
88                                    ui_task_runner(),
89                                    client_session_control);
90     bool active = curtain_->Activate();
91     if (!active)
92       LOG(ERROR) << "Failed to activate the curtain mode.";
93     return active;
94   }
95
96   // Otherwise, if the session is shared with the local user start monitoring
97   // the local input and create the in-session UI.
98
99 #if defined(OS_LINUX)
100   bool want_user_interface = false;
101 #elif defined(OS_MACOSX)
102   // Don't try to display any UI on top of the system's login screen as this
103   // is rejected by the Window Server on OS X 10.7.4, and prevents the
104   // capturer from working (http://crbug.com/140984).
105
106   // TODO(lambroslambrou): Use a better technique of detecting whether we're
107   // running in the LoginWindow context, and refactor this into a separate
108   // function to be used here and in CurtainMode::ActivateCurtain().
109   bool want_user_interface = getuid() != 0;
110 #elif defined(OS_WIN)
111   bool want_user_interface = true;
112 #endif  // defined(OS_WIN)
113
114   // Create the disconnect window.
115   if (want_user_interface) {
116     // Create the local input monitor.
117     local_input_monitor_ = LocalInputMonitor::Create(caller_task_runner(),
118                                                      input_task_runner(),
119                                                      ui_task_runner(),
120                                                      client_session_control);
121
122     disconnect_window_ = HostWindow::CreateDisconnectWindow();
123     disconnect_window_.reset(new HostWindowProxy(
124         caller_task_runner(),
125         ui_task_runner(),
126         disconnect_window_.Pass()));
127     disconnect_window_->Start(client_session_control);
128   }
129
130   return true;
131 }
132
133 void Me2MeDesktopEnvironment::SetEnableGnubbyAuth(bool gnubby_auth_enabled) {
134   gnubby_auth_enabled_ = gnubby_auth_enabled;
135 }
136
137 Me2MeDesktopEnvironmentFactory::Me2MeDesktopEnvironmentFactory(
138     scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
139     scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
140     scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
141     : BasicDesktopEnvironmentFactory(caller_task_runner,
142                                      input_task_runner,
143                                      ui_task_runner),
144       curtain_enabled_(false) {
145 }
146
147 Me2MeDesktopEnvironmentFactory::~Me2MeDesktopEnvironmentFactory() {
148 }
149
150 scoped_ptr<DesktopEnvironment> Me2MeDesktopEnvironmentFactory::Create(
151     base::WeakPtr<ClientSessionControl> client_session_control) {
152   DCHECK(caller_task_runner()->BelongsToCurrentThread());
153
154   scoped_ptr<Me2MeDesktopEnvironment> desktop_environment(
155       new Me2MeDesktopEnvironment(caller_task_runner(),
156                                   input_task_runner(),
157                                   ui_task_runner()));
158   if (!desktop_environment->InitializeSecurity(client_session_control,
159                                                curtain_enabled_)) {
160     return scoped_ptr<DesktopEnvironment>();
161   }
162   desktop_environment->SetEnableGnubbyAuth(gnubby_auth_enabled_);
163
164   return desktop_environment.PassAs<DesktopEnvironment>();
165 }
166
167 void Me2MeDesktopEnvironmentFactory::SetEnableCurtaining(bool enable) {
168   DCHECK(caller_task_runner()->BelongsToCurrentThread());
169
170   curtain_enabled_ = enable;
171 }
172
173 void Me2MeDesktopEnvironmentFactory::SetEnableGnubbyAuth(
174     bool gnubby_auth_enabled) {
175   gnubby_auth_enabled_ = gnubby_auth_enabled;
176 }
177
178 }  // namespace remoting