[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / android_webview / java / src / org / chromium / android_webview / AwContentViewClient.java
blobfb5b55d61172c3e6df7013c188fd97e69eebd631
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;
19 /**
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;
34 mContext = context;
37 @Override
38 public void onBackgroundColorChanged(int color) {
39 mAwContentsClient.onBackgroundColorChanged(color);
42 @Override
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);
47 return;
50 // Comes from WebViewImpl::detectContentOnTouch in Blink, so must be user-initiated, and
51 // isn't a redirect.
52 AwContentsClient.sendBrowsingIntent(context, contentUrl, true, false);
55 @Override
56 public void onUpdateTitle(String title) {
57 mAwContentsClient.updateTitle(title, true);
60 @Override
61 public boolean shouldOverrideKeyEvent(KeyEvent event) {
62 if (mAwContentsClient.hasWebViewClient()) {
63 // The check below is reflecting Chrome's behavior and is a workaround for
64 // http://b/7697782.
65 if (!ContentViewClient.shouldPropagateKey(event.getKeyCode())) return true;
66 return mAwContentsClient.shouldOverrideKeyEvent(event);
69 return super.shouldOverrideKeyEvent(event);
72 @Override
73 public WebActionMode startActionMode(
74 View view, ActionHandler actionHandler, boolean floating) {
75 return mAwContentsClient.startActionMode(view, actionHandler, floating);
78 @Override
79 public boolean supportsFloatingActionMode() {
80 return mAwContentsClient.supportsFloatingActionMode();
83 @Override
84 public final ContentVideoViewClient getContentVideoViewClient() {
85 return this;
88 @Override
89 public boolean shouldBlockMediaRequest(String url) {
90 return mAwSettings != null
91 ? mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true;
94 @Override
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.
100 return;
102 mCustomView.addView(videoView, 0);
105 @Override
106 public void exitFullscreenVideo() {
107 // Intentional no-op
110 @Override
111 public View getVideoLoadingProgressView() {
112 return mAwContentsClient.getVideoLoadingProgressView();
115 @Override
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()) {
129 return;
131 View fullscreenView = mAwContents.enterFullScreen();
132 if (fullscreenView == null) {
133 return;
135 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCallback() {
136 @Override
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) {
153 mCustomView = null;
154 mAwContents.exitFullScreen();
155 mAwContentsClient.onHideCustomView();
159 @Override
160 public boolean isExternalScrollActive() {
161 return mAwContents.isSmoothScrollingActive();