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

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: remove blank line 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 plugin.setAttribute('id', remoting.HOST_PLUGIN_ID); 269 plugin.setAttribute('id', remoting.HOST_PLUGIN_ID);
270 div.appendChild(plugin); 270 div.appendChild(plugin);
271 plugin.onStateChanged = onStateChanged_; 271 plugin.onStateChanged = onStateChanged_;
272 plugin.logDebugInfo = debugInfoCallback_; 272 plugin.logDebugInfo = debugInfoCallback_;
273 plugin.connect(getEmail(), 273 plugin.connect(getEmail(),
274 'oauth2:' + remoting.oauth2.getAccessToken()); 274 'oauth2:' + remoting.oauth2.getAccessToken());
275 } 275 }
276 remoting.tryShare = tryShare;
277 276
278 function onStateChanged_() { 277 function onStateChanged_() {
279 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID); 278 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
280 var state = plugin.state; 279 var state = plugin.state;
281 if (state == plugin.REQUESTED_ACCESS_CODE) { 280 if (state == plugin.REQUESTED_ACCESS_CODE) {
282 setHostMode('preparing-to-share'); 281 remoting.setHostMode('preparing-to-share');
283 } else if (state == plugin.RECEIVED_ACCESS_CODE) { 282 } else if (state == plugin.RECEIVED_ACCESS_CODE) {
284 var accessCode = plugin.accessCode; 283 var accessCode = plugin.accessCode;
285 var accessCodeDisplay = document.getElementById('access-code-display'); 284 var accessCodeDisplay = document.getElementById('access-code-display');
286 accessCodeDisplay.innerText = ''; 285 accessCodeDisplay.innerText = '';
287 // Display the access code in groups of four digits for readability. 286 // Display the access code in groups of four digits for readability.
288 for (var i = 0; i < accessCode.length; i += kDigitsPerGroup) { 287 for (var i = 0; i < accessCode.length; i += kDigitsPerGroup) {
289 var nextFourDigits = document.createElement('span'); 288 var nextFourDigits = document.createElement('span');
290 nextFourDigits.className = 'access-code-digit-group'; 289 nextFourDigits.className = 'access-code-digit-group';
291 nextFourDigits.innerText = accessCode.substring(i, i + kDigitsPerGroup); 290 nextFourDigits.innerText = accessCode.substring(i, i + kDigitsPerGroup);
292 accessCodeDisplay.appendChild(nextFourDigits); 291 accessCodeDisplay.appendChild(nextFourDigits);
293 } 292 }
294 setHostMode('ready-to-share'); 293 remoting.setHostMode('ready-to-share');
295 } else if (state == plugin.CONNECTED) { 294 } else if (state == plugin.CONNECTED) {
296 setHostMode('shared'); 295 remoting.setHostMode('shared');
297 } else if (state == plugin.DISCONNECTED) { 296 } else if (state == plugin.DISCONNECTED) {
298 setGlobalMode(remoting.AppMode.HOST); 297 setGlobalMode(remoting.AppMode.HOST);
299 setHostMode('unshared'); 298 remoting.setHostMode('unshared');
300 plugin.parentNode.removeChild(plugin); 299 plugin.parentNode.removeChild(plugin);
301 } else { 300 } else {
302 remoting.debug.log('Unknown state -> ' + state); 301 remoting.debug.log('Unknown state -> ' + state);
303 } 302 }
304 } 303 }
305 304
306 /** 305 /**
307 * This is that callback that the host plugin invokes to indicate that there 306 * This is that callback that the host plugin invokes to indicate that there
308 * is additional debug log info to display. 307 * is additional debug log info to display.
309 */ 308 */
310 function debugInfoCallback_(msg) { 309 function debugInfoCallback_(msg) {
311 remoting.debug.log('plugin: ' + msg); 310 remoting.debug.log('plugin: ' + msg);
312 } 311 }
313 312
314 function showShareError_(errorCode) { 313 function showShareError_(errorCode) {
315 var errorDiv = document.getElementById(errorCode); 314 var errorDiv = document.getElementById(errorCode);
316 errorDiv.style.display = 'block'; 315 errorDiv.style.display = 'block';
317 remoting.debug.log("Sharing error: " + errorCode); 316 remoting.debug.log("Sharing error: " + errorCode);
318 setHostMode('share-failed'); 317 remoting.setHostMode('share-failed');
319 } 318 }
320 319
321 function cancelShare() { 320 remoting.cancelShare = function() {
322 remoting.debug.log('Canceling share...'); 321 remoting.debug.log('Canceling share...');
323 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID); 322 var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
324 plugin.disconnect(); 323 plugin.disconnect();
325 } 324 }
326 remoting.cancelShare = cancelShare;
327 325
328 /** 326 /**
329 * Show a client message that stays on the screeen until the state changes. 327 * Show a client message that stays on the screeen until the state changes.
330 * 328 *
331 * @param {string} message The message to display. 329 * @param {string} message The message to display.
332 */ 330 */
333 function setClientStateMessage(message) { 331 function setClientStateMessage(message) {
334 var msg = document.getElementById('session-status-message'); 332 var msg = document.getElementById('session-status-message');
335 msg.innerText = message; 333 msg.innerText = message;
336 } 334 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (responseCode == 404) { 410 if (responseCode == 404) {
413 invalid.style.display = 'block'; 411 invalid.style.display = 'block';
414 other.style.display = 'none'; 412 other.style.display = 'none';
415 } else { 413 } else {
416 invalid.style.display = 'none'; 414 invalid.style.display = 'none';
417 other.style.display = 'block'; 415 other.style.display = 'block';
418 var responseNode = document.getElementById('server-response'); 416 var responseNode = document.getElementById('server-response');
419 responseNode.innerText = responseString + ' (' + responseCode + ')'; 417 responseNode.innerText = responseString + ' (' + responseCode + ')';
420 } 418 }
421 remoting.accessCode = ''; 419 remoting.accessCode = '';
422 setClientMode('connect-failed'); 420 remoting.setClientMode('connect-failed');
423 } 421 }
424 422
425 function parseServerResponse_(xhr) { 423 function parseServerResponse_(xhr) {
426 if (xhr.status == 200) { 424 if (xhr.status == 200) {
427 var host = JSON.parse(xhr.responseText); 425 var host = JSON.parse(xhr.responseText);
428 if (host.data && host.data.jabberId) { 426 if (host.data && host.data.jabberId) {
429 remoting.hostJid = host.data.jabberId; 427 remoting.hostJid = host.data.jabberId;
430 remoting.hostPublicKey = host.data.publicKey; 428 remoting.hostPublicKey = host.data.publicKey;
431 startSession_(); 429 startSession_();
432 return; 430 return;
(...skipping 14 matching lines...) Expand all
447 }; 445 };
448 446
449 remoting.xhr.get( 447 remoting.xhr.get(
450 'https://www.googleapis.com/chromoting/v1/support-hosts/' + 448 'https://www.googleapis.com/chromoting/v1/support-hosts/' +
451 encodeURIComponent(supportId), 449 encodeURIComponent(supportId),
452 parseServerResponse_, 450 parseServerResponse_,
453 '', 451 '',
454 headers); 452 headers);
455 } 453 }
456 454
457 function tryConnect() { 455 remoting.tryConnect = function() {
458 if (remoting.oauth2.needsNewAccessToken()) { 456 if (remoting.oauth2.needsNewAccessToken()) {
459 remoting.oauth2.refreshAccessToken(function() { 457 remoting.oauth2.refreshAccessToken(function() {
460 if (remoting.oauth2.needsNewAccessToken()) { 458 if (remoting.oauth2.needsNewAccessToken()) {
461 // If we still need it, we're going to infinite loop. 459 // If we still need it, we're going to infinite loop.
462 throw 'Unable to get access token.'; 460 throw 'Unable to get access token.';
463 } 461 }
464 tryConnect(); 462 remoting.tryConnect();
465 }); 463 });
466 return; 464 return;
467 } 465 }
468 var accessCode = document.getElementById('access-code-entry').value; 466 var accessCode = document.getElementById('access-code-entry').value;
469 remoting.accessCode = normalizeAccessCode_(accessCode); 467 remoting.accessCode = normalizeAccessCode_(accessCode);
470 // At present, only 12-digit access codes are supported, of which the first 468 // At present, only 12-digit access codes are supported, of which the first
471 // 7 characters are the supportId. 469 // 7 characters are the supportId.
472 if (remoting.accessCode.length != kAccessCodeLen) { 470 if (remoting.accessCode.length != kAccessCodeLen) {
473 showConnectError_(404); 471 showConnectError_(404);
474 } else { 472 } else {
475 var supportId = remoting.accessCode.substring(0, kSupportIdLen); 473 var supportId = remoting.accessCode.substring(0, kSupportIdLen);
476 setClientMode('connecting'); 474 remoting.setClientMode('connecting');
477 resolveSupportId(supportId); 475 resolveSupportId(supportId);
478 } 476 }
479 } 477 }
480 remoting.tryConnect = tryConnect;
481 478
482 function cancelPendingOperation() { 479 remoting.cancelPendingOperation = function() {
483 document.getElementById('cancel-button').disabled = true; 480 document.getElementById('cancel-button').disabled = true;
484 if (remoting.currentMode == remoting.AppMode.HOST) { 481 if (remoting.currentMode == remoting.AppMode.HOST) {
485 cancelShare(); 482 remoting.cancelShare();
486 } 483 }
487 } 484 }
488 485
489 /** 486 /**
490 * Changes the major-mode of the application (Eg., client or host). 487 * Changes the major-mode of the application (Eg., client or host).
491 * 488 *
492 * @param {remoting.AppMode} mode The mode to shift the application into. 489 * @param {remoting.AppMode} mode The mode to shift the application into.
493 * @return {void} 490 * @return {void}
494 */ 491 */
495 remoting.setAppMode = function(mode) { 492 remoting.setAppMode = function(mode) {
(...skipping 15 matching lines...) Expand all
511 } 508 }
512 509
513 remoting.toggleScaleToFit = function() { 510 remoting.toggleScaleToFit = function() {
514 remoting.scaleToFit = !remoting.scaleToFit; 511 remoting.scaleToFit = !remoting.scaleToFit;
515 document.getElementById('scale-to-fit-toggle').value = 512 document.getElementById('scale-to-fit-toggle').value =
516 remoting.scaleToFit ? 'No scaling' : 'Scale to fit'; 513 remoting.scaleToFit ? 'No scaling' : 'Scale to fit';
517 remoting.session.toggleScaleToFit(remoting.scaleToFit); 514 remoting.session.toggleScaleToFit(remoting.scaleToFit);
518 } 515 }
519 516
520 }()); 517 }());
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