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
;
16 import org
.chromium
.content
.browser
.WebActionMode
;
17 import org
.chromium
.content
.browser
.WebActionModeCallback
.ActionHandler
;
20 * ContentViewClient implementation for WebView
22 public class AwContentViewClient
extends ContentViewClient
implements ContentVideoViewClient
{
23 private final AwContentsClient mAwContentsClient
;
24 private final AwSettings mAwSettings
;
25 private final AwContents mAwContents
;
26 private final Context mContext
;
27 private FrameLayout mCustomView
;
29 public AwContentViewClient(AwContentsClient awContentsClient
, AwSettings awSettings
,
30 AwContents awContents
, Context context
) {
31 mAwContentsClient
= awContentsClient
;
32 mAwSettings
= awSettings
;
33 mAwContents
= awContents
;
38 public void onBackgroundColorChanged(int color
) {
39 mAwContentsClient
.onBackgroundColorChanged(color
);
43 public void onStartContentIntent(Context context
, String contentUrl
) {
44 if (mAwContentsClient
.hasWebViewClient()) {
45 // Callback when detecting a click on a content link.
46 mAwContentsClient
.shouldOverrideUrlLoading(contentUrl
);
50 // Comes from WebViewImpl::detectContentOnTouch in Blink, so must be user-initiated, and
52 AwContentsClient
.sendBrowsingIntent(context
, contentUrl
, true, false);
56 public void onUpdateTitle(String title
) {
57 mAwContentsClient
.updateTitle(title
, true);
61 public boolean shouldOverrideKeyEvent(KeyEvent event
) {
62 if (mAwContentsClient
.hasWebViewClient()) {
63 // The check below is reflecting Chrome's behavior and is a workaround for
65 if (!ContentViewClient
.shouldPropagateKey(event
.getKeyCode())) return true;
66 return mAwContentsClient
.shouldOverrideKeyEvent(event
);
69 return super.shouldOverrideKeyEvent(event
);
73 public WebActionMode
startActionMode(
74 View view
, ActionHandler actionHandler
, boolean floating
) {
75 return mAwContentsClient
.startActionMode(view
, actionHandler
, floating
);
79 public boolean supportsFloatingActionMode() {
80 return mAwContentsClient
.supportsFloatingActionMode();
84 public final ContentVideoViewClient
getContentVideoViewClient() {
89 public boolean shouldBlockMediaRequest(String url
) {
90 return mAwSettings
!= null
91 ? mAwSettings
.getBlockNetworkLoads() && URLUtil
.isNetworkUrl(url
) : true;
95 public void enterFullscreenVideo(View videoView
) {
96 if (mCustomView
== null) {
97 // enterFullscreenVideo will only be called after enterFullscreen, but
98 // in this case exitFullscreen has been invoked in between them.
99 // TODO(igsolla): Fix http://crbug/425926 and replace with assert.
102 mCustomView
.addView(videoView
, 0);
106 public void exitFullscreenVideo() {
111 public View
getVideoLoadingProgressView() {
112 return mAwContentsClient
.getVideoLoadingProgressView();
116 public void setSystemUiVisibility(boolean enterFullscreen
) {
120 * Called to show the web contents in fullscreen mode.
122 * <p>If entering fullscreen on a video element the web contents will contain just
123 * the html5 video controls. {@link #enterFullscreenVideo(View)} will be called later
124 * once the ContentVideoView, which contains the hardware accelerated fullscreen video,
125 * is ready to be shown.
127 public void enterFullscreen() {
128 if (mAwContents
.isFullScreen()) {
131 View fullscreenView
= mAwContents
.enterFullScreen();
132 if (fullscreenView
== null) {
135 WebChromeClient
.CustomViewCallback cb
= new WebChromeClient
.CustomViewCallback() {
137 public void onCustomViewHidden() {
138 if (mCustomView
!= null) {
139 mAwContents
.requestExitFullscreen();
143 mCustomView
= new FrameLayout(mContext
);
144 mCustomView
.addView(fullscreenView
);
145 mAwContentsClient
.onShowCustomView(mCustomView
, cb
);
149 * Called to show the web contents in embedded mode.
151 public void exitFullscreen() {
152 if (mCustomView
!= null) {
154 mAwContents
.exitFullScreen();
155 mAwContentsClient
.onHideCustomView();
160 public boolean isExternalScrollActive() {
161 return mAwContents
.isSmoothScrollingActive();