Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: remoting/webapp/me2mom/remoting.js

Issue 7329011: Chromoting: Move set(Client|Host)Mode into remoting namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 var remoting = remoting || {}; 5 var remoting = remoting || {};
6 6
7 (function() { 7 (function() {
8 "use strict"; 8 "use strict";
9 9
10 /** @enum {string} */ 10 /** @enum {string} */
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 } 168 }
169 169
170 remoting.init = function() { 170 remoting.init = function() {
171 // Create global objects. 171 // Create global objects.
172 remoting.oauth2 = new remoting.OAuth2(); 172 remoting.oauth2 = new remoting.OAuth2();
173 remoting.debug = new remoting.DebugLog(document.getElementById('debug-log')); 173 remoting.debug = new remoting.DebugLog(document.getElementById('debug-log'));
174 174
175 updateAuthStatus_(); 175 updateAuthStatus_();
176 refreshEmail_(); 176 refreshEmail_();
177 setHostMode('unshared'); 177 remoting.setHostMode('unshared');
178 setClientMode('unconnected'); 178 remoting.setClientMode('unconnected');
179 setGlobalMode(getAppStartupMode()); 179 setGlobalMode(getAppStartupMode());
180 addClass(document.getElementById('loading-mode'), 'hidden'); 180 addClass(document.getElementById('loading-mode'), 'hidden');
181 removeClass(document.getElementById('choice-mode'), 'hidden'); 181 removeClass(document.getElementById('choice-mode'), 'hidden');
182 } 182 }
183 183
184 function setGlobalMode(mode) { 184 function setGlobalMode(mode) {
185 var elementsToShow = []; 185 var elementsToShow = [];
186 var elementsToHide = []; 186 var elementsToHide = [];
187 var hostElements = document.getElementsByClassName('host-element'); 187 var hostElements = document.getElementsByClassName('host-element');
188 hostElements = Array.prototype.slice.apply(hostElements); 188 hostElements = Array.prototype.slice.apply(hostElements);
(...skipping 28 matching lines...) Expand all
217 setGlobalMode(mode); 217 setGlobalMode(mode);
218 // TODO(ajwong): Does it make sense for "in_session" to be a peer to "host" 218 // TODO(ajwong): Does it make sense for "in_session" to be a peer to "host"
219 // or "client mode"? I don't think so, but not sure how to restructure UI. 219 // or "client mode"? I don't think so, but not sure how to restructure UI.
220 if (mode != remoting.AppMode.IN_SESSION) { 220 if (mode != remoting.AppMode.IN_SESSION) {
221 remoting.storage.setStartupMode(mode); 221 remoting.storage.setStartupMode(mode);
222 } else { 222 } else {
223 remoting.storage.setStartupMode(remoting.AppMode.CLIENT); 223 remoting.storage.setStartupMode(remoting.AppMode.CLIENT);
224 } 224 }
225 } 225 }
226 226
227 function setHostMode(mode) { 227 remoting.setHostMode = function(mode) {
228 var section = document.getElementById('host-panel'); 228 var section = document.getElementById('host-panel');
229 var modes = section.getElementsByClassName('mode'); 229 var modes = section.getElementsByClassName('mode');
230 remoting.debug.log('Host mode: ' + mode); 230 remoting.debug.log('Host mode: ' + mode);
231 setMode_(mode, modes); 231 setMode_(mode, modes);
232 } 232 }
233 233
234 function setClientMode(mode) { 234 remoting.setClientMode = function(mode) {
235 var section = document.getElementById('client-panel'); 235 var section = document.getElementById('client-panel');
236 var modes = section.getElementsByClassName('mode'); 236 var modes = section.getElementsByClassName('mode');
237 remoting.debug.log('Client mode: ' + mode); 237 remoting.debug.log('Client mode: ' + mode);
238 setMode_(mode, modes); 238 setMode_(mode, modes);
239 } 239 }
240 240
241 function showWaiting_() { 241 function showWaiting_() {
242 showElement(document.getElementById('client-footer-text'), false); 242 showElement(document.getElementById('client-footer-text'), false);
243 showElement(document.getElementById('host-footer-text'), false); 243 showElement(document.getElementById('host-footer-text'), false);
244 showElement(document.getElementById('waiting-footer'), true); 244 showElement(document.getElementById('waiting-footer'), true);
245 document.getElementById('cancel-button').disabled = false; 245 document.getElementById('cancel-button').disabled = false;
246 } 246 }
247 247
248 function tryShare() { 248 remoting.tryShare = function() {
249 remoting.debug.log('Attempting to share...'); 249 remoting.debug.log('Attempting to share...');
250 if (remoting.oauth2.needsNewAccessToken()) { 250 if (remoting.oauth2.needsNewAccessToken()) {
251 remoting.debug.log('Refreshing token...'); 251 remoting.debug.log('Refreshing token...');
252 remoting.oauth2.refreshAccessToken(function() { 252 remoting.oauth2.refreshAccessToken(function() {
253 if (remoting.oauth2.needsNewAccessToken()) { 253 if (remoting.oauth2.needsNewAccessToken()) {
254 // If we still need it, we're going to infinite loop. 254 // If we still need it, we're going to infinite loop.
255 showShareError_('unable-to-get-token'); 255 showShareError_('unable-to-get-token');
256 throw 'Unable to get access token'; 256 throw 'Unable to get access token';
257 } 257 }
258 tryShare(); 258 remoting.tryShare();
259 }); 259 });
260 return; 260 return;
261 } 261 }
262 262
263 showWaiting_(); 263 showWaiting_();
264 264
265 var div = document.getElementById('host-plugin-container'); 265 var div = document.getElementById('host-plugin-container');
266 var plugin = document.createElement('embed'); 266 var plugin = document.createElement('embed');
267 plugin.setAttribute('type', remoting.PLUGIN_MIMETYPE); 267 plugin.setAttribute('type', remoting.PLUGIN_MIMETYPE);
268 plugin.setAttribute('hidden', 'true'); 268 plugin.setAttribute('hidden', 'true');
269
Jamie 2011/07/08 16:09:45 Is this blank line deliberate? I can't see why it'
garykac 2011/07/08 17:36:42 Curious. It was not intended. Removed.
269 plugin.setAttribute('id', remoting.HOST_PLUGIN_ID); 270 plugin.setAttribute('id', remoting.HOST_PLUGIN_ID);
270 div.appendChild(plugin); 271 div.appendChild(plugin);
271 plugin.onStateChanged = onStateChanged_; 272 plugin.onStateChanged = onStateChanged_;
272 plugin.logDebugInfo = debugInfoCallback_; 273 plugin.logDebugInfo = debugInfoCallback_;
273 plugin.connect(getEmail(), 274 plugin.connect(getEmail(),
274 'oauth2:' + remoting.oauth2.getAccessToken()); 275 'oauth2:' + remoting.oauth2.getAccessToken());
275 } 276 }
276 remoting.tryShare = tryShare;
277 277
278 function onStateChanged_() { 278 function onStateChanged_() {
279 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID); 279 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
280 var state = plugin.state; 280 var state = plugin.state;
281 if (state == plugin.REQUESTED_ACCESS_CODE) { 281 if (state == plugin.REQUESTED_ACCESS_CODE) {
282 setHostMode('preparing-to-share'); 282 remoting.setHostMode('preparing-to-share');
283 } else if (state == plugin.RECEIVED_ACCESS_CODE) { 283 } else if (state == plugin.RECEIVED_ACCESS_CODE) {
284 var accessCode = plugin.accessCode; 284 var accessCode = plugin.accessCode;
285 var accessCodeDisplay = document.getElementById('access-code-display'); 285 var accessCodeDisplay = document.getElementById('access-code-display');
286 accessCodeDisplay.innerText = ''; 286 accessCodeDisplay.innerText = '';
287 // Display the access code in groups of four digits for readability. 287 // Display the access code in groups of four digits for readability.
288 for (var i = 0; i < accessCode.length; i += kDigitsPerGroup) { 288 for (var i = 0; i < accessCode.length; i += kDigitsPerGroup) {
289 var nextFourDigits = document.createElement('span'); 289 var nextFourDigits = document.createElement('span');
290 nextFourDigits.className = 'access-code-digit-group'; 290 nextFourDigits.className = 'access-code-digit-group';
291 nextFourDigits.innerText = accessCode.substring(i, i + kDigitsPerGroup); 291 nextFourDigits.innerText = accessCode.substring(i, i + kDigitsPerGroup);
292 accessCodeDisplay.appendChild(nextFourDigits); 292 accessCodeDisplay.appendChild(nextFourDigits);
293 } 293 }
294 setHostMode('ready-to-share'); 294 remoting.setHostMode('ready-to-share');
295 } else if (state == plugin.CONNECTED) { 295 } else if (state == plugin.CONNECTED) {
296 setHostMode('shared'); 296 remoting.setHostMode('shared');
297 } else if (state == plugin.DISCONNECTED) { 297 } else if (state == plugin.DISCONNECTED) {
298 setGlobalMode(remoting.AppMode.HOST); 298 setGlobalMode(remoting.AppMode.HOST);
299 setHostMode('unshared'); 299 remoting.setHostMode('unshared');
300 plugin.parentNode.removeChild(plugin); 300 plugin.parentNode.removeChild(plugin);
301 } else { 301 } else {
302 remoting.debug.log('Unknown state -> ' + state); 302 remoting.debug.log('Unknown state -> ' + state);
303 } 303 }
304 } 304 }
305 305
306 /** 306 /**
307 * This is that callback that the host plugin invokes to indicate that there 307 * This is that callback that the host plugin invokes to indicate that there
308 * is additional debug log info to display. 308 * is additional debug log info to display.
309 */ 309 */
310 function debugInfoCallback_(msg) { 310 function debugInfoCallback_(msg) {
311 remoting.debug.log('plugin: ' + msg); 311 remoting.debug.log('plugin: ' + msg);
312 } 312 }
313 313
314 function showShareError_(errorCode) { 314 function showShareError_(errorCode) {
315 var errorDiv = document.getElementById(errorCode); 315 var errorDiv = document.getElementById(errorCode);
316 errorDiv.style.display = 'block'; 316 errorDiv.style.display = 'block';
317 remoting.debug.log("Sharing error: " + errorCode); 317 remoting.debug.log("Sharing error: " + errorCode);
318 setHostMode('share-failed'); 318 remoting.setHostMode('share-failed');
319 } 319 }
320 320
321 function cancelShare() { 321 remoting.cancelShare = function() {
322 remoting.debug.log('Canceling share...'); 322 remoting.debug.log('Canceling share...');
323 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID); 323 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
324 plugin.disconnect(); 324 plugin.disconnect();
325 } 325 }
326 remoting.cancelShare = cancelShare;
327 326
328 /** 327 /**
329 * Show a client message that stays on the screeen until the state changes. 328 * Show a client message that stays on the screeen until the state changes.
330 * 329 *
331 * @param {string} message The message to display. 330 * @param {string} message The message to display.
332 */ 331 */
333 function setClientStateMessage(message) { 332 function setClientStateMessage(message) {
334 var msg = document.getElementById('session-status-message'); 333 var msg = document.getElementById('session-status-message');
335 msg.innerText = message; 334 msg.innerText = message;
336 } 335 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (responseCode == 404) { 411 if (responseCode == 404) {
413 invalid.style.display = 'block'; 412 invalid.style.display = 'block';
414 other.style.display = 'none'; 413 other.style.display = 'none';
415 } else { 414 } else {
416 invalid.style.display = 'none'; 415 invalid.style.display = 'none';
417 other.style.display = 'block'; 416 other.style.display = 'block';
418 var responseNode = document.getElementById('server-response'); 417 var responseNode = document.getElementById('server-response');
419 responseNode.innerText = responseString + ' (' + responseCode + ')'; 418 responseNode.innerText = responseString + ' (' + responseCode + ')';
420 } 419 }
421 remoting.accessCode = ''; 420 remoting.accessCode = '';
422 setClientMode('connect-failed'); 421 remoting.setClientMode('connect-failed');
423 } 422 }
424 423
425 function parseServerResponse_(xhr) { 424 function parseServerResponse_(xhr) {
426 if (xhr.status == 200) { 425 if (xhr.status == 200) {
427 var host = JSON.parse(xhr.responseText); 426 var host = JSON.parse(xhr.responseText);
428 if (host.data && host.data.jabberId) { 427 if (host.data && host.data.jabberId) {
429 remoting.hostJid = host.data.jabberId; 428 remoting.hostJid = host.data.jabberId;
430 remoting.hostPublicKey = host.data.publicKey; 429 remoting.hostPublicKey = host.data.publicKey;
431 startSession_(); 430 startSession_();
432 return; 431 return;
(...skipping 14 matching lines...) Expand all
447 }; 446 };
448 447
449 remoting.xhr.get( 448 remoting.xhr.get(
450 'https://www.googleapis.com/chromoting/v1/support-hosts/' + 449 'https://www.googleapis.com/chromoting/v1/support-hosts/' +
451 encodeURIComponent(supportId), 450 encodeURIComponent(supportId),
452 parseServerResponse_, 451 parseServerResponse_,
453 '', 452 '',
454 headers); 453 headers);
455 } 454 }
456 455
457 function tryConnect() { 456 remoting.tryConnect = function() {
458 if (remoting.oauth2.needsNewAccessToken()) { 457 if (remoting.oauth2.needsNewAccessToken()) {
459 remoting.oauth2.refreshAccessToken(function() { 458 remoting.oauth2.refreshAccessToken(function() {
460 if (remoting.oauth2.needsNewAccessToken()) { 459 if (remoting.oauth2.needsNewAccessToken()) {
461 // If we still need it, we're going to infinite loop. 460 // If we still need it, we're going to infinite loop.
462 throw 'Unable to get access token.'; 461 throw 'Unable to get access token.';
463 } 462 }
464 tryConnect(); 463 remoting.tryConnect();
465 }); 464 });
466 return; 465 return;
467 } 466 }
468 var accessCode = document.getElementById('access-code-entry').value; 467 var accessCode = document.getElementById('access-code-entry').value;
469 remoting.accessCode = normalizeAccessCode_(accessCode); 468 remoting.accessCode = normalizeAccessCode_(accessCode);
470 // At present, only 12-digit access codes are supported, of which the first 469 // At present, only 12-digit access codes are supported, of which the first
471 // 7 characters are the supportId. 470 // 7 characters are the supportId.
472 if (remoting.accessCode.length != kAccessCodeLen) { 471 if (remoting.accessCode.length != kAccessCodeLen) {
473 showConnectError_(404); 472 showConnectError_(404);
474 } else { 473 } else {
475 var supportId = remoting.accessCode.substring(0, kSupportIdLen); 474 var supportId = remoting.accessCode.substring(0, kSupportIdLen);
476 setClientMode('connecting'); 475 remoting.setClientMode('connecting');
477 resolveSupportId(supportId); 476 resolveSupportId(supportId);
478 } 477 }
479 } 478 }
480 remoting.tryConnect = tryConnect;
481 479
482 function cancelPendingOperation() { 480 remoting.cancelPendingOperation = function() {
483 document.getElementById('cancel-button').disabled = true; 481 document.getElementById('cancel-button').disabled = true;
484 if (remoting.currentMode == remoting.AppMode.HOST) { 482 if (remoting.currentMode == remoting.AppMode.HOST) {
485 cancelShare(); 483 remoting.cancelShare();
486 } 484 }
487 } 485 }
488 486
489 /** 487 /**
490 * Changes the major-mode of the application (Eg., client or host). 488 * Changes the major-mode of the application (Eg., client or host).
491 * 489 *
492 * @param {remoting.AppMode} mode The mode to shift the application into. 490 * @param {remoting.AppMode} mode The mode to shift the application into.
493 * @return {void} 491 * @return {void}
494 */ 492 */
495 remoting.setAppMode = function(mode) { 493 remoting.setAppMode = function(mode) {
(...skipping 15 matching lines...) Expand all
511 } 509 }
512 510
513 remoting.toggleScaleToFit = function() { 511 remoting.toggleScaleToFit = function() {
514 remoting.scaleToFit = !remoting.scaleToFit; 512 remoting.scaleToFit = !remoting.scaleToFit;
515 document.getElementById('scale-to-fit-toggle').value = 513 document.getElementById('scale-to-fit-toggle').value =
516 remoting.scaleToFit ? 'No scaling' : 'Scale to fit'; 514 remoting.scaleToFit ? 'No scaling' : 'Scale to fit';
517 remoting.session.toggleScaleToFit(remoting.scaleToFit); 515 remoting.session.toggleScaleToFit(remoting.scaleToFit);
518 } 516 }
519 517
520 }()); 518 }());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698