| OLD | NEW | 
 | (Empty) | 
|    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. |  | 
|    4  |  | 
|    5 'use strict'; |  | 
|    6  |  | 
|    7 /** @suppress {duplicate} */ |  | 
|    8 var remoting = remoting || {}; |  | 
|    9  |  | 
|   10 /** @type {remoting.HostSession} */ remoting.hostSession = null; |  | 
|   11  |  | 
|   12 /** |  | 
|   13  * @enum {string} All error messages from messages.json |  | 
|   14  */ |  | 
|   15 remoting.Error = { |  | 
|   16   NO_RESPONSE: /*i18n-content*/'ERROR_NO_RESPONSE', |  | 
|   17   INVALID_ACCESS_CODE: /*i18n-content*/'ERROR_INVALID_ACCESS_CODE', |  | 
|   18   MISSING_PLUGIN: /*i18n-content*/'ERROR_MISSING_PLUGIN', |  | 
|   19   AUTHENTICATION_FAILED: /*i18n-content*/'ERROR_AUTHENTICATION_FAILED', |  | 
|   20   HOST_IS_OFFLINE: /*i18n-content*/'ERROR_HOST_IS_OFFLINE', |  | 
|   21   INCOMPATIBLE_PROTOCOL: /*i18n-content*/'ERROR_INCOMPATIBLE_PROTOCOL', |  | 
|   22   BAD_PLUGIN_VERSION: /*i18n-content*/'ERROR_BAD_PLUGIN_VERSION', |  | 
|   23   GENERIC: /*i18n-content*/'ERROR_GENERIC', |  | 
|   24   UNEXPECTED: /*i18n-content*/'ERROR_UNEXPECTED', |  | 
|   25   SERVICE_UNAVAILABLE: /*i18n-content*/'ERROR_SERVICE_UNAVAILABLE' |  | 
|   26 }; |  | 
|   27  |  | 
|   28 /** |  | 
|   29  * Entry point for app initialization. |  | 
|   30  */ |  | 
|   31 remoting.init = function() { |  | 
|   32   l10n.localize(); |  | 
|   33   var button = document.getElementById('toggle-scaling'); |  | 
|   34   button.title = chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_SCALING'); |  | 
|   35   // Create global objects. |  | 
|   36   remoting.oauth2 = new remoting.OAuth2(); |  | 
|   37   remoting.debug = new remoting.DebugLog( |  | 
|   38       document.getElementById('debug-messages'), |  | 
|   39       document.getElementById('statistics')); |  | 
|   40   remoting.hostList = new remoting.HostList( |  | 
|   41       document.getElementById('host-list'), |  | 
|   42       document.getElementById('host-list-error')); |  | 
|   43   remoting.toolbar = new remoting.Toolbar( |  | 
|   44       document.getElementById('session-toolbar')); |  | 
|   45  |  | 
|   46   refreshEmail_(); |  | 
|   47   var email = remoting.oauth2.getCachedEmail(); |  | 
|   48   if (email) { |  | 
|   49     document.getElementById('current-email').innerText = email; |  | 
|   50   } |  | 
|   51  |  | 
|   52   window.addEventListener('blur', pluginLostFocus_, false); |  | 
|   53  |  | 
|   54   // Parse URL parameters. |  | 
|   55   var urlParams = getUrlParameters(); |  | 
|   56   if ('mode' in urlParams) { |  | 
|   57     if (urlParams['mode'] == 'me2me') { |  | 
|   58       var hostId = urlParams['hostId']; |  | 
|   59       remoting.connectMe2Me(hostId, true); |  | 
|   60       return; |  | 
|   61     } |  | 
|   62   } |  | 
|   63  |  | 
|   64   // No valid URL parameters, start up normally. |  | 
|   65   remoting.setMode(getAppStartupMode_()); |  | 
|   66   if (isHostModeSupported_()) { |  | 
|   67     var noShare = document.getElementById('chrome-os-no-share'); |  | 
|   68     noShare.parentNode.removeChild(noShare); |  | 
|   69   } else { |  | 
|   70     var button = document.getElementById('share-button'); |  | 
|   71     button.disabled = true; |  | 
|   72   } |  | 
|   73 }; |  | 
|   74  |  | 
|   75 /** |  | 
|   76  * If there is an incomplete share or connection in progress, cancel it. |  | 
|   77  */ |  | 
|   78 remoting.cancelPendingOperation = function() { |  | 
|   79   document.getElementById('cancel-button').disabled = true; |  | 
|   80   switch (remoting.getMajorMode()) { |  | 
|   81     case remoting.AppMode.HOST: |  | 
|   82       remoting.cancelShare(); |  | 
|   83       break; |  | 
|   84     case remoting.AppMode.CLIENT: |  | 
|   85       remoting.cancelConnect(); |  | 
|   86       break; |  | 
|   87   } |  | 
|   88 }; |  | 
|   89  |  | 
|   90 /** |  | 
|   91  * If the client is connected, or the host is shared, prompt before closing. |  | 
|   92  * |  | 
|   93  * @return {?string} The prompt string if a connection is active. |  | 
|   94  */ |  | 
|   95 remoting.promptClose = function() { |  | 
|   96   switch (remoting.currentMode) { |  | 
|   97     case remoting.AppMode.CLIENT_CONNECTING: |  | 
|   98     case remoting.AppMode.HOST_WAITING_FOR_CODE: |  | 
|   99     case remoting.AppMode.HOST_WAITING_FOR_CONNECTION: |  | 
|  100     case remoting.AppMode.HOST_SHARED: |  | 
|  101     case remoting.AppMode.IN_SESSION: |  | 
|  102       var result = chrome.i18n.getMessage(/*i18n-content*/'CLOSE_PROMPT'); |  | 
|  103       return result; |  | 
|  104     default: |  | 
|  105       return null; |  | 
|  106   } |  | 
|  107 }; |  | 
|  108  |  | 
|  109 /** |  | 
|  110  * Sign the user out of Chromoting by clearing the OAuth refresh token. |  | 
|  111  */ |  | 
|  112 remoting.clearOAuth2 = function() { |  | 
|  113   remoting.oauth2.clear(); |  | 
|  114   window.localStorage.removeItem(KEY_EMAIL_); |  | 
|  115   remoting.setMode(remoting.AppMode.UNAUTHENTICATED); |  | 
|  116 }; |  | 
|  117  |  | 
|  118 /** |  | 
|  119  * Callback function called when the browser window loses focus. In this case, |  | 
|  120  * release all keys to prevent them becoming 'stuck down' on the host. |  | 
|  121  */ |  | 
|  122 function pluginLostFocus_() { |  | 
|  123   if (remoting.clientSession && remoting.clientSession.plugin) { |  | 
|  124     remoting.clientSession.plugin.releaseAllKeys(); |  | 
|  125   } |  | 
|  126 } |  | 
|  127  |  | 
|  128 /** |  | 
|  129  * If the user is authenticated, but there is no email address cached, get one. |  | 
|  130  */ |  | 
|  131 function refreshEmail_() { |  | 
|  132   if (!getEmail_() && remoting.oauth2.isAuthenticated()) { |  | 
|  133     remoting.oauth2.getEmail(setEmail_); |  | 
|  134   } |  | 
|  135 } |  | 
|  136  |  | 
|  137 /** |  | 
|  138  * The key under which the email address is stored. |  | 
|  139  * @private |  | 
|  140  */ |  | 
|  141 var KEY_EMAIL_ = 'remoting-email'; |  | 
|  142  |  | 
|  143 /** |  | 
|  144  * Save the user's email address in local storage. |  | 
|  145  * |  | 
|  146  * @param {?string} email The email address to place in local storage. |  | 
|  147  * @return {void} Nothing. |  | 
|  148  */ |  | 
|  149 function setEmail_(email) { |  | 
|  150   if (email) { |  | 
|  151     document.getElementById('current-email').innerText = email; |  | 
|  152   } else { |  | 
|  153     // TODO(ajwong): Have a better way of showing an error. |  | 
|  154     document.getElementById('current-email').innerText = '???'; |  | 
|  155   } |  | 
|  156 } |  | 
|  157  |  | 
|  158 /** |  | 
|  159  * Read the user's email address from local storage. |  | 
|  160  * |  | 
|  161  * @return {?string} The email address associated with the auth credentials. |  | 
|  162  */ |  | 
|  163 function getEmail_() { |  | 
|  164   var result = window.localStorage.getItem(KEY_EMAIL_); |  | 
|  165   return typeof result == 'string' ? result : null; |  | 
|  166 } |  | 
|  167  |  | 
|  168 /** |  | 
|  169  * Gets the major-mode that this application should start up in. |  | 
|  170  * |  | 
|  171  * @return {remoting.AppMode} The mode to start in. |  | 
|  172  */ |  | 
|  173 function getAppStartupMode_() { |  | 
|  174   return remoting.oauth2.isAuthenticated() ? remoting.AppMode.HOME : |  | 
|  175       remoting.AppMode.UNAUTHENTICATED; |  | 
|  176 } |  | 
|  177  |  | 
|  178 /** |  | 
|  179  * Returns whether Host mode is supported on this platform. |  | 
|  180  * |  | 
|  181  * @return {boolean} True if Host mode is supported. |  | 
|  182  */ |  | 
|  183 function isHostModeSupported_() { |  | 
|  184   // Currently, sharing on Chromebooks is not supported. |  | 
|  185   return !navigator.userAgent.match(/\bCrOS\b/); |  | 
|  186 } |  | 
| OLD | NEW |