OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Functions related to the 'host screen' for Chromoting. | 7 * Functions related to the 'host screen' for Chromoting. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 15 matching lines...) Expand all Loading... |
26 * to install them if necessary. | 26 * to install them if necessary. |
27 */ | 27 */ |
28 remoting.tryShare = function() { | 28 remoting.tryShare = function() { |
29 /** @type {remoting.HostIt2MeDispatcher} */ | 29 /** @type {remoting.HostIt2MeDispatcher} */ |
30 var hostDispatcher = new remoting.HostIt2MeDispatcher(); | 30 var hostDispatcher = new remoting.HostIt2MeDispatcher(); |
31 | 31 |
32 /** @type {remoting.HostInstallDialog} */ | 32 /** @type {remoting.HostInstallDialog} */ |
33 var hostInstallDialog = null; | 33 var hostInstallDialog = null; |
34 | 34 |
35 var tryInitializeDispatcher = function() { | 35 var tryInitializeDispatcher = function() { |
36 hostDispatcher.initialize(createPluginForIt2Me, | 36 hostDispatcher.initialize(onDispatcherInitialized, |
37 onDispatcherInitialized, | |
38 onDispatcherInitializationFailed); | 37 onDispatcherInitializationFailed); |
39 } | 38 } |
40 | 39 |
41 /** @return {remoting.HostPlugin} */ | |
42 var createPluginForIt2Me = function() { | |
43 return remoting.createNpapiPlugin( | |
44 document.getElementById('host-plugin-container')); | |
45 } | |
46 | |
47 var onDispatcherInitialized = function () { | 40 var onDispatcherInitialized = function () { |
48 if (hostDispatcher.usingNpapi()) { | 41 // Host already installed. |
49 hostInstallDialog = new remoting.HostInstallDialog(); | 42 remoting.startHostUsingDispatcher_(hostDispatcher); |
50 hostInstallDialog.show(tryInitializeDispatcher, onInstallError); | |
51 } else { | |
52 // Host alrady installed. | |
53 remoting.startHostUsingDispatcher_(hostDispatcher); | |
54 } | |
55 }; | 43 }; |
56 | 44 |
57 /** @param {remoting.Error} error */ | 45 /** @param {remoting.Error} error */ |
58 var onDispatcherInitializationFailed = function(error) { | 46 var onDispatcherInitializationFailed = function(error) { |
59 if (error != remoting.Error.MISSING_PLUGIN) { | 47 if (error != remoting.Error.MISSING_PLUGIN) { |
60 showShareError_(error); | 48 showShareError_(error); |
61 return; | 49 return; |
62 } | 50 } |
63 | 51 |
64 // If we failed to initialize the dispatcher then prompt the user to install | 52 // If we failed to initialize the dispatcher then prompt the user to install |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (remoting.currentMode != remoting.AppMode.HOST_SHARE_FAILED) { | 162 if (remoting.currentMode != remoting.AppMode.HOST_SHARE_FAILED) { |
175 // If an error is being displayed, then the plugin should not be able to | 163 // If an error is being displayed, then the plugin should not be able to |
176 // hide it by setting the state. Errors must be dismissed by the user | 164 // hide it by setting the state. Errors must be dismissed by the user |
177 // clicking OK, which puts the app into mode HOME. | 165 // clicking OK, which puts the app into mode HOME. |
178 if (lastShareWasCancelled_) { | 166 if (lastShareWasCancelled_) { |
179 remoting.setMode(remoting.AppMode.HOME); | 167 remoting.setMode(remoting.AppMode.HOME); |
180 } else { | 168 } else { |
181 remoting.setMode(remoting.AppMode.HOST_SHARE_FINISHED); | 169 remoting.setMode(remoting.AppMode.HOST_SHARE_FINISHED); |
182 } | 170 } |
183 } | 171 } |
184 remoting.hostSession.cleanup(); | |
185 | |
186 } else if (state == remoting.HostSession.State.ERROR) { | 172 } else if (state == remoting.HostSession.State.ERROR) { |
187 console.error('Host state: ERROR'); | 173 console.error('Host state: ERROR'); |
188 showShareError_(remoting.Error.UNEXPECTED); | 174 showShareError_(remoting.Error.UNEXPECTED); |
189 } else if (state == remoting.HostSession.State.INVALID_DOMAIN_ERROR) { | 175 } else if (state == remoting.HostSession.State.INVALID_DOMAIN_ERROR) { |
190 console.error('Host state: INVALID_DOMAIN_ERROR'); | 176 console.error('Host state: INVALID_DOMAIN_ERROR'); |
191 showShareError_(remoting.Error.INVALID_HOST_DOMAIN); | 177 showShareError_(remoting.Error.INVALID_HOST_DOMAIN); |
192 } else { | 178 } else { |
193 console.error('Unknown state -> ' + state); | 179 console.error('Unknown state -> ' + state); |
194 } | 180 } |
195 } | 181 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 * @private | 340 * @private |
355 */ | 341 */ |
356 function onNatTraversalPolicyChanged_(enabled) { | 342 function onNatTraversalPolicyChanged_(enabled) { |
357 var natBox = document.getElementById('nat-box'); | 343 var natBox = document.getElementById('nat-box'); |
358 if (enabled) { | 344 if (enabled) { |
359 natBox.classList.add('traversal-enabled'); | 345 natBox.classList.add('traversal-enabled'); |
360 } else { | 346 } else { |
361 natBox.classList.remove('traversal-enabled'); | 347 natBox.classList.remove('traversal-enabled'); |
362 } | 348 } |
363 } | 349 } |
OLD | NEW |