Skip to content

Commit

Permalink
[android_view] Implementation of WebChromeClient.getVideoLoadingProgr…
Browse files Browse the repository at this point in the history
…essView

BUG=http://b/6294738


Review URL: https://chromiumcodereview.appspot.com/12393060

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186376 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
michaelbai@chromium.org committed Mar 6, 2013
1 parent a445857 commit 6fe2519
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 3 deletions.
2 changes: 2 additions & 0 deletions android_webview/android_webview_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'additional_input_paths': [
'<(PRODUCT_DIR)/android_webview_test_apk/assets/asset_file.html',
'<(PRODUCT_DIR)/android_webview_test_apk/assets/asset_icon.png',
'<(PRODUCT_DIR)/android_webview_test_apk/assets/get_video_loading_progress_view_test.html',
],
},
'copies': [
Expand All @@ -29,6 +30,7 @@
'files': [
'<(java_in_dir)/assets/asset_file.html',
'<(java_in_dir)/assets/asset_icon.png',
'<(java_in_dir)/assets/get_video_loading_progress_view_test.html',
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public AwContentVideoViewDelegate(AwContentsClient client, Context context) {
mContext = context;
}

@Override
public void onShowCustomView(View view) {
CustomViewCallback cb = new CustomViewCallback() {
@Override
Expand All @@ -36,35 +37,47 @@ public void onCustomViewHidden() {
cb);
}

@Override
public void onDestroyContentVideoView() {
}

@Override
public Context getContext() {
return mContext;
}

@Override
public String getPlayBackErrorText() {
return mContext.getString(
org.chromium.content.R.string.media_player_error_text_invalid_progressive_playback);
}

@Override
public String getUnknownErrorText() {
return mContext.getString(
org.chromium.content.R.string.media_player_error_text_unknown);
}

@Override
public String getErrorButton() {
return mContext.getString(
org.chromium.content.R.string.media_player_error_button);
}

@Override
public String getErrorTitle() {
return mContext.getString(
org.chromium.content.R.string.media_player_error_title);
}

@Override
public String getVideoLoadingText() {
return mContext.getString(
org.chromium.content.R.string.media_player_loading_video);
}

@Override
public View getVideoLoadingProgressView() {
return mAwContentsClient.getVideoLoadingProgressView();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ public void onReceivedIcon(Bitmap bitmap) { }

protected abstract void onRequestFocus();

// TODO (michaelbai): This method should be abstract, having empty body here
// makes the merge to the Android easy.
protected View getVideoLoadingProgressView() {
return null;
}

//--------------------------------------------------------------------------------------------
// Other WebView-specific methods
//--------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<script>
function goFullscreen(id) {
var element = document.getElementById(id);
if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}

addEventListener('Loaded', function() {
document.getElementById('video').addEventListener('play', function() {
console.log('Video Played');
}, false);
}, false);
</script>
</head>
<body>
</script></head><body>
<button autofocus style ='padding:1024px 1024px;' onclick="goFullscreen('video'); return false">Big enough you can't miss it</button>
<p></p>
<video style = 'width: 10px; height: 10px;' id='video' controls>
<source id="webm" src="VIDEO_FILE_URL" type="video/webm">
</video>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.android_webview.test;

import android.test.suitebuilder.annotation.SmallTest;
import android.test.TouchUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.widget.FrameLayout;

import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.test.util.VideoTestWebServer;
import org.chromium.base.test.util.Feature;

import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;

/**
* Test for AwContentClient.GetVideoLoadingProgressView.
*
* This test takes advantage of onViewAttachedToWindow, and assume our progress view
* is shown once it attached to window.
*
* As it needs user gesture to switch to the full screen mode video, A large button
* used to trigger switch occupies almost the whole WebView so the simulated click event
* can't miss it.
*/
public class AwContentsClientGetVideoLoadingProgressViewTest extends AndroidWebViewTestBase
implements View.OnAttachStateChangeListener {
private Object mViewAttachedEvent = new Object();
private boolean mViewAttached = false;

@Override
public void onViewAttachedToWindow(View view) {
synchronized(mViewAttachedEvent) {
mViewAttachedEvent.notify();
mViewAttached = true;
view.removeOnAttachStateChangeListener(this);
}
}

@Override
public void onViewDetachedFromWindow(View arg0) {
}

private void waitForViewAttached() throws InterruptedException {
synchronized(mViewAttachedEvent) {
while (!mViewAttached) {
mViewAttachedEvent.wait();
}
}
}

@Feature({"AndroidWebView"})
@SmallTest
public void testGetVideoLoadingProgressView() throws Throwable {
TestAwContentsClient contentsClient = new TestAwContentsClient() {
@Override
protected View getVideoLoadingProgressView() {
View view = new View(getInstrumentation().getContext());
view.addOnAttachStateChangeListener(
AwContentsClientGetVideoLoadingProgressViewTest.this);
return view;
}

@Override
public void onShowCustomView(View view, int requestedOrientation,
WebChromeClient.CustomViewCallback callback) {
getActivity().getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

getActivity().getWindow().addContentView(view,
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER));
}
};
final AwTestContainerView testContainerView =
createAwTestContainerViewOnMainSync(contentsClient);
final AwContents awContents = testContainerView.getAwContents();
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.getContentViewCore().getContentSettings().setJavaScriptEnabled(true);
}
});
VideoTestWebServer webServer = new VideoTestWebServer();
try {
loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
getData(webServer.getOnePixelOneFrameWebmURL()), "text/html", false);
TouchUtils.clickView(AwContentsClientGetVideoLoadingProgressViewTest.this,
testContainerView);
waitForViewAttached();
} finally {
if (webServer != null) webServer.getTestWebServer().shutdown();
}
}

private String getData(String url) throws IOException {
InputStream in = getInstrumentation().getContext().getAssets().open(
"get_video_loading_progress_view_test.html");
ByteArrayOutputStream os = new ByteArrayOutputStream();
int buflen = 128;
byte[] buffer = new byte[buflen];
int len = in.read(buffer, 0, buflen);
while (len != -1) {
os.write(buffer, 0, len);
if (len < buflen) break;
len = in.read(buffer, 0, buflen);
}
return os.toString().replace("VIDEO_FILE_URL", url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,9 @@ public void onShowCustomView(View view,
@Override
public void onScaleChangedScaled(float oldScale, float newScale) {
}

@Override
protected View getVideoLoadingProgressView() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public ActivityContentVideoViewDelegate(Activity activity) {
this.mActivity = activity;
}

@Override
public void onShowCustomView(View view) {
mActivity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
Expand All @@ -37,31 +38,43 @@ public void onShowCustomView(View view) {
Gravity.CENTER));
}

@Override
public void onDestroyContentVideoView() {
mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

@Override
public Context getContext() {
return mActivity;
}

@Override
public String getPlayBackErrorText() {
return mActivity.getString(R.string.media_player_error_text_invalid_progressive_playback);
}

@Override
public String getUnknownErrorText() {
return mActivity.getString(R.string.media_player_error_text_unknown);
}

@Override
public String getErrorButton() {
return mActivity.getString(R.string.media_player_error_button);
}

@Override
public String getErrorTitle() {
return mActivity.getString(R.string.media_player_error_title);
}

@Override
public String getVideoLoadingText() {
return mActivity.getString(R.string.media_player_loading_video);
}

@Override
public View getVideoLoadingProgressView() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
private VideoSurfaceView mVideoSurfaceView;

// Progress view when the video is loading.
private ProgressView mProgressView;
private View mProgressView;

private Surface mSurface = null;

Expand Down Expand Up @@ -187,7 +187,7 @@ public ContentVideoView(Context context) {
this(context, 0);
}

public ContentVideoView(Context context, int nativeContentVideoView) {
private ContentVideoView(Context context, int nativeContentVideoView) {
super(context);
initResources(context);

Expand All @@ -196,7 +196,6 @@ public ContentVideoView(Context context, int nativeContentVideoView) {

mCurrentBufferPercentage = 0;
mVideoSurfaceView = new VideoSurfaceView(context);
mProgressView = new ProgressView(context);
}

private static void initResources(Context context) {
Expand All @@ -214,6 +213,12 @@ void showContentVideoView() {
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.CENTER);
this.addView(mVideoSurfaceView, layoutParams);
View progressView = sDelegate.getVideoLoadingProgressView();
if (progressView != null) {
mProgressView = progressView;
} else {
mProgressView = new ProgressView(getContext());
}
this.addView(mProgressView, layoutParams);
mVideoSurfaceView.setZOrderOnTop(true);
mVideoSurfaceView.setOnKeyListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public interface ContentVideoViewContextDelegate {
public String getErrorButton();
public String getErrorTitle();
public String getVideoLoadingText();
public View getVideoLoadingProgressView();
}

0 comments on commit 6fe2519

Please sign in to comment.