Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1191)

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java

Issue 450003002: Pass display names for uploaded content URI files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move getDisplayName(Uri, ContentResolver) to ContentUriUtils Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.content.ContentResolver;
8 import android.content.Context;
9 import android.net.Uri;
7 import android.os.Handler; 10 import android.os.Handler;
8 import android.os.Message; 11 import android.os.Message;
9 import android.util.Log; 12 import android.util.Log;
10 import android.view.KeyEvent; 13 import android.view.KeyEvent;
11 import android.view.View; 14 import android.view.View;
12 import android.webkit.ConsoleMessage; 15 import android.webkit.ConsoleMessage;
13 import android.webkit.ValueCallback; 16 import android.webkit.ValueCallback;
14 17
18 import org.chromium.base.ContentUriUtils;
15 import org.chromium.base.ThreadUtils; 19 import org.chromium.base.ThreadUtils;
16 import org.chromium.content.browser.ContentVideoView; 20 import org.chromium.content.browser.ContentVideoView;
17 import org.chromium.content.browser.ContentViewCore; 21 import org.chromium.content.browser.ContentViewCore;
18 22
19 /** 23 /**
20 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. 24 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface.
21 * This class also serves a secondary function of routing certain callbacks from the content layer 25 * This class also serves a secondary function of routing certain callbacks from the content layer
22 * to specific listener interfaces. 26 * to specific listener interfaces.
23 */ 27 */
24 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { 28 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate {
25 private static final String TAG = "AwWebContentsDelegateAdapter"; 29 private static final String TAG = "AwWebContentsDelegateAdapter";
26 30
27 final AwContentsClient mContentsClient; 31 final AwContentsClient mContentsClient;
28 View mContainerView; 32 View mContainerView;
33 final Context mContext;
29 34
30 public AwWebContentsDelegateAdapter(AwContentsClient contentsClient, 35 public AwWebContentsDelegateAdapter(AwContentsClient contentsClient,
31 View containerView) { 36 View containerView, Context context) {
32 mContentsClient = contentsClient; 37 mContentsClient = contentsClient;
33 setContainerView(containerView); 38 setContainerView(containerView);
39 mContext = context;
34 } 40 }
35 41
36 public void setContainerView(View containerView) { 42 public void setContainerView(View containerView) {
37 mContainerView = containerView; 43 mContainerView = containerView;
38 } 44 }
39 45
40 @Override 46 @Override
41 public void onLoadProgressChanged(int progress) { 47 public void onLoadProgressChanged(int progress) {
42 mContentsClient.onProgressChanged(progress); 48 mContentsClient.onProgressChanged(progress);
43 } 49 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 params.capture = capture; 177 params.capture = capture;
172 178
173 mContentsClient.showFileChooser(new ValueCallback<String[]>() { 179 mContentsClient.showFileChooser(new ValueCallback<String[]>() {
174 boolean mCompleted = false; 180 boolean mCompleted = false;
175 @Override 181 @Override
176 public void onReceiveValue(String[] results) { 182 public void onReceiveValue(String[] results) {
177 if (mCompleted) { 183 if (mCompleted) {
178 throw new IllegalStateException("Duplicate showFileChooser r esult"); 184 throw new IllegalStateException("Duplicate showFileChooser r esult");
179 } 185 }
180 mCompleted = true; 186 mCompleted = true;
181 nativeFilesSelectedInChooser(processId, renderId, mode_flags, re sults); 187 if (results == null) {
188 nativeFilesSelectedInChooser(
189 processId, renderId, mode_flags, null, null);
190 return;
191 }
192 String[] displayNames = new String[results.length];
193 for (int i = 0; i < results.length; ++i) {
194 displayNames[i] = resolveFileName(results[i]);
195 }
196 nativeFilesSelectedInChooser(
197 processId, renderId, mode_flags, results, displayNames);
182 } 198 }
183 }, params); 199 }, params);
184 } 200 }
185 201
186 @Override 202 @Override
187 public boolean addNewContents(boolean isDialog, boolean isUserGesture) { 203 public boolean addNewContents(boolean isDialog, boolean isUserGesture) {
188 return mContentsClient.onCreateWindow(isDialog, isUserGesture); 204 return mContentsClient.onCreateWindow(isDialog, isUserGesture);
189 } 205 }
190 206
191 @Override 207 @Override
192 public void activateContents() { 208 public void activateContents() {
193 mContentsClient.onRequestFocus(); 209 mContentsClient.onRequestFocus();
194 } 210 }
195 211
196 @Override 212 @Override
197 public void toggleFullscreenModeForTab(boolean enterFullscreen) { 213 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
198 if (!enterFullscreen) { 214 if (!enterFullscreen) {
199 ContentVideoView videoView = ContentVideoView.getContentVideoView(); 215 ContentVideoView videoView = ContentVideoView.getContentVideoView();
200 if (videoView != null) videoView.exitFullscreen(false); 216 if (videoView != null) videoView.exitFullscreen(false);
201 } 217 }
202 } 218 }
219
220 /**
221 * @return the display name of a path if it is a content URI and is present in the database
222 * or an empty string otherwise.
223 */
224 private String resolveFileName(String filePath) {
225 // Querying the ContentResolver on the UI thread may introduce extra lat ency.
226 // However, that is incomparable to the latency introduce by user intera ction
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
227 // with the select file dialog.
228 // TODO(qinmin): Run an async task to resolve all the file names, and pa ss
229 // the result back to the UI thread to run nativeFilesSelectedInChooser.
230 ContentResolver contentResolver = mContext.getContentResolver();
231 if (contentResolver == null || filePath == null) return "";
232 Uri uri = Uri.parse(filePath);
233 return ContentUriUtils.getDisplayName(uri, contentResolver);
234 }
203 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698