GUAC-589: Fix regression in clipboard support - do not handle Ctrl-V unless clipboard integration is actually enabled.

This commit is contained in:
Michael Jumper
2014-03-28 15:00:06 -07:00
parent e44ea62d83
commit 84b505dcb7
4 changed files with 74 additions and 28 deletions

View File

@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleServerException; import org.glyptodon.guacamole.GuacamoleServerException;
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.auth.UserContext;
import org.glyptodon.guacamole.properties.BooleanGuacamoleProperty; import org.glyptodon.guacamole.properties.BooleanGuacamoleProperty;
import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.glyptodon.guacamole.properties.GuacamoleProperties;
@@ -79,6 +80,10 @@ public class CaptureClipboard extends AuthenticatingHttpServlet {
} }
// Otherwise, inform not supported
else
throw new GuacamoleUnsupportedException("Clipboard integration not supported");
} }
} }

View File

@@ -645,8 +645,8 @@ GuacAdmin.UserEditor = function(name, parameters) {
GuacAdmin.reset(); GuacAdmin.reset();
} }
catch (e) { catch (status) {
alert(e.message); alert(status.message);
} }
}; };
@@ -684,8 +684,8 @@ GuacAdmin.UserEditor = function(name, parameters) {
} }
// Alert on failure // Alert on failure
catch (e) { catch (status) {
alert(e.message); alert(status.message);
} }
} }
@@ -983,8 +983,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
GuacAdmin.reset(); GuacAdmin.reset();
} }
catch (e) { catch (status) {
alert(e.message); alert(status.message);
} }
}; };
@@ -1022,8 +1022,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
} }
// Alert on failure // Alert on failure
catch (e) { catch (status) {
alert(e.message); alert(status.message);
} }
} }
@@ -1176,8 +1176,8 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) {
GuacAdmin.reset(); GuacAdmin.reset();
} }
catch (e) { catch (status) {
alert(e.message); alert(status.message);
} }
}; };
@@ -1215,8 +1215,8 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) {
} }
// Alert on failure // Alert on failure
catch (e) { catch (status) {
alert(e.message); alert(status.message);
} }
} }
@@ -1406,8 +1406,8 @@ GuacAdmin.reset = function() {
} }
// Alert on failure // Alert on failure
catch (e) { catch (status) {
alert(e.message); alert(tatusmessage);
} }
}; };

View File

@@ -254,7 +254,9 @@ GuacUI.Client = {
"connectionName" : "Guacamole", "connectionName" : "Guacamole",
"overrideAutoFit" : false, "overrideAutoFit" : false,
"attachedClient" : null "attachedClient" : null,
"clipboard_integration_enabled" : undefined,
}; };
@@ -1310,25 +1312,61 @@ GuacUI.Client.attach = function(guac) {
}; };
/**
* Returns the contents of the remote clipboard if clipboard integration is
* enabled, and null otherwise.
*/
function get_clipboard_data() {
// If integration not enabled, do not attempt retrieval
if (GuacUI.Client.clipboard_integration_enabled === false)
return null;
// Otherwise, attempt retrieval and update integration status
try {
var data = GuacamoleService.Clipboard.get();
GuacUI.Client.clipboard_integration_enabled = true;
return data;
}
catch (status) {
GuacUI.Client.clipboard_integration_enabled = false;
return null;
}
}
// Set local clipboard contents on cut // Set local clipboard contents on cut
document.body.addEventListener("cut", function handle_cut(e) { document.body.addEventListener("cut", function handle_cut(e) {
e.preventDefault(); var data = get_clipboard_data();
var data = GuacamoleService.Clipboard.get(); if (data !== null) {
e.clipboardData.setData("text/plain", data); e.preventDefault();
e.clipboardData.setData("text/plain", data);
}
}, false); }, false);
// Set local clipboard contents on copy // Set local clipboard contents on copy
document.body.addEventListener("copy", function handle_copy(e) { document.body.addEventListener("copy", function handle_copy(e) {
e.preventDefault(); var data = get_clipboard_data();
var data = GuacamoleService.Clipboard.get(); if (data !== null) {
e.clipboardData.setData("text/plain", data); e.preventDefault();
e.clipboardData.setData("text/plain", data);
}
}, false); }, false);
// Set remote clipboard contents on paste // Set remote clipboard contents on paste
document.body.addEventListener("paste", function handle_paste(e) { document.body.addEventListener("paste", function handle_paste(e) {
e.preventDefault();
if (GuacUI.Client.attachedClient) // If status of clipboard integration is unknown, attempt to define it
GuacUI.Client.attachedClient.setClipboard(e.clipboardData.getData("text/plain")); if (GuacUI.Client.clipboard_integration_enabled === undefined)
get_clipboard_data();
// Override and handle paste only if integration is enabled
if (GuacUI.Client.clipboard_integration_enabled) {
e.preventDefault();
if (GuacUI.Client.attachedClient)
GuacUI.Client.attachedClient.setClipboard(e.clipboardData.getData("text/plain"));
}
}, false); }, false);
/* /*

View File

@@ -325,19 +325,22 @@ GuacamoleService.PermissionSet = function() {
GuacamoleService.handleResponse = function(xhr) { GuacamoleService.handleResponse = function(xhr) {
// For HTTP Forbidden, just return permission denied // For HTTP Forbidden, just return permission denied
if (xhr.status == 403) if (xhr.status === 403)
throw new Error("Permission denied."); throw new Guacamole.Status(Guacamole.Status.Code.CLIENT_FORBIDDEN, "Permission denied.");
// Otherwise, if unsuccessful, throw error with message derived from // Otherwise, if unsuccessful, throw error with message derived from
// response // response
if (xhr.status != 200) { if (xhr.status !== 200) {
// Retrieve error code
var code = parseInt(xhr.getResponseHeader("Guacamole-Status-Code"));
// Retrieve error message // Retrieve error message
var message = xhr.getResponseHeader("Guacamole-Error-Message") var message = xhr.getResponseHeader("Guacamole-Error-Message")
|| xhr.statusText; || xhr.statusText;
// Throw error with derived message // Throw error with derived message
throw new Error(message); throw new Guacamole.Status(code, message);
} }