Commit 70c3c5ac authored by Yusuf Ozuysal's avatar Yusuf Ozuysal Committed by Commit Bot

CustomTabs: Add a way to send scrolling state of the bottom bar to client

- Adds a request setter for the callback. Set to false by default.
- Starts sending the callback from bottom bar delegate only when
completely hidden or shown.
- If the bottom bar is not set, use the toolbar values to send the same
signal, so that bottom bar can be set as desired

BUG=746648

Change-Id: I6f60dde5e39354b33503ce9553b67cf953a9b533
Reviewed-on: https://chromium-review.googlesource.com/578392
Commit-Queue: Yusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488289}
parent fa25b051
......@@ -129,6 +129,7 @@ class ClientManager {
private boolean mShouldHideDomain;
private boolean mShouldPrerenderOnCellular;
private boolean mShouldSendNavigationInfo;
private boolean mShouldSendBottomBarScrollState;
private KeepAliveServiceConnection mKeepAliveConnection;
private String mPredictedUrl;
private long mLastMayLaunchUrlTimestamp;
......@@ -414,6 +415,24 @@ class ClientManager {
if (params != null) params.mShouldHideDomain = hide;
}
/**
* @return Whether bottom bar scrolling state should be recorded and shared for the session.
*/
public synchronized boolean shouldSendBottomBarScrollStateForSession(
CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
return params != null ? params.mShouldSendBottomBarScrollState : false;
}
/**
* Sets whether bottom bar scrolling state should be recorded and shared for the session.
*/
public synchronized void setSendBottomBarScrollingStateForSessionn(
CustomTabsSessionToken session, boolean send) {
SessionParams params = mSessionParams.get(session);
if (params != null) params.mShouldSendBottomBarScrollState = send;
}
/**
* @return Whether navigation info should be recorded and shared for the session.
*/
......
......@@ -211,6 +211,16 @@ class CustomTabBottomBarDelegate implements FullscreenListener {
public void onControlsOffsetChanged(float topOffset, float bottomOffset,
boolean needsAnimate) {
if (mBottomBarView != null) mBottomBarView.setTranslationY(bottomOffset);
// If the bottom bar is not visible use the top controls as a guide to set state.
float offset = getBottomBarHeight() == 0 ? topOffset : bottomOffset;
float height = getBottomBarHeight() == 0 ? mFullscreenManager.getTopControlsHeight()
: mFullscreenManager.getBottomControlsHeight();
// Avoid spamming this callback across process boundaries, by only sending messages at
// absolute transitions.
if (Math.abs(offset) == height || offset == 0) {
CustomTabsConnection.getInstance().onBottomBarScrollStateChanged(
mDataProvider.getSession(), offset != 0);
}
}
@Override
......
......@@ -80,6 +80,7 @@ public class CustomTabsConnection {
@VisibleForTesting
static final String PAGE_LOAD_METRICS_CALLBACK = "NavigationMetrics";
static final String BOTTOM_BAR_SCROLL_STATE_CALLBACK = "onBottomBarScrollStateChanged";
// For CustomTabs.SpeculationStatusOnStart, see tools/metrics/enums.xml. Append only.
private static final int SPECULATION_STATUS_ON_START_ALLOWED = 0;
......@@ -777,6 +778,11 @@ public class CustomTabsConnection {
return mClientManager.shouldSendNavigationInfoForSession(session);
}
/** @see ClientManager#shouldSendBottomBarScrollStateForSession(CustomTabsSessionToken) */
public boolean shouldSendBottomBarScrollStateForSession(CustomTabsSessionToken session) {
return mClientManager.shouldSendBottomBarScrollStateForSession(session);
}
/** See {@link ClientManager#getClientPackageNameForSession(CustomTabsSessionToken)} */
public String getClientPackageNameForSession(CustomTabsSessionToken session) {
return mClientManager.getClientPackageNameForSession(session);
......@@ -845,6 +851,30 @@ public class CustomTabsConnection {
public void sendNavigationInfo(
CustomTabsSessionToken session, String url, String title, Bitmap screenshot) { }
/**
* Called when the bottom bar for the custom tab has been hidden or shown completely by user
* scroll.
*
* @param session The session that is linked with the custom tab.
* @param hidden Whether the bottom bar is hidden or shown.
*/
public void onBottomBarScrollStateChanged(CustomTabsSessionToken session, boolean hidden) {
if (!shouldSendBottomBarScrollStateForSession(session)) return;
CustomTabsCallback callback = mClientManager.getCallbackForSession(session);
Bundle args = new Bundle();
args.putBoolean("hidden", hidden);
try {
callback.extraCallback(BOTTOM_BAR_SCROLL_STATE_CALLBACK, args);
} catch (Exception e) {
// Pokemon exception handling, see above and crbug.com/517023.
return;
}
if (mLogRequests) {
logCallback("extraCallback(" + BOTTOM_BAR_SCROLL_STATE_CALLBACK + ")", hidden);
}
}
/**
* Notifies the application of a navigation event.
*
......
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