Skip to content

Commit

Permalink
[Chromoting] Add onConnectionFailed callback to app Delegate.
Browse files Browse the repository at this point in the history
As part of this, more CRD-specific files have been moved out of the
common JS file arrays (in the GPY file). A few new CRD-specific JS files
have been added as well.

BUG=

Review URL: https://codereview.chromium.org/795283002

Cr-Commit-Position: refs/heads/master@{#309292}
  • Loading branch information
garykac authored and Commit bot committed Dec 19, 2014
1 parent e6b8303 commit 846c7c7
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 360 deletions.
40 changes: 21 additions & 19 deletions remoting/remoting_webapp_files.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,27 @@
'webapp/crd/js/xhr.js',
],
# Host JavaScript files.
# Includes both it2me and me2me files.
'remoting_webapp_js_host_files': [
'webapp/crd/js/host.js',
'webapp/crd/js/host_settings.js',
],
# Files for controlling the local machine as a host.
# Includes both it2me and me2me files.
'remoting_webapp_js_host_control_files': [
'webapp/crd/js/host_controller.js',
'webapp/crd/js/host_daemon_facade.js',
'webapp/crd/js/it2me_host_facade.js',
'webapp/crd/js/host_screen.js',
'webapp/crd/js/host_session.js',
'webapp/crd/js/host_setup_dialog.js',
'webapp/crd/js/host_install_dialog.js',
'webapp/crd/js/host_installer.js',
'webapp/crd/js/it2me_host_facade.js',
'webapp/crd/js/paired_client_manager.js',
],
# Files for displaying (in the client) info about available hosts.
'remoting_webapp_js_host_display_files': [
'webapp/crd/js/host_list.js',
'webapp/crd/js/host_table_entry.js',
],
# Logging and stats JavaScript files.
'remoting_webapp_js_logging_files': [
Expand All @@ -100,21 +115,6 @@
'webapp/crd/js/toolbar.js',
'webapp/crd/js/window_frame.js',
],
# UI files for controlling the local machine as a host.
'remoting_webapp_js_ui_host_control_files': [
'webapp/crd/js/host_screen.js',
'webapp/crd/js/host_setup_dialog.js',
'webapp/crd/js/host_install_dialog.js',
'webapp/crd/js/host_installer.js',
'webapp/crd/js/paired_client_manager.js',
],
# UI files for displaying (in the client) info about available hosts.
'remoting_webapp_js_ui_host_display_files': [
'webapp/crd/js/host.js',
'webapp/crd/js/host_list.js',
'webapp/crd/js/host_settings.js',
'webapp/crd/js/host_table_entry.js',
],
# Remoting signaling files.
'remoting_webapp_js_signaling_files': [
'webapp/crd/js/signal_strategy.js',
Expand Down Expand Up @@ -188,10 +188,10 @@
'<@(remoting_webapp_js_gnubby_auth_files)',
'<@(remoting_webapp_js_cast_extension_files)',
'<@(remoting_webapp_js_host_files)',
'<@(remoting_webapp_js_host_control_files)',
'<@(remoting_webapp_js_host_display_files)',
'<@(remoting_webapp_js_logging_files)',
'<@(remoting_webapp_js_ui_files)',
'<@(remoting_webapp_js_ui_host_control_files)',
'<@(remoting_webapp_js_ui_host_display_files)',
'<@(remoting_webapp_js_signaling_files)',
# Uncomment this line to include browser test files in the web app
# to expedite debugging or local development.
Expand All @@ -200,6 +200,8 @@

# The CRD-specific JavaScript files required by main.html.
'remoting_webapp_crd_main_html_js_files': [
'webapp/crd/js/crd_connect.js',
'webapp/crd/js/crd_event_handlers.js',
'webapp/crd/js/crd_main.js',
'webapp/crd/js/desktop_remoting.js',
],
Expand Down
46 changes: 34 additions & 12 deletions remoting/webapp/base/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ remoting.Application.prototype.setDelegate = function(appDelegate) {
*
* @return {void} Nothing.
*/
remoting.Application.prototype.init = function() {
remoting.Application.prototype.start = function() {
this.delegate_.init();
};

Expand All @@ -65,7 +65,7 @@ remoting.Application.prototype.onConnected = function(clientSession) {
remoting.ClientSession.State.CONNECTED
);

this.delegate_.onConnected(clientSession);
this.delegate_.handleConnected(clientSession);
};

/**
Expand All @@ -74,7 +74,17 @@ remoting.Application.prototype.onConnected = function(clientSession) {
* @return {void} Nothing.
*/
remoting.Application.prototype.onDisconnected = function() {
this.delegate_.onDisconnected();
this.delegate_.handleDisconnected();
};

/**
* Called when the current session's connection has failed.
*
* @param {remoting.Error} error
* @return {void} Nothing.
*/
remoting.Application.prototype.onConnectionFailed = function(error) {
this.delegate_.handleConnectionFailed(this.session_connector_, error);
};

/**
Expand All @@ -84,7 +94,7 @@ remoting.Application.prototype.onDisconnected = function() {
* @return {void} Nothing.
*/
remoting.Application.prototype.onVideoStreamingStarted = function() {
this.delegate_.onVideoStreamingStarted();
this.delegate_.handleVideoStreamingStarted();
};

/**
Expand All @@ -96,7 +106,7 @@ remoting.Application.prototype.onVideoStreamingStarted = function() {
*/
remoting.Application.prototype.onExtensionMessage = function(type, data) {
// Give the delegate a chance to handle this extension message first.
if (this.delegate_.onExtensionMessage(type, data)) {
if (this.delegate_.handleExtensionMessage(type, data)) {
return true;
}

Expand All @@ -113,7 +123,7 @@ remoting.Application.prototype.onExtensionMessage = function(type, data) {
* @return {void} Nothing.
*/
remoting.Application.prototype.onError = function(errorTag) {
this.delegate_.onError(errorTag);
this.delegate_.handleError(errorTag);
};

/**
Expand All @@ -128,6 +138,7 @@ remoting.Application.prototype.getSessionConnector = function() {
this.onConnected.bind(this),
this.onError.bind(this),
this.onExtensionMessage.bind(this),
this.onConnectionFailed.bind(this),
this.delegate_.getRequiredCapabilities(),
this.delegate_.getDefaultRemapKeys());
}
Expand Down Expand Up @@ -165,23 +176,34 @@ remoting.Application.Delegate.prototype.getRequiredCapabilities = function() {};
* @param {remoting.ClientSession} clientSession
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.onConnected = function(clientSession) {
};
remoting.Application.Delegate.prototype.handleConnected = function(
clientSession) {};

/**
* Called when the current session has been disconnected.
*
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.onDisconnected = function() {};
remoting.Application.Delegate.prototype.handleDisconnected = function() {};

/**
* Called when the current session's connection has failed.
*
* @param {remoting.SessionConnector} connector
* @param {remoting.Error} error
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.handleConnectionFailed = function(
connector, error) {};

/**
* Called when the current session has reached the point where the host has
* started streaming video frames to the client.
*
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.onVideoStreamingStarted = function() {};
remoting.Application.Delegate.prototype.handleVideoStreamingStarted = function(
) {};

/**
* Called when an extension message needs to be handled.
Expand All @@ -190,7 +212,7 @@ remoting.Application.Delegate.prototype.onVideoStreamingStarted = function() {};
* @param {string} data The payload of the extension message.
* @return {boolean} Return true if the extension message was recognized.
*/
remoting.Application.Delegate.prototype.onExtensionMessage = function(
remoting.Application.Delegate.prototype.handleExtensionMessage = function(
type, data) {};

/**
Expand All @@ -199,7 +221,7 @@ remoting.Application.Delegate.prototype.onExtensionMessage = function(
* @param {remoting.Error} errorTag The error to be localized and displayed.
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.onError = function(errorTag) {};
remoting.Application.Delegate.prototype.handleError = function(errorTag) {};


/** @type {remoting.Application} */
Expand Down
150 changes: 0 additions & 150 deletions remoting/webapp/crd/js/client_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ var remoting = remoting || {};
*/
remoting.clientSession = null;

/**
* Initiate an IT2Me connection.
*/
remoting.connectIT2Me = function() {
var connector = remoting.app.getSessionConnector();
var accessCode = document.getElementById('access-code-entry').value;
remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
connector.connectIT2Me(accessCode);
};

/**
* Update the remoting client layout in response to a resize event.
*
Expand Down Expand Up @@ -129,143 +119,3 @@ function updateStatistics_() {
// Update the stats once per second.
window.setTimeout(updateStatistics_, 1000);
}

/**
* Entry-point for Me2Me connections, handling showing of the host-upgrade nag
* dialog if necessary.
*
* @param {string} hostId The unique id of the host.
* @return {void} Nothing.
*/
remoting.connectMe2Me = function(hostId) {
var host = remoting.hostList.getHostForId(hostId);
if (!host) {
remoting.app.onError(remoting.Error.HOST_IS_OFFLINE);
return;
}
var webappVersion = chrome.runtime.getManifest().version;
if (remoting.Host.needsUpdate(host, webappVersion)) {
var needsUpdateMessage =
document.getElementById('host-needs-update-message');
l10n.localizeElementFromTag(needsUpdateMessage,
/*i18n-content*/'HOST_NEEDS_UPDATE_TITLE',
host.hostName);
/** @type {Element} */
var connect = document.getElementById('host-needs-update-connect-button');
/** @type {Element} */
var cancel = document.getElementById('host-needs-update-cancel-button');
/** @param {Event} event */
var onClick = function(event) {
connect.removeEventListener('click', onClick, false);
cancel.removeEventListener('click', onClick, false);
if (event.target == connect) {
remoting.connectMe2MeHostVersionAcknowledged_(host);
} else {
remoting.setMode(remoting.AppMode.HOME);
}
}
connect.addEventListener('click', onClick, false);
cancel.addEventListener('click', onClick, false);
remoting.setMode(remoting.AppMode.CLIENT_HOST_NEEDS_UPGRADE);
} else {
remoting.connectMe2MeHostVersionAcknowledged_(host);
}
};

/**
* Shows PIN entry screen localized to include the host name, and registers
* a host-specific one-shot event handler for the form submission.
*
* @param {remoting.Host} host The Me2Me host to which to connect.
* @return {void} Nothing.
*/
remoting.connectMe2MeHostVersionAcknowledged_ = function(host) {
/** @type {remoting.SessionConnector} */
var connector = remoting.app.getSessionConnector();
remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);

/**
* @param {string} tokenUrl Token-issue URL received from the host.
* @param {string} scope OAuth scope to request the token for.
* @param {string} hostPublicKey Host public key (DER and Base64 encoded).
* @param {function(string, string):void} onThirdPartyTokenFetched Callback.
*/
var fetchThirdPartyToken = function(
tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) {
var thirdPartyTokenFetcher = new remoting.ThirdPartyTokenFetcher(
tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns,
onThirdPartyTokenFetched);
thirdPartyTokenFetcher.fetchToken();
};

/**
* @param {boolean} supportsPairing
* @param {function(string):void} onPinFetched
*/
var requestPin = function(supportsPairing, onPinFetched) {
/** @type {Element} */
var pinForm = document.getElementById('pin-form');
/** @type {Element} */
var pinCancel = document.getElementById('cancel-pin-entry-button');
/** @type {Element} */
var rememberPin = document.getElementById('remember-pin');
/** @type {Element} */
var rememberPinCheckbox = document.getElementById('remember-pin-checkbox');
/**
* Event handler for both the 'submit' and 'cancel' actions. Using
* a single handler for both greatly simplifies the task of making
* them one-shot. If separate handlers were used, each would have
* to unregister both itself and the other.
*
* @param {Event} event The click or submit event.
*/
var onSubmitOrCancel = function(event) {
pinForm.removeEventListener('submit', onSubmitOrCancel, false);
pinCancel.removeEventListener('click', onSubmitOrCancel, false);
var pinField = document.getElementById('pin-entry');
var pin = pinField.value;
pinField.value = '';
if (event.target == pinForm) {
event.preventDefault();

// Set the focus away from the password field. This has to be done
// before the password field gets hidden, to work around a Blink
// clipboard-handling bug - http://crbug.com/281523.
document.getElementById('pin-connect-button').focus();

remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
onPinFetched(pin);
if (/** @type {boolean} */(rememberPinCheckbox.checked)) {
/** @type {boolean} */
remoting.pairingRequested = true;
}
} else {
remoting.setMode(remoting.AppMode.HOME);
}
};
pinForm.addEventListener('submit', onSubmitOrCancel, false);
pinCancel.addEventListener('click', onSubmitOrCancel, false);
rememberPin.hidden = !supportsPairing;
rememberPinCheckbox.checked = false;
var message = document.getElementById('pin-message');
l10n.localizeElement(message, host.hostName);
remoting.setMode(remoting.AppMode.CLIENT_PIN_PROMPT);
};

/** @param {Object} settings */
var connectMe2MeHostSettingsRetrieved = function(settings) {
/** @type {string} */
var clientId = '';
/** @type {string} */
var sharedSecret = '';
var pairingInfo = /** @type {Object} */ (settings['pairingInfo']);
if (pairingInfo) {
clientId = /** @type {string} */ (pairingInfo['clientId']);
sharedSecret = /** @type {string} */ (pairingInfo['sharedSecret']);
}
connector.connectMe2Me(host, requestPin, fetchThirdPartyToken,
clientId, sharedSecret);
}

remoting.HostSettings.load(host.hostId, connectMe2MeHostSettingsRetrieved);
};
Loading

0 comments on commit 846c7c7

Please sign in to comment.