| 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   if (remoting.desktopConnectedView && |  | 
| 91       remoting.desktopConnectedView.getMode() == |  | 
| 92           remoting.DesktopConnectedView.Mode.IT2ME) { |  | 
| 93     switch (remoting.currentMode) { |  | 
| 94       case remoting.AppMode.CLIENT_CONNECTING: |  | 
| 95       case remoting.AppMode.HOST_WAITING_FOR_CODE: |  | 
| 96       case remoting.AppMode.HOST_WAITING_FOR_CONNECTION: |  | 
| 97       case remoting.AppMode.HOST_SHARED: |  | 
| 98       case remoting.AppMode.IN_SESSION: |  | 
| 99         return chrome.i18n.getMessage(/*i18n-content*/'CLOSE_PROMPT'); |  | 
| 100       default: |  | 
| 101         return null; |  | 
| 102     } |  | 
| 103   } |  | 
| 104 }; |  | 
| 105 |  | 
| 106 /** |  | 
| 107  * Sign the user out of Chromoting by clearing (and revoking, if possible) the |  | 
| 108  * OAuth refresh token. |  | 
| 109  * |  | 
| 110  * Also clear all local storage, to avoid leaking information. |  | 
| 111  */ |  | 
| 112 remoting.signOut = function() { |  | 
| 113   remoting.oauth2.removeCachedAuthToken().then(function(){ |  | 
| 114     chrome.storage.local.clear(); |  | 
| 115     remoting.setMode(remoting.AppMode.HOME); |  | 
| 116     window.location.reload(); |  | 
| 117   }); |  | 
| 118 }; |  | 
| 119 |  | 
| 120 /** |  | 
| 121  * Callback function called when the browser window gets a paste operation. | 68  * Callback function called when the browser window gets a paste operation. | 
| 122  * | 69  * | 
| 123  * @param {Event} event | 70  * @param {Event} event | 
| 124  * @return {void} Nothing. | 71  * @return {void} Nothing. | 
| 125  */ | 72  */ | 
| 126 function pluginGotPaste_(event) { | 73 function pluginGotPaste_(event) { | 
| 127   if (event && event.clipboardData) { | 74   if (event && event.clipboardData) { | 
| 128     remoting.clipboard.toHost(event.clipboardData); | 75     remoting.clipboard.toHost(event.clipboardData); | 
| 129   } | 76   } | 
| 130 } | 77 } | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 162       result = new Array(len - result.length + 1).join('0') + result; | 109       result = new Array(len - result.length + 1).join('0') + result; | 
| 163     } | 110     } | 
| 164     return result; | 111     return result; | 
| 165   }; | 112   }; | 
| 166   var now = new Date(); | 113   var now = new Date(); | 
| 167   var timestamp = pad(now.getMonth() + 1, 2) + pad(now.getDate(), 2) + '/' + | 114   var timestamp = pad(now.getMonth() + 1, 2) + pad(now.getDate(), 2) + '/' + | 
| 168       pad(now.getHours(), 2) + pad(now.getMinutes(), 2) + | 115       pad(now.getHours(), 2) + pad(now.getMinutes(), 2) + | 
| 169       pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3); | 116       pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3); | 
| 170   return '[' + timestamp + ']'; | 117   return '[' + timestamp + ']'; | 
| 171 }; | 118 }; | 
| 172 |  | 
| 173 /** |  | 
| 174  * Show an error message, optionally including a short-cut for signing in to |  | 
| 175  * Chromoting again. |  | 
| 176  * |  | 
| 177  * @param {!remoting.Error} error |  | 
| 178  * @return {void} Nothing. |  | 
| 179  */ |  | 
| 180 remoting.showErrorMessage = function(error) { |  | 
| 181   l10n.localizeElementFromTag( |  | 
| 182       document.getElementById('token-refresh-error-message'), |  | 
| 183       error.getTag()); |  | 
| 184   var auth_failed = (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)); |  | 
| 185   if (auth_failed && base.isAppsV2()) { |  | 
| 186     remoting.handleAuthFailureAndRelaunch(); |  | 
| 187   } else { |  | 
| 188     document.getElementById('token-refresh-auth-failed').hidden = !auth_failed; |  | 
| 189     document.getElementById('token-refresh-other-error').hidden = auth_failed; |  | 
| 190     remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED); |  | 
| 191   } |  | 
| 192 }; |  | 
| 193 |  | 
| 194 /** |  | 
| 195  * Determine whether or not the app is running in a window. |  | 
| 196  * @param {function(boolean):void} callback Callback to receive whether or not |  | 
| 197  *     the current tab is running in windowed mode. |  | 
| 198  */ |  | 
| 199 function isWindowed_(callback) { |  | 
| 200   /** @param {chrome.Window} win The current window. */ |  | 
| 201   var windowCallback = function(win) { |  | 
| 202     callback(win.type == 'popup'); |  | 
| 203   }; |  | 
| 204   /** @param {chrome.Tab} tab The current tab. */ |  | 
| 205   var tabCallback = function(tab) { |  | 
| 206     if (tab.pinned) { |  | 
| 207       callback(false); |  | 
| 208     } else { |  | 
| 209       chrome.windows.get(tab.windowId, null, windowCallback); |  | 
| 210     } |  | 
| 211   }; |  | 
| 212   if (chrome.tabs) { |  | 
| 213     chrome.tabs.getCurrent(tabCallback); |  | 
| 214   } else { |  | 
| 215     console.error('chome.tabs is not available.'); |  | 
| 216   } |  | 
| 217 } |  | 
| OLD | NEW | 
|---|