Commit a2e73cd3 authored by Jan Lamecki's avatar Jan Lamecki Committed by Commit Bot

Remove dependency on Activity from CastWebContentsSurfaceHelper.

Bug: internal b/112463440.
Change-Id: I6c652d45c1e5b6343f04932a9afe0b9731546207
Reviewed-on: https://chromium-review.googlesource.com/c/1344059
Commit-Queue: Jan Lamecki <jachor@google.com>
Reviewed-by: default avatarSimeon Anfinrud <sanfin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609987}
parent b9df950d
...@@ -88,7 +88,7 @@ public class CastWebContentsActivity extends Activity { ...@@ -88,7 +88,7 @@ public class CastWebContentsActivity extends Activity {
setContentView(R.layout.cast_web_contents_activity); setContentView(R.layout.cast_web_contents_activity);
mSurfaceHelperState.set(new CastWebContentsSurfaceHelper(this /* hostActivity */, mSurfaceHelperState.set(new CastWebContentsSurfaceHelper(
CastWebContentsScopes.onLayoutActivity(this, CastWebContentsScopes.onLayoutActivity(this,
(FrameLayout) findViewById(R.id.web_contents_container), (FrameLayout) findViewById(R.id.web_contents_container),
CastSwitches.getSwitchValueColor( CastSwitches.getSwitchValueColor(
...@@ -168,6 +168,11 @@ public class CastWebContentsActivity extends Activity { ...@@ -168,6 +168,11 @@ public class CastWebContentsActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mCreatedState.set(Unit.unit()); mCreatedState.set(Unit.unit());
mGotIntentState.set(getIntent()); mGotIntentState.set(getIntent());
// Whenever our app is visible, volume controls should modify the music stream.
// For more information read:
// http://developer.android.com/training/managing-audio/volume-playback.html
setVolumeControlStream(AudioManager.STREAM_MUSIC);
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ import android.app.Fragment; ...@@ -8,6 +8,7 @@ import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -87,7 +88,7 @@ public class CastWebContentsFragment extends Fragment { ...@@ -87,7 +88,7 @@ public class CastWebContentsFragment extends Fragment {
return; return;
} }
mSurfaceHelper = new CastWebContentsSurfaceHelper(/* hostActivity= */ getActivity(), mSurfaceHelper = new CastWebContentsSurfaceHelper(
CastWebContentsScopes.onLayoutFragment(getActivity(), CastWebContentsScopes.onLayoutFragment(getActivity(),
(FrameLayout) getView().findViewById(R.id.web_contents_container), (FrameLayout) getView().findViewById(R.id.web_contents_container),
CastSwitches.getSwitchValueColor( CastSwitches.getSwitchValueColor(
...@@ -102,6 +103,11 @@ public class CastWebContentsFragment extends Fragment { ...@@ -102,6 +103,11 @@ public class CastWebContentsFragment extends Fragment {
mAppId = CastWebContentsIntentUtils.getAppId(bundle); mAppId = CastWebContentsIntentUtils.getAppId(bundle);
mInitialVisiblityPriority = CastWebContentsIntentUtils.getVisibilityPriority(bundle); mInitialVisiblityPriority = CastWebContentsIntentUtils.getVisibilityPriority(bundle);
mSurfaceHelper.onNewStartParams(params); mSurfaceHelper.onNewStartParams(params);
// Whenever our app is visible, volume controls should modify the music stream.
// For more information read:
// http://developer.android.com/training/managing-audio/volume-playback.html
getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
} }
@Override @Override
......
...@@ -33,10 +33,10 @@ class CastWebContentsScopes { ...@@ -33,10 +33,10 @@ class CastWebContentsScopes {
return onLayoutInternal(activity, layout, window, backgroundColor); return onLayoutInternal(activity, layout, window, backgroundColor);
} }
private static Observer<WebContents> onLayoutInternal(Activity activity, FrameLayout layout, private static Observer<WebContents> onLayoutInternal(Context context, FrameLayout layout,
WindowAndroid window, @ColorInt int backgroundColor) { WindowAndroid window, @ColorInt int backgroundColor) {
return (WebContents webContents) -> { return (WebContents webContents) -> {
ContentViewRenderView contentViewRenderView = new ContentViewRenderView(activity) { ContentViewRenderView contentViewRenderView = new ContentViewRenderView(context) {
@Override @Override
protected void onReadyToRender() { protected void onReadyToRender() {
setOverlayVideoMode(true); setOverlayVideoMode(true);
...@@ -48,7 +48,7 @@ class CastWebContentsScopes { ...@@ -48,7 +48,7 @@ class CastWebContentsScopes {
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
layout.addView(contentViewRenderView, matchParent); layout.addView(contentViewRenderView, matchParent);
ContentView contentView = ContentView.createContentView(activity, webContents); ContentView contentView = ContentView.createContentView(context, webContents);
// TODO(derekjchow): productVersion // TODO(derekjchow): productVersion
webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(contentView), webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(contentView),
contentView, window, WebContents.createDefaultInternalsHolder()); contentView, window, WebContents.createDefaultInternalsHolder());
......
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
package org.chromium.chromecast.shell; package org.chromium.chromecast.shell;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
...@@ -103,12 +101,11 @@ class CastWebContentsSurfaceHelper { ...@@ -103,12 +101,11 @@ class CastWebContentsSurfaceHelper {
} }
/** /**
* @param hostActivity Activity hosts the view showing WebContents
* @param webContentsView A Observer that displays incoming WebContents. * @param webContentsView A Observer that displays incoming WebContents.
* @param finishCallback Invoked to tell host to finish. * @param finishCallback Invoked to tell host to finish.
*/ */
CastWebContentsSurfaceHelper(Activity hostActivity, Observer<WebContents> webContentsView, CastWebContentsSurfaceHelper(
Consumer<Uri> finishCallback) { Observer<WebContents> webContentsView, Consumer<Uri> finishCallback) {
Handler handler = new Handler(); Handler handler = new Handler();
mMediaSessionGetter = mMediaSessionGetter =
...@@ -170,10 +167,6 @@ class CastWebContentsSurfaceHelper { ...@@ -170,10 +167,6 @@ class CastWebContentsSurfaceHelper {
// Miscellaneous actions responding to WebContents lifecycle. // Miscellaneous actions responding to WebContents lifecycle.
webContentsState.subscribe((WebContents webContents) -> { webContentsState.subscribe((WebContents webContents) -> {
// Whenever our app is visible, volume controls should modify the music stream.
// For more information read:
// http://developer.android.com/training/managing-audio/volume-playback.html
hostActivity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
// Notify CastWebContentsComponent when closed. // Notify CastWebContentsComponent when closed.
return () -> CastWebContentsComponent.onComponentClosed(mSessionId); return () -> CastWebContentsComponent.onComponentClosed(mSessionId);
}); });
......
...@@ -61,6 +61,13 @@ public class CastWebContentsActivityTest { ...@@ -61,6 +61,13 @@ public class CastWebContentsActivityTest {
mShadowActivity = Shadows.shadowOf(mActivity); mShadowActivity = Shadows.shadowOf(mActivity);
} }
@Test
public void testSetsVolumeControlStream() {
mActivityLifecycle.create();
assertEquals(AudioManager.STREAM_MUSIC, mActivity.getVolumeControlStream());
}
@Test @Test
public void testNewIntentAfterFinishLaunchesNewActivity() { public void testNewIntentAfterFinishLaunchesNewActivity() {
mActivityLifecycle.create(); mActivityLifecycle.create();
......
...@@ -14,10 +14,8 @@ import static org.mockito.Mockito.never; ...@@ -14,10 +14,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.PatternMatcher; import android.os.PatternMatcher;
...@@ -47,7 +45,6 @@ import java.util.List; ...@@ -47,7 +45,6 @@ import java.util.List;
@RunWith(BaseRobolectricTestRunner.class) @RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class CastWebContentsSurfaceHelperTest { public class CastWebContentsSurfaceHelperTest {
private @Mock Activity mActivity;
private @Mock Observer<WebContents> mWebContentsView; private @Mock Observer<WebContents> mWebContentsView;
private @Mock Consumer<Uri> mFinishCallback; private @Mock Consumer<Uri> mFinishCallback;
private CastWebContentsSurfaceHelper mSurfaceHelper; private CastWebContentsSurfaceHelper mSurfaceHelper;
...@@ -120,8 +117,7 @@ public class CastWebContentsSurfaceHelperTest { ...@@ -120,8 +117,7 @@ public class CastWebContentsSurfaceHelperTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mMediaSessionGetter.get(any())).thenReturn(mMediaSessionImpl); when(mMediaSessionGetter.get(any())).thenReturn(mMediaSessionImpl);
when(mWebContentsView.open(any())).thenReturn(mock(Scope.class)); when(mWebContentsView.open(any())).thenReturn(mock(Scope.class));
mSurfaceHelper = mSurfaceHelper = new CastWebContentsSurfaceHelper(mWebContentsView, mFinishCallback);
new CastWebContentsSurfaceHelper(mActivity, mWebContentsView, mFinishCallback);
mSurfaceHelper.setMediaSessionGetterForTesting(mMediaSessionGetter); mSurfaceHelper.setMediaSessionGetterForTesting(mMediaSessionGetter);
} }
...@@ -265,13 +261,6 @@ public class CastWebContentsSurfaceHelperTest { ...@@ -265,13 +261,6 @@ public class CastWebContentsSurfaceHelperTest {
assertFalse(mSurfaceHelper.isTouchInputEnabled()); assertFalse(mSurfaceHelper.isTouchInputEnabled());
} }
@Test
public void testSetsVolumeControlStreamOfHostActivity() {
StartParams params = new StartParamsBuilder().build();
mSurfaceHelper.onNewStartParams(params);
verify(mActivity).setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
@Test @Test
public void testSendsComponentClosedBroadcastWhenWebContentsViewIsClosedAlt() { public void testSendsComponentClosedBroadcastWhenWebContentsViewIsClosedAlt() {
StartParams params1 = new StartParamsBuilder().withId("1").build(); StartParams params1 = new StartParamsBuilder().withId("1").build();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment