OLD | NEW |
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; |
| 10 import android.os.AsyncTask; |
7 import android.os.Handler; | 11 import android.os.Handler; |
8 import android.os.Message; | 12 import android.os.Message; |
| 13 import android.provider.MediaStore; |
9 import android.util.Log; | 14 import android.util.Log; |
10 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
11 import android.view.View; | 16 import android.view.View; |
12 import android.webkit.ConsoleMessage; | 17 import android.webkit.ConsoleMessage; |
13 import android.webkit.ValueCallback; | 18 import android.webkit.ValueCallback; |
14 | 19 |
| 20 import org.chromium.base.ContentUriUtils; |
15 import org.chromium.base.ThreadUtils; | 21 import org.chromium.base.ThreadUtils; |
16 import org.chromium.content.browser.ContentVideoView; | 22 import org.chromium.content.browser.ContentVideoView; |
17 import org.chromium.content.browser.ContentViewCore; | 23 import org.chromium.content.browser.ContentViewCore; |
18 | 24 |
19 /** | 25 /** |
20 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. | 26 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. |
21 * This class also serves a secondary function of routing certain callbacks from
the content layer | 27 * This class also serves a secondary function of routing certain callbacks from
the content layer |
22 * to specific listener interfaces. | 28 * to specific listener interfaces. |
23 */ | 29 */ |
24 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { | 30 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { |
25 private static final String TAG = "AwWebContentsDelegateAdapter"; | 31 private static final String TAG = "AwWebContentsDelegateAdapter"; |
26 | 32 |
27 final AwContentsClient mContentsClient; | 33 final AwContentsClient mContentsClient; |
28 View mContainerView; | 34 View mContainerView; |
| 35 final Context mContext; |
29 | 36 |
30 public AwWebContentsDelegateAdapter(AwContentsClient contentsClient, | 37 public AwWebContentsDelegateAdapter(AwContentsClient contentsClient, |
31 View containerView) { | 38 View containerView, Context context) { |
32 mContentsClient = contentsClient; | 39 mContentsClient = contentsClient; |
33 setContainerView(containerView); | 40 setContainerView(containerView); |
| 41 mContext = context; |
34 } | 42 } |
35 | 43 |
36 public void setContainerView(View containerView) { | 44 public void setContainerView(View containerView) { |
37 mContainerView = containerView; | 45 mContainerView = containerView; |
38 } | 46 } |
39 | 47 |
40 @Override | 48 @Override |
41 public void onLoadProgressChanged(int progress) { | 49 public void onLoadProgressChanged(int progress) { |
42 mContentsClient.onProgressChanged(progress); | 50 mContentsClient.onProgressChanged(progress); |
43 } | 51 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 162 } |
155 } | 163 } |
156 }; | 164 }; |
157 | 165 |
158 Message resend = handler.obtainMessage(MSG_CONTINUE_PENDING_RELOAD); | 166 Message resend = handler.obtainMessage(MSG_CONTINUE_PENDING_RELOAD); |
159 Message dontResend = handler.obtainMessage(MSG_CANCEL_PENDING_RELOAD); | 167 Message dontResend = handler.obtainMessage(MSG_CANCEL_PENDING_RELOAD); |
160 mContentsClient.onFormResubmission(dontResend, resend); | 168 mContentsClient.onFormResubmission(dontResend, resend); |
161 } | 169 } |
162 | 170 |
163 @Override | 171 @Override |
164 public void runFileChooser(final int processId, final int renderId, final in
t mode_flags, | 172 public void runFileChooser(final int processId, final int renderId, final in
t modeFlags, |
165 String acceptTypes, String title, String defaultFilename, boolean ca
pture) { | 173 String acceptTypes, String title, String defaultFilename, boolean ca
pture) { |
166 AwContentsClient.FileChooserParams params = new AwContentsClient.FileCho
oserParams(); | 174 AwContentsClient.FileChooserParams params = new AwContentsClient.FileCho
oserParams(); |
167 params.mode = mode_flags; | 175 params.mode = modeFlags; |
168 params.acceptTypes = acceptTypes; | 176 params.acceptTypes = acceptTypes; |
169 params.title = title; | 177 params.title = title; |
170 params.defaultFilename = defaultFilename; | 178 params.defaultFilename = defaultFilename; |
171 params.capture = capture; | 179 params.capture = capture; |
172 | 180 |
173 mContentsClient.showFileChooser(new ValueCallback<String[]>() { | 181 mContentsClient.showFileChooser(new ValueCallback<String[]>() { |
174 boolean mCompleted = false; | 182 boolean mCompleted = false; |
175 @Override | 183 @Override |
176 public void onReceiveValue(String[] results) { | 184 public void onReceiveValue(String[] results) { |
177 if (mCompleted) { | 185 if (mCompleted) { |
178 throw new IllegalStateException("Duplicate showFileChooser r
esult"); | 186 throw new IllegalStateException("Duplicate showFileChooser r
esult"); |
179 } | 187 } |
180 mCompleted = true; | 188 mCompleted = true; |
181 nativeFilesSelectedInChooser(processId, renderId, mode_flags, re
sults); | 189 if (results == null) { |
| 190 nativeFilesSelectedInChooser( |
| 191 processId, renderId, modeFlags, null, null); |
| 192 return; |
| 193 } |
| 194 GetDisplayNameTask task = new GetDisplayNameTask( |
| 195 mContext.getContentResolver(), processId, renderId, mode
Flags, results); |
| 196 task.execute(); |
182 } | 197 } |
183 }, params); | 198 }, params); |
184 } | 199 } |
185 | 200 |
186 @Override | 201 @Override |
187 public boolean addNewContents(boolean isDialog, boolean isUserGesture) { | 202 public boolean addNewContents(boolean isDialog, boolean isUserGesture) { |
188 return mContentsClient.onCreateWindow(isDialog, isUserGesture); | 203 return mContentsClient.onCreateWindow(isDialog, isUserGesture); |
189 } | 204 } |
190 | 205 |
191 @Override | 206 @Override |
192 public void activateContents() { | 207 public void activateContents() { |
193 mContentsClient.onRequestFocus(); | 208 mContentsClient.onRequestFocus(); |
194 } | 209 } |
195 | 210 |
196 @Override | 211 @Override |
197 public void toggleFullscreenModeForTab(boolean enterFullscreen) { | 212 public void toggleFullscreenModeForTab(boolean enterFullscreen) { |
198 if (!enterFullscreen) { | 213 if (!enterFullscreen) { |
199 ContentVideoView videoView = ContentVideoView.getContentVideoView(); | 214 ContentVideoView videoView = ContentVideoView.getContentVideoView(); |
200 if (videoView != null) videoView.exitFullscreen(false); | 215 if (videoView != null) videoView.exitFullscreen(false); |
201 } | 216 } |
202 } | 217 } |
| 218 |
| 219 private static class GetDisplayNameTask extends AsyncTask<Void, Void, String
[]> { |
| 220 final int mProcessId; |
| 221 final int mRenderId; |
| 222 final int mModeFlags; |
| 223 final String[] mFilePaths; |
| 224 final ContentResolver mContentResolver; |
| 225 |
| 226 public GetDisplayNameTask(ContentResolver contentResolver, int processId
, int renderId, |
| 227 int modeFlags, String[] filePaths) { |
| 228 mProcessId = processId; |
| 229 mRenderId = renderId; |
| 230 mModeFlags = modeFlags; |
| 231 mFilePaths = filePaths; |
| 232 mContentResolver = contentResolver; |
| 233 } |
| 234 |
| 235 @Override |
| 236 protected String[] doInBackground(Void...voids) { |
| 237 String[] displayNames = new String[mFilePaths.length]; |
| 238 for (int i = 0; i < mFilePaths.length; i++) { |
| 239 displayNames[i] = resolveFileName(mFilePaths[i]); |
| 240 } |
| 241 return displayNames; |
| 242 } |
| 243 |
| 244 @Override |
| 245 protected void onPostExecute(String[] result) { |
| 246 nativeFilesSelectedInChooser(mProcessId, mRenderId, mModeFlags, mFil
ePaths, result); |
| 247 } |
| 248 |
| 249 /** |
| 250 * @return the display name of a path if it is a content URI and is pres
ent in the database |
| 251 * or an empty string otherwise. |
| 252 */ |
| 253 private String resolveFileName(String filePath) { |
| 254 if (mContentResolver == null || filePath == null) return ""; |
| 255 Uri uri = Uri.parse(filePath); |
| 256 return ContentUriUtils.getDisplayName( |
| 257 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME)
; |
| 258 } |
| 259 } |
203 } | 260 } |
OLD | NEW |