summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-06 00:29:32 +0000
committerjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-06 00:29:32 +0000
commit14edde9955b8b212760702ff7c22da232373942f (patch)
tree9304456682bfad3d17e4a8172b1cb844fec1e533
parentd2ebb571c3283cf58c13c0620080b6c68c0dc484 (diff)
downloadchromium_src-14edde9955b8b212760702ff7c22da232373942f.zip
chromium_src-14edde9955b8b212760702ff7c22da232373942f.tar.gz
chromium_src-14edde9955b8b212760702ff7c22da232373942f.tar.bz2
Add beforeUnload handler to confirm exit.
BUG=91835 TEST=Close the window at various points and check that you are prompted (or not) according to whether or not there is a connection pending or in progress. Review URL: http://codereview.chromium.org/7583018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95696 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/webapp/me2mom/_locales/en/messages.json8
-rw-r--r--remoting/webapp/me2mom/choice.html3
-rw-r--r--remoting/webapp/me2mom/remoting.js31
3 files changed, 39 insertions, 3 deletions
diff --git a/remoting/webapp/me2mom/_locales/en/messages.json b/remoting/webapp/me2mom/_locales/en/messages.json
index a0d51dc..c8001f7 100644
--- a/remoting/webapp/me2mom/_locales/en/messages.json
+++ b/remoting/webapp/me2mom/_locales/en/messages.json
@@ -11,6 +11,14 @@
"message": "Cancel",
"description": "Label for general-purpose Cancel buttons"
},
+ "closePromptClient": {
+ "message": "Navigating away from this page will end your Chromoting session.",
+ "description": "Message shown when the client tab is closed while a connection is active."
+ },
+ "closePromptHost": {
+ "message": "Navigating away from this page will disconnect the Chromoting viewer.",
+ "description": "Message shown when the host tab is closed while a connection is active."
+ },
"connectButton": {
"message": "Connect",
"description": "Label for the connect button"
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html
index c71f800..1b0cdef 100644
--- a/remoting/webapp/me2mom/choice.html
+++ b/remoting/webapp/me2mom/choice.html
@@ -25,7 +25,8 @@ found in the LICENSE file.
<title i18n-content="pageTitle"></title>
</head>
- <body onLoad="remoting.init();"
+ <body onBeforeUnload="return remoting.promptClose();"
+ onLoad="remoting.init();"
onUnload="remoting.disconnect();">
<!-- loading-mode is initially visible, but becomes hidden as soon as an
diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js
index 8947e59..aedac36 100644
--- a/remoting/webapp/me2mom/remoting.js
+++ b/remoting/webapp/me2mom/remoting.js
@@ -189,7 +189,15 @@ remoting.setMode = function(mode) {
element.hidden = hidden;
}
remoting.debug.log('App mode: ' + mode);
- remoting.currentMode = modes[0];
+ remoting.currentMode = mode;
+}
+
+/**
+ * Get the major mode that the app is running in.
+ * @return {remoting.Mode} The app's current major mode.
+ */
+remoting.getMajorMode = function(mode) {
+ return remoting.currentMode.split('.')[0];
}
remoting.tryShare = function() {
@@ -520,7 +528,7 @@ remoting.tryConnect = function() {
remoting.cancelPendingOperation = function() {
document.getElementById('cancel-button').disabled = true;
- if (remoting.currentMode == remoting.AppMode.HOST) {
+ if (remoting.getMajorMode() == remoting.AppMode.HOST) {
remoting.cancelShare();
}
}
@@ -590,4 +598,23 @@ remoting.disconnect = function() {
}
}
+/** If the client is connected, or the host is shared, prompt before closing.
+ *
+ * @return {(string|void)} The prompt string if a connection is active.
+ */
+remoting.promptClose = function() {
+ var messageId = null;
+ if (remoting.getMajorMode() == remoting.AppMode.HOST &&
+ remoting.currentMode != remoting.AppMode.HOST_UNSHARED) {
+ messageId = 'closePromptHost';
+ } else if (remoting.getMajorMode() == remoting.AppMode.IN_SESSION ||
+ remoting.currentMode == remoting.AppMode.CLIENT_CONNECTING) {
+ messageId = 'closePromptClient';
+ }
+ if (messageId) {
+ var result = chrome.i18n.getMessage(messageId);
+ return result;
+ }
+}
+
}());