org.chromium.ui.base.Clipboard.setPrimaryClipNoException not getting called
Reported by
lge-systemwebview@lge.com,
Aug 12 2016
|
|||||||||
Issue descriptionSteps to reproduce the problem: In WebView Editor -> Longpress on text -> text will be selected then -> Select Copy from the bubble popup to copy the content to clipboard. Selected content is not getting copied to clipboard. What is the expected behavior? Selected content should be copied to ClipBoardManager. What went wrong? When we copy the selected , we think org.chromium.ui.base.Clipboard.setPrimaryClipNoException is called and ClipboardManager is not called in response to chromium's call. This issue was observed only in 52.X version. This issue was not exists in the previous versions. Did this work before? Yes All previous Webview view versions( i.e before 52.X) Chrome version: 52.0.2743.116 Channel: stable OS Version: Flash Version: We are clearing the selection using after copy selection from bubble popup using below code, window.getSelection().collapseToStart(); or range.collapse(); sel.removeAllRanges(); sel.addRange(range); sel.addRange(range);
,
Aug 12 2016
If you go to Settings > About Phone > Legal Information > System WebView licenses, and attempt to copy some text from there, does it end up on the clipboard? I think we'll need a minimal repro case in order to debug this further; text copying works locally in the webview shell.
,
Aug 12 2016
,
Aug 15 2016
Route to WebView.
,
Aug 16 2016
I couldn't repro in the Google Inbox editor either. It seems very specific to how the app is using it. It looks like LG email app apks crash on startup on non-LG phones, unfortunately, so it's a bit hard to test. 52 is already in stable channel so it's unfortunately late for a WebView-side fix, it might have to wait for 53 even if we did. I'd suggest trying to workaround/fix the issue on your end? And please get back to us if the nature of the fix gives you more details that make it seem like the bug is really in WebView.
,
Aug 16 2016
This issue was not observed with same code with previous 52.X < web view versions.
,
Aug 16 2016
If you could extract your html+js into something we could test without needing an LG phone (for which we won't have a userdebug image, and so we won't be able to test any fixes on directly) that would be most helpful. Have you looked at the console in chrome devtools to see whether any js errors are being logged?
,
Aug 16 2016
I have attached sample app source code and APK.
Steps to reproduce:
1. Run the attached APK. Place cursor in Editor , type something and try to select word and do "copy" option. copy is not done. Try 3~4 times in case not reproducible.
We tested on Nexus 5 Device with system webview >=52.x version.
Basically below is the approach for copy scenario:
1. In our app, we are overriding startActionMode and creating our own bubble popup options.
2. When user clicks "Copy", we are getting the html and plain text from Javascript.
---------------------------------------------------------------------------
var selObject = new Object();
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
selObject.html = container.innerHTML;
selObject.text = container.innerText;
}
-------------------------------------------------------------------------------
Some times we are not getting HTML content from container.innerHTML. So in this case, we are routing the copy call back to system webview via inputConnection.performContextMenuAction(android.R.id.copy). But this call will not clear the selection after text is copied. Hence we are clearing it from javascript side (See CopyPaste.js file)
----------------------------------------------------------------------------
var sel = window.getSelection();
range = sel.getRangeAt(0);
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
-----------------------------------------------------------------------------
3. What we observed is, if we dont clear from javascript side, copy is success otherwise failed.
Let us know incase if more information is required.
,
Aug 16 2016
Trying the app on trunk webview just crashes, so that's great.. 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.input.ImeUtils.checkCondition(ImeUtils.java:143) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.input.ThreadedInputConnection.assertOnImeThread(ThreadedInputConnection.java:237) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.input.ThreadedInputConnection.getSelectedText(ThreadedInputConnection.java:560) 08-16 13:53:31.791 8841 8841 W System.err: at com.example.edittextsamples.MyInputConnection.getSelectedText(MyInputConnection.java:83) 08-16 13:53:31.791 8841 8841 W System.err: at com.example.edittextsamples.MyWebView.hasSelection(MyWebView.java:103) 08-16 13:53:31.791 8841 8841 W System.err: at com.example.edittextsamples.MyWebView.startActionMode(MyWebView.java:90) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.ContentViewCore.startFloatingActionMode(ContentViewCore.java:2038) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.ContentViewCore.startActionMode(ContentViewCore.java:2023) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.ContentViewCore.showSelectActionMode(ContentViewCore.java:1998) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.content.browser.ContentViewCore.onSelectionEvent(ContentViewCore.java:2101) 08-16 13:53:31.791 8841 8841 W System.err: at org.chromium.android_webview.AwContents.nativeOnDraw(Native Method) 08-16 13:53:31.792 8841 8841 W System.err: at org.chromium.android_webview.AwContents.access$4700(AwContents.java:100) 08-16 13:53:31.792 8841 8841 W System.err: at org.chromium.android_webview.AwContents$AwViewMethodsImpl.onDraw(AwContents.java:2997) 08-16 13:53:31.792 8841 8841 W System.err: at org.chromium.android_webview.AwContents.onDraw(AwContents.java:1328) 08-16 13:53:31.792 8841 8841 W System.err: at com.android.webview.chromium.WebViewChromium.onDraw(WebViewChromium.java:1630)
,
Aug 16 2016
I can reproduce this on m52 maybe half of the time. Seems like a racy issue where the page is trying to change the selection while ime input is going on at the same time. I'm inclined to blame page doing weird things but I'll wait for accessment from changwan
,
Aug 16 2016
,
Aug 16 2016
I took a look at your sample. I believe "inputConnection.performContextMenuAction" and "mWebview.evaluateJavascript("javascript:clearSelection(false)", null);" are racing with each other. They'll both return immediately, posting tasks to perform their action and there's no guarantee those tasks will execute in the posted order. I consider the previously observed ordering guarantee to be mostly an accident and it's not something that we want to maintain.
You can fix the problem on your end by adding more ordering to your code. There are probably several ways to do that, but one approach I would suggest is to use https://developer.android.com/reference/android/content/ClipboardManager.html#addPrimaryClipChangedListener to confirm that the copy successfully completed, and only then do "javascript:clearSelection(false)".
Also, I don't really understand what this complicated machinery is for in the first place. At first glance it seems equivalent to WebView's default Copy behavior. If there's a problem with WebView's default Copy behavior, please let us know what it is.
,
Aug 17 2016
Thanks for the suggestion. We will check with clip change listener. -> This may create problem in multi window case where two apps can be used. This listener will receive event even if the copy is done from other app in multi window. Actually we are handling copy behavior our own to support Image features in LG proprietary ClipTray feature. Ex: 1. Assume Webview editor has inline image(inserted image into editor). When user select and do copy, system webview copy will not handle Image scenario. 2. User typed some text and inserted one image to editor(image tag path file://..../data/....../sample.png). In this case if user selects both text and image, only text is copied with system webview default copy). In these two cases, webview will copy html content and plain text to clipboard but not as different clip items(i.e html content, plain text, image uri, plain text...etc). Because of this, user cannot copy image from webview editor. Because of above two reasons, we are handling copy functionality manually. We have query related to clearing selection. inputConnection.performContextMenuAction(android.R.id.copy) inputConnection.performContextMenuAction(android.R.id.cut) In above two calls, why system webview is not clearing the selection(in case of copy) or deleting the text(in case of cut). can it be supported by system webview by itself?
,
Aug 17 2016
The multiwindow bug problem seems solvable, just keep some state and only clear during the interval of interest. Or there are other ways, for example you could post a JS task on the JS oncopy event, not using Java at all. We can look into clearing the selection automatically, that request seems to make sense. It might take a few releases to get to it so I still recommend fixing the ordering on your end.
,
Aug 18 2016
Okay fine. We are handling this from app side.
Requesting to clear the selection(i.e after copying) from webview side at lease in M54 build.
Any idea why html content is not coming when the selected content have only text(i.e no image). Below is the code block for retreiving content from JS side.
var selObject = new Object();
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
selObject.html = container.innerHTML;
}
,
Sep 7 2016
OK, I've filed bugs for your two requests in #14 in http://crbug.com/644590 (image clipboard support in general) and http://crbug.com/644591 (performContextMenuAction() not clearing/deleting). Closing this bug since you're taking action on your side.
,
Oct 12 2016
|
|||||||||
►
Sign in to add a comment |
|||||||||
Comment 1 by dtapu...@chromium.org
, Aug 12 2016