Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / remoting / webapp / crd / js / desktop_remoting_activity.js
bloba06c099194d0010cd7a70a970995e5474eeb3f46
1 // Copyright 2015 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 /** @suppress {duplicate} */
6 var remoting = remoting || {};
8 (function() {
10 'use strict';
12 /**
13  * This class provides common functionality to Me2MeActivity and It2MeActivity,
14  * e.g. constructing the relevant UX, and delegate the custom handling of the
15  * session state changes to the |parentActivity|.
16  *
17  * @param {remoting.Activity} parentActivity
18  * @implements {remoting.ClientSession.EventHandler}
19  * @implements {base.Disposable}
20  * @constructor
21  */
22 remoting.DesktopRemotingActivity = function(parentActivity) {
23   /** @private */
24   this.parentActivity_ = parentActivity;
25   /** @private {remoting.DesktopConnectedView} */
26   this.connectedView_ = null;
28   /** @private */
29   this.sessionFactory_ = new remoting.ClientSessionFactory(
30       document.querySelector('#client-container .client-plugin-container'),
31       remoting.app_capabilities());
33   /** @private {remoting.ClientSession} */
34   this.session_ = null;
35   /** @private {remoting.ConnectingDialog} */
36   this.connectingDialog_ =
37       new remoting.ConnectingDialog(parentActivity.stop.bind(parentActivity));
40 /**
41  * Initiates a connection.
42  *
43  * @param {remoting.Host} host the Host to connect to.
44  * @param {remoting.CredentialsProvider} credentialsProvider
45  * @param {boolean=} opt_suppressOfflineError
46  * @return {void} Nothing.
47  */
48 remoting.DesktopRemotingActivity.prototype.start =
49     function(host, credentialsProvider, opt_suppressOfflineError) {
50   var that = this;
51   this.sessionFactory_.createSession(this).then(
52     function(/** remoting.ClientSession */ session) {
53       that.session_ = session;
54       session.logHostOfflineErrors(!opt_suppressOfflineError);
55       session.getLogger().setHostVersion(host.hostVersion);
57       var mode = remoting.ServerLogEntry.VALUE_MODE_UNKNOWN;
58       if (that.parentActivity_ instanceof remoting.It2MeActivity) {
59           mode = remoting.ServerLogEntry.VALUE_MODE_IT2ME;
60       } else if (that.parentActivity_ instanceof remoting.Me2MeActivity) {
61           mode = remoting.ServerLogEntry.VALUE_MODE_ME2ME;
62       }
63       session.getLogger().setLogEntryMode(mode);
65       session.connect(host, credentialsProvider);
66   }).catch(remoting.Error.handler(
67     function(/** !remoting.Error */ error) {
68       that.parentActivity_.onConnectionFailed(error);
69   }));
72 remoting.DesktopRemotingActivity.prototype.stop = function() {
73   if (this.session_) {
74     this.session_.disconnect(remoting.Error.none());
75     console.log('Disconnected.');
76   }
79 /**
80  * @param {remoting.ConnectionInfo} connectionInfo
81  */
82 remoting.DesktopRemotingActivity.prototype.onConnected =
83     function(connectionInfo) {
84   this.connectingDialog_.hide();
85   remoting.setMode(remoting.AppMode.IN_SESSION);
86   if (!base.isAppsV2()) {
87     remoting.toolbar.center();
88     remoting.toolbar.preview();
89   }
91   this.connectedView_ = new remoting.DesktopConnectedView(
92       document.getElementById('client-container'), connectionInfo);
94   // Apply the default or previously-specified keyboard remapping.
95   var remapping = connectionInfo.host().options.remapKeys;
96   if (remapping === '' && remoting.platformIsChromeOS()) {
97     // Under ChromeOS, remap the right Control key to the right Win/Cmd key.
98     remapping = '0x0700e4>0x0700e7';
99   }
100   connectionInfo.plugin().setRemapKeys(remapping);
102   if (connectionInfo.plugin().hasCapability(
103           remoting.ClientSession.Capability.VIDEO_RECORDER)) {
104     var recorder = new remoting.VideoFrameRecorder();
105     connectionInfo.plugin().extensions().register(recorder);
106     this.connectedView_.setVideoFrameRecorder(recorder);
107   }
109   this.parentActivity_.onConnected(connectionInfo);
112 remoting.DesktopRemotingActivity.prototype.onDisconnected = function(reason) {
113   if (this.handleError_(reason)) {
114     return;
115   }
116   this.parentActivity_.onDisconnected(reason);
120  * @param {!remoting.Error} error
121  */
122 remoting.DesktopRemotingActivity.prototype.onConnectionFailed =
123     function(error) {
124   if (this.handleError_(error)) {
125     return;
126   }
127   this.parentActivity_.onConnectionFailed(error);
131  * @param {!remoting.Error} error The error to be localized and displayed.
132  * @return {boolean} returns true if the error is handled.
133  * @private
134  */
135 remoting.DesktopRemotingActivity.prototype.handleError_ = function(error) {
136   if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) {
137     remoting.setMode(remoting.AppMode.HOME);
138     remoting.handleAuthFailureAndRelaunch();
139     return true;
140   }
141   return false;
144 remoting.DesktopRemotingActivity.prototype.dispose = function() {
145   base.dispose(this.connectedView_);
146   this.connectedView_ = null;
147   base.dispose(this.session_);
148   this.session_ = null;
149   this.connectingDialog_.hide();
152 /** @return {remoting.DesktopConnectedView} */
153 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() {
154   return this.connectedView_;
158  * @return {remoting.ClientSession}.
159  */
160 remoting.DesktopRemotingActivity.prototype.getSession = function() {
161   return this.session_;
164 /** @return {remoting.ConnectingDialog} */
165 remoting.DesktopRemotingActivity.prototype.getConnectingDialog = function() {
166   return this.connectingDialog_;
169 })();