Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java b/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java |
| index 85466cecd6db88d9d7b636ba107591430121121e..738b54af30f3e3d74501780409b10853ba7b08ff 100644 |
| --- a/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java |
| @@ -4,6 +4,9 @@ |
| package org.chromium.android_webview; |
| +import android.content.ContentResolver; |
| +import android.content.Context; |
| +import android.net.Uri; |
| import android.os.Handler; |
| import android.os.Message; |
| import android.util.Log; |
| @@ -12,6 +15,7 @@ import android.view.View; |
| import android.webkit.ConsoleMessage; |
| import android.webkit.ValueCallback; |
| +import org.chromium.base.ContentUriUtils; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.content.browser.ContentVideoView; |
| import org.chromium.content.browser.ContentViewCore; |
| @@ -26,11 +30,13 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { |
| final AwContentsClient mContentsClient; |
| View mContainerView; |
| + final Context mContext; |
| public AwWebContentsDelegateAdapter(AwContentsClient contentsClient, |
| - View containerView) { |
| + View containerView, Context context) { |
| mContentsClient = contentsClient; |
| setContainerView(containerView); |
| + mContext = context; |
| } |
| public void setContainerView(View containerView) { |
| @@ -178,7 +184,17 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { |
| throw new IllegalStateException("Duplicate showFileChooser result"); |
| } |
| mCompleted = true; |
| - nativeFilesSelectedInChooser(processId, renderId, mode_flags, results); |
| + if (results == null) { |
| + nativeFilesSelectedInChooser( |
| + processId, renderId, mode_flags, null, null); |
| + return; |
| + } |
| + String[] displayNames = new String[results.length]; |
| + for (int i = 0; i < results.length; ++i) { |
| + displayNames[i] = resolveFileName(results[i]); |
| + } |
| + nativeFilesSelectedInChooser( |
| + processId, renderId, mode_flags, results, displayNames); |
| } |
| }, params); |
| } |
| @@ -200,4 +216,20 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { |
| if (videoView != null) videoView.exitFullscreen(false); |
| } |
| } |
| + |
| + /** |
| + * @return the display name of a path if it is a content URI and is present in the database |
| + * or an empty string otherwise. |
| + */ |
| + private String resolveFileName(String filePath) { |
| + // Querying the ContentResolver on the UI thread may introduce extra latency. |
| + // However, that is incomparable to the latency introduce by user interaction |
|
boliu
2014/08/11 19:58:14
That's a bad argument, because this delay is *afte
sgurun-gerrit only
2014/08/11 21:23:24
agreed with Bo. This is after user already chose t
qinmin
2014/08/11 22:49:29
Ok, moved all the contentResolver queries to an as
|
| + // with the select file dialog. |
| + // TODO(qinmin): Run an async task to resolve all the file names, and pass |
| + // the result back to the UI thread to run nativeFilesSelectedInChooser. |
| + ContentResolver contentResolver = mContext.getContentResolver(); |
| + if (contentResolver == null || filePath == null) return ""; |
| + Uri uri = Uri.parse(filePath); |
| + return ContentUriUtils.getDisplayName(uri, contentResolver); |
| + } |
| } |