diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/CaptureClipboard.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/CaptureClipboard.java index 4b16a0240..f28309808 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/CaptureClipboard.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/CaptureClipboard.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleServerException; +import org.glyptodon.guacamole.GuacamoleUnsupportedException; import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.properties.BooleanGuacamoleProperty; 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"); + } } diff --git a/guacamole/src/main/webapp/scripts/admin-ui.js b/guacamole/src/main/webapp/scripts/admin-ui.js index e21150b31..50bdc19b5 100644 --- a/guacamole/src/main/webapp/scripts/admin-ui.js +++ b/guacamole/src/main/webapp/scripts/admin-ui.js @@ -645,8 +645,8 @@ GuacAdmin.UserEditor = function(name, parameters) { GuacAdmin.reset(); } - catch (e) { - alert(e.message); + catch (status) { + alert(status.message); } }; @@ -684,8 +684,8 @@ GuacAdmin.UserEditor = function(name, parameters) { } // Alert on failure - catch (e) { - alert(e.message); + catch (status) { + alert(status.message); } } @@ -983,8 +983,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) { GuacAdmin.reset(); } - catch (e) { - alert(e.message); + catch (status) { + alert(status.message); } }; @@ -1022,8 +1022,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) { } // Alert on failure - catch (e) { - alert(e.message); + catch (status) { + alert(status.message); } } @@ -1176,8 +1176,8 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) { GuacAdmin.reset(); } - catch (e) { - alert(e.message); + catch (status) { + alert(status.message); } }; @@ -1215,8 +1215,8 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) { } // Alert on failure - catch (e) { - alert(e.message); + catch (status) { + alert(status.message); } } @@ -1406,8 +1406,8 @@ GuacAdmin.reset = function() { } // Alert on failure - catch (e) { - alert(e.message); + catch (status) { + alert(tatusmessage); } }; diff --git a/guacamole/src/main/webapp/scripts/client-ui.js b/guacamole/src/main/webapp/scripts/client-ui.js index 1b29362e0..8f41a567b 100644 --- a/guacamole/src/main/webapp/scripts/client-ui.js +++ b/guacamole/src/main/webapp/scripts/client-ui.js @@ -254,7 +254,9 @@ GuacUI.Client = { "connectionName" : "Guacamole", "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 document.body.addEventListener("cut", function handle_cut(e) { - e.preventDefault(); - var data = GuacamoleService.Clipboard.get(); - e.clipboardData.setData("text/plain", data); + var data = get_clipboard_data(); + if (data !== null) { + e.preventDefault(); + e.clipboardData.setData("text/plain", data); + } }, false); // Set local clipboard contents on copy document.body.addEventListener("copy", function handle_copy(e) { - e.preventDefault(); - var data = GuacamoleService.Clipboard.get(); - e.clipboardData.setData("text/plain", data); + var data = get_clipboard_data(); + if (data !== null) { + e.preventDefault(); + e.clipboardData.setData("text/plain", data); + } }, false); // Set remote clipboard contents on paste document.body.addEventListener("paste", function handle_paste(e) { - e.preventDefault(); - if (GuacUI.Client.attachedClient) - GuacUI.Client.attachedClient.setClipboard(e.clipboardData.getData("text/plain")); + + // If status of clipboard integration is unknown, attempt to define it + 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); /* diff --git a/guacamole/src/main/webapp/scripts/service.js b/guacamole/src/main/webapp/scripts/service.js index 9a2efc833..d9f09c126 100644 --- a/guacamole/src/main/webapp/scripts/service.js +++ b/guacamole/src/main/webapp/scripts/service.js @@ -325,19 +325,22 @@ GuacamoleService.PermissionSet = function() { GuacamoleService.handleResponse = function(xhr) { // For HTTP Forbidden, just return permission denied - if (xhr.status == 403) - throw new Error("Permission denied."); + if (xhr.status === 403) + throw new Guacamole.Status(Guacamole.Status.Code.CLIENT_FORBIDDEN, "Permission denied."); // Otherwise, if unsuccessful, throw error with message derived from // response - if (xhr.status != 200) { + if (xhr.status !== 200) { + + // Retrieve error code + var code = parseInt(xhr.getResponseHeader("Guacamole-Status-Code")); // Retrieve error message var message = xhr.getResponseHeader("Guacamole-Error-Message") || xhr.statusText; // Throw error with derived message - throw new Error(message); + throw new Guacamole.Status(code, message); }