Commit 0fa8dcfa authored by Zhiheng Vincent Li's avatar Zhiheng Vincent Li Committed by Commit Bot

Add two methods in CastWebContentsIntentUtils.java

and updates some debug logs.

Change-Id: Ib6f108d7ac90d355b8d80eee16b893ef0eaa6ee7
Bug: 72436104 65100261
Test: CastWebContentsIntentUtilsTest.java
Reviewed-on: https://chromium-review.googlesource.com/974453
Commit-Queue: Zhiheng(Vincent) Li <vincentli@google.com>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544940}
parent 22741917
...@@ -87,12 +87,14 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp ...@@ -87,12 +87,14 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp
@SuppressWarnings("unused") @SuppressWarnings("unused")
@CalledByNative @CalledByNative
private void requestVisibilityPriority(int visisbilityPriority) { private void requestVisibilityPriority(int visisbilityPriority) {
if (DEBUG) Log.d(TAG, "requestVisibilityPriority visibility=" + visisbilityPriority);
mComponent.requestVisibilityPriority(visisbilityPriority); mComponent.requestVisibilityPriority(visisbilityPriority);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@CalledByNative @CalledByNative
private void requestMoveOut() { private void requestMoveOut() {
if (DEBUG) Log.d(TAG, "requestMoveOut");
mComponent.requestMoveOut(); mComponent.requestMoveOut();
} }
...@@ -114,7 +116,7 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp ...@@ -114,7 +116,7 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp
@Override @Override
public void onVisibilityChange(int visibilityType) { public void onVisibilityChange(int visibilityType) {
if (DEBUG) Log.d(TAG, "onVisibilityChange"); if (DEBUG) Log.d(TAG, "onVisibilityChange type=" + visibilityType);
if (mNativeCastContentWindowAndroid != 0) { if (mNativeCastContentWindowAndroid != 0) {
nativeOnVisibilityChange(mNativeCastContentWindowAndroid, visibilityType); nativeOnVisibilityChange(mNativeCastContentWindowAndroid, visibilityType);
} }
...@@ -122,7 +124,7 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp ...@@ -122,7 +124,7 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp
@Override @Override
public boolean consumeGesture(int gestureType) { public boolean consumeGesture(int gestureType) {
if (DEBUG) Log.d(TAG, "onVisibilityChange"); if (DEBUG) Log.d(TAG, "onVisibilityChange type=" + gestureType);
if (mNativeCastContentWindowAndroid != 0) { if (mNativeCastContentWindowAndroid != 0) {
return nativeConsumeGesture(mNativeCastContentWindowAndroid, gestureType); return nativeConsumeGesture(mNativeCastContentWindowAndroid, gestureType);
} }
......
...@@ -201,26 +201,34 @@ public class CastWebContentsComponent { ...@@ -201,26 +201,34 @@ public class CastWebContentsComponent {
private void onReceiveIntent(Intent intent) { private void onReceiveIntent(Intent intent) {
if (CastWebContentsIntentUtils.isIntentOfActivityStopped(intent)) { if (CastWebContentsIntentUtils.isIntentOfActivityStopped(intent)) {
if (DEBUG) Log.d(TAG, "onReceive ACTION_ACTIVITY_STOPPED"); if (DEBUG) Log.d(TAG, "onReceive ACTION_ACTIVITY_STOPPED instance=" + mInstanceId);
if (mComponentClosedHandler != null) mComponentClosedHandler.onComponentClosed(); if (mComponentClosedHandler != null) mComponentClosedHandler.onComponentClosed();
} else if (CastWebContentsIntentUtils.isIntentOfKeyEvent(intent)) { } else if (CastWebContentsIntentUtils.isIntentOfKeyEvent(intent)) {
if (DEBUG) Log.d(TAG, "onReceive ACTION_KEY_EVENT"); if (DEBUG) Log.d(TAG, "onReceive ACTION_KEY_EVENT instance=" + mInstanceId);
int keyCode = CastWebContentsIntentUtils.getKeyCode(intent); int keyCode = CastWebContentsIntentUtils.getKeyCode(intent);
if (mKeyDownHandler != null) mKeyDownHandler.onKeyDown(keyCode); if (mKeyDownHandler != null) mKeyDownHandler.onKeyDown(keyCode);
} else if (CastWebContentsIntentUtils.isIntentOfVisiblityChange(intent)) { } else if (CastWebContentsIntentUtils.isIntentOfVisibilityChange(intent)) {
if (DEBUG) Log.d(TAG, "onReceive ACTION_ON_VISIBILITY_CHANGE");
int visibilityType = CastWebContentsIntentUtils.getVisibilityType(intent); int visibilityType = CastWebContentsIntentUtils.getVisibilityType(intent);
if (DEBUG) {
Log.d(TAG, "onReceive ACTION_ON_VISIBILITY_CHANGE instance=" + mInstanceId
+ "; visibility=" + visibilityType);
}
if (mSurfaceEventHandler != null) { if (mSurfaceEventHandler != null) {
mSurfaceEventHandler.onVisibilityChange(visibilityType); mSurfaceEventHandler.onVisibilityChange(visibilityType);
} }
} else if (CastWebContentsIntentUtils.isIntentOfGesturing(intent)) { } else if (CastWebContentsIntentUtils.isIntentOfGesturing(intent)) {
if (DEBUG) Log.d(TAG, "onReceive ACTION_ON_GESTURE");
int gestureType = CastWebContentsIntentUtils.getGestureType(intent); int gestureType = CastWebContentsIntentUtils.getGestureType(intent);
if (DEBUG) {
Log.d(TAG, "onReceive ACTION_ON_VISIBILITY_CHANGE instance=" + mInstanceId
+ "; gesture=" + gestureType);
}
if (mSurfaceEventHandler != null) { if (mSurfaceEventHandler != null) {
if (mSurfaceEventHandler.consumeGesture(gestureType)) { if (mSurfaceEventHandler.consumeGesture(gestureType)) {
if (DEBUG) Log.d(TAG, "send gesture consumed instance=" + mInstanceId);
sendIntentSync(CastWebContentsIntentUtils.gestureConsumed( sendIntentSync(CastWebContentsIntentUtils.gestureConsumed(
mInstanceId, gestureType, true)); mInstanceId, gestureType, true));
} else { } else {
if (DEBUG) Log.d(TAG, "send gesture NOT consumed instance=" + mInstanceId);
sendIntentSync(CastWebContentsIntentUtils.gestureConsumed( sendIntentSync(CastWebContentsIntentUtils.gestureConsumed(
mInstanceId, gestureType, false)); mInstanceId, gestureType, false));
} }
...@@ -272,13 +280,14 @@ public class CastWebContentsComponent { ...@@ -272,13 +280,14 @@ public class CastWebContentsComponent {
} }
public void requestVisibilityPriority(int visibilityPriority) { public void requestVisibilityPriority(int visibilityPriority) {
if (DEBUG) Log.d(TAG, "requestVisibilityPriority"); if (DEBUG) Log.d(TAG, "requestVisibilityPriority: " + mInstanceId + "; Visibility:"
+ visibilityPriority);
sendIntentSync(CastWebContentsIntentUtils.requestVisibilityPriority( sendIntentSync(CastWebContentsIntentUtils.requestVisibilityPriority(
mInstanceId, visibilityPriority)); mInstanceId, visibilityPriority));
} }
public void requestMoveOut() { public void requestMoveOut() {
if (DEBUG) Log.d(TAG, "requestMoveOut"); if (DEBUG) Log.d(TAG, "requestMoveOut: " + mInstanceId);
sendIntentSync(CastWebContentsIntentUtils.requestMoveOut(mInstanceId)); sendIntentSync(CastWebContentsIntentUtils.requestMoveOut(mInstanceId));
} }
...@@ -297,13 +306,13 @@ public class CastWebContentsComponent { ...@@ -297,13 +306,13 @@ public class CastWebContentsComponent {
sendIntentSync(CastWebContentsIntentUtils.onKeyDown(instanceId, keyCode)); sendIntentSync(CastWebContentsIntentUtils.onKeyDown(instanceId, keyCode));
} }
public static void onVisiblityChange(String instanceId, int visibilityType) { public static void onVisibilityChange(String instanceId, int visibilityType) {
if (DEBUG) Log.d(TAG, "onVisiblityChange"); if (DEBUG) Log.d(TAG, "onVisibilityChange");
sendIntentSync(CastWebContentsIntentUtils.onVisiblityChange(instanceId, visibilityType)); sendIntentSync(CastWebContentsIntentUtils.onVisibilityChange(instanceId, visibilityType));
} }
public static void onGesture(String instanceId, int gestureType) { public static void onGesture(String instanceId, int gestureType) {
if (DEBUG) Log.d(TAG, "onGesture"); if (DEBUG) Log.d(TAG, "onGesture: " + instanceId + "; gestureType: "+ gestureType);
sendIntentSync(CastWebContentsIntentUtils.onGesture(instanceId, gestureType)); sendIntentSync(CastWebContentsIntentUtils.onGesture(instanceId, gestureType));
} }
......
...@@ -133,12 +133,21 @@ public class CastWebContentsIntentUtils { ...@@ -133,12 +133,21 @@ public class CastWebContentsIntentUtils {
return intent; return intent;
} }
// Host acitivity of CastWebContentsFragment -> CastWebContentsComponent.Receiver // Host activity of CastWebContentsFragment -> CastWebContentsComponent.Receiver
// -> CastContentWindowAndroid // -> CastContentWindowAndroid
public static Intent onGesture(String instanceId, int gestureType) { public static Intent onGesture(String instanceId, int gestureType) {
if (DEBUG) Log.d(TAG, "onGesture"); return onGesture(getInstanceUri(instanceId), gestureType);
}
// Host activity of CastWebContentsFragment -> CastWebContentsComponent.Receiver
// -> CastContentWindowAndroid
public static Intent onGestureWithUriString(String uri, int gestureType) {
return onGesture(Uri.parse(uri), gestureType);
}
Intent intent = new Intent(ACTION_ON_GESTURE, getInstanceUri(instanceId)); private static Intent onGesture(Uri uri, int gestureType) {
if (DEBUG) Log.d(TAG, "onGesture with uri:" + uri + " type:" + gestureType);
Intent intent = new Intent(ACTION_ON_GESTURE, uri);
intent.putExtra(INTENT_EXTRA_GESTURE_TYPE, gestureType); intent.putExtra(INTENT_EXTRA_GESTURE_TYPE, gestureType);
return intent; return intent;
} }
...@@ -151,22 +160,34 @@ public class CastWebContentsIntentUtils { ...@@ -151,22 +160,34 @@ public class CastWebContentsIntentUtils {
return intent; return intent;
} }
// Host acitivity of CastWebContentsFragment -> CastWebContentsComponent.Receiver // Host activity of CastWebContentsFragment -> CastWebContentsComponent.Receiver
// -> CastContentWindowAndroid // -> CastContentWindowAndroid
public static Intent onVisiblityChange(String instanceId, int visibilityType) { public static Intent onVisibilityChange(String instanceId, int visibilityType) {
Intent intent = new Intent(ACTION_ON_VISIBILITY_CHANGE, getInstanceUri(instanceId)); return onVisibilityChange(getInstanceUri(instanceId), visibilityType);
}
// Host activity of CastWebContentsFragment -> CastWebContentsComponent.Receiver
// -> CastContentWindowAndroid
public static Intent onVisibilityChangeWithUriString(String uri, int visibilityType) {
return onVisibilityChange(Uri.parse(uri), visibilityType);
}
private static Intent onVisibilityChange(Uri uri, int visibilityType) {
if (DEBUG) Log.d(TAG, "onVisibilityChange with uri:" + uri + " type:" + visibilityType);
Intent intent = new Intent(ACTION_ON_VISIBILITY_CHANGE, uri);
intent.putExtra(INTENT_EXTRA_VISIBILITY_TYPE, visibilityType); intent.putExtra(INTENT_EXTRA_VISIBILITY_TYPE, visibilityType);
return intent; return intent;
} }
// CastContentWindowAndroid -> Host acitivity of CastWebContentsFragment // CastContentWindowAndroid -> Host activity of CastWebContentsFragment
public static Intent requestMoveOut(String instanceId) { public static Intent requestMoveOut(String instanceId) {
Intent intent = new Intent(ACTION_REQUEST_MOVE_OUT); Intent intent = new Intent(ACTION_REQUEST_MOVE_OUT);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString()); intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
return intent; return intent;
} }
// CastContentWindowAndroid -> Host acitivity of CastWebContentsFragment // CastContentWindowAndroid -> Host activity of CastWebContentsFragment
public static Intent requestVisibilityPriority(String instanceId, int visibilityPriority) { public static Intent requestVisibilityPriority(String instanceId, int visibilityPriority) {
Intent intent = new Intent(ACTION_REQUEST_VISIBILITY_PRIORITY); Intent intent = new Intent(ACTION_REQUEST_VISIBILITY_PRIORITY);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString()); intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
...@@ -174,7 +195,7 @@ public class CastWebContentsIntentUtils { ...@@ -174,7 +195,7 @@ public class CastWebContentsIntentUtils {
return intent; return intent;
} }
// CastWebContentsComponent.Receiver -> Host acitivity of CastWebContentsFragment // CastWebContentsComponent.Receiver -> Host activity of CastWebContentsFragment
public static Intent gestureConsumed(String instanceId, int gestureType, boolean consumed) { public static Intent gestureConsumed(String instanceId, int gestureType, boolean consumed) {
Intent intent = new Intent(ACTION_GESTURE_CONSUMED); Intent intent = new Intent(ACTION_GESTURE_CONSUMED);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString()); intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
...@@ -230,7 +251,7 @@ public class CastWebContentsIntentUtils { ...@@ -230,7 +251,7 @@ public class CastWebContentsIntentUtils {
return in.getAction().equals(ACTION_KEY_EVENT); return in.getAction().equals(ACTION_KEY_EVENT);
} }
public static boolean isIntentOfVisiblityChange(Intent in) { public static boolean isIntentOfVisibilityChange(Intent in) {
return in.getAction().equals(ACTION_ON_VISIBILITY_CHANGE); return in.getAction().equals(ACTION_ON_VISIBILITY_CHANGE);
} }
......
...@@ -202,7 +202,7 @@ public class CastWebContentsComponentTest { ...@@ -202,7 +202,7 @@ public class CastWebContentsComponentTest {
CastWebContentsComponent component = CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, callback, false, false); new CastWebContentsComponent(INSTANCE_ID, null, null, callback, false, false);
component.start(mStartParams); component.start(mStartParams);
CastWebContentsComponent.onVisiblityChange(INSTANCE_ID, 2); CastWebContentsComponent.onVisibilityChange(INSTANCE_ID, 2);
component.stop(mActivity); component.stop(mActivity);
verify(callback).onVisibilityChange(2); verify(callback).onVisibilityChange(2);
......
...@@ -79,6 +79,14 @@ public class CastWebContentsIntentUtilsTest { ...@@ -79,6 +79,14 @@ public class CastWebContentsIntentUtilsTest {
int type = CastWebContentsIntentUtils.getGestureType(in); int type = CastWebContentsIntentUtils.getGestureType(in);
Assert.assertEquals(1, type); Assert.assertEquals(1, type);
Assert.assertTrue(CastWebContentsIntentUtils.isIntentOfGesturing(in)); Assert.assertTrue(CastWebContentsIntentUtils.isIntentOfGesturing(in));
in = CastWebContentsIntentUtils.onGestureWithUriString(EXPECTED_URI, 2);
uri = in.getDataString();
Assert.assertNotNull(uri);
Assert.assertEquals(EXPECTED_URI, uri);
type = CastWebContentsIntentUtils.getGestureType(in);
Assert.assertEquals(2, type);
Assert.assertTrue(CastWebContentsIntentUtils.isIntentOfGesturing(in));
} }
@Test @Test
...@@ -94,13 +102,21 @@ public class CastWebContentsIntentUtilsTest { ...@@ -94,13 +102,21 @@ public class CastWebContentsIntentUtilsTest {
@Test @Test
public void testOnVisibilityChange() { public void testOnVisibilityChange() {
Intent in = CastWebContentsIntentUtils.onVisiblityChange(INSTANCE_ID, 3); Intent in = CastWebContentsIntentUtils.onVisibilityChange(INSTANCE_ID, 3);
String uri = in.getDataString(); String uri = in.getDataString();
Assert.assertNotNull(uri); Assert.assertNotNull(uri);
Assert.assertEquals(EXPECTED_URI, uri); Assert.assertEquals(EXPECTED_URI, uri);
int type = CastWebContentsIntentUtils.getVisibilityType(in); int type = CastWebContentsIntentUtils.getVisibilityType(in);
Assert.assertEquals(3, type); Assert.assertEquals(3, type);
Assert.assertTrue(CastWebContentsIntentUtils.isIntentOfVisiblityChange(in)); Assert.assertTrue(CastWebContentsIntentUtils.isIntentOfVisibilityChange(in));
in = CastWebContentsIntentUtils.onVisibilityChangeWithUriString(EXPECTED_URI, 2);
uri = in.getDataString();
Assert.assertNotNull(uri);
Assert.assertEquals(EXPECTED_URI, uri);
type = CastWebContentsIntentUtils.getVisibilityType(in);
Assert.assertEquals(2, type);
Assert.assertTrue(CastWebContentsIntentUtils.isIntentOfVisibilityChange(in));
} }
@Test @Test
......
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