Commit 14edde99 authored by jamiewalch@google.com's avatar jamiewalch@google.com

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
parent d2ebb571
...@@ -11,6 +11,14 @@ ...@@ -11,6 +11,14 @@
"message": "Cancel", "message": "Cancel",
"description": "Label for general-purpose Cancel buttons" "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": { "connectButton": {
"message": "Connect", "message": "Connect",
"description": "Label for the connect button" "description": "Label for the connect button"
......
...@@ -25,7 +25,8 @@ found in the LICENSE file. ...@@ -25,7 +25,8 @@ found in the LICENSE file.
<title i18n-content="pageTitle"></title> <title i18n-content="pageTitle"></title>
</head> </head>
<body onLoad="remoting.init();" <body onBeforeUnload="return remoting.promptClose();"
onLoad="remoting.init();"
onUnload="remoting.disconnect();"> onUnload="remoting.disconnect();">
<!-- loading-mode is initially visible, but becomes hidden as soon as an <!-- loading-mode is initially visible, but becomes hidden as soon as an
......
...@@ -189,7 +189,15 @@ remoting.setMode = function(mode) { ...@@ -189,7 +189,15 @@ remoting.setMode = function(mode) {
element.hidden = hidden; element.hidden = hidden;
} }
remoting.debug.log('App mode: ' + mode); 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() { remoting.tryShare = function() {
...@@ -520,7 +528,7 @@ remoting.tryConnect = function() { ...@@ -520,7 +528,7 @@ remoting.tryConnect = function() {
remoting.cancelPendingOperation = function() { remoting.cancelPendingOperation = function() {
document.getElementById('cancel-button').disabled = true; document.getElementById('cancel-button').disabled = true;
if (remoting.currentMode == remoting.AppMode.HOST) { if (remoting.getMajorMode() == remoting.AppMode.HOST) {
remoting.cancelShare(); remoting.cancelShare();
} }
} }
...@@ -590,4 +598,23 @@ remoting.disconnect = function() { ...@@ -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;
}
}
}()); }());
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment