 Chromium Code Reviews
 Chromium Code Reviews Issue 1020743002:
  [Chromoting] Move app-specific code out of remoting.js  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1020743002:
  [Chromoting] Move app-specific code out of remoting.js  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 * This class implements the functionality that is specific to desktop | 7 * This class implements the functionality that is specific to desktop | 
| 8 * remoting ("Chromoting" or CRD). | 8 * remoting ("Chromoting" or CRD). | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 } | 69 } | 
| 70 } | 70 } | 
| 71 ); | 71 ); | 
| 72 | 72 | 
| 73 } else { | 73 } else { | 
| 74 remoting.fullscreen = new remoting.FullscreenAppsV1(); | 74 remoting.fullscreen = new remoting.FullscreenAppsV1(); | 
| 75 remoting.toolbar = new remoting.Toolbar( | 75 remoting.toolbar = new remoting.Toolbar( | 
| 76 document.getElementById('session-toolbar')); | 76 document.getElementById('session-toolbar')); | 
| 77 remoting.optionsMenu = remoting.toolbar.createOptionsMenu(); | 77 remoting.optionsMenu = remoting.toolbar.createOptionsMenu(); | 
| 78 | 78 | 
| 79 window.addEventListener('beforeunload', remoting.promptClose, false); | 79 window.addEventListener('beforeunload', | 
| 80 this.promptClose_.bind(this), false); | |
| 80 window.addEventListener('unload', | 81 window.addEventListener('unload', | 
| 81 remoting.app.disconnect.bind(remoting.app), false); | 82 remoting.app.disconnect.bind(remoting.app), false); | 
| 82 } | 83 } | 
| 83 | 84 | 
| 84 remoting.initHostlist_(); | 85 remoting.initHostlist_(); | 
| 85 | 86 | 
| 86 var homeFeedback = new remoting.MenuButton( | 87 var homeFeedback = new remoting.MenuButton( | 
| 87 document.getElementById('help-feedback-main')); | 88 document.getElementById('help-feedback-main')); | 
| 88 var toolbarFeedback = new remoting.MenuButton( | 89 var toolbarFeedback = new remoting.MenuButton( | 
| 89 document.getElementById('help-feedback-toolbar')); | 90 document.getElementById('help-feedback-toolbar')); | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 102 // For Apps v1, check the tab type to warn the user if they are not getting | 103 // For Apps v1, check the tab type to warn the user if they are not getting | 
| 103 // the best keyboard experience. | 104 // the best keyboard experience. | 
| 104 if (!base.isAppsV2() && !remoting.platformIsMac()) { | 105 if (!base.isAppsV2() && !remoting.platformIsMac()) { | 
| 105 /** @param {boolean} isWindowed */ | 106 /** @param {boolean} isWindowed */ | 
| 106 var onIsWindowed = function(isWindowed) { | 107 var onIsWindowed = function(isWindowed) { | 
| 107 if (!isWindowed) { | 108 if (!isWindowed) { | 
| 108 document.getElementById('startup-mode-box-me2me').hidden = false; | 109 document.getElementById('startup-mode-box-me2me').hidden = false; | 
| 109 document.getElementById('startup-mode-box-it2me').hidden = false; | 110 document.getElementById('startup-mode-box-it2me').hidden = false; | 
| 110 } | 111 } | 
| 111 }; | 112 }; | 
| 112 isWindowed_(onIsWindowed); | 113 this.isWindowed_(onIsWindowed); | 
| 113 } | 114 } | 
| 114 | 115 | 
| 115 remoting.ClientPlugin.factory.preloadPlugin(); | 116 remoting.ClientPlugin.factory.preloadPlugin(); | 
| 116 } | 117 } | 
| 117 | 118 | 
| 118 /** | 119 /** | 
| 119 * Start the application. Once start() is called, the delegate can assume that | 120 * Start the application. Once start() is called, the delegate can assume that | 
| 120 * the user has consented to all permissions specified in the manifest. | 121 * the user has consented to all permissions specified in the manifest. | 
| 121 * | 122 * | 
| 122 * @param {remoting.SessionConnector} connector | 123 * @param {remoting.SessionConnector} connector | 
| 123 * @param {string} token An OAuth access token. The delegate should not cache | 124 * @param {string} token An OAuth access token. The delegate should not cache | 
| 124 * this token, but can assume that it will remain valid during application | 125 * this token, but can assume that it will remain valid during application | 
| 125 * start-up. | 126 * start-up. | 
| 126 */ | 127 */ | 
| 127 remoting.DesktopRemoting.prototype.start = function(connector, token) { | 128 remoting.DesktopRemoting.prototype.start = function(connector, token) { | 
| 128 remoting.identity.getEmail().then( | 129 remoting.identity.getEmail().then( | 
| 129 function(/** string */ email) { | 130 function(/** string */ email) { | 
| 130 document.getElementById('current-email').innerText = email; | 131 document.getElementById('current-email').innerText = email; | 
| 131 document.getElementById('get-started-it2me').disabled = false; | 132 document.getElementById('get-started-it2me').disabled = false; | 
| 132 document.getElementById('get-started-me2me').disabled = false; | 133 document.getElementById('get-started-me2me').disabled = false; | 
| 133 }); | 134 }); | 
| 134 }; | 135 }; | 
| 135 | 136 | 
| 136 /** | 137 /** | 
| 137 * Report an authentication error to the user. This is called in lieu of start() | |
| 138 * if the user cannot be authenticated or if they decline the app permissions. | |
| 139 * | |
| 140 * @param {!remoting.Error} error The failure reason. | |
| 141 */ | |
| 142 remoting.DesktopRemoting.prototype.signInFailed = function(error) { | |
| 143 remoting.showErrorMessage(error); | |
| 144 }; | |
| 145 | |
| 146 /** | |
| 147 * @return {string} Application product name to be used in UI. | 138 * @return {string} Application product name to be used in UI. | 
| 148 */ | 139 */ | 
| 149 remoting.DesktopRemoting.prototype.getApplicationName = function() { | 140 remoting.DesktopRemoting.prototype.getApplicationName = function() { | 
| 150 return chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME'); | 141 return chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME'); | 
| 151 }; | 142 }; | 
| 152 | 143 | 
| 153 /** | 144 /** | 
| 154 * @return {string} The default remap keys for the current platform. | 145 * @return {string} The default remap keys for the current platform. | 
| 155 */ | 146 */ | 
| 156 remoting.DesktopRemoting.prototype.getDefaultRemapKeys = function() { | 147 remoting.DesktopRemoting.prototype.getDefaultRemapKeys = function() { | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 var mode = remoting.clientSession ? remoting.desktopConnectedView.getMode() | 309 var mode = remoting.clientSession ? remoting.desktopConnectedView.getMode() | 
| 319 : this.app_.getSessionConnector().getConnectionMode(); | 310 : this.app_.getSessionConnector().getConnectionMode(); | 
| 320 if (mode == remoting.DesktopConnectedView.Mode.IT2ME) { | 311 if (mode == remoting.DesktopConnectedView.Mode.IT2ME) { | 
| 321 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | 312 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | 
| 322 } else { | 313 } else { | 
| 323 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 314 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 
| 324 } | 315 } | 
| 325 }; | 316 }; | 
| 326 | 317 | 
| 327 /** | 318 /** | 
| 319 * Report an authentication error to the user. This is called in lieu of start() | |
| 320 * if the user cannot be authenticated or if they decline the app permissions. | |
| 321 * | |
| 322 * @param {!remoting.Error} error The failure reason. | |
| 323 */ | |
| 324 remoting.DesktopRemoting.prototype.handleAuthError = function(error) { | |
| 
garykac
2015/03/19 01:03:43
function copied from remoting.showErrorMessage
 | |
| 325 l10n.localizeElementFromTag( | |
| 326 document.getElementById('token-refresh-error-message'), | |
| 327 error.getTag()); | |
| 328 var auth_failed = (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)); | |
| 329 if (auth_failed && base.isAppsV2()) { | |
| 330 remoting.handleAuthFailureAndRelaunch(); | |
| 331 } else { | |
| 332 document.getElementById('token-refresh-auth-failed').hidden = !auth_failed; | |
| 333 document.getElementById('token-refresh-other-error').hidden = auth_failed; | |
| 334 remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED); | |
| 335 } | |
| 336 }; | |
| 337 | |
| 338 /** | |
| 328 * No cleanup required for desktop remoting. | 339 * No cleanup required for desktop remoting. | 
| 329 */ | 340 */ | 
| 330 remoting.DesktopRemoting.prototype.handleExit = function() { | 341 remoting.DesktopRemoting.prototype.handleExit = function() { | 
| 331 }; | 342 }; | 
| 343 | |
| 344 /** | |
| 345 * Determine whether or not the app is running in a window. | |
| 346 * @param {function(boolean):void} callback Callback to receive whether or not | |
| 347 * the current tab is running in windowed mode. | |
| 348 * @private | |
| 349 */ | |
| 350 remoting.DesktopRemoting.prototype.isWindowed_ = function(callback) { | |
| 
garykac
2015/03/19 01:03:43
moved here from remoting.js
 | |
| 351 /** @param {chrome.Window} win The current window. */ | |
| 352 var windowCallback = function(win) { | |
| 353 callback(win.type == 'popup'); | |
| 354 }; | |
| 355 /** @param {chrome.Tab} tab The current tab. */ | |
| 356 var tabCallback = function(tab) { | |
| 357 if (tab.pinned) { | |
| 358 callback(false); | |
| 359 } else { | |
| 360 chrome.windows.get(tab.windowId, null, windowCallback); | |
| 361 } | |
| 362 }; | |
| 363 if (chrome.tabs) { | |
| 364 chrome.tabs.getCurrent(tabCallback); | |
| 365 } else { | |
| 366 console.error('chome.tabs is not available.'); | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 /** | |
| 371 * If an IT2Me client or host is active then prompt the user before closing. | |
| 372 * If a Me2Me client is active then don't bother, since closing the window is | |
| 373 * the more intuitive way to end a Me2Me session, and re-connecting is easy. | |
| 374 * @private | |
| 375 */ | |
| 376 remoting.DesktopRemoting.prototype.promptClose_ = function() { | |
| 
garykac
2015/03/19 01:03:44
moved here from remoting.js
 | |
| 377 if (remoting.desktopConnectedView && | |
| 
kelvinp
2015/03/19 17:50:20
desktopConnectedView is gone now.  Need remerging.
 
garykac
2015/03/19 21:58:38
Acknowledged.
 | |
| 378 remoting.desktopConnectedView.getMode() == | |
| 379 remoting.DesktopConnectedView.Mode.IT2ME) { | |
| 380 switch (remoting.currentMode) { | |
| 381 case remoting.AppMode.CLIENT_CONNECTING: | |
| 382 case remoting.AppMode.HOST_WAITING_FOR_CODE: | |
| 383 case remoting.AppMode.HOST_WAITING_FOR_CONNECTION: | |
| 384 case remoting.AppMode.HOST_SHARED: | |
| 385 case remoting.AppMode.IN_SESSION: | |
| 386 return chrome.i18n.getMessage(/*i18n-content*/'CLOSE_PROMPT'); | |
| 387 default: | |
| 388 return null; | |
| 389 } | |
| 390 } | |
| 391 }; | |
| OLD | NEW |