Commit aad14f9e authored by yusufo's avatar yusufo Committed by Commit bot

Add APIs to cache navigation info and send via callback

Adds no-op APIs to cache navigation info for custom tabs like
url, title and content screenshot and send them via a callback
to the client app.

BUG=647342

Review-Url: https://codereview.chromium.org/2348573002
Cr-Commit-Position: refs/heads/master@{#419328}
parent f955ff0a
......@@ -317,6 +317,8 @@
<dimen name="custom_tabs_url_text_size">12sp</dimen>
<dimen name="custom_tabs_title_text_size">16sp</dimen>
<dimen name="custom_tabs_bottom_bar_max_height">60dp</dimen>
<dimen name="custom_tabs_screenshot_height">300dp</dimen>
<dimen name="custom_tabs_screenshot_width">190dp</dimen>
<!-- Favicon dimensions -->
<dimen name="default_favicon_size">16dp</dimen>
......
......@@ -57,6 +57,7 @@ class ClientManager {
public boolean mIgnoreFragments;
private boolean mShouldHideDomain;
private boolean mShouldPrerenderOnCellular;
private boolean mShouldSendNavigationInfo;
private ServiceConnection mKeepAliveConnection;
private String mPredictedUrl;
private long mLastMayLaunchUrlTimestamp;
......@@ -250,6 +251,23 @@ class ClientManager {
if (params != null) params.mShouldHideDomain = hide;
}
/**
* @return Whether navigation info should be recorded and shared for the session.
*/
public synchronized boolean shouldSendNavigationInfoForSession(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
return params != null ? params.mShouldSendNavigationInfo : false;
}
/**
* Sets whether navigation info should be recorded and shared for the session.
*/
public synchronized void setSendNavigationInfoForSession(
CustomTabsSessionToken session, boolean save) {
SessionParams params = mSessionParams.get(session);
if (params != null) params.mShouldSendNavigationInfo = save;
}
/**
* @return Whether the fragment should be ignored for prerender matching.
*/
......
......@@ -5,15 +5,20 @@
package org.chromium.chrome.browser.customtabs;
import android.app.Application;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.SystemClock;
import android.support.customtabs.CustomTabsCallback;
import android.support.customtabs.CustomTabsSessionToken;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.ContentBitmapCallback;
import org.chromium.content_public.browser.LoadUrlParams;
import java.util.concurrent.TimeUnit;
......@@ -25,6 +30,7 @@ class CustomTabObserver extends EmptyTabObserver {
private final CustomTabsConnection mCustomTabsConnection;
private final CustomTabsSessionToken mSession;
private final boolean mOpenedByChrome;
private float mScaleForNavigationInfo = 1f;
private long mIntentReceivedTimestamp;
private long mPageLoadStartedTimestamp;
......@@ -42,6 +48,15 @@ class CustomTabObserver extends EmptyTabObserver {
mCustomTabsConnection = CustomTabsConnection.getInstance(application);
}
mSession = session;
if (!openedByChrome && mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) {
float desiredWidth = application.getResources().getDimensionPixelSize(
R.dimen.custom_tabs_screenshot_width);
float desiredHeight = application.getResources().getDimensionPixelSize(
R.dimen.custom_tabs_screenshot_height);
Rect bounds = ExternalPrerenderHandler.estimateContentSize(application, false);
mScaleForNavigationInfo = (bounds.width() == 0 || bounds.height() == 0) ? 1f :
Math.min(desiredWidth / bounds.width(), desiredHeight / bounds.height());
}
mOpenedByChrome = openedByChrome;
resetPageLoadTracking();
}
......@@ -113,6 +128,7 @@ class CustomTabObserver extends EmptyTabObserver {
TimeUnit.MILLISECONDS, 100);
}
resetPageLoadTracking();
captureNavigationInfo(tab);
}
@Override
......@@ -138,4 +154,19 @@ class CustomTabObserver extends EmptyTabObserver {
mCurrentState = STATE_RESET;
mIntentReceivedTimestamp = -1;
}
private void captureNavigationInfo(final Tab tab) {
if (mCustomTabsConnection == null) return;
if (!mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) return;
ContentBitmapCallback callback = new ContentBitmapCallback() {
@Override
public void onFinishGetBitmap(Bitmap bitmap, int response) {
mCustomTabsConnection.sendNavigationInfo(
mSession, tab.getUrl(), tab.getTitle(), bitmap);
}
};
tab.getWebContents().getContentBitmapAsync(
Bitmap.Config.ARGB_8888, mScaleForNavigationInfo, new Rect(), callback);
}
}
......@@ -480,6 +480,11 @@ public class CustomTabsConnection {
return mClientManager.shouldPrerenderOnCellularForSession(session);
}
/** @see ClientManager#shouldSendNavigationInfoForSession(CustomTabsSessionToken) */
public boolean shouldSendNavigationInfoForSession(CustomTabsSessionToken session) {
return mClientManager.shouldSendNavigationInfoForSession(session);
}
/** See {@link ClientManager#getClientPackageNameForSession(CustomTabsSessionToken)} */
public String getClientPackageNameForSession(CustomTabsSessionToken session) {
return mClientManager.getClientPackageNameForSession(session);
......@@ -523,6 +528,16 @@ public class CustomTabsConnection {
*/
public void sendFirstRunCallbackIfNecessary(Intent intent, boolean resultOK) { }
/**
* Sends the navigation info that was captured to the client callback.
* @param session The session to use for getting client callback.
* @param url The current url for the tab.
* @param title The current title for the tab.
* @param screenshot A screenshot of the tab contents.
*/
public void sendNavigationInfo(
CustomTabsSessionToken session, String url, String title, Bitmap screenshot) { }
/**
* 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