Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / me2me_desktop_environment.cc
blobbe41bfb25f5d0bfeb435c58f0c3feef5dc302da2
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 "remoting/protocol/capability_names.h"
21 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
22 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
24 #if defined(OS_POSIX)
25 #include <sys/types.h>
26 #include <unistd.h>
27 #endif // defined(OS_POSIX)
29 namespace remoting {
31 Me2MeDesktopEnvironment::~Me2MeDesktopEnvironment() {
32 DCHECK(caller_task_runner()->BelongsToCurrentThread());
35 scoped_ptr<ScreenControls> Me2MeDesktopEnvironment::CreateScreenControls() {
36 DCHECK(caller_task_runner()->BelongsToCurrentThread());
38 return make_scoped_ptr(new ResizingHostObserver(DesktopResizer::Create()));
41 std::string Me2MeDesktopEnvironment::GetCapabilities() const {
42 std::string capabilities = BasicDesktopEnvironment::GetCapabilities();
43 if (!capabilities.empty())
44 capabilities.append(" ");
45 capabilities.append(protocol::kRateLimitResizeRequests);
47 return capabilities;
50 Me2MeDesktopEnvironment::Me2MeDesktopEnvironment(
51 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
52 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
53 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
54 bool supports_touch_events)
55 : BasicDesktopEnvironment(caller_task_runner,
56 input_task_runner,
57 ui_task_runner,
58 supports_touch_events),
59 gnubby_auth_enabled_(false) {
60 DCHECK(caller_task_runner->BelongsToCurrentThread());
61 desktop_capture_options()->set_use_update_notifications(true);
64 scoped_ptr<GnubbyAuthHandler> Me2MeDesktopEnvironment::CreateGnubbyAuthHandler(
65 protocol::ClientStub* client_stub) {
66 DCHECK(caller_task_runner()->BelongsToCurrentThread());
68 if (gnubby_auth_enabled_)
69 return GnubbyAuthHandler::Create(client_stub);
71 HOST_LOG << "gnubby auth is not enabled";
72 return nullptr;
75 bool Me2MeDesktopEnvironment::InitializeSecurity(
76 base::WeakPtr<ClientSessionControl> client_session_control,
77 bool curtain_enabled) {
78 DCHECK(caller_task_runner()->BelongsToCurrentThread());
80 // Detach the session from the local console if the caller requested.
81 if (curtain_enabled) {
82 curtain_ = CurtainMode::Create(caller_task_runner(),
83 ui_task_runner(),
84 client_session_control);
85 bool active = curtain_->Activate();
86 if (!active)
87 LOG(ERROR) << "Failed to activate the curtain mode.";
88 return active;
91 // Otherwise, if the session is shared with the local user start monitoring
92 // the local input and create the in-session UI.
94 #if defined(OS_LINUX)
95 bool want_user_interface = false;
96 #elif defined(OS_MACOSX)
97 // Don't try to display any UI on top of the system's login screen as this
98 // is rejected by the Window Server on OS X 10.7.4, and prevents the
99 // capturer from working (http://crbug.com/140984).
101 // TODO(lambroslambrou): Use a better technique of detecting whether we're
102 // running in the LoginWindow context, and refactor this into a separate
103 // function to be used here and in CurtainMode::ActivateCurtain().
104 bool want_user_interface = getuid() != 0;
105 #elif defined(OS_WIN)
106 bool want_user_interface = true;
107 #endif // defined(OS_WIN)
109 // Create the disconnect window.
110 if (want_user_interface) {
111 // Create the local input monitor.
112 local_input_monitor_ = LocalInputMonitor::Create(caller_task_runner(),
113 input_task_runner(),
114 ui_task_runner(),
115 client_session_control);
117 disconnect_window_ = HostWindow::CreateDisconnectWindow();
118 disconnect_window_.reset(new HostWindowProxy(
119 caller_task_runner(),
120 ui_task_runner(),
121 disconnect_window_.Pass()));
122 disconnect_window_->Start(client_session_control);
125 return true;
128 void Me2MeDesktopEnvironment::SetEnableGnubbyAuth(bool gnubby_auth_enabled) {
129 gnubby_auth_enabled_ = gnubby_auth_enabled;
132 Me2MeDesktopEnvironmentFactory::Me2MeDesktopEnvironmentFactory(
133 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
134 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
135 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
136 : BasicDesktopEnvironmentFactory(caller_task_runner,
137 input_task_runner,
138 ui_task_runner),
139 curtain_enabled_(false) {
142 Me2MeDesktopEnvironmentFactory::~Me2MeDesktopEnvironmentFactory() {
145 scoped_ptr<DesktopEnvironment> Me2MeDesktopEnvironmentFactory::Create(
146 base::WeakPtr<ClientSessionControl> client_session_control) {
147 DCHECK(caller_task_runner()->BelongsToCurrentThread());
149 scoped_ptr<Me2MeDesktopEnvironment> desktop_environment(
150 new Me2MeDesktopEnvironment(caller_task_runner(),
151 input_task_runner(),
152 ui_task_runner(),
153 supports_touch_events()));
154 if (!desktop_environment->InitializeSecurity(client_session_control,
155 curtain_enabled_)) {
156 return nullptr;
158 desktop_environment->SetEnableGnubbyAuth(gnubby_auth_enabled_);
160 return desktop_environment.Pass();
163 void Me2MeDesktopEnvironmentFactory::SetEnableCurtaining(bool enable) {
164 DCHECK(caller_task_runner()->BelongsToCurrentThread());
166 curtain_enabled_ = enable;
169 void Me2MeDesktopEnvironmentFactory::SetEnableGnubbyAuth(
170 bool gnubby_auth_enabled) {
171 gnubby_auth_enabled_ = gnubby_auth_enabled;
174 } // namespace remoting