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 {
setContentView(R.layout.cast_web_contents_activity);
mSurfaceHelperState.set(new CastWebContentsSurfaceHelper(this /* hostActivity */,
mSurfaceHelperState.set(new CastWebContentsSurfaceHelper(
CastWebContentsScopes.onLayoutActivity(this,
(FrameLayout) findViewById(R.id.web_contents_container),
CastSwitches.getSwitchValueColor(
......@@ -168,6 +168,11 @@ public class CastWebContentsActivity extends Activity {
super.onCreate(savedInstanceState);
mCreatedState.set(Unit.unit());
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
......
......@@ -8,6 +8,7 @@ import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
......@@ -87,7 +88,7 @@ public class CastWebContentsFragment extends Fragment {
return;
}
mSurfaceHelper = new CastWebContentsSurfaceHelper(/* hostActivity= */ getActivity(),
mSurfaceHelper = new CastWebContentsSurfaceHelper(
CastWebContentsScopes.onLayoutFragment(getActivity(),
(FrameLayout) getView().findViewById(R.id.web_contents_container),
CastSwitches.getSwitchValueColor(
......@@ -102,6 +103,11 @@ public class CastWebContentsFragment extends Fragment {
mAppId = CastWebContentsIntentUtils.getAppId(bundle);
mInitialVisiblityPriority = CastWebContentsIntentUtils.getVisibilityPriority(bundle);
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
......
......@@ -33,10 +33,10 @@ class CastWebContentsScopes {
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) {
return (WebContents webContents) -> {
ContentViewRenderView contentViewRenderView = new ContentViewRenderView(activity) {
ContentViewRenderView contentViewRenderView = new ContentViewRenderView(context) {
@Override
protected void onReadyToRender() {
setOverlayVideoMode(true);
......@@ -48,7 +48,7 @@ class CastWebContentsScopes {
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
layout.addView(contentViewRenderView, matchParent);
ContentView contentView = ContentView.createContentView(activity, webContents);
ContentView contentView = ContentView.createContentView(context, webContents);
// TODO(derekjchow): productVersion
webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(contentView),
contentView, window, WebContents.createDefaultInternalsHolder());
......
......@@ -4,10 +4,8 @@
package org.chromium.chromecast.shell;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
......@@ -103,12 +101,11 @@ class CastWebContentsSurfaceHelper {
}
/**
* @param hostActivity Activity hosts the view showing WebContents
* @param webContentsView A Observer that displays incoming WebContents.
* @param finishCallback Invoked to tell host to finish.
*/
CastWebContentsSurfaceHelper(Activity hostActivity, Observer<WebContents> webContentsView,
Consumer<Uri> finishCallback) {
CastWebContentsSurfaceHelper(
Observer<WebContents> webContentsView, Consumer<Uri> finishCallback) {
Handler handler = new Handler();
mMediaSessionGetter =
......@@ -170,10 +167,6 @@ class CastWebContentsSurfaceHelper {
// Miscellaneous actions responding to WebContents lifecycle.
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.
return () -> CastWebContentsComponent.onComponentClosed(mSessionId);
});
......
......@@ -61,6 +61,13 @@ public class CastWebContentsActivityTest {
mShadowActivity = Shadows.shadowOf(mActivity);
}
@Test
public void testSetsVolumeControlStream() {
mActivityLifecycle.create();
assertEquals(AudioManager.STREAM_MUSIC, mActivity.getVolumeControlStream());
}
@Test
public void testNewIntentAfterFinishLaunchesNewActivity() {
mActivityLifecycle.create();
......
......@@ -14,10 +14,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri;
import android.os.PatternMatcher;
......@@ -47,7 +45,6 @@ import java.util.List;
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class CastWebContentsSurfaceHelperTest {
private @Mock Activity mActivity;
private @Mock Observer<WebContents> mWebContentsView;
private @Mock Consumer<Uri> mFinishCallback;
private CastWebContentsSurfaceHelper mSurfaceHelper;
......@@ -120,8 +117,7 @@ public class CastWebContentsSurfaceHelperTest {
MockitoAnnotations.initMocks(this);
when(mMediaSessionGetter.get(any())).thenReturn(mMediaSessionImpl);
when(mWebContentsView.open(any())).thenReturn(mock(Scope.class));
mSurfaceHelper =
new CastWebContentsSurfaceHelper(mActivity, mWebContentsView, mFinishCallback);
mSurfaceHelper = new CastWebContentsSurfaceHelper(mWebContentsView, mFinishCallback);
mSurfaceHelper.setMediaSessionGetterForTesting(mMediaSessionGetter);
}
......@@ -265,13 +261,6 @@ public class CastWebContentsSurfaceHelperTest {
assertFalse(mSurfaceHelper.isTouchInputEnabled());
}
@Test
public void testSetsVolumeControlStreamOfHostActivity() {
StartParams params = new StartParamsBuilder().build();
mSurfaceHelper.onNewStartParams(params);
verify(mActivity).setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
@Test
public void testSendsComponentClosedBroadcastWhenWebContentsViewIsClosedAlt() {
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