From b84dfa6202c3b65387978a1c909638d396f0e730 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 28 Jun 2019 23:10:58 +0100 Subject: [PATCH 1/2] 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 --- .../android/ui/activity/RichDocumentsWebView.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java b/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java index 53e36cb853..34780f0d8b 100644 --- a/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java +++ b/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)); + } } From c0588a0d1fcd376d508313ae7325cb60aa92e996 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 23 Jul 2019 14:06:55 +0200 Subject: [PATCH 2/2] Paste only for >=N Signed-off-by: tobiasKaminsky --- .../android/ui/activity/RichDocumentsWebView.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java b/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java index 34780f0d8b..af07a4cbe4 100644 --- a/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java +++ b/src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java @@ -35,8 +35,8 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; -import android.view.View; import android.view.KeyEvent; +import android.view.View; import android.webkit.JavascriptInterface; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; @@ -423,8 +423,10 @@ public class RichDocumentsWebView extends ExternalSiteWebView { @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)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PASTE)); + webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_PASTE)); + } } }