Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java

Issue 2348573002: Add APIs to cache navigation info and send via callback (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java
index a6b0cad5e461c0ad677ae5c90bf6c8f6c56c3169..4008f84f73300e0266fd9c694130304b0a141b14 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java
@@ -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 final float mScaleForNavigationInfo;
private long mIntentReceivedTimestamp;
private long mPageLoadStartedTimestamp;
@@ -42,6 +48,17 @@ 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);
Ian Wen 2016/09/16 22:32:39 Special case if bounds is 0? In this case, mark sc
Yusuf 2016/09/16 22:40:59 Done.
+ mScaleForNavigationInfo =
+ Math.min(desiredWidth / bounds.width(), desiredHeight / bounds.height());
+ } else {
+ mScaleForNavigationInfo = 1f;
Ian Wen 2016/09/16 22:32:40 You could pre-initialize mScale to 1f above, and r
Yusuf 2016/09/16 22:40:59 Done.
+ }
mOpenedByChrome = openedByChrome;
resetPageLoadTracking();
}
@@ -113,6 +130,7 @@ class CustomTabObserver extends EmptyTabObserver {
TimeUnit.MILLISECONDS, 100);
}
resetPageLoadTracking();
+ captureNavigationInfo(tab);
}
@Override
@@ -138,4 +156,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);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698