Chromium Code Reviews| 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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.ContentResolver; | 8 import android.content.ContentResolver; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.media.AudioManager; | 10 import android.media.AudioManager; |
| 11 import android.net.Uri; | 11 import android.net.Uri; |
| 12 import android.os.AsyncTask; | 12 import android.os.AsyncTask; |
| 13 import android.os.Build; | 13 import android.os.Build; |
| 14 import android.os.Handler; | 14 import android.os.Handler; |
| 15 import android.os.Message; | 15 import android.os.Message; |
| 16 import android.provider.MediaStore; | 16 import android.provider.MediaStore; |
| 17 import android.text.TextUtils; | 17 import android.text.TextUtils; |
| 18 import android.util.Log; | 18 import android.util.Log; |
| 19 import android.view.KeyEvent; | 19 import android.view.KeyEvent; |
| 20 import android.view.View; | 20 import android.view.View; |
| 21 import android.webkit.ConsoleMessage; | 21 import android.webkit.ConsoleMessage; |
| 22 import android.webkit.URLUtil; | |
| 22 import android.webkit.ValueCallback; | 23 import android.webkit.ValueCallback; |
| 24 import android.webkit.WebChromeClient; | |
| 25 import android.widget.FrameLayout; | |
| 23 | 26 |
| 24 import org.chromium.base.ContentUriUtils; | 27 import org.chromium.base.ContentUriUtils; |
| 25 import org.chromium.base.ThreadUtils; | 28 import org.chromium.base.ThreadUtils; |
| 29 import org.chromium.content.browser.ContentVideoViewEmbedder; | |
| 26 import org.chromium.content_public.browser.InvalidateTypes; | 30 import org.chromium.content_public.browser.InvalidateTypes; |
| 27 import org.chromium.content_public.common.ResourceRequestBody; | 31 import org.chromium.content_public.common.ResourceRequestBody; |
| 28 | 32 |
| 29 /** | 33 /** |
| 30 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. | 34 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. |
| 31 * This class also serves a secondary function of routing certain callbacks from the content layer | 35 * This class also serves a secondary function of routing certain callbacks from the content layer |
| 32 * to specific listener interfaces. | 36 * to specific listener interfaces. |
| 33 */ | 37 */ |
| 34 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 38 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 35 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { | 39 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { |
| 36 private static final String TAG = "AwWebContentsDelegateAdapter"; | 40 private static final String TAG = "AwWebContentsDelegateAdapter"; |
| 37 | 41 |
| 38 private final AwContents mAwContents; | 42 private final AwContents mAwContents; |
| 39 private final AwContentsClient mContentsClient; | 43 private final AwContentsClient mContentsClient; |
| 40 private final AwContentViewClient mContentViewClient; | 44 private final AwSettings mAwSettings; |
| 41 private final Context mContext; | 45 private final Context mContext; |
| 42 private View mContainerView; | 46 private View mContainerView; |
| 47 private FrameLayout mCustomView; | |
| 48 private AwContentVideoViewEmbedder mVideoViewEmbedder; | |
| 43 | 49 |
| 44 public AwWebContentsDelegateAdapter(AwContents awContents, AwContentsClient contentsClient, | 50 public AwWebContentsDelegateAdapter(AwContents awContents, AwContentsClient contentsClient, |
| 45 AwContentViewClient contentViewClient, Context context, View contain erView) { | 51 AwSettings settings, Context context, View containerView) { |
| 46 mAwContents = awContents; | 52 mAwContents = awContents; |
| 47 mContentsClient = contentsClient; | 53 mContentsClient = contentsClient; |
| 48 mContentViewClient = contentViewClient; | 54 mAwSettings = settings; |
| 49 mContext = context; | 55 mContext = context; |
| 50 setContainerView(containerView); | 56 setContainerView(containerView); |
| 51 } | 57 } |
| 52 | 58 |
| 53 public void setContainerView(View containerView) { | 59 public void setContainerView(View containerView) { |
| 54 mContainerView = containerView; | 60 mContainerView = containerView; |
| 55 } | 61 } |
| 56 | 62 |
| 57 @Override | 63 @Override |
| 58 public void onLoadProgressChanged(int progress) { | 64 public void onLoadProgressChanged(int progress) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 // the pending entry. | 263 // the pending entry. |
| 258 String url = mAwContents.getLastCommittedUrl(); | 264 String url = mAwContents.getLastCommittedUrl(); |
| 259 url = TextUtils.isEmpty(url) ? "about:blank" : url; | 265 url = TextUtils.isEmpty(url) ? "about:blank" : url; |
| 260 mContentsClient.getCallbackHelper().postSynthesizedPageLoadingForUrl BarUpdate(url); | 266 mContentsClient.getCallbackHelper().postSynthesizedPageLoadingForUrl BarUpdate(url); |
| 261 } | 267 } |
| 262 } | 268 } |
| 263 | 269 |
| 264 @Override | 270 @Override |
| 265 public void toggleFullscreenModeForTab(boolean enterFullscreen) { | 271 public void toggleFullscreenModeForTab(boolean enterFullscreen) { |
| 266 if (enterFullscreen) { | 272 if (enterFullscreen) { |
| 267 mContentViewClient.enterFullscreen(); | 273 enterFullscreen(); |
| 268 } else { | 274 } else { |
| 269 mContentViewClient.exitFullscreen(); | 275 exitFullscreen(); |
| 270 } | 276 } |
| 271 } | 277 } |
| 272 | 278 |
| 273 @Override | 279 @Override |
| 274 public void loadingStateChanged() { | 280 public void loadingStateChanged() { |
| 275 mContentsClient.updateTitle(mAwContents.getTitle(), false); | 281 mContentsClient.updateTitle(mAwContents.getTitle(), false); |
| 276 } | 282 } |
| 277 | 283 |
| 284 /** | |
| 285 * Called to show the web contents in fullscreen mode. | |
| 286 * | |
| 287 * <p>If entering fullscreen on a video element the web contents will contai n just | |
| 288 * the html5 video controls. {@link #enterFullscreenVideo(View)} will be cal led later | |
| 289 * once the ContentVideoView, which contains the hardware accelerated fullsc reen video, | |
| 290 * is ready to be shown. | |
| 291 */ | |
| 292 public void enterFullscreen() { | |
|
boliu
2016/09/26 21:25:24
private
Jinsuk Kim
2016/09/27 10:08:58
Done.
| |
| 293 if (mAwContents.isFullScreen()) { | |
| 294 return; | |
| 295 } | |
| 296 View fullscreenView = mAwContents.enterFullScreen(); | |
| 297 if (fullscreenView == null) { | |
| 298 return; | |
| 299 } | |
| 300 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCa llback() { | |
| 301 @Override | |
| 302 public void onCustomViewHidden() { | |
| 303 if (mCustomView != null) { | |
| 304 mAwContents.requestExitFullscreen(); | |
| 305 } | |
| 306 } | |
| 307 }; | |
| 308 mCustomView = new FrameLayout(mContext); | |
| 309 mCustomView.addView(fullscreenView); | |
| 310 mContentsClient.onShowCustomView(mCustomView, cb); | |
| 311 } | |
| 312 | |
| 313 /** | |
| 314 * Called to show the web contents in embedded mode. | |
| 315 */ | |
| 316 public void exitFullscreen() { | |
|
boliu
2016/09/26 21:25:24
private
Jinsuk Kim
2016/09/27 10:08:58
Done.
| |
| 317 if (mCustomView != null) { | |
| 318 mCustomView = null; | |
| 319 if (mVideoViewEmbedder != null) mVideoViewEmbedder.setCustomView(nul l); | |
| 320 mAwContents.exitFullScreen(); | |
| 321 mContentsClient.onHideCustomView(); | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 @Override | |
| 326 public ContentVideoViewEmbedder getContentVideoViewEmbedder() { | |
| 327 mVideoViewEmbedder = new AwContentVideoViewEmbedder(mContext, mContentsC lient, mCustomView); | |
| 328 return mVideoViewEmbedder; | |
| 329 } | |
| 330 | |
| 331 @Override | |
| 332 protected boolean shouldBlockMediaRequest(String url) { | |
| 333 return mAwSettings != null | |
| 334 ? mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url ) : true; | |
| 335 } | |
| 336 | |
| 278 private static class GetDisplayNameTask extends AsyncTask<Void, Void, String []> { | 337 private static class GetDisplayNameTask extends AsyncTask<Void, Void, String []> { |
| 279 final int mProcessId; | 338 final int mProcessId; |
| 280 final int mRenderId; | 339 final int mRenderId; |
| 281 final int mModeFlags; | 340 final int mModeFlags; |
| 282 final String[] mFilePaths; | 341 final String[] mFilePaths; |
| 283 final ContentResolver mContentResolver; | 342 final ContentResolver mContentResolver; |
| 284 | 343 |
| 285 public GetDisplayNameTask(ContentResolver contentResolver, int processId , int renderId, | 344 public GetDisplayNameTask(ContentResolver contentResolver, int processId , int renderId, |
| 286 int modeFlags, String[] filePaths) { | 345 int modeFlags, String[] filePaths) { |
| 287 mProcessId = processId; | 346 mProcessId = processId; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 310 * or an empty string otherwise. | 369 * or an empty string otherwise. |
| 311 */ | 370 */ |
| 312 private String resolveFileName(String filePath) { | 371 private String resolveFileName(String filePath) { |
| 313 if (mContentResolver == null || filePath == null) return ""; | 372 if (mContentResolver == null || filePath == null) return ""; |
| 314 Uri uri = Uri.parse(filePath); | 373 Uri uri = Uri.parse(filePath); |
| 315 return ContentUriUtils.getDisplayName( | 374 return ContentUriUtils.getDisplayName( |
| 316 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME) ; | 375 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME) ; |
| 317 } | 376 } |
| 318 } | 377 } |
| 319 } | 378 } |
| OLD | NEW |