Răsfoiți Sursa

Provide a banal 'paste' postmessage implementation.

Browsers will allow apps to populate the clipboard, but not read
from it without user input. This patch makes it possible for
context menus with 'Paste' in them to trigger a real OS paste
when hosted inside the webview.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Michael Meeks 5 ani în urmă
părinte
comite
b84dfa6202

+ 8 - 0
src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java

@@ -36,6 +36,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.view.View;
+import android.view.KeyEvent;
 import android.webkit.JavascriptInterface;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
@@ -418,6 +419,13 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
                 Log_OC.e(this, "Failed to parse rename json message: " + e);
             }
         }
+
+        @JavascriptInterface
+        public void paste() {
+           // Javascript cannot do this by itself, so help out.
+            webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PASTE));
+            webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_PASTE));
+        }
     }