summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 23:54:42 +0000
committerjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 23:54:42 +0000
commitdbab5967fbb48ffff0555e0612b72343e3ad5652 (patch)
tree1741091c61422fb75776393aaa422c1a158e4702 /remoting
parent4f15afe4d244f7247101cbb76dfb252f647baf3b (diff)
downloadchromium_src-dbab5967fbb48ffff0555e0612b72343e3ad5652.zip
chromium_src-dbab5967fbb48ffff0555e0612b72343e3ad5652.tar.gz
chromium_src-dbab5967fbb48ffff0555e0612b72343e3ad5652.tar.bz2
Implement access code countdown timer (b/4987025).
BUG=None TEST=Start sharing; waiting 4:30; check timer appears; wait another 0:20; check access code turns red; wait another 0:10; check sharing is cancelled. Review URL: http://codereview.chromium.org/7445006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/webapp/me2mom/choice.css10
-rw-r--r--remoting/webapp/me2mom/choice.html6
-rw-r--r--remoting/webapp/me2mom/remoting.js81
3 files changed, 95 insertions, 2 deletions
diff --git a/remoting/webapp/me2mom/choice.css b/remoting/webapp/me2mom/choice.css
index eef223b..c7842c8 100644
--- a/remoting/webapp/me2mom/choice.css
+++ b/remoting/webapp/me2mom/choice.css
@@ -121,6 +121,10 @@ label {
*/
}
+.expiring {
+ color: #900 !important;
+}
+
[hidden] {
display: none !important;
}
@@ -156,9 +160,13 @@ label {
padding: 5px 10px;
}
+#access-code-countdown-container {
+ height: 50px;
+ text-align: center;
+}
+
#access-code-display {
margin-top: 50px;
- margin-bottom: 50px;
color: rgb(0, 0, 0);
font-weight: bold;
font-size: 26px;
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html
index 7a453d3..1866098 100644
--- a/remoting/webapp/me2mom/choice.html
+++ b/remoting/webapp/me2mom/choice.html
@@ -113,6 +113,12 @@ found in the LICENSE file.
</div>
<div id="access-code-display">
</div>
+ <div id="access-code-countdown-container">
+ <div id="access-code-countdown" class="expiring" hidden>
+ This access code will expire in
+ 0:<span id="seconds-remaining"></span>
+ </div>
+ </div>
<div class="description">
Once they enter the code your sharing session will begin.
</div>
diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js
index d4aa384..f5801e4 100644
--- a/remoting/webapp/me2mom/remoting.js
+++ b/remoting/webapp/me2mom/remoting.js
@@ -43,6 +43,20 @@ var kHostSecretLen = 5;
var kAccessCodeLen = kSupportIdLen + kHostSecretLen;
var kDigitsPerGroup = 4;
+function hasClass(element, cls) {
+ return element.className.match(new RegExp('\\b' + cls + '\\b'));
+}
+
+function addClass(element, cls) {
+ if (!hasClass(element, cls))
+ element.className = element.className + ' ' + cls;
+}
+
+function removeClass(element, cls) {
+ element.className =
+ element.className.replace(new RegExp('\\b' + cls + '\\b', 'g'), '');
+}
+
function retrieveEmail_(access_token) {
var headers = {
'Authorization': 'OAuth ' + remoting.oauth2.getAccessToken()
@@ -256,11 +270,61 @@ remoting.tryShare = function() {
'oauth2:' + remoting.oauth2.getAccessToken());
}
+function disableTimeoutCountdown_() {
+ if (remoting.timerRunning) {
+ clearInterval(remoting.accessCodeTimerId);
+ remoting.timerRunning = false;
+ updateTimeoutStyles_();
+ }
+}
+
+var ACCESS_CODE_TIMER_DISPLAY_THRESHOLD = 30;
+var ACCESS_CODE_RED_THRESHOLD = 10;
+
+/**
+ * Show/hide or restyle various elements, depending on the remaining countdown
+ * and timer state.
+ *
+ * @return {bool} True if the timeout is in progress, false if it has expired.
+ */
+function updateTimeoutStyles_() {
+ if (remoting.timerRunning) {
+ if (remoting.accessCodeExpiresIn <= 0) {
+ remoting.cancelShare();
+ return false;
+ }
+ if (remoting.accessCodeExpiresIn <= ACCESS_CODE_RED_THRESHOLD) {
+ addClass(document.getElementById('access-code-display'), 'expiring');
+ } else {
+ removeClass(document.getElementById('access-code-display'), 'expiring');
+ }
+ }
+ document.getElementById('access-code-countdown').hidden =
+ (remoting.accessCodeExpiresIn > ACCESS_CODE_TIMER_DISPLAY_THRESHOLD ) ||
+ !remoting.timerRunning;
+ return true;
+}
+
+remoting.decrementAccessCodeTimeout_ = function() {
+ --remoting.accessCodeExpiresIn;
+ remoting.updateAccessCodeTimeoutElement_();
+}
+
+remoting.updateAccessCodeTimeoutElement_ = function() {
+ var pad = (remoting.accessCodeExpiresIn < 10) ? '0' : '';
+ document.getElementById('seconds-remaining').innerText =
+ pad + remoting.accessCodeExpiresIn;
+ if (!updateTimeoutStyles_()) {
+ disableTimeoutCountdown_();
+ }
+}
+
function onStateChanged_() {
var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
var state = plugin.state;
if (state == plugin.REQUESTED_ACCESS_CODE) {
remoting.setHostMode('preparing-to-share');
+ disableTimeoutCountdown_();
} else if (state == plugin.RECEIVED_ACCESS_CODE) {
var accessCode = plugin.accessCode;
var accessCodeDisplay = document.getElementById('access-code-display');
@@ -272,7 +336,21 @@ function onStateChanged_() {
nextFourDigits.innerText = accessCode.substring(i, i + kDigitsPerGroup);
accessCodeDisplay.appendChild(nextFourDigits);
}
- remoting.setHostMode('ready-to-share');
+ // TODO(jamiewalch): Get the validity period from the cloud.
+ remoting.accessCodeExpiresIn = 300;
+ if (remoting.accessCodeExpiresIn > 0) { // Check it hasn't expired.
+ remoting.accessCodeTimerId = setInterval(
+ 'remoting.decrementAccessCodeTimeout_()', 1000);
+ remoting.timerRunning = true;
+ remoting.updateAccessCodeTimeoutElement_();
+ updateTimeoutStyles_();
+ remoting.setHostMode('ready-to-share');
+ } else {
+ // This can only happen if the access code takes more than 5m to get from
+ // the cloud to the web-app, so we don't care how clean this UX is.
+ remoting.debug.log('Access code already invalid on receipt!');
+ remoting.cancelShare();
+ }
} else if (state == plugin.CONNECTED) {
remoting.setHostMode('shared');
} else if (state == plugin.DISCONNECTED) {
@@ -303,6 +381,7 @@ remoting.cancelShare = function() {
remoting.debug.log('Canceling share...');
var plugin = document.getElementById(remoting.HOST_PLUGIN_ID);
plugin.disconnect();
+ disableTimeoutCountdown_();
}
/**