Chromium Code Reviews| 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 /** @type {remoting.HostSession} */ remoting.hostSession = null; | 10 /** @type {remoting.HostSession} */ remoting.hostSession = null; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * @type {base.EventSource} An event source object for handling global events. | 13 * @type {base.EventSource} An event source object for handling global events. |
| 14 * This is an interim hack. Eventually, we should move functionalities | 14 * This is an interim hack. Eventually, we should move functionalities |
| 15 * away from the remoting namespace and into smaller objects. | 15 * away from the remoting namespace and into smaller objects. |
| 16 */ | 16 */ |
| 17 remoting.testEvents; | 17 remoting.testEvents; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Show the authorization consent UI and register a one-shot event handler to | 20 * Initialization tasks that are common to all remoting apps. |
| 21 * continue the authorization process. | |
| 22 * | |
| 23 * @param {function():void} authContinue Callback to invoke when the user | |
| 24 * clicks "Continue". | |
| 25 */ | 21 */ |
| 26 function consentRequired_(authContinue) { | 22 remoting.initCommon = function() { |
|
garykac
2014/11/18 21:45:54
consentRequired moved into auth_init.js
| |
| 27 /** @type {HTMLElement} */ | |
| 28 var dialog = document.getElementById('auth-dialog'); | |
| 29 /** @type {HTMLElement} */ | |
| 30 var button = document.getElementById('auth-button'); | |
| 31 var consentGranted = function(event) { | |
| 32 dialog.hidden = true; | |
| 33 button.removeEventListener('click', consentGranted, false); | |
| 34 authContinue(); | |
| 35 remoting.windowShape.updateClientWindowShape(); | |
| 36 }; | |
| 37 dialog.hidden = false; | |
| 38 | |
| 39 /** @type {HTMLElement} */ | |
| 40 var dialog_border = document.getElementById('auth-dialog-border'); | |
| 41 // TODO(garykac): Refactor to remove auth dialog from the main html file | |
| 42 // and place in a separate window. | |
| 43 remoting.authDialog = new remoting.AuthDialog(dialog_border); | |
| 44 remoting.windowShape.addCallback(remoting.authDialog); | |
| 45 | |
| 46 button.addEventListener('click', consentGranted, false); | |
| 47 } | |
| 48 | |
| 49 /** | |
| 50 * Entry point for app initialization. | |
| 51 */ | |
| 52 remoting.init = function() { | |
| 53 if (base.isAppsV2()) { | 23 if (base.isAppsV2()) { |
| 54 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); | 24 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); |
| 55 htmlNode.classList.add('apps-v2'); | 25 htmlNode.classList.add('apps-v2'); |
| 56 } else { | 26 } else { |
| 57 migrateLocalToChromeStorage_(); | 27 migrateLocalToChromeStorage_(); |
| 58 } | 28 } |
| 59 | 29 |
| 60 console.log(remoting.getExtensionInfo()); | 30 console.log(remoting.getExtensionInfo()); |
| 61 l10n.localize(); | 31 l10n.localize(); |
| 62 | 32 |
| 63 // Create global objects. | 33 // Create global objects. |
| 64 remoting.ClientPlugin.factory = new remoting.DefaultClientPluginFactory(); | 34 remoting.ClientPlugin.factory = new remoting.DefaultClientPluginFactory(); |
| 65 remoting.SessionConnector.factory = | 35 remoting.SessionConnector.factory = |
| 66 new remoting.DefaultSessionConnectorFactory(); | 36 new remoting.DefaultSessionConnectorFactory(); |
| 67 remoting.settings = new remoting.Settings(); | 37 remoting.settings = new remoting.Settings(); |
| 38 | |
| 68 if (base.isAppsV2()) { | 39 if (base.isAppsV2()) { |
| 69 remoting.identity = new remoting.Identity(consentRequired_); | |
|
garykac
2014/11/18 21:45:54
identity is inited in auth_init
| |
| 70 remoting.fullscreen = new remoting.FullscreenAppsV2(); | 40 remoting.fullscreen = new remoting.FullscreenAppsV2(); |
| 71 remoting.windowFrame = new remoting.WindowFrame( | |
|
garykac
2014/11/18 21:45:54
windowFrame, optionsMenu and toolbar are crd-speci
| |
| 72 document.getElementById('title-bar')); | |
| 73 remoting.optionsMenu = remoting.windowFrame.createOptionsMenu(); | |
| 74 } else { | 41 } else { |
| 75 remoting.oauth2 = new remoting.OAuth2(); | |
| 76 if (!remoting.oauth2.isAuthenticated()) { | |
| 77 document.getElementById('auth-dialog').hidden = false; | |
| 78 } | |
| 79 remoting.identity = remoting.oauth2; | |
| 80 remoting.fullscreen = new remoting.FullscreenAppsV1(); | 42 remoting.fullscreen = new remoting.FullscreenAppsV1(); |
| 81 remoting.toolbar = new remoting.Toolbar( | |
| 82 document.getElementById('session-toolbar')); | |
| 83 remoting.optionsMenu = remoting.toolbar.createOptionsMenu(); | |
| 84 } | 43 } |
| 44 | |
| 85 remoting.stats = new remoting.ConnectionStats( | 45 remoting.stats = new remoting.ConnectionStats( |
| 86 document.getElementById('statistics')); | 46 document.getElementById('statistics')); |
| 87 remoting.formatIq = new remoting.FormatIq(); | 47 remoting.formatIq = new remoting.FormatIq(); |
| 88 remoting.hostList = new remoting.HostList( | 48 |
| 89 document.getElementById('host-list'), | |
| 90 document.getElementById('host-list-empty'), | |
| 91 document.getElementById('host-list-error-message'), | |
| 92 document.getElementById('host-list-refresh-failed-button'), | |
| 93 document.getElementById('host-list-loading-indicator')); | |
| 94 remoting.clipboard = new remoting.Clipboard(); | 49 remoting.clipboard = new remoting.Clipboard(); |
| 95 var sandbox = /** @type {HTMLIFrameElement} */ | 50 var sandbox = /** @type {HTMLIFrameElement} */ |
| 96 document.getElementById('wcs-sandbox'); | 51 document.getElementById('wcs-sandbox'); |
| 97 remoting.wcsSandbox = new remoting.WcsSandboxContainer(sandbox.contentWindow); | 52 remoting.wcsSandbox = new remoting.WcsSandboxContainer(sandbox.contentWindow); |
| 98 var homeFeedback = new remoting.MenuButton( | |
| 99 document.getElementById('help-feedback-main')); | |
| 100 var toolbarFeedback = new remoting.MenuButton( | |
| 101 document.getElementById('help-feedback-toolbar')); | |
| 102 remoting.manageHelpAndFeedback( | |
| 103 document.getElementById('title-bar')); | |
| 104 remoting.manageHelpAndFeedback( | |
| 105 document.getElementById('help-feedback-toolbar')); | |
| 106 remoting.manageHelpAndFeedback( | |
| 107 document.getElementById('help-feedback-main')); | |
| 108 | |
| 109 /** @param {remoting.Error} error */ | |
| 110 var onGetEmailError = function(error) { | |
| 111 // No need to show the error message for NOT_AUTHENTICATED | |
| 112 // because we will show "auth-dialog". | |
| 113 if (error != remoting.Error.NOT_AUTHENTICATED) { | |
| 114 remoting.showErrorMessage(error); | |
| 115 } | |
| 116 } | |
| 117 remoting.identity.getEmail(remoting.onEmail, onGetEmailError); | |
| 118 | |
| 119 remoting.windowShape.updateClientWindowShape(); | |
| 120 | |
| 121 remoting.showOrHideIT2MeUi(); | |
| 122 remoting.showOrHideMe2MeUi(); | |
| 123 | 53 |
| 124 // The plugin's onFocus handler sends a paste command to |window|, because | 54 // The plugin's onFocus handler sends a paste command to |window|, because |
| 125 // it can't send one to the plugin element itself. | 55 // it can't send one to the plugin element itself. |
| 126 window.addEventListener('paste', pluginGotPaste_, false); | 56 window.addEventListener('paste', pluginGotPaste_, false); |
| 127 window.addEventListener('copy', pluginGotCopy_, false); | 57 window.addEventListener('copy', pluginGotCopy_, false); |
| 128 | 58 |
| 129 remoting.initModalDialogs(); | 59 remoting.initModalDialogs(); |
| 60 remoting.initTesting_(); | |
| 61 } | |
| 130 | 62 |
| 131 isHostModeSupported_().then( | 63 remoting.initTesting_ = function() { |
| 132 /** @param {Boolean} supported */ | |
| 133 function(supported){ | |
| 134 if (supported) { | |
| 135 var noShare = document.getElementById('chrome-os-no-share'); | |
| 136 noShare.parentNode.removeChild(noShare); | |
| 137 } else { | |
| 138 var button = document.getElementById('share-button'); | |
| 139 button.disabled = true; | |
| 140 } | |
| 141 }); | |
| 142 | |
| 143 /** | |
| 144 * @return {Promise} A promise that resolves to the id of the current | |
| 145 * containing tab/window. | |
| 146 */ | |
| 147 var getCurrentId = function () { | |
| 148 if (base.isAppsV2()) { | |
| 149 return Promise.resolve(chrome.app.window.current().id); | |
| 150 } | |
| 151 | |
| 152 /** | |
| 153 * @param {function(*=):void} resolve | |
| 154 * @param {function(*=):void} reject | |
| 155 */ | |
| 156 return new Promise(function(resolve, reject) { | |
| 157 /** @param {chrome.Tab} tab */ | |
| 158 chrome.tabs.getCurrent(function(tab){ | |
| 159 if (tab) { | |
| 160 resolve(String(tab.id)); | |
| 161 } | |
| 162 reject('Cannot retrieve the current tab.'); | |
| 163 }); | |
| 164 }); | |
| 165 }; | |
| 166 | |
| 167 var onLoad = function() { | |
| 168 // Parse URL parameters. | |
| 169 var urlParams = getUrlParameters_(); | |
| 170 if ('mode' in urlParams) { | |
| 171 if (urlParams['mode'] === 'me2me') { | |
| 172 var hostId = urlParams['hostId']; | |
| 173 remoting.connectMe2Me(hostId); | |
| 174 return; | |
| 175 } else if (urlParams['mode'] === 'hangout') { | |
| 176 /** @param {*} id */ | |
| 177 getCurrentId().then(function(id) { | |
| 178 /** @type {string} */ | |
| 179 var accessCode = urlParams['accessCode']; | |
| 180 remoting.ensureSessionConnector_(); | |
| 181 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
| 182 remoting.connector.connectIT2Me(accessCode); | |
| 183 | |
| 184 document.body.classList.add('hangout-remote-desktop'); | |
| 185 var senderId = /** @type {string} */ String(id); | |
| 186 var hangoutSession = new remoting.HangoutSession(senderId); | |
| 187 hangoutSession.init(); | |
| 188 }); | |
| 189 return; | |
| 190 } | |
| 191 } | |
| 192 // No valid URL parameters, start up normally. | |
| 193 remoting.initHomeScreenUi(); | |
| 194 } | |
| 195 remoting.hostList.load(onLoad); | |
| 196 | |
| 197 // For Apps v1, check the tab type to warn the user if they are not getting | |
| 198 // the best keyboard experience. | |
| 199 if (!base.isAppsV2() && !remoting.platformIsMac()) { | |
| 200 /** @param {boolean} isWindowed */ | |
| 201 var onIsWindowed = function(isWindowed) { | |
| 202 if (!isWindowed) { | |
| 203 document.getElementById('startup-mode-box-me2me').hidden = false; | |
| 204 document.getElementById('startup-mode-box-it2me').hidden = false; | |
| 205 } | |
| 206 }; | |
| 207 isWindowed_(onIsWindowed); | |
| 208 } | |
| 209 | |
| 210 remoting.testEvents = new base.EventSource(); | 64 remoting.testEvents = new base.EventSource(); |
| 211 | |
| 212 /** @enum {string} */ | 65 /** @enum {string} */ |
| 213 remoting.testEvents.Names = { | 66 remoting.testEvents.Names = { |
| 214 uiModeChanged: 'uiModeChanged' | 67 uiModeChanged: 'uiModeChanged' |
| 215 }; | 68 }; |
| 216 remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names)); | 69 remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names)); |
| 217 | 70 } |
| 218 remoting.ClientPlugin.factory.preloadPlugin(); | |
| 219 }; | |
| 220 | 71 |
| 221 /** | 72 /** |
| 222 * Returns true if the current platform is fully supported. It's only used when | 73 * Returns true if the current platform is fully supported. It's only used when |
| 223 * we detect that host native messaging components are not installed. In that | 74 * we detect that host native messaging components are not installed. In that |
| 224 * case the result of this function determines if the webapp should show the | 75 * case the result of this function determines if the webapp should show the |
| 225 * controls that allow to install and enable Me2Me host. | 76 * controls that allow to install and enable Me2Me host. |
| 226 * | 77 * |
| 227 * @return {boolean} | 78 * @return {boolean} |
| 228 */ | 79 */ |
| 229 remoting.isMe2MeInstallable = function() { | 80 remoting.isMe2MeInstallable = function() { |
| 230 // The chromoting host is currently not installable on ChromeOS. | 81 // The chromoting host is currently not installable on ChromeOS. |
| 231 // For Linux, we have a install package for Ubuntu but not other distros. | 82 // For Linux, we have a install package for Ubuntu but not other distros. |
| 232 // Since we cannot tell from javascript alone the Linux distro the client is | 83 // Since we cannot tell from javascript alone the Linux distro the client is |
| 233 // on, we don't show the daemon-control UI for Linux unless the host is | 84 // on, we don't show the daemon-control UI for Linux unless the host is |
| 234 // installed. | 85 // installed. |
| 235 return remoting.platformIsWindows() || remoting.platformIsMac(); | 86 return remoting.platformIsWindows() || remoting.platformIsMac(); |
| 236 } | 87 } |
| 237 | 88 |
| 238 /** | 89 /** |
| 239 * Display the user's email address and allow access to the rest of the app, | |
| 240 * including parsing URL parameters. | |
| 241 * | |
| 242 * @param {string} email The user's email address. | |
| 243 * @return {void} Nothing. | |
| 244 */ | |
| 245 remoting.onEmail = function(email) { | |
| 246 document.getElementById('current-email').innerText = email; | |
| 247 document.getElementById('get-started-it2me').disabled = false; | |
| 248 document.getElementById('get-started-me2me').disabled = false; | |
| 249 }; | |
| 250 | |
| 251 /** | |
| 252 * initHomeScreenUi is called if the app is not starting up in session mode, | |
| 253 * and also if the user cancels pin entry or the connection in session mode. | |
| 254 */ | |
| 255 remoting.initHomeScreenUi = function() { | |
| 256 remoting.hostController = new remoting.HostController(); | |
| 257 remoting.setMode(remoting.AppMode.HOME); | |
| 258 remoting.hostSetupDialog = | |
| 259 new remoting.HostSetupDialog(remoting.hostController); | |
| 260 var dialog = document.getElementById('paired-clients-list'); | |
| 261 var message = document.getElementById('paired-client-manager-message'); | |
| 262 var deleteAll = document.getElementById('delete-all-paired-clients'); | |
| 263 var close = document.getElementById('close-paired-client-manager-dialog'); | |
| 264 var working = document.getElementById('paired-client-manager-dialog-working'); | |
| 265 var error = document.getElementById('paired-client-manager-dialog-error'); | |
| 266 var noPairedClients = document.getElementById('no-paired-clients'); | |
| 267 remoting.pairedClientManager = | |
| 268 new remoting.PairedClientManager(remoting.hostController, dialog, message, | |
| 269 deleteAll, close, noPairedClients, | |
| 270 working, error); | |
| 271 // Display the cached host list, then asynchronously update and re-display it. | |
| 272 remoting.updateLocalHostState(); | |
| 273 remoting.hostList.refresh(remoting.updateLocalHostState); | |
| 274 remoting.butterBar = new remoting.ButterBar(); | |
| 275 }; | |
| 276 | |
| 277 /** | |
| 278 * Fetches local host state and updates the DOM accordingly. | |
| 279 */ | |
| 280 remoting.updateLocalHostState = function() { | |
| 281 /** | |
| 282 * @param {remoting.HostController.State} state Host state. | |
| 283 */ | |
| 284 var onHostState = function(state) { | |
| 285 if (state == remoting.HostController.State.STARTED) { | |
| 286 remoting.hostController.getLocalHostId(onHostId.bind(null, state)); | |
| 287 } else { | |
| 288 onHostId(state, null); | |
| 289 } | |
| 290 }; | |
| 291 | |
| 292 /** | |
| 293 * @param {remoting.HostController.State} state Host state. | |
| 294 * @param {string?} hostId Host id. | |
| 295 */ | |
| 296 var onHostId = function(state, hostId) { | |
| 297 remoting.hostList.setLocalHostStateAndId(state, hostId); | |
| 298 remoting.hostList.display(); | |
| 299 }; | |
| 300 | |
| 301 /** | |
| 302 * @param {boolean} response True if the feature is present. | |
| 303 */ | |
| 304 var onHasFeatureResponse = function(response) { | |
| 305 /** | |
| 306 * @param {remoting.Error} error | |
| 307 */ | |
| 308 var onError = function(error) { | |
| 309 console.error('Failed to get pairing status: ' + error); | |
| 310 remoting.pairedClientManager.setPairedClients([]); | |
| 311 }; | |
| 312 | |
| 313 if (response) { | |
| 314 remoting.hostController.getPairedClients( | |
| 315 remoting.pairedClientManager.setPairedClients.bind( | |
| 316 remoting.pairedClientManager), | |
| 317 onError); | |
| 318 } else { | |
| 319 console.log('Pairing registry not supported by host.'); | |
| 320 remoting.pairedClientManager.setPairedClients([]); | |
| 321 } | |
| 322 }; | |
| 323 | |
| 324 remoting.hostController.hasFeature( | |
| 325 remoting.HostController.Feature.PAIRING_REGISTRY, onHasFeatureResponse); | |
| 326 remoting.hostController.getLocalHostState(onHostState); | |
| 327 }; | |
| 328 | |
| 329 /** | |
| 330 * @return {string} Information about the current extension. | 90 * @return {string} Information about the current extension. |
| 331 */ | 91 */ |
| 332 remoting.getExtensionInfo = function() { | 92 remoting.getExtensionInfo = function() { |
| 333 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; | 93 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; |
| 334 var manifest = chrome.runtime.getManifest(); | 94 var manifest = chrome.runtime.getManifest(); |
| 335 if (manifest && manifest.version) { | 95 if (manifest && manifest.version) { |
| 336 var name = chrome.i18n.getMessage('PRODUCT_NAME'); | 96 var name = chrome.i18n.getMessage('PRODUCT_NAME'); |
| 337 return name + ' version: ' + manifest.version + v2OrLegacy; | 97 return name + ' version: ' + manifest.version + v2OrLegacy; |
| 338 } else { | 98 } else { |
| 339 return 'Failed to get product version. Corrupt manifest?'; | 99 return 'Failed to get product version. Corrupt manifest?'; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 ]; | 278 ]; |
| 519 for (var setting in window.localStorage) { | 279 for (var setting in window.localStorage) { |
| 520 if (oauthSettings.indexOf(setting) == -1) { | 280 if (oauthSettings.indexOf(setting) == -1) { |
| 521 var copy = {} | 281 var copy = {} |
| 522 copy[setting] = window.localStorage.getItem(setting); | 282 copy[setting] = window.localStorage.getItem(setting); |
| 523 chrome.storage.local.set(copy); | 283 chrome.storage.local.set(copy); |
| 524 window.localStorage.removeItem(setting); | 284 window.localStorage.removeItem(setting); |
| 525 } | 285 } |
| 526 } | 286 } |
| 527 } | 287 } |
| OLD | NEW |