GUAC-1480: Only check clipboard when window regains focus. Do not attempt to 
read clipboard unless textarea actually has focus (paste may occur elsewhere 
otherwise).

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/43022c14
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/43022c14
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/43022c14

Branch: refs/heads/master
Commit: 43022c14b383dc519d6ab2ea46f57de7b0f92b9b
Parents: 31eb5ec
Author: Michael Jumper <[email protected]>
Authored: Thu Feb 4 22:01:36 2016 -0800
Committer: Michael Jumper <[email protected]>
Committed: Thu Feb 4 22:01:36 2016 -0800

----------------------------------------------------------------------
 .../main/webapp/app/client/services/clipboardService.js  | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/43022c14/guacamole/src/main/webapp/app/client/services/clipboardService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/services/clipboardService.js 
b/guacamole/src/main/webapp/app/client/services/clipboardService.js
index b981b8b..0aa68ed 100644
--- a/guacamole/src/main/webapp/app/client/services/clipboardService.js
+++ b/guacamole/src/main/webapp/app/client/services/clipboardService.js
@@ -110,10 +110,11 @@ angular.module('client').factory('clipboardService', 
['$injector',
 
             // Clear and select the clipboard DOM element
             clipboardContent.value = '';
+            clipboardContent.focus();
             clipboardContent.select();
 
             // Attempt paste local clipboard into clipboard DOM element
-            if (document.execCommand('paste'))
+            if (document.activeElement === clipboardContent && 
document.execCommand('paste'))
                 deferred.resolve(clipboardContent.value);
             else
                 deferred.reject();
@@ -142,7 +143,13 @@ angular.module('client').factory('clipboardService', 
['$injector',
     // Attempt to read the clipboard if it may have changed
     window.addEventListener('copy',  checkClipboard, true);
     window.addEventListener('cut',   checkClipboard, true);
-    window.addEventListener('focus', checkClipboard, true);
+    window.addEventListener('focus', function focusGained(e) {
+
+        // Only recheck clipboard if it's the window itself that gained focus
+        if (e.target === window)
+            checkClipboard();
+
+    }, true);
 
     return service;
 

Reply via email to