summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgunsch <gunsch@chromium.org>2015-05-07 15:24:12 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-07 22:25:07 +0000
commit3ea31790faf24c410a330065cb953eab2ecf087d (patch)
tree5c95509fca6a269c2d3003fe5e803508c8694d79
parenteb9ce0de55f3746e59ea805ca954a1be849b3815 (diff)
downloadchromium_src-3ea31790faf24c410a330065cb953eab2ecf087d.zip
chromium_src-3ea31790faf24c410a330065cb953eab2ecf087d.tar.gz
chromium_src-3ea31790faf24c410a330065cb953eab2ecf087d.tar.bz2
Componentizes external_video_surface to reduce webview/Cast duplication.
R=boliu@chromium.org,qinmin@chromium.org,tedchoc@chromium.org,danakj@chromium.org,caitkp@chromium.org BUG=484911 Review URL: https://codereview.chromium.org/1123993002 Cr-Commit-Position: refs/heads/master@{#328859}
-rw-r--r--android_webview/android_webview.gyp1
-rw-r--r--android_webview/javatests/DEPS1
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/ExternalVideoSurfaceContainerTest.java2
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/util/VideoSurfaceViewUtils.java2
-rw-r--r--android_webview/lib/main/aw_main_delegate.cc5
-rw-r--r--android_webview/lib/main/webview_jni_onload.cc5
-rw-r--r--android_webview/native/DEPS1
-rw-r--r--android_webview/native/android_webview_jni_registrar.cc4
-rw-r--r--android_webview/native/webview_native.gyp6
-rw-r--r--chromecast/android/DEPS1
-rw-r--r--chromecast/android/cast_jni_registrar.cc4
-rw-r--r--chromecast/browser/DEPS1
-rw-r--r--chromecast/browser/android/apk/src/org/chromium/chromecast/shell/ExternalVideoSurfaceContainer.java318
-rw-r--r--chromecast/browser/android/external_video_surface_container_impl.cc111
-rw-r--r--chromecast/browser/android/external_video_surface_container_impl.h61
-rw-r--r--chromecast/browser/cast_content_browser_client.cc5
-rw-r--r--chromecast/chromecast.gyp4
-rw-r--r--components/OWNERS3
-rw-r--r--components/components.gyp1
-rw-r--r--components/external_video_surface.gypi49
-rw-r--r--components/external_video_surface/BUILD.gn40
-rw-r--r--components/external_video_surface/DEPS6
-rw-r--r--components/external_video_surface/OWNERS2
-rw-r--r--components/external_video_surface/android/java/src/org/chromium/components/external_video_surface/ExternalVideoSurfaceContainer.java (renamed from android_webview/java/src/org/chromium/android_webview/ExternalVideoSurfaceContainer.java)5
-rw-r--r--components/external_video_surface/browser/android/external_video_surface_container_impl.cc (renamed from android_webview/native/external_video_surface_container_impl.cc)15
-rw-r--r--components/external_video_surface/browser/android/external_video_surface_container_impl.h (renamed from android_webview/native/external_video_surface_container_impl.h)19
-rw-r--r--components/external_video_surface/component_jni_registrar.cc23
-rw-r--r--components/external_video_surface/component_jni_registrar.h17
28 files changed, 184 insertions, 528 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp
index db9b49d..3528246 100644
--- a/android_webview/android_webview.gyp
+++ b/android_webview/android_webview.gyp
@@ -352,6 +352,7 @@
'target_name': 'android_webview_java',
'type': 'none',
'dependencies': [
+ '../components/components.gyp:external_video_surface_java',
'../components/components.gyp:navigation_interception_java',
'../components/components.gyp:web_contents_delegate_android_java',
'../content/content.gyp:content_java',
diff --git a/android_webview/javatests/DEPS b/android_webview/javatests/DEPS
index 799bc5b..12ec677 100644
--- a/android_webview/javatests/DEPS
+++ b/android_webview/javatests/DEPS
@@ -1,4 +1,5 @@
include_rules = [
+ "+components/external_video_surface/android/java",
"+content/public/android/java",
"+content/public/test/android/javatests",
]
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/ExternalVideoSurfaceContainerTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/ExternalVideoSurfaceContainerTest.java
index 762cd47..1c64ca8 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/ExternalVideoSurfaceContainerTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/ExternalVideoSurfaceContainerTest.java
@@ -8,10 +8,10 @@ import android.graphics.RectF;
import android.os.Build;
import android.test.suitebuilder.annotation.SmallTest;
-import org.chromium.android_webview.ExternalVideoSurfaceContainer;
import org.chromium.android_webview.test.util.VideoTestUtil;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
+import org.chromium.components.external_video_surface.ExternalVideoSurfaceContainer;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.CallbackHelper;
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoSurfaceViewUtils.java b/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoSurfaceViewUtils.java
index 0508be4..a0d2d4c 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoSurfaceViewUtils.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoSurfaceViewUtils.java
@@ -9,8 +9,8 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import android.view.View;
import android.view.ViewGroup;
-import org.chromium.android_webview.ExternalVideoSurfaceContainer.NoPunchingSurfaceView;
import org.chromium.android_webview.test.AwTestBase;
+import org.chromium.components.external_video_surface.ExternalVideoSurfaceContainer.NoPunchingSurfaceView;
import org.chromium.content.browser.ContentVideoView;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc
index 8520816..d9cbab8 100644
--- a/android_webview/lib/main/aw_main_delegate.cc
+++ b/android_webview/lib/main/aw_main_delegate.cc
@@ -14,7 +14,6 @@
#include "android_webview/native/aw_quota_manager_bridge_impl.h"
#include "android_webview/native/aw_web_contents_view_delegate.h"
#include "android_webview/native/aw_web_preferences_populater_impl.h"
-#include "android_webview/native/external_video_surface_container_impl.h"
#include "android_webview/native/public/aw_assets.h"
#include "android_webview/renderer/aw_content_renderer_client.h"
#include "base/command_line.h"
@@ -25,6 +24,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_restrictions.h"
#include "cc/base/switches.h"
+#include "components/external_video_surface/browser/android/external_video_surface_container_impl.h"
#include "content/public/browser/android/browser_media_player_manager.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/browser/browser_thread.h"
@@ -195,7 +195,8 @@ AwMessagePortService* AwMainDelegate::CreateAwMessagePortService() {
content::ExternalVideoSurfaceContainer*
AwMainDelegate::CreateExternalVideoSurfaceContainer(
content::WebContents* web_contents) {
- return ExternalVideoSurfaceContainerImpl::Create(web_contents);
+ return external_video_surface::ExternalVideoSurfaceContainerImpl::Create(
+ web_contents);
}
#endif
diff --git a/android_webview/lib/main/webview_jni_onload.cc b/android_webview/lib/main/webview_jni_onload.cc
index e728d62..49d3c63 100644
--- a/android_webview/lib/main/webview_jni_onload.cc
+++ b/android_webview/lib/main/webview_jni_onload.cc
@@ -9,6 +9,7 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/bind.h"
+#include "components/external_video_surface/component_jni_registrar.h"
#include "components/navigation_interception/component_jni_registrar.h"
#include "components/web_contents_delegate_android/component_jni_registrar.h"
#include "content/public/app/content_jni_onload.h"
@@ -21,6 +22,10 @@ namespace {
static base::android::RegistrationMethod
kWebViewDependencyRegisteredMethods[] = {
+#if defined(VIDEO_HOLE)
+ { "ExternalVideoSurfaceContainer",
+ external_video_surface::RegisterExternalVideoSurfaceJni },
+#endif
{ "NavigationInterception",
navigation_interception::RegisterNavigationInterceptionJni },
{ "WebContentsDelegateAndroid",
diff --git a/android_webview/native/DEPS b/android_webview/native/DEPS
index d1c0799..4337129 100644
--- a/android_webview/native/DEPS
+++ b/android_webview/native/DEPS
@@ -13,6 +13,7 @@ include_rules = [
"+components/autofill/core/common",
"+components/data_reduction_proxy/core/browser",
"+components/devtools_http_handler",
+ "+components/external_video_surface",
"+components/navigation_interception",
"+components/user_prefs",
"+components/web_contents_delegate_android",
diff --git a/android_webview/native/android_webview_jni_registrar.cc b/android_webview/native/android_webview_jni_registrar.cc
index 1de8c4c..82b2bc7 100644
--- a/android_webview/native/android_webview_jni_registrar.cc
+++ b/android_webview/native/android_webview_jni_registrar.cc
@@ -22,7 +22,6 @@
#include "android_webview/native/aw_web_contents_delegate.h"
#include "android_webview/native/aw_web_resource_response_impl.h"
#include "android_webview/native/cookie_manager.h"
-#include "android_webview/native/external_video_surface_container_impl.h"
#include "android_webview/native/input_stream_impl.h"
#include "android_webview/native/java_browser_view_renderer_helper.h"
#include "android_webview/native/permission/aw_permission_request.h"
@@ -53,9 +52,6 @@ static base::android::RegistrationMethod kWebViewRegisteredMethods[] = {
{ "AwResource", AwResource::RegisterAwResource },
{ "AwWebContentsDelegate", RegisterAwWebContentsDelegate },
{ "CookieManager", RegisterCookieManager },
-#if defined(VIDEO_HOLE)
- { "ExternalVideoSurfaceContainer", RegisterExternalVideoSurfaceContainer },
-#endif
{ "AwWebResourceResponseImpl", RegisterAwWebResourceResponse },
{ "InputStream", RegisterInputStream },
{ "JavaBrowserViewRendererHelper", RegisterJavaBrowserViewRendererHelper },
diff --git a/android_webview/native/webview_native.gyp b/android_webview/native/webview_native.gyp
index 960dc0f..a7ab2e2 100644
--- a/android_webview/native/webview_native.gyp
+++ b/android_webview/native/webview_native.gyp
@@ -103,9 +103,8 @@
],
'conditions': [
['video_hole==1', {
- 'sources': [
- 'external_video_surface_container_impl.cc',
- 'external_video_surface_container_impl.h',
+ 'dependencies': [
+ '../../components/components.gyp:external_video_surface',
],
}],
],
@@ -142,7 +141,6 @@
'../java/src/org/chromium/android_webview/AwSettings.java',
'../java/src/org/chromium/android_webview/AwWebContentsDelegate.java',
'../java/src/org/chromium/android_webview/AwWebResourceResponse.java',
- '../java/src/org/chromium/android_webview/ExternalVideoSurfaceContainer.java',
'../java/src/org/chromium/android_webview/InputStreamUtil.java',
'../java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java',
'../java/src/org/chromium/android_webview/permission/AwPermissionRequest.java',
diff --git a/chromecast/android/DEPS b/chromecast/android/DEPS
index 9659c05..df718c8 100644
--- a/chromecast/android/DEPS
+++ b/chromecast/android/DEPS
@@ -3,4 +3,5 @@ include_rules = [
"+chromecast/android",
"+chromecast/browser/android",
"+chromecast/crash/android",
+ "+components/external_video_surface",
]
diff --git a/chromecast/android/cast_jni_registrar.cc b/chromecast/android/cast_jni_registrar.cc
index da2f021..ed31dbb 100644
--- a/chromecast/android/cast_jni_registrar.cc
+++ b/chromecast/android/cast_jni_registrar.cc
@@ -8,8 +8,8 @@
#include "base/android/jni_registrar.h"
#include "chromecast/browser/android/cast_window_android.h"
#include "chromecast/browser/android/cast_window_manager.h"
-#include "chromecast/browser/android/external_video_surface_container_impl.h"
#include "chromecast/crash/android/crash_handler.h"
+#include "components/external_video_surface/component_jni_registrar.h"
namespace chromecast {
namespace android {
@@ -21,7 +21,7 @@ static base::android::RegistrationMethod kMethods[] = {
{ "CastWindowManager", shell::RegisterCastWindowManager },
{ "CrashHandler", CrashHandler::RegisterCastCrashJni },
{ "ExternalVideoSurfaceContainer",
- shell::RegisterExternalVideoSurfaceContainer },
+ external_video_surface::RegisterExternalVideoSurfaceJni },
};
} // namespace
diff --git a/chromecast/browser/DEPS b/chromecast/browser/DEPS
index c4a4b0e..4efe5cf 100644
--- a/chromecast/browser/DEPS
+++ b/chromecast/browser/DEPS
@@ -7,6 +7,7 @@ include_rules = [
"+components/crash",
"+components/devtools_discovery",
"+components/devtools_http_handler",
+ "+components/external_video_surface",
"+components/network_hints/browser",
"+content/public/browser",
"+gin/v8_initializer.h",
diff --git a/chromecast/browser/android/apk/src/org/chromium/chromecast/shell/ExternalVideoSurfaceContainer.java b/chromecast/browser/android/apk/src/org/chromium/chromecast/shell/ExternalVideoSurfaceContainer.java
deleted file mode 100644
index 31e3b4f..0000000
--- a/chromecast/browser/android/apk/src/org/chromium/chromecast/shell/ExternalVideoSurfaceContainer.java
+++ /dev/null
@@ -1,318 +0,0 @@
-// Copyright 2014 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.chromecast.shell;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.ViewGroup;
-
-import org.chromium.base.CalledByNative;
-import org.chromium.base.JNINamespace;
-import org.chromium.base.VisibleForTesting;
-import org.chromium.content.browser.ContainerViewObserver;
-import org.chromium.content.browser.ContentViewCore;
-import org.chromium.content.browser.RenderCoordinates;
-
-import java.lang.ref.WeakReference;
-
-//TODO(gunsch): componentize this class.
-/**
- * This is a container for external video surfaces.
- * The object is owned by the native peer and it is owned by WebContents.
- *
- * The expected behavior of the media player on the video hole punching is as follows.
- * 1) If it requests the surface, it will call requestExternalVideoSurface().
- * When the resolution of the video is changed, it'll call requestExternalVideoSurface().
- * 2) Whenever the size or the position of the video element is changed, it'll notify through
- * onExternalVideoSurfacePositionChanged().
- * 3) Whenever the page that contains the video element is scrolled or zoomed,
- * onFrameInfoUpdated() will be called.
- * 4) Usually steps 1) ~ 3) are repeated during the playback.
- * 5) If the player no longer needs the surface any more, it'll call
- * releaseExternalVideoSurface().
- *
- * Please contact ycheo@chromium.org or wonsik@chromium.org if you have any
- * questions or issues for this class.
- *
- * Note(gunsch): This class was copied wholesale from android_webview/native
- * for the use of chromecast/. Owners of content/ have expressed not wanting
- * this code in content/ to discourage usage, since they don't plan to support
- * hole-punching long term. In the meantime, this copy is a workaround to avoid
- * a dependency on android_webview.
- */
-@JNINamespace("chromecast::shell")
-public class ExternalVideoSurfaceContainer implements SurfaceHolder.Callback {
- protected static final int INVALID_PLAYER_ID = -1;
-
- /**
- * Because WebView does hole-punching by itself, instead, the hole-punching logic
- * in SurfaceView can clear out some web elements like media control or subtitle.
- * So we need to disable its hole-punching logic.
- */
- @VisibleForTesting
- public static class NoPunchingSurfaceView extends SurfaceView {
- public NoPunchingSurfaceView(Context context) {
- super(context);
- }
- // SurfaceView.dispatchDraw implementation punches a hole in the view hierarchy.
- // Disable this by making this a no-op.
- @Override
- protected void dispatchDraw(Canvas canvas) {}
- }
-
- // There can be at most 1 external video surface for now.
- // If there are the multiple requests for the surface, then the second video will
- // kick the first one off.
- // To support the mulitple video surfaces seems impractical, because z-order between
- // the multiple SurfaceViews is non-deterministic.
- private static WeakReference<ExternalVideoSurfaceContainer> sActiveContainer =
- new WeakReference<ExternalVideoSurfaceContainer>(null);
-
- private final long mNativeExternalVideoSurfaceContainer;
- private final ContentViewCore mContentViewCore;
- private ViewGroup mContainerView;
- private ContainerViewObserver mContainerViewObserver;
- private int mPlayerId = INVALID_PLAYER_ID;
- private SurfaceView mSurfaceView;
-
- // The absolute CSS coordinates of the video element.
- private float mLeft;
- private float mTop;
- private float mRight;
- private float mBottom;
-
- // The physical location/size of the external video surface in pixels.
- private int mX;
- private int mY;
- private int mWidth;
- private int mHeight;
-
- /**
- * Factory class to facilitate dependency injection.
- */
- public static class Factory {
- public ExternalVideoSurfaceContainer create(
- long nativeExternalVideoSurfaceContainer, ContentViewCore contentViewCore) {
- return new ExternalVideoSurfaceContainer(
- nativeExternalVideoSurfaceContainer, contentViewCore);
- }
- }
- private static Factory sFactory = new Factory();
-
- @VisibleForTesting
- public static void setFactory(Factory factory) {
- sFactory = factory;
- }
-
- @CalledByNative
- private static ExternalVideoSurfaceContainer create(
- long nativeExternalVideoSurfaceContainer, ContentViewCore contentViewCore) {
- return sFactory.create(nativeExternalVideoSurfaceContainer, contentViewCore);
- }
-
- protected ExternalVideoSurfaceContainer(
- long nativeExternalVideoSurfaceContainer, ContentViewCore contentViewCore) {
- assert contentViewCore != null;
- mNativeExternalVideoSurfaceContainer = nativeExternalVideoSurfaceContainer;
- mContentViewCore = contentViewCore;
- initializeCurrentPositionOfSurfaceView();
- }
-
- /**
- * Called when a media player wants to request an external video surface.
- * @param playerId The ID of the media player.
- */
- @CalledByNative
- protected void requestExternalVideoSurface(int playerId) {
- assert playerId != INVALID_PLAYER_ID;
-
- if (mPlayerId == playerId) return;
-
- setActiveContainer(this);
-
- mPlayerId = playerId;
- initializeCurrentPositionOfSurfaceView();
-
- createSurfaceView();
- }
-
- /**
- * Returns id of player currently using the external video surface.
- */
- @CalledByNative
- protected int getCurrentPlayerId() {
- return mPlayerId;
- }
-
- /**
- * Called when a media player wants to release an external video surface.
- * @param playerId The ID of the media player.
- */
- @CalledByNative
- protected void releaseExternalVideoSurface(int playerId) {
- if (mPlayerId != playerId) return;
-
- releaseIfActiveContainer(this);
-
- mPlayerId = INVALID_PLAYER_ID;
- }
-
- @CalledByNative
- protected void destroy() {
- releaseExternalVideoSurface(mPlayerId);
- }
-
- private void initializeCurrentPositionOfSurfaceView() {
- mX = Integer.MIN_VALUE;
- mY = Integer.MIN_VALUE;
- mWidth = 0;
- mHeight = 0;
- }
-
- private static void setActiveContainer(ExternalVideoSurfaceContainer container) {
- ExternalVideoSurfaceContainer activeContainer = sActiveContainer.get();
- if (activeContainer != null) {
- activeContainer.removeSurfaceView();
- }
- sActiveContainer = new WeakReference<ExternalVideoSurfaceContainer>(container);
- }
-
- private static void releaseIfActiveContainer(ExternalVideoSurfaceContainer container) {
- ExternalVideoSurfaceContainer activeContainer = sActiveContainer.get();
- if (activeContainer == container) {
- setActiveContainer(null);
- }
- }
-
- private void createSurfaceView() {
- assert mSurfaceView == null;
- assert mContainerView == null;
- assert mContainerViewObserver == null;
-
- mSurfaceView = new NoPunchingSurfaceView(mContentViewCore.getContext());
- mSurfaceView.getHolder().addCallback(this);
- // SurfaceHoder.surfaceCreated() will be called after the SurfaceView is attached to
- // the Window and becomes visible.
- mContainerView = mContentViewCore.getContainerView();
- mContainerView.addView(mSurfaceView);
- mContainerViewObserver = new ContainerViewObserver() {
- @Override
- public void onContainerViewChanged(ViewGroup newContainerView) {
- mContainerView.removeView(mSurfaceView);
- mContainerView = newContainerView;
- mContainerView.addView(mSurfaceView);
- }
- };
- mContentViewCore.addContainerViewObserver(mContainerViewObserver);
- }
-
- private void removeSurfaceView() {
- assert mSurfaceView != null;
- assert mContainerView != null;
- assert mContainerViewObserver != null;
-
- // SurfaceHoder.surfaceDestroyed() will be called in ViewGroup.removeView()
- // as soon as the SurfaceView is detached from the Window.
- mContentViewCore.removeContainerViewObserver(mContainerViewObserver);
- mContainerView.removeView(mSurfaceView);
-
- mContainerViewObserver = null;
- mSurfaceView = null;
- mContainerView = null;
- }
-
- /**
- * Called when the position of the video element which uses the external
- * video surface is changed.
- * @param playerId The ID of the media player.
- * @param left The absolute CSS X coordinate of the left side of the video element.
- * @param top The absolute CSS Y coordinate of the top side of the video element.
- * @param right The absolute CSS X coordinate of the right side of the video element.
- * @param bottom The absolute CSS Y coordinate of the bottom side of the video element.
- */
- @CalledByNative
- protected void onExternalVideoSurfacePositionChanged(
- int playerId, float left, float top, float right, float bottom) {
- if (mPlayerId != playerId) return;
-
- mLeft = left;
- mTop = top;
- mRight = right;
- mBottom = bottom;
-
- layOutSurfaceView();
- }
-
- /**
- * Called when the page that contains the video element is scrolled or zoomed.
- */
- @CalledByNative
- protected void onFrameInfoUpdated() {
- if (mPlayerId == INVALID_PLAYER_ID) return;
-
- layOutSurfaceView();
- }
-
- private void layOutSurfaceView() {
- RenderCoordinates renderCoordinates = mContentViewCore.getRenderCoordinates();
- RenderCoordinates.NormalizedPoint topLeft = renderCoordinates.createNormalizedPoint();
- RenderCoordinates.NormalizedPoint bottomRight = renderCoordinates.createNormalizedPoint();
- topLeft.setAbsoluteCss(mLeft, mTop);
- bottomRight.setAbsoluteCss(mRight, mBottom);
- float top = topLeft.getYPix();
- float left = topLeft.getXPix();
- float bottom = bottomRight.getYPix();
- float right = bottomRight.getXPix();
-
- int x = Math.round(left + renderCoordinates.getScrollXPix());
- int y = Math.round(top + renderCoordinates.getScrollYPix());
- int width = Math.round(right - left);
- int height = Math.round(bottom - top);
- if (mX == x && mY == y && mWidth == width && mHeight == height) return;
- mX = x;
- mY = y;
- mWidth = width;
- mHeight = height;
-
- mSurfaceView.setX(x);
- mSurfaceView.setY(y);
- ViewGroup.LayoutParams layoutParams = mSurfaceView.getLayoutParams();
- layoutParams.width = width;
- layoutParams.height = height;
- mSurfaceView.requestLayout();
- }
-
- // SurfaceHolder.Callback methods.
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
-
- @Override
- // surfaceCreated() callback can be called regardless of requestExternalVideoSurface,
- // if the activity comes back from the background and becomes visible.
- public void surfaceCreated(SurfaceHolder holder) {
- if (mPlayerId != INVALID_PLAYER_ID) {
- nativeSurfaceCreated(
- mNativeExternalVideoSurfaceContainer, mPlayerId, holder.getSurface());
- }
- }
-
- // surfaceDestroyed() callback can be called regardless of releaseExternalVideoSurface,
- // if the activity moves to the backgound and becomes invisible.
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- if (mPlayerId != INVALID_PLAYER_ID) {
- nativeSurfaceDestroyed(mNativeExternalVideoSurfaceContainer, mPlayerId);
- }
- }
-
- private native void nativeSurfaceCreated(
- long nativeExternalVideoSurfaceContainerImpl, int playerId, Surface surface);
-
- private native void nativeSurfaceDestroyed(
- long nativeExternalVideoSurfaceContainerImpl, int playerId);
-}
diff --git a/chromecast/browser/android/external_video_surface_container_impl.cc b/chromecast/browser/android/external_video_surface_container_impl.cc
deleted file mode 100644
index e830575..0000000
--- a/chromecast/browser/android/external_video_surface_container_impl.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2014 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.
-
-#include "chromecast/browser/android/external_video_surface_container_impl.h"
-
-#include "base/android/jni_android.h"
-#include "content/public/browser/android/content_view_core.h"
-#include "jni/ExternalVideoSurfaceContainer_jni.h"
-#include "ui/gfx/geometry/rect_f.h"
-
-namespace chromecast {
-namespace shell {
-// static
-ExternalVideoSurfaceContainerImpl* ExternalVideoSurfaceContainerImpl::Create(
- content::WebContents* web_contents) {
- content::ContentViewCore* cvc =
- content::ContentViewCore::FromWebContents(web_contents);
- if (!cvc)
- return nullptr;
- base::android::ScopedJavaLocalRef<jobject> jcvc = cvc->GetJavaObject();
- if (jcvc.is_null())
- return nullptr;
- return new ExternalVideoSurfaceContainerImpl(jcvc);
-}
-
-ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl(
- base::android::ScopedJavaLocalRef<jobject> java_content_view_core) {
- JNIEnv* env = base::android::AttachCurrentThread();
- jobject_.Reset(Java_ExternalVideoSurfaceContainer_create(
- env, reinterpret_cast<intptr_t>(this), java_content_view_core.obj()));
-}
-
-ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() {
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj());
- jobject_.Reset();
-}
-
-void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface(
- int player_id,
- const SurfaceCreatedCB& surface_created_cb,
- const SurfaceDestroyedCB& surface_destroyed_cb) {
- surface_created_cb_ = surface_created_cb;
- surface_destroyed_cb_ = surface_destroyed_cb;
-
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_ExternalVideoSurfaceContainer_requestExternalVideoSurface(
- env, jobject_.obj(), static_cast<jint>(player_id));
-}
-
-int ExternalVideoSurfaceContainerImpl::GetCurrentPlayerId() {
- JNIEnv* env = base::android::AttachCurrentThread();
-
- int current_player = static_cast<int>(
- Java_ExternalVideoSurfaceContainer_getCurrentPlayerId(
- env, jobject_.obj()));
-
- if (current_player < 0)
- return kInvalidPlayerId;
- else
- return current_player;
-}
-
-void ExternalVideoSurfaceContainerImpl::ReleaseExternalVideoSurface(
- int player_id) {
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_ExternalVideoSurfaceContainer_releaseExternalVideoSurface(
- env, jobject_.obj(), static_cast<jint>(player_id));
-
- surface_created_cb_.Reset();
- surface_destroyed_cb_.Reset();
-}
-
-void ExternalVideoSurfaceContainerImpl::OnFrameInfoUpdated() {
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_ExternalVideoSurfaceContainer_onFrameInfoUpdated(env, jobject_.obj());
-}
-
-void ExternalVideoSurfaceContainerImpl::OnExternalVideoSurfacePositionChanged(
- int player_id, const gfx::RectF& rect) {
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_ExternalVideoSurfaceContainer_onExternalVideoSurfacePositionChanged(
- env,
- jobject_.obj(),
- static_cast<jint>(player_id),
- static_cast<jfloat>(rect.x()),
- static_cast<jfloat>(rect.y()),
- static_cast<jfloat>(rect.x() + rect.width()),
- static_cast<jfloat>(rect.y() + rect.height()));
-}
-
-// Methods called from Java.
-void ExternalVideoSurfaceContainerImpl::SurfaceCreated(
- JNIEnv* env, jobject obj, jint player_id, jobject jsurface) {
- if (!surface_created_cb_.is_null())
- surface_created_cb_.Run(static_cast<int>(player_id), jsurface);
-}
-
-void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed(
- JNIEnv* env, jobject obj, jint player_id) {
- if (!surface_destroyed_cb_.is_null())
- surface_destroyed_cb_.Run(static_cast<int>(player_id));
-}
-
-bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-} // namespace shell
-} // namespace chromecast
diff --git a/chromecast/browser/android/external_video_surface_container_impl.h b/chromecast/browser/android/external_video_surface_container_impl.h
deleted file mode 100644
index d864d06..0000000
--- a/chromecast/browser/android/external_video_surface_container_impl.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef CHROMECAST_BROWSER_ANDROID_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
-#define CHROMECAST_BROWSER_ANDROID_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
-
-#include <jni.h>
-
-#include "base/android/scoped_java_ref.h"
-#include "base/callback.h"
-#include "base/compiler_specific.h"
-#include "content/public/browser/android/external_video_surface_container.h"
-
-namespace chromecast {
-namespace shell {
-
-class ExternalVideoSurfaceContainerImpl
- : public content::ExternalVideoSurfaceContainer {
- public:
- typedef base::Callback<void(int, jobject)> SurfaceCreatedCB;
- typedef base::Callback<void(int)> SurfaceDestroyedCB;
-
- static ExternalVideoSurfaceContainerImpl* Create(
- content::WebContents* web_contents);
-
- // ExternalVideoSurfaceContainer implementation.
- void RequestExternalVideoSurface(
- int player_id,
- const SurfaceCreatedCB& surface_created_cb,
- const SurfaceDestroyedCB& surface_destroyed_cb) override;
- int GetCurrentPlayerId() override;
- void ReleaseExternalVideoSurface(int player_id) override;
- void OnFrameInfoUpdated() override;
- void OnExternalVideoSurfacePositionChanged(
- int player_id, const gfx::RectF& rect) override;
-
- // Methods called from Java.
- void SurfaceCreated(
- JNIEnv* env, jobject obj, jint player_id, jobject jsurface);
- void SurfaceDestroyed(JNIEnv* env, jobject obj, jint player_id);
-
- private:
- explicit ExternalVideoSurfaceContainerImpl(
- base::android::ScopedJavaLocalRef<jobject> java_content_view_core);
- ~ExternalVideoSurfaceContainerImpl() override;
-
- base::android::ScopedJavaGlobalRef<jobject> jobject_;
-
- SurfaceCreatedCB surface_created_cb_;
- SurfaceDestroyedCB surface_destroyed_cb_;
-
- DISALLOW_COPY_AND_ASSIGN(ExternalVideoSurfaceContainerImpl);
-};
-
-bool RegisterExternalVideoSurfaceContainer(JNIEnv* env);
-
-} // namespace shell
-} // namespace chromecast
-
-#endif // CHROMECAST_BROWSER_ANDROID_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
diff --git a/chromecast/browser/cast_content_browser_client.cc b/chromecast/browser/cast_content_browser_client.cc
index a6178e4..3e075fa 100644
--- a/chromecast/browser/cast_content_browser_client.cc
+++ b/chromecast/browser/cast_content_browser_client.cc
@@ -44,8 +44,8 @@
#include "ui/gl/gl_switches.h"
#if defined(OS_ANDROID)
-#include "chromecast/browser/android/external_video_surface_container_impl.h"
#include "components/crash/browser/crash_dump_manager_android.h"
+#include "components/external_video_surface/browser/android/external_video_surface_container_impl.h"
#endif // defined(OS_ANDROID)
namespace chromecast {
@@ -375,7 +375,8 @@ void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
content::ExternalVideoSurfaceContainer*
CastContentBrowserClient::OverrideCreateExternalVideoSurfaceContainer(
content::WebContents* web_contents) {
- return ExternalVideoSurfaceContainerImpl::Create(web_contents);
+ return external_video_surface::ExternalVideoSurfaceContainerImpl::Create(
+ web_contents);
}
#endif // defined(OS_ANDROID) && defined(VIDEO_HOLE)
diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp
index 45532d8..258812d 100644
--- a/chromecast/chromecast.gyp
+++ b/chromecast/chromecast.gyp
@@ -425,6 +425,7 @@
'../breakpad/breakpad.gyp:breakpad_client',
'../components/components.gyp:breakpad_host',
'../components/components.gyp:crash_component',
+ '../components/components.gyp:external_video_surface',
'../content/content.gyp:content',
'../skia/skia.gyp:skia',
'../ui/gfx/gfx.gyp:gfx',
@@ -444,8 +445,6 @@
'browser/android/cast_window_android.h',
'browser/android/cast_window_manager.cc',
'browser/android/cast_window_manager.h',
- 'browser/android/external_video_surface_container_impl.cc',
- 'browser/android/external_video_surface_container_impl.h',
'crash/android/cast_crash_reporter_client_android.cc',
'crash/android/cast_crash_reporter_client_android.h',
'crash/android/crash_handler.cc',
@@ -524,7 +523,6 @@
'browser/android/apk/src/org/chromium/chromecast/shell/CastCrashHandler.java',
'browser/android/apk/src/org/chromium/chromecast/shell/CastWindowAndroid.java',
'browser/android/apk/src/org/chromium/chromecast/shell/CastWindowManager.java',
- 'browser/android/apk/src/org/chromium/chromecast/shell/ExternalVideoSurfaceContainer.java',
],
'direct_dependent_settings': {
'include_dirs': [
diff --git a/components/OWNERS b/components/OWNERS
index 0c5f5f5..73dcea1 100644
--- a/components/OWNERS
+++ b/components/OWNERS
@@ -91,6 +91,9 @@ per-file enhanced_bookmarks*=sky@chromium.org
per-file error_page*=mmenke@chromium.org
per-file error_page*=ttuttle@chromium.org
+per-file external_video_surface.gypi=boliu@chromium.org
+per-file external_video_surface.gypi=qinmin@chromium.org
+
per-file favicon*=pkotwicz@chromium.org
per-file favicon*=sky@chromium.org
per-file favicon*=stevenjb@chromium.org
diff --git a/components/components.gyp b/components/components.gyp
index b59e82c..0bdfebb 100644
--- a/components/components.gyp
+++ b/components/components.gyp
@@ -81,6 +81,7 @@
'conditions': [
['OS == "android"', {
'includes': [
+ 'external_video_surface.gypi',
'service_tab_launcher.gypi',
],
}],
diff --git a/components/external_video_surface.gypi b/components/external_video_surface.gypi
new file mode 100644
index 0000000..b6abe3d
--- /dev/null
+++ b/components/external_video_surface.gypi
@@ -0,0 +1,49 @@
+# Copyright 2015 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.
+
+{
+ 'variables': {
+ 'chromium_code': 1
+ },
+ 'targets': [
+ {
+ 'target_name': 'external_video_surface',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../content/content.gyp:content_browser',
+ 'external_video_surface_jni_headers',
+ ],
+ 'sources': [
+ 'external_video_surface/browser/android/external_video_surface_container_impl.cc',
+ 'external_video_surface/browser/android/external_video_surface_container_impl.h',
+ 'external_video_surface/component_jni_registrar.cc',
+ 'external_video_surface/component_jni_registrar.h',
+ ],
+ },
+ {
+ 'target_name': 'external_video_surface_java',
+ 'type': 'none',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../content/content.gyp:content_java',
+ ],
+ 'variables': {
+ 'java_in_dir': 'external_video_surface/android/java',
+ },
+ 'includes': [ '../build/java.gypi' ],
+ },
+ {
+ 'target_name': 'external_video_surface_jni_headers',
+ 'type': 'none',
+ 'sources': [
+ 'external_video_surface/android/java/src/org/chromium/components/external_video_surface/ExternalVideoSurfaceContainer.java',
+ ],
+ 'variables': {
+ 'jni_gen_package': 'external_video_surface',
+ },
+ 'includes': [ '../build/jni_generator.gypi' ],
+ },
+ ],
+}
diff --git a/components/external_video_surface/BUILD.gn b/components/external_video_surface/BUILD.gn
new file mode 100644
index 0000000..553234a
--- /dev/null
+++ b/components/external_video_surface/BUILD.gn
@@ -0,0 +1,40 @@
+# Copyright 2015 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.
+
+if (is_android) {
+ import("//build/config/android/rules.gni")
+}
+
+static_library("external_video_surface") {
+ if (is_android) {
+ sources += [
+ "browser/android/external_video_surface_container_impl.cc",
+ "browser/android/external_video_surface_container_impl.h",
+ "component_jni_registrar.cc",
+ "component_jni_registrar.h",
+ ]
+
+ deps = [
+ ":jni_headers",
+ "//base",
+ "//content/public/browser",
+ ]
+ }
+}
+
+if (is_android) {
+ android_library("java") {
+ java_files = [ "android/java/src/org/chromium/components/external_video_surface/ExternalVideoSurfaceContainer.java" ]
+ deps = [
+ "//base:base_java",
+ "//content/public/android:content_java",
+ ]
+ }
+ generate_jni("jni_headers") {
+ sources = [
+ "android/java/src/org/chromium/components/external_video_surface/ExternalVideoSurfaceContainer.java",
+ ]
+ jni_package = "external_video_surface"
+ }
+}
diff --git a/components/external_video_surface/DEPS b/components/external_video_surface/DEPS
new file mode 100644
index 0000000..f9011b6
--- /dev/null
+++ b/components/external_video_surface/DEPS
@@ -0,0 +1,6 @@
+include_rules = [
+ "+content/public/android/java/src/org/chromium/content/browser",
+ "+content/public/browser/android",
+ "+jni",
+ "+ui/gfx/geometry",
+]
diff --git a/components/external_video_surface/OWNERS b/components/external_video_surface/OWNERS
new file mode 100644
index 0000000..c77681b
--- /dev/null
+++ b/components/external_video_surface/OWNERS
@@ -0,0 +1,2 @@
+boliu@chromium.org
+qinmin@chromium.org
diff --git a/android_webview/java/src/org/chromium/android_webview/ExternalVideoSurfaceContainer.java b/components/external_video_surface/android/java/src/org/chromium/components/external_video_surface/ExternalVideoSurfaceContainer.java
index 45e7af7..baa2a69 100644
--- a/android_webview/java/src/org/chromium/android_webview/ExternalVideoSurfaceContainer.java
+++ b/components/external_video_surface/android/java/src/org/chromium/components/external_video_surface/ExternalVideoSurfaceContainer.java
@@ -2,7 +2,7 @@
// 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;
+package org.chromium.components.external_video_surface;
import android.content.Context;
import android.graphics.Canvas;
@@ -20,7 +20,6 @@ import org.chromium.content.browser.RenderCoordinates;
import java.lang.ref.WeakReference;
-// TODO(gunsch): componentize this class.
/**
* This is a container for external video surfaces.
* The object is owned by the native peer and it is owned by WebContents.
@@ -39,7 +38,7 @@ import java.lang.ref.WeakReference;
* Please contact ycheo@chromium.org or wonsik@chromium.org if you have any
* questions or issues for this class.
*/
-@JNINamespace("android_webview")
+@JNINamespace("external_video_surface")
public class ExternalVideoSurfaceContainer implements SurfaceHolder.Callback {
protected static final int INVALID_PLAYER_ID = -1;
diff --git a/android_webview/native/external_video_surface_container_impl.cc b/components/external_video_surface/browser/android/external_video_surface_container_impl.cc
index 64270ef..c707425 100644
--- a/android_webview/native/external_video_surface_container_impl.cc
+++ b/components/external_video_surface/browser/android/external_video_surface_container_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "android_webview/native/external_video_surface_container_impl.h"
+#include "components/external_video_surface/browser/android/external_video_surface_container_impl.h"
#include "base/android/jni_android.h"
#include "content/public/browser/android/content_view_core.h"
@@ -12,7 +12,12 @@
using base::android::AttachCurrentThread;
using content::ContentViewCore;
-namespace android_webview {
+namespace external_video_surface {
+
+// static
+bool ExternalVideoSurfaceContainerImpl::RegisterJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
// static
ExternalVideoSurfaceContainerImpl* ExternalVideoSurfaceContainerImpl::Create(
@@ -105,8 +110,4 @@ void ExternalVideoSurfaceContainerImpl::SurfaceDestroyed(
surface_destroyed_cb_.Run(static_cast<int>(player_id));
}
-bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-} // namespace android_webview
+} // namespace external_video_surface
diff --git a/android_webview/native/external_video_surface_container_impl.h b/components/external_video_surface/browser/android/external_video_surface_container_impl.h
index 48ccd94..10d0471 100644
--- a/android_webview/native/external_video_surface_container_impl.h
+++ b/components/external_video_surface/browser/android/external_video_surface_container_impl.h
@@ -2,28 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef ANDROID_WEBVIEW_NATIVE_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
-#define ANDROID_WEBVIEW_NATIVE_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
+#ifndef COMPONENTS_EXTERNAL_VIDEO_SURFACE_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
+#define COMPONENTS_EXTERNAL_VIDEO_SURFACE_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
#include <jni.h>
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/macros.h"
#include "content/public/browser/android/external_video_surface_container.h"
-namespace android_webview {
+namespace external_video_surface {
class ExternalVideoSurfaceContainerImpl
: public content::ExternalVideoSurfaceContainer {
public:
+ static bool RegisterJni(JNIEnv* env);
+
typedef base::Callback<void(int, jobject)> SurfaceCreatedCB;
typedef base::Callback<void(int)> SurfaceDestroyedCB;
static ExternalVideoSurfaceContainerImpl* Create(
content::WebContents* web_contents);
- // ExternalVideoSurfaceContainer implementation.
+ // content::ExternalVideoSurfaceContainer implementation.
void RequestExternalVideoSurface(
int player_id,
const SurfaceCreatedCB& surface_created_cb,
@@ -49,11 +52,9 @@ class ExternalVideoSurfaceContainerImpl
SurfaceCreatedCB surface_created_cb_;
SurfaceDestroyedCB surface_destroyed_cb_;
- DISALLOW_COPY_AND_ASSIGN(ExternalVideoSurfaceContainerImpl);
+ DISALLOW_COPY_AND_ASSIGN(ExternalVideoSurfaceContainerImpl);
};
-bool RegisterExternalVideoSurfaceContainer(JNIEnv* env);
-
-} // namespace android_webview
+} // namespace external_video_surface
-#endif // ANDROID_WEBVIEW_NATIVE_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
+#endif // COMPONENTS_EXTERNAL_VIDEO_SURFACE_EXTERNAL_VIDEO_SURFACE_CONTAINER_IMPL_H_
diff --git a/components/external_video_surface/component_jni_registrar.cc b/components/external_video_surface/component_jni_registrar.cc
new file mode 100644
index 0000000..98e9029
--- /dev/null
+++ b/components/external_video_surface/component_jni_registrar.cc
@@ -0,0 +1,23 @@
+// Copyright 2015 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.
+
+#include "components/external_video_surface/component_jni_registrar.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "components/external_video_surface/browser/android/external_video_surface_container_impl.h"
+
+namespace external_video_surface {
+
+static base::android::RegistrationMethod kComponentRegisteredMethods[] = {
+ { "ExternalVideoSurface", ExternalVideoSurfaceContainerImpl::RegisterJni },
+};
+
+bool RegisterExternalVideoSurfaceJni(JNIEnv* env) {
+ return RegisterNativeMethods(env,
+ kComponentRegisteredMethods, arraysize(kComponentRegisteredMethods));
+}
+
+} // namespace external_video_surface
+
diff --git a/components/external_video_surface/component_jni_registrar.h b/components/external_video_surface/component_jni_registrar.h
new file mode 100644
index 0000000..f1578cb
--- /dev/null
+++ b/components/external_video_surface/component_jni_registrar.h
@@ -0,0 +1,17 @@
+// Copyright 2015 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.
+
+#ifndef COMPONENTS_EXTERNAL_VIDEO_SURFACE_COMPONENT_JNI_REGISTRAR_H_
+#define COMPONENTS_EXTERNAL_VIDEO_SURFACE_COMPONENT_JNI_REGISTRAR_H_
+
+#include <jni.h>
+
+namespace external_video_surface {
+
+// Register all JNI bindings necessary for the external_video_surface component.
+bool RegisterExternalVideoSurfaceJni(JNIEnv* env);
+
+} // namespace external_video_surface
+
+#endif // COMPONENTS_EXTERNAL_VIDEO_SURFACE_COMPONENT_JNI_REGISTRAR_H_