diff options
author | igsolla <igsolla@chromium.org> | 2014-10-16 07:31:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-16 14:32:06 +0000 |
commit | 3e28946a9edc2d794a894a6a4a0be965f8b62761 (patch) | |
tree | 3bd852d1364284b075683daee32088ed2572f325 /android_webview/java/src/org/chromium | |
parent | 6eebf52c51ac70a7c89a81241a92a0b1df1f205f (diff) | |
download | chromium_src-3e28946a9edc2d794a894a6a4a0be965f8b62761.zip chromium_src-3e28946a9edc2d794a894a6a4a0be965f8b62761.tar.gz chromium_src-3e28946a9edc2d794a894a6a4a0be965f8b62761.tar.bz2 |
Support fullscreen for non-video elements in the WebView.
When the browser receives the toggleFullscreenModeForTab
IPC we ask the app to show the custom ViewGroup (containing
a FullscreenView with the web contents in fullscreen). If
later (for the video element case) a ContentVideoView is
created then we add it to the custom ViewGroup.
The next steps (in subsequent changes) are:
1. Add tests for fullscreen for non-media elements in the
WebView.
2. Changes to ensure that the power saver blocker works
for video elements contained inside other elements.
3. Changes to ensure that scrolling works in fullscreen.
This change also removes the now unused
disallow_fullscreen_for_non_media_elements setting and
simplifies the JNI interface in ContentVideoView.
BUG=398485
Review URL: https://codereview.chromium.org/618013003
Cr-Commit-Position: refs/heads/master@{#299889}
Diffstat (limited to 'android_webview/java/src/org/chromium')
3 files changed, 72 insertions, 52 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java index a5dd9e1..a189e29 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java @@ -11,7 +11,6 @@ import android.webkit.URLUtil; import android.webkit.WebChromeClient; import android.widget.FrameLayout; -import org.chromium.content.browser.ContentVideoView; import org.chromium.content.browser.ContentVideoViewClient; import org.chromium.content.browser.ContentViewClient; @@ -19,14 +18,14 @@ import org.chromium.content.browser.ContentViewClient; * ContentViewClient implementation for WebView */ public class AwContentViewClient extends ContentViewClient implements ContentVideoViewClient { - private AwContentsClient mAwContentsClient; - private AwSettings mAwSettings; - private AwContents mAwContents; - private Context mContext; - - public AwContentViewClient( - AwContentsClient awContentsClient, AwSettings awSettings, AwContents awContents, - Context context) { + private final AwContentsClient mAwContentsClient; + private final AwSettings mAwSettings; + private final AwContents mAwContents; + private final Context mContext; + private FrameLayout mCustomView; + + public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awSettings, + AwContents awContents, Context context) { mAwContentsClient = awContentsClient; mAwSettings = awSettings; mAwContents = awContents; @@ -66,45 +65,57 @@ public class AwContentViewClient extends ContentViewClient implements ContentVid } @Override - public void enterFullscreenVideo(View view) { - final FrameLayout viewGroup = new FrameLayout(mContext); - viewGroup.addView(view); - viewGroup.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { - @Override - public void onViewDetachedFromWindow(View v) { - // Intentional no-op (see onDestroyContentVideoView). - } - - @Override - public void onViewAttachedToWindow(View v) { - if (mAwContents.isFullScreen()) { - return; - } - View fullscreenView = mAwContents.enterFullScreen(); - if (fullscreenView != null) { - viewGroup.addView(fullscreenView); - } - } - }); - WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCallback() { - @Override - public void onCustomViewHidden() { - ContentVideoView contentVideoView = ContentVideoView.getContentVideoView(); - if (contentVideoView != null) - contentVideoView.exitFullscreen(false); - } - }; - mAwContentsClient.onShowCustomView(viewGroup, cb); + public void enterFullscreenVideo(View videoView) { + // enterFullscreenVideo will only be called after enterFullscreen. + assert mCustomView != null; + mCustomView.addView(videoView, 0); } @Override public void exitFullscreenVideo() { - mAwContents.exitFullScreen(); - mAwContentsClient.onHideCustomView(); + // Intentional no-op } @Override public View getVideoLoadingProgressView() { return mAwContentsClient.getVideoLoadingProgressView(); } + + /** + * Called to show the web contents in fullscreen mode. + * + * <p>If entering fullscreen on a video element the web contents will contain just + * the html5 video controls. {@link #enterFullscreenVideo(View)} will be called later + * once the ContentVideoView, which contains the hardware accelerated fullscreen video, + * is ready to be shown. + */ + public void enterFullscreen() { + if (mAwContents.isFullScreen()) { + return; + } + View fullscreenView = mAwContents.enterFullScreen(); + if (fullscreenView == null) { + return; + } + WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCallback() { + @Override + public void onCustomViewHidden() { + mAwContents.requestExitFullscreen(); + } + }; + mCustomView = new FrameLayout(mContext); + mCustomView.addView(fullscreenView); + mAwContentsClient.onShowCustomView(mCustomView, cb); + } + + /** + * Called to show the web contents in embedded mode. + */ + public void exitFullscreen() { + if (mCustomView != null) { + mAwContents.exitFullScreen(); + mAwContentsClient.onHideCustomView(); + mCustomView = null; + } + } } diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index d8a2eea..a4d2d25 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -581,8 +581,8 @@ public class AwContents { mDIPScale = DeviceDisplayInfo.create(mContext).getDIPScale(); mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); mLayoutSizer.setDIPScale(mDIPScale); - mWebContentsDelegate = new AwWebContentsDelegateAdapter(this, contentsClient, - mContainerView, mContext); + mWebContentsDelegate = new AwWebContentsDelegateAdapter( + this, contentsClient, mContentViewClient, mContext, mContainerView); mContentsClientBridge = new AwContentsClientBridge(contentsClient, mBrowserContext.getKeyStore(), AwContentsStatics.getClientCertLookupTable()); mZoomControls = new AwZoomControls(this); @@ -668,6 +668,13 @@ public class AwContents { } /** + * Called when the app has requested to exit fullscreen. + */ + void requestExitFullscreen() { + mContentViewCore.getWebContents().exitFullscreen(); + } + + /** * Returns this {@link AwContents} to embedded mode, where the {@link AwContents} are drawn * in the WebView. */ diff --git a/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java b/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java index 2d8b633..5ce7257 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java +++ b/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java @@ -19,7 +19,6 @@ import android.webkit.ValueCallback; import org.chromium.base.ContentUriUtils; import org.chromium.base.ThreadUtils; -import org.chromium.content.browser.ContentVideoView; /** * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. @@ -29,17 +28,19 @@ import org.chromium.content.browser.ContentVideoView; class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { private static final String TAG = "AwWebContentsDelegateAdapter"; - final AwContents mAwContents; - final AwContentsClient mContentsClient; - View mContainerView; - final Context mContext; + private final AwContents mAwContents; + private final AwContentsClient mContentsClient; + private final AwContentViewClient mContentViewClient; + private final Context mContext; + private View mContainerView; public AwWebContentsDelegateAdapter(AwContents awContents, AwContentsClient contentsClient, - View containerView, Context context) { + AwContentViewClient contentViewClient, Context context, View containerView) { mAwContents = awContents; mContentsClient = contentsClient; - setContainerView(containerView); + mContentViewClient = contentViewClient; mContext = context; + setContainerView(containerView); } public void setContainerView(View containerView) { @@ -213,9 +214,10 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { @Override public void toggleFullscreenModeForTab(boolean enterFullscreen) { - if (!enterFullscreen) { - ContentVideoView videoView = ContentVideoView.getContentVideoView(); - if (videoView != null) videoView.exitFullscreen(false); + if (enterFullscreen) { + mContentViewClient.enterFullscreen(); + } else { + mContentViewClient.exitFullscreen(); } } |