summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-22 01:11:46 +0000
committerjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-22 01:11:46 +0000
commit9abd5ec877f61b73af61a0239afa07c48e1def50 (patch)
tree04ff581477bd0a2e51e77323ee17da88cf1be9e2 /remoting
parent503282a4ed8df3a2523628ac3320a11180896fab (diff)
downloadchromium_src-9abd5ec877f61b73af61a0239afa07c48e1def50.zip
chromium_src-9abd5ec877f61b73af61a0239afa07c48e1def50.tar.gz
chromium_src-9abd5ec877f61b73af61a0239afa07c48e1def50.tar.bz2
Use new-style event listeners.
This will be necessary in order to use a v2 manifest, but also allows compile-time checks that aren't possible if event handlers are specified in the HTML. BUG=None TEST=Manual Review URL: http://codereview.chromium.org/8999003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115459 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/remoting.gyp1
-rw-r--r--remoting/webapp/me2mom/choice.html74
-rw-r--r--remoting/webapp/me2mom/client_screen.js26
-rw-r--r--remoting/webapp/me2mom/event_handlers.js62
-rw-r--r--remoting/webapp/me2mom/host_screen.js10
-rw-r--r--remoting/webapp/me2mom/host_table_entry.js12
-rw-r--r--remoting/webapp/me2mom/remoting.js19
7 files changed, 139 insertions, 65 deletions
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index fbc65b8..9f65fc2 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -115,6 +115,7 @@
'webapp/me2mom/debug_log.js',
'webapp/me2mom/dividerbottom.png',
'webapp/me2mom/dividertop.png',
+ 'webapp/me2mom/event_handlers.js',
'webapp/me2mom/host_list.js',
'webapp/me2mom/host_screen.js',
'webapp/me2mom/host_session.js',
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html
index 38ebf25..9ff1a5e 100644
--- a/remoting/webapp/me2mom/choice.html
+++ b/remoting/webapp/me2mom/choice.html
@@ -18,6 +18,7 @@ found in the LICENSE file.
<script src="client_screen.js"></script>
<script src="client_session.js"></script>
<script src="debug_log.js"></script>
+ <script src="event_handlers.js"></script>
<script src="host_list.js"></script>
<script src="host_screen.js"></script>
<script src="host_session.js"></script>
@@ -38,10 +39,7 @@ found in the LICENSE file.
<title i18n-content="PRODUCT_NAME"></title>
</head>
- <body onBeforeUnload="return remoting.promptClose();"
- onLoad="remoting.init();"
- onResize="remoting.onResize();"
- onUnload="remoting.disconnect();">
+ <body>
<!-- loading-mode is initially visible, but becomes hidden as soon as an
AppMode is selected by remoting.init. All other divs are initially
@@ -56,8 +54,7 @@ found in the LICENSE file.
<span id="email-status">
<span id="current-email"></span>
<span data-ui-mode="home client.unconnected client.connect-failed">
- (<a href="#" onclick="remoting.clearOAuth2();"
- i18n-content="SIGN_OUT_BUTTON"></a>)
+ (<a id="clear-oauth" href="#" i18n-content="SIGN_OUT_BUTTON"></a>)
</span>
</span>
</div>
@@ -74,11 +71,12 @@ found in the LICENSE file.
<div class="toolbar-border">
<span id="session-status-message" i18n-content="LABEL_CONNECTED"></span>
<strong id="connected-to"></strong>
- <button type="button" onclick="remoting.disconnect();"
- i18n-content="DISCONNECT_MYSELF_BUTTON"></button>
+ <button id="toolbar-disconnect"
+ type="button"
+ i18n-content="DISCONNECT_MYSELF_BUTTON">
+ </button>
<span class="end-align">
- <button id="toggle-scaling"
- onClick="remoting.toggleScaleToFit(this);">
+ <button id="toggle-scaling">
<img src="scale-to-fit.png">
</button>
</span>
@@ -106,9 +104,11 @@ found in the LICENSE file.
<div id="auth-panel" data-ui-mode="auth">
<div class="description" i18n-content="DESCRIPTION_AUTHORIZE"></div>
<div class="centered-button">
- <button id="auth-button" class="big-button"
- type="button" onclick="remoting.oauth2.doAuthRedirect();"
- i18n-content="CONTINUE_BUTTON"></button>
+ <button id="auth-button"
+ class="big-button"
+ type="button"
+ i18n-content="CONTINUE_BUTTON">
+ </button>
</div>
</div> <!-- auth-panel -->
@@ -128,9 +128,9 @@ found in the LICENSE file.
<td>
<button id="share-button"
i18n-content="HOME_SHARE_BUTTON"
- onclick="remoting.tryShare();"
class="mode-select-button"
- type="button"></button>
+ type="button">
+ </button>
</td>
</tr>
<tr class="mode-select-table-underline mode-select-table-spacer">
@@ -142,11 +142,11 @@ found in the LICENSE file.
<td i18n-content="HOME_ACCESS_DESCRIPTION"
class="mode-select-label"></td>
<td>
- <button i18n-content="HOME_ACCESS_BUTTON"
- onclick="remoting.setMode(
- remoting.AppMode.CLIENT_UNCONNECTED);"
+ <button id="access-mode-button"
+ i18n-content="HOME_ACCESS_BUTTON"
class="mode-select-button"
- type="button"></button>
+ type="button">
+ </button>
</td>
</tr>
</table>
@@ -186,8 +186,9 @@ found in the LICENSE file.
<div id="host-shared-message" class="message"
i18n-content="MESSAGE_SHARED"></div>
<div class="centered-button">
- <button type="button" class="big-button"
- onclick="remoting.cancelShare();"
+ <button id="cancel-share-button"
+ type="button"
+ class="big-button"
i18n-content="STOP_SHARING_BUTTON">
</button>
</div>
@@ -203,10 +204,10 @@ found in the LICENSE file.
<div class="centered-button"
data-ui-mode="host.share-failed host.share-finished">
- <button type="button"
+ <button id="host-finished-button"
+ type="button"
class="big-button"
autofocus="autofocus"
- onclick="remoting.setMode(remoting.AppMode.HOME);"
i18n-content="OK">
</button>
</div>
@@ -219,17 +220,21 @@ found in the LICENSE file.
<div data-ui-mode="client.unconnected">
<div class="description" i18n-content="DESCRIPTION_CONNECT"></div>
<div id="access-code-entry-row">
- <form action="" onsubmit="remoting.tryConnect(); return false;">
+ <form id="access-code-form" action="">
<label for="access-code-entry" i18n-content="ACCESS_CODE"></label>
<input id="access-code-entry"
type="text"
autofocus="autofocus"
autocomplete="off"/>
- <button id="connect-button" class="big-button"
- type="submit" i18n-content="CONNECT_BUTTON"></button>
- <button class="big-button" type="button"
- i18n-content="CANCEL"
- onclick="remoting.setMode(remoting.AppMode.HOME);">
+ <button id="connect-button"
+ class="big-button"
+ type="submit"
+ i18n-content="CONNECT_BUTTON">
+ </button>
+ <button id="client-cancel-button"
+ class="big-button"
+ type="button"
+ i18n-content="CANCEL">
</button>
</form>
</div> <!-- code-entry-row -->
@@ -250,12 +255,11 @@ found in the LICENSE file.
<div data-ui-mode="client.connect-failed.it2me client.session-finished.it2me"
class="centered-button">
- <button type="button"
+ <button id="client-finished-button"
+ type="button"
class="big-button"
i18n-content="OK"
- autofocus="autofocus"
- onclick="remoting.setMode(
- remoting.AppMode.CLIENT_UNCONNECTED);">
+ autofocus="autofocus">
</button>
</div> <!-- client.connect-failed client.session-finished -->
@@ -271,8 +275,8 @@ found in the LICENSE file.
data-ui-mode="host.waiting-for-connection host.waiting-for-code client.connecting">
<img src="spinner.gif">
<span class="waiting icon-label" i18n-content="FOOTER_WAITING"></span>
- <button id="cancel-button" class="big-button"
- onclick="remoting.cancelPendingOperation();"
+ <button id="cancel-button"
+ class="big-button"
i18n-content="CANCEL">
</button>
</div> <!-- waiting-footer -->
diff --git a/remoting/webapp/me2mom/client_screen.js b/remoting/webapp/me2mom/client_screen.js
index 52a131a..bc79e4f 100644
--- a/remoting/webapp/me2mom/client_screen.js
+++ b/remoting/webapp/me2mom/client_screen.js
@@ -12,8 +12,6 @@
/** @suppress {duplicate} */
var remoting = remoting || {};
-(function() {
-
/**
* @type {boolean} Whether or not the plugin should scale itself.
*/
@@ -49,6 +47,7 @@ remoting.hostPublicKey = '';
/**
* @type {XMLHttpRequest} The XHR object corresponding to the current
* support-hosts request, if there is one outstanding.
+ * @private
*/
remoting.supportHostsXhr_ = null;
@@ -85,7 +84,7 @@ remoting.tryConnect = function() {
} else {
tryConnectWithAccessToken_();
}
-}
+};
/**
* Cancel an incomplete connect operation.
@@ -102,16 +101,17 @@ remoting.cancelConnect = function() {
remoting.clientSession = null;
}
remoting.setMode(remoting.AppMode.HOME);
-}
+};
/**
* Enable or disable scale-to-fit.
*
- * @param {Element} button The scale-to-fit button. The style of this button is
- * updated to reflect the new scaling state.
+ * @param {Event} event The click event. The style of the target is updated to
+ * reflect the new scaling state.
* @return {void} Nothing.
*/
-remoting.toggleScaleToFit = function(button) {
+remoting.toggleScaleToFit = function(event) {
+ var button = /** @type Element */(event.target);
remoting.scaleToFit = !remoting.scaleToFit;
if (remoting.scaleToFit) {
addClass(button, 'toggle-button-active');
@@ -119,7 +119,7 @@ remoting.toggleScaleToFit = function(button) {
removeClass(button, 'toggle-button-active');
}
remoting.clientSession.updateDimensions();
-}
+};
/**
* Update the remoting client layout in response to a resize event.
@@ -129,7 +129,7 @@ remoting.toggleScaleToFit = function(button) {
remoting.onResize = function() {
if (remoting.clientSession)
remoting.clientSession.onResize();
-}
+};
/**
* Disconnect the remoting client.
@@ -147,7 +147,7 @@ remoting.disconnect = function() {
remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME);
}
}
-}
+};
/**
* Second stage of the 'connect' functionality. Once an access token is
@@ -462,7 +462,7 @@ remoting.connectHost = function(hostId, retryIfOffline) {
remoting.oauth2.callWithToken(setToken);
};
remoting.wcsLoader.startAsync(callWithToken, remoting.connectHostWithWcs);
-}
+};
/**
* Continue making the connection to a host, once WCS has initialized.
@@ -483,6 +483,4 @@ remoting.connectHostWithWcs = function() {
};
remoting.oauth2.callWithToken(createPluginAndConnect);
-}
-
-}());
+};
diff --git a/remoting/webapp/me2mom/event_handlers.js b/remoting/webapp/me2mom/event_handlers.js
new file mode 100644
index 0000000..0d28a98a
--- /dev/null
+++ b/remoting/webapp/me2mom/event_handlers.js
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+function onLoad() {
+ var goHome = function() {
+ remoting.setMode(remoting.AppMode.HOME);
+ };
+ var goClient = function() {
+ remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED);
+ };
+ var sendAccessCode = function() {
+ remoting.tryConnect();
+ return false;
+ };
+ var doAuthRedirect = function() {
+ remoting.oauth2.doAuthRedirect();
+ }
+ /** @type {Array.<{event: string, id: string, fn: function(Event):void}>} */
+ var actions = [
+ { event: 'click', id: 'clear-oauth', fn: remoting.clearOAuth2 },
+ { event: 'click', id: 'toolbar-disconnect', fn: remoting.disconnect },
+ { event: 'click', id: 'toggle-scaling', fn: remoting.toggleScaleToFit },
+ { event: 'click', id: 'auth-button', fn: doAuthRedirect },
+ { event: 'click', id: 'share-button', fn: remoting.tryShare },
+ { event: 'click', id: 'access-mode-button', fn: goClient },
+ { event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare },
+ { event: 'click', id: 'host-finished-button', fn: goHome },
+ { event: 'click', id: 'client-cancel-button', fn: goHome },
+ { event: 'click', id: 'client-finished-button', fn: goClient },
+ { event: 'click', id: 'cancel-button',
+ fn: remoting.cancelPendingOperation },
+ { event: 'submit', id: 'access-code-form', fn: sendAccessCode }
+ ];
+
+ for (var i = 0; i < actions.length; ++i) {
+ var action = actions[i];
+ var element = document.getElementById(action.id);
+ if (element) {
+ element.addEventListener(action.event, action.fn, false);
+ } else {
+ console.error('Could not set ' + action.id +
+ ' event handler on element ' + action.event +
+ ': element not found.');
+ }
+ }
+ remoting.init();
+}
+
+function onBeforeUnload() {
+ return remoting.promptClose();
+}
+
+window.addEventListener('load', onLoad, false);
+window.addEventListener('beforeunload', onBeforeUnload, false);
+window.addEventListener('resize', remoting.onResize, false);
+window.addEventListener('unload', remoting.disconnect, false);
diff --git a/remoting/webapp/me2mom/host_screen.js b/remoting/webapp/me2mom/host_screen.js
index 2b00cea..2af3b84 100644
--- a/remoting/webapp/me2mom/host_screen.js
+++ b/remoting/webapp/me2mom/host_screen.js
@@ -12,12 +12,11 @@
/** @suppress {duplicate} */
var remoting = remoting || {};
-(function() {
-
/**
* @type {boolean} Whether or not the last share was cancelled by the user.
* This controls what screen is shown when the host plugin signals
* completion.
+ * @private
*/
var lastShareWasCancelled_ = false;
@@ -179,22 +178,26 @@ remoting.cancelShare = function() {
/**
* @type {boolean} Whether or not the access code timeout countdown is running.
+ * @private
*/
var timerRunning_ = false;
/**
* @type {number} The id of the access code expiry countdown timer.
+ * @private
*/
var accessCodeTimerId_ = 0;
/**
* @type {number} The number of seconds until the access code expires.
+ * @private
*/
var accessCodeExpiresIn_ = 0;
/**
* The timer callback function, which needs to be visible from the global
* namespace.
+ * @private
*/
remoting.decrementAccessCodeTimeout_ = function() {
--accessCodeExpiresIn_;
@@ -214,6 +217,7 @@ function disableTimeoutCountdown_() {
/**
* Constants controlling the access code timer countdown display.
+ * @private
*/
var ACCESS_CODE_TIMER_DISPLAY_THRESHOLD_ = 30;
var ACCESS_CODE_RED_THRESHOLD_ = 10;
@@ -265,5 +269,3 @@ function onNatTraversalPolicyChanged_(enabled) {
var container = document.getElementById('nat-box-container');
container.hidden = enabled;
}
-
-}());
diff --git a/remoting/webapp/me2mom/host_table_entry.js b/remoting/webapp/me2mom/host_table_entry.js
index 62a4613..86e9409 100644
--- a/remoting/webapp/me2mom/host_table_entry.js
+++ b/remoting/webapp/me2mom/host_table_entry.js
@@ -44,6 +44,8 @@ remoting.HostTableEntry = function() {
this.hostNameCell_ = null;
/** @type {function(remoting.HostTableEntry):void} @private */
this.onRename_ = function(hostId) {};
+ /** @type {function():void} @private */
+ this.onBlurReference_ = function() {};
};
/**
@@ -139,11 +141,13 @@ remoting.HostTableEntry.prototype.beginRename_ = function() {
/** @type {remoting.HostTableEntry} */
var that = this;
- editBox.onblur = function() { that.commitRename_(); };
+ // Keep a reference to the blur event handler so that we can remove it later.
+ this.onBlurReference_ = function() { that.commitRename_(); };
+ editBox.addEventListener('blur', this.onBlurReference_, false);
/** @param {Event} event The keydown event. */
var onKeydown = function(event) { that.onKeydown_(event); }
- editBox.onkeydown = onKeydown;
+ editBox.addEventListener('keydown', onKeydown, false);
};
/**
@@ -171,9 +175,9 @@ remoting.HostTableEntry.prototype.removeEditBox_ = function() {
var editBox = this.hostNameCell_.querySelector('input');
if (editBox) {
// onblur will fire when the edit box is removed, so remove the hook.
- editBox.onblur = null;
+ editBox.removeEventListener('blur', this.onBlurReference_, false);
}
- this.hostNameCell_.innerHTML = '';
+ this.hostNameCell_.innerHTML = ''; // Remove the edit box.
this.hostNameCell_.appendChild(document.createTextNode(this.host.hostName));
};
diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js
index 18bcedb..b06686f 100644
--- a/remoting/webapp/me2mom/remoting.js
+++ b/remoting/webapp/me2mom/remoting.js
@@ -25,8 +25,6 @@ remoting.Error = {
SERVICE_UNAVAILABLE: /*i18n-content*/'ERROR_SERVICE_UNAVAILABLE'
};
-(function() {
-
/**
* Entry point for app initialization.
*/
@@ -72,8 +70,11 @@ remoting.init = function() {
var button = document.getElementById('share-button');
button.disabled = true;
}
-}
+};
+/**
+ * If there is an incomplete share or connection in progress, cancel it.
+ */
remoting.cancelPendingOperation = function() {
document.getElementById('cancel-button').disabled = true;
switch (remoting.getMajorMode()) {
@@ -84,7 +85,7 @@ remoting.cancelPendingOperation = function() {
remoting.cancelConnect();
break;
}
-}
+};
/**
* If the client is connected, or the host is shared, prompt before closing.
@@ -103,7 +104,7 @@ remoting.promptClose = function() {
default:
return null;
}
-}
+};
/**
* Sign the user out of Chromoting by clearing the OAuth refresh token.
@@ -112,7 +113,7 @@ remoting.clearOAuth2 = function() {
remoting.oauth2.clear();
window.localStorage.removeItem(KEY_EMAIL_);
remoting.setMode(remoting.AppMode.UNAUTHENTICATED);
-}
+};
/**
* Callback function called when the browser window loses focus. In this case,
@@ -133,7 +134,10 @@ function refreshEmail_() {
}
}
-/** The key under which the email address is stored. */
+/**
+ * The key under which the email address is stored.
+ * @private
+ */
var KEY_EMAIL_ = 'remoting-email';
/**
@@ -180,4 +184,3 @@ function isHostModeSupported_() {
// Currently, sharing on Chromebooks is not supported.
return !navigator.userAgent.match(/\bCrOS\b/);
}
-}());