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
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import android.content.Context;
8 import android.view.KeyEvent;
9 import android.view.View;
10 import android.webkit.URLUtil;
11 import android.webkit.WebChromeClient;
12 import android.widget.FrameLayout;
14 import org.chromium.content.browser.ContentVideoViewClient;
15 import org.chromium.content.browser.ContentViewClient;
18 * ContentViewClient implementation for WebView
20 public class AwContentViewClient extends ContentViewClient implements ContentVideoViewClient {
21 private final AwContentsClient mAwContentsClient;
22 private final AwSettings mAwSettings;
23 private final AwContents mAwContents;
24 private final Context mContext;
25 private FrameLayout mCustomView;
27 public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awSettings,
28 AwContents awContents, Context context) {
29 mAwContentsClient = awContentsClient;
30 mAwSettings = awSettings;
31 mAwContents = awContents;
36 public void onBackgroundColorChanged(int color) {
37 mAwContentsClient.onBackgroundColorChanged(color);
41 public void onStartContentIntent(Context context, String contentUrl) {
42 // Callback when detecting a click on a content link.
43 mAwContentsClient.shouldOverrideUrlLoading(contentUrl);
47 public void onUpdateTitle(String title) {
48 mAwContentsClient.onReceivedTitle(title);
52 public boolean shouldOverrideKeyEvent(KeyEvent event) {
53 return mAwContentsClient.shouldOverrideKeyEvent(event);
57 public final ContentVideoViewClient getContentVideoViewClient() {
62 public boolean shouldBlockMediaRequest(String url) {
63 return mAwSettings != null
64 ? mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true;
68 public void enterFullscreenVideo(View videoView) {
69 if (mCustomView == null) {
70 // enterFullscreenVideo will only be called after enterFullscreen, but
71 // in this case exitFullscreen has been invoked in between them.
72 // TODO(igsolla): Fix http://crbug/425926 and replace with assert.
75 mCustomView.addView(videoView, 0);
79 public void exitFullscreenVideo() {
84 public View getVideoLoadingProgressView() {
85 return mAwContentsClient.getVideoLoadingProgressView();
89 * Called to show the web contents in fullscreen mode.
91 * <p>If entering fullscreen on a video element the web contents will contain just
92 * the html5 video controls. {@link #enterFullscreenVideo(View)} will be called later
93 * once the ContentVideoView, which contains the hardware accelerated fullscreen video,
94 * is ready to be shown.
96 public void enterFullscreen() {
97 if (mAwContents.isFullScreen()) {
100 View fullscreenView = mAwContents.enterFullScreen();
101 if (fullscreenView == null) {
104 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCallback() {
106 public void onCustomViewHidden() {
107 mAwContents.requestExitFullscreen();
110 mCustomView = new FrameLayout(mContext);
111 mCustomView.addView(fullscreenView);
112 mAwContentsClient.onShowCustomView(mCustomView, cb);
116 * Called to show the web contents in embedded mode.
118 public void exitFullscreen() {
119 if (mCustomView != null) {
120 mAwContents.exitFullScreen();
121 mAwContentsClient.onHideCustomView();