Skip to content

Commit 63d2736

Browse files
mmeekstobiasKaminsky
authored andcommitted
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>
1 parent a1477a1 commit 63d2736

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/com/owncloud/android/ui/activity/RichDocumentsWebView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.os.Bundle;
3737
import android.text.TextUtils;
3838
import android.view.View;
39+
import android.view.KeyEvent;
3940
import android.webkit.JavascriptInterface;
4041
import android.webkit.ValueCallback;
4142
import android.webkit.WebChromeClient;
@@ -418,6 +419,13 @@ public void fileRename(String renameString) {
418419
Log_OC.e(this, "Failed to parse rename json message: " + e);
419420
}
420421
}
422+
423+
@JavascriptInterface
424+
public void paste() {
425+
// Javascript cannot do this by itself, so help out.
426+
webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PASTE));
427+
webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_PASTE));
428+
}
421429
}
422430

423431

0 commit comments

Comments
 (0)