OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 /** | |
6 * @fileoverview | |
7 * This class implements the functionality that is specific to Remote Desktop. | |
Jamie
2014/12/06 01:58:00
s/Remote Desktop/Chrome Remote Desktop/?
garykac
2014/12/06 02:15:50
Done.
| |
8 */ | |
9 | |
10 'use strict'; | |
11 | |
12 /** @suppress {duplicate} */ | |
13 var remoting = remoting || {}; | |
14 | |
15 /** | |
16 * @param {remoting.Application} app The main app that owns this delegate. | |
17 * @constructor | |
18 * @implements {remoting.Application.Delegate} | |
19 */ | |
20 remoting.DesktopRemoting = function(app) { | |
21 /** | |
22 * TODO(garykac): Remove this reference to the Application. It's only | |
23 * needed to get the current mode when reporting errors. So we should be | |
24 * able to refactor and remove this reference cycle. | |
25 * | |
26 * @type {remoting.Application} | |
27 * @private | |
28 */ | |
29 this.app_ = app; | |
30 app.setDelegate(this); | |
31 }; | |
32 | |
33 remoting.DesktopRemoting.prototype.init = function() { | |
34 remoting.initGlobalObjects(); | |
35 remoting.initIdentity(); | |
36 remoting.initIdentityEmail(remoting.onEmailAvailable); | |
37 | |
38 remoting.initEventHandlers(); | |
39 | |
40 if (base.isAppsV2()) { | |
41 remoting.fullscreen = new remoting.FullscreenAppsV2(); | |
42 remoting.windowFrame = new remoting.WindowFrame( | |
43 document.getElementById('title-bar')); | |
44 remoting.optionsMenu = remoting.windowFrame.createOptionsMenu(); | |
45 } else { | |
46 remoting.fullscreen = new remoting.FullscreenAppsV1(); | |
47 remoting.toolbar = new remoting.Toolbar( | |
48 document.getElementById('session-toolbar')); | |
49 remoting.optionsMenu = remoting.toolbar.createOptionsMenu(); | |
50 } | |
51 | |
52 remoting.initHostlist_(); | |
53 | |
54 var homeFeedback = new remoting.MenuButton( | |
55 document.getElementById('help-feedback-main')); | |
56 var toolbarFeedback = new remoting.MenuButton( | |
57 document.getElementById('help-feedback-toolbar')); | |
58 remoting.manageHelpAndFeedback( | |
59 document.getElementById('title-bar')); | |
60 remoting.manageHelpAndFeedback( | |
61 document.getElementById('help-feedback-toolbar')); | |
62 remoting.manageHelpAndFeedback( | |
63 document.getElementById('help-feedback-main')); | |
64 | |
65 remoting.windowShape.updateClientWindowShape(); | |
66 | |
67 remoting.showOrHideIT2MeUi(); | |
68 remoting.showOrHideMe2MeUi(); | |
69 | |
70 // For Apps v1, check the tab type to warn the user if they are not getting | |
71 // the best keyboard experience. | |
72 if (!base.isAppsV2() && !remoting.platformIsMac()) { | |
73 /** @param {boolean} isWindowed */ | |
74 var onIsWindowed = function(isWindowed) { | |
75 if (!isWindowed) { | |
76 document.getElementById('startup-mode-box-me2me').hidden = false; | |
77 document.getElementById('startup-mode-box-it2me').hidden = false; | |
78 } | |
79 }; | |
80 isWindowed_(onIsWindowed); | |
81 } | |
82 | |
83 remoting.ClientPlugin.factory.preloadPlugin(); | |
84 } | |
85 | |
86 /** | |
87 * @param {remoting.ClientSession} clientSession | |
88 */ | |
89 remoting.DesktopRemoting.prototype.onConnected = function(clientSession) { | |
90 // Set the text on the buttons shown under the error message so that they are | |
91 // easy to understand in the case where a successful connection failed, as | |
92 // opposed to the case where a connection never succeeded. | |
93 // TODO(garykac): Investigate to see if these need to be reverted to their | |
94 // original values in the onDisconnected method. | |
95 var button1 = document.getElementById('client-reconnect-button'); | |
96 l10n.localizeElementFromTag(button1, /*i18n-content*/'RECONNECT'); | |
97 button1.removeAttribute('autofocus'); | |
98 var button2 = document.getElementById('client-finished-me2me-button'); | |
99 l10n.localizeElementFromTag(button2, /*i18n-content*/'OK'); | |
100 button2.setAttribute('autofocus', 'autofocus'); | |
101 | |
102 document.getElementById('access-code-entry').value = ''; | |
103 remoting.setMode(remoting.AppMode.IN_SESSION); | |
104 if (!base.isAppsV2()) { | |
105 remoting.toolbar.center(); | |
106 remoting.toolbar.preview(); | |
107 } | |
108 | |
109 if (remoting.pairingRequested) { | |
110 /** | |
111 * @param {string} clientId | |
112 * @param {string} sharedSecret | |
113 */ | |
114 var onPairingComplete = function(clientId, sharedSecret) { | |
115 var pairingInfo = { | |
116 pairingInfo: { | |
117 clientId: clientId, | |
118 sharedSecret: sharedSecret | |
119 } | |
120 }; | |
121 var connector = remoting.app.getSessionConnector(); | |
122 remoting.HostSettings.save(connector.getHostId(), pairingInfo); | |
123 connector.updatePairingInfo(clientId, sharedSecret); | |
124 }; | |
125 // Use the platform name as a proxy for the local computer name. | |
126 // TODO(jamiewalch): Use a descriptive name for the local computer, for | |
127 // example, its Chrome Sync name. | |
128 var clientName = ''; | |
129 if (remoting.platformIsMac()) { | |
130 clientName = 'Mac'; | |
131 } else if (remoting.platformIsWindows()) { | |
132 clientName = 'Windows'; | |
133 } else if (remoting.platformIsChromeOS()) { | |
134 clientName = 'ChromeOS'; | |
135 } else if (remoting.platformIsLinux()) { | |
136 clientName = 'Linux'; | |
137 } else { | |
138 console.log('Unrecognized client platform. Using navigator.platform.'); | |
139 clientName = navigator.platform; | |
140 } | |
141 clientSession.requestPairing(clientName, onPairingComplete); | |
142 } | |
143 }; | |
144 | |
145 remoting.DesktopRemoting.prototype.onDisconnected = function() { | |
146 }; | |
147 | |
148 remoting.DesktopRemoting.prototype.onVideoStreamingStarted = function() { | |
149 }; | |
150 | |
151 /** | |
152 * @param {string} type The type of the extension message. | |
153 * @param {string} data The payload of the extension message. | |
154 * @return {boolean} Return true if the extension message was recognized. | |
155 */ | |
156 remoting.DesktopRemoting.prototype.onExtensionMessage = function(type, data) { | |
157 if (remoting.clientSession) { | |
158 return remoting.clientSession.handleExtensionMessage(type, data); | |
159 } | |
160 return false; | |
161 }; | |
162 | |
163 /** | |
164 * Show a client-side error message. | |
165 * | |
166 * @param {remoting.Error} errorTag The error to be localized and displayed. | |
167 * @return {void} Nothing. | |
168 */ | |
169 remoting.DesktopRemoting.prototype.onError = function(errorTag) { | |
170 console.error('Connection failed: ' + errorTag); | |
171 remoting.accessCode = ''; | |
172 | |
173 var errorDiv = document.getElementById('connect-error-message'); | |
174 l10n.localizeElementFromTag(errorDiv, /** @type {string} */ (errorTag)); | |
175 | |
176 var mode = remoting.clientSession ? remoting.clientSession.getMode() | |
177 : this.app_.getSessionConnector().getConnectionMode(); | |
178 if (mode == remoting.ClientSession.Mode.IT2ME) { | |
179 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | |
180 remoting.hangoutSessionEvents.raiseEvent( | |
181 remoting.hangoutSessionEvents.sessionStateChanged, | |
182 remoting.ClientSession.State.FAILED | |
183 ); | |
184 } else { | |
185 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); | |
186 } | |
187 }; | |
OLD | NEW |