| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 remoting.testEvents = new base.EventSourceImpl(); | 45 remoting.testEvents = new base.EventSourceImpl(); |
| 46 /** @enum {string} */ | 46 /** @enum {string} */ |
| 47 remoting.testEvents.Names = { | 47 remoting.testEvents.Names = { |
| 48 uiModeChanged: 'uiModeChanged' | 48 uiModeChanged: 'uiModeChanged' |
| 49 }; | 49 }; |
| 50 remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names)); | 50 remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Returns true if the current platform is fully supported. It's only used when | |
| 55 * we detect that host native messaging components are not installed. In that | |
| 56 * case the result of this function determines if the webapp should show the | |
| 57 * controls that allow to install and enable Me2Me host. | |
| 58 * | |
| 59 * @return {boolean} | |
| 60 */ | |
| 61 remoting.isMe2MeInstallable = function() { | |
| 62 // The chromoting host is currently not installable on ChromeOS. | |
| 63 // For Linux, we have a install package for Ubuntu but not other distros. | |
| 64 // Since we cannot tell from javascript alone the Linux distro the client is | |
| 65 // on, we don't show the daemon-control UI for Linux unless the host is | |
| 66 // installed. | |
| 67 return remoting.platformIsWindows() || remoting.platformIsMac(); | |
| 68 } | |
| 69 | |
| 70 /** | |
| 71 * @return {string} Information about the current extension. | 54 * @return {string} Information about the current extension. |
| 72 */ | 55 */ |
| 73 remoting.getExtensionInfo = function() { | 56 remoting.getExtensionInfo = function() { |
| 74 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; | 57 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; |
| 75 var manifest = chrome.runtime.getManifest(); | 58 var manifest = chrome.runtime.getManifest(); |
| 76 if (manifest && manifest.version) { | 59 if (manifest && manifest.version) { |
| 77 var name = remoting.app.getApplicationName(); | 60 var name = remoting.app.getApplicationName(); |
| 78 return name + ' version: ' + manifest.version + v2OrLegacy; | 61 return name + ' version: ' + manifest.version + v2OrLegacy; |
| 79 } else { | 62 } else { |
| 80 return 'Failed to get product version. Corrupt manifest?'; | 63 return 'Failed to get product version. Corrupt manifest?'; |
| 81 } | 64 } |
| 82 }; | 65 }; |
| 83 | 66 |
| 84 /** | 67 /** |
| 85 * If an IT2Me client or host is active then prompt the user before closing. | |
| 86 * If a Me2Me client is active then don't bother, since closing the window is | |
| 87 * the more intuitive way to end a Me2Me session, and re-connecting is easy. | |
| 88 */ | |
| 89 remoting.promptClose = function() { | |
| 90 var sessionConnector = remoting.app.getSessionConnector(); | |
| 91 if (sessionConnector && | |
| 92 sessionConnector.getConnectionMode() === | |
| 93 remoting.DesktopConnectedView.Mode.IT2ME) { | |
| 94 switch (remoting.currentMode) { | |
| 95 case remoting.AppMode.CLIENT_CONNECTING: | |
| 96 case remoting.AppMode.HOST_WAITING_FOR_CODE: | |
| 97 case remoting.AppMode.HOST_WAITING_FOR_CONNECTION: | |
| 98 case remoting.AppMode.HOST_SHARED: | |
| 99 case remoting.AppMode.IN_SESSION: | |
| 100 return chrome.i18n.getMessage(/*i18n-content*/'CLOSE_PROMPT'); | |
| 101 default: | |
| 102 return null; | |
| 103 } | |
| 104 } | |
| 105 }; | |
| 106 | |
| 107 /** | |
| 108 * Sign the user out of Chromoting by clearing (and revoking, if possible) the | |
| 109 * OAuth refresh token. | |
| 110 * | |
| 111 * Also clear all local storage, to avoid leaking information. | |
| 112 */ | |
| 113 remoting.signOut = function() { | |
| 114 remoting.oauth2.removeCachedAuthToken().then(function(){ | |
| 115 chrome.storage.local.clear(); | |
| 116 remoting.setMode(remoting.AppMode.HOME); | |
| 117 window.location.reload(); | |
| 118 }); | |
| 119 }; | |
| 120 | |
| 121 /** | |
| 122 * Callback function called when the browser window gets a paste operation. | 68 * Callback function called when the browser window gets a paste operation. |
| 123 * | 69 * |
| 124 * @param {Event} event | 70 * @param {Event} event |
| 125 * @return {void} Nothing. | 71 * @return {void} Nothing. |
| 126 */ | 72 */ |
| 127 function pluginGotPaste_(event) { | 73 function pluginGotPaste_(event) { |
| 128 if (event && event.clipboardData) { | 74 if (event && event.clipboardData) { |
| 129 remoting.clipboard.toHost(event.clipboardData); | 75 remoting.clipboard.toHost(event.clipboardData); |
| 130 } | 76 } |
| 131 } | 77 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 result = new Array(len - result.length + 1).join('0') + result; | 109 result = new Array(len - result.length + 1).join('0') + result; |
| 164 } | 110 } |
| 165 return result; | 111 return result; |
| 166 }; | 112 }; |
| 167 var now = new Date(); | 113 var now = new Date(); |
| 168 var timestamp = pad(now.getMonth() + 1, 2) + pad(now.getDate(), 2) + '/' + | 114 var timestamp = pad(now.getMonth() + 1, 2) + pad(now.getDate(), 2) + '/' + |
| 169 pad(now.getHours(), 2) + pad(now.getMinutes(), 2) + | 115 pad(now.getHours(), 2) + pad(now.getMinutes(), 2) + |
| 170 pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3); | 116 pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3); |
| 171 return '[' + timestamp + ']'; | 117 return '[' + timestamp + ']'; |
| 172 }; | 118 }; |
| 173 | |
| 174 /** | |
| 175 * Show an error message, optionally including a short-cut for signing in to | |
| 176 * Chromoting again. | |
| 177 * | |
| 178 * @param {!remoting.Error} error | |
| 179 * @return {void} Nothing. | |
| 180 */ | |
| 181 remoting.showErrorMessage = function(error) { | |
| 182 l10n.localizeElementFromTag( | |
| 183 document.getElementById('token-refresh-error-message'), | |
| 184 error.getTag()); | |
| 185 var auth_failed = (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)); | |
| 186 if (auth_failed && base.isAppsV2()) { | |
| 187 remoting.handleAuthFailureAndRelaunch(); | |
| 188 } else { | |
| 189 document.getElementById('token-refresh-auth-failed').hidden = !auth_failed; | |
| 190 document.getElementById('token-refresh-other-error').hidden = auth_failed; | |
| 191 remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED); | |
| 192 } | |
| 193 }; | |
| 194 | |
| 195 /** | |
| 196 * Determine whether or not the app is running in a window. | |
| 197 * @param {function(boolean):void} callback Callback to receive whether or not | |
| 198 * the current tab is running in windowed mode. | |
| 199 */ | |
| 200 function isWindowed_(callback) { | |
| 201 /** @param {chrome.Window} win The current window. */ | |
| 202 var windowCallback = function(win) { | |
| 203 callback(win.type == 'popup'); | |
| 204 }; | |
| 205 /** @param {chrome.Tab} tab The current tab. */ | |
| 206 var tabCallback = function(tab) { | |
| 207 if (tab.pinned) { | |
| 208 callback(false); | |
| 209 } else { | |
| 210 chrome.windows.get(tab.windowId, null, windowCallback); | |
| 211 } | |
| 212 }; | |
| 213 if (chrome.tabs) { | |
| 214 chrome.tabs.getCurrent(tabCallback); | |
| 215 } else { | |
| 216 console.error('chome.tabs is not available.'); | |
| 217 } | |
| 218 } | |
| OLD | NEW |