Support for measuring page load times.
An app can attached a pending intent to an intent sent to the browser
which will be send when the load completes. The browser will fill in
the timestamp of when the page load completed, and details of preloading
success or otherwise if this was used.
Bug: 5259031
Change-Id: I2d025caabd6055ac25f06e69897a03d5c57c4f41
diff --git a/src/com/android/browser/PreloadedTabControl.java b/src/com/android/browser/PreloadedTabControl.java
index 4ffe6b4..b0eff63 100644
--- a/src/com/android/browser/PreloadedTabControl.java
+++ b/src/com/android/browser/PreloadedTabControl.java
@@ -15,6 +15,7 @@
*/
package com.android.browser;
+import android.app.PendingIntent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
@@ -39,7 +40,7 @@
mTab = t;
}
- private void maybeSetQuery(final String query, SearchBox sb) {
+ private boolean maybeSetQuery(final String query, SearchBox sb) {
if (!TextUtils.equals(mLastQuery, query)) {
if (sb != null) {
if (LOGD_ENABLED) Log.d(LOGTAG, "Changing searchbox query to " + query);
@@ -55,25 +56,27 @@
}
}
});
+ return true;
} else {
if (LOGD_ENABLED) Log.d(LOGTAG, "Cannot set query: no searchbox interface");
}
}
+ return false;
}
public void setQuery(String query) {
maybeSetQuery(query, mTab.getWebView().getSearchBox());
}
- public boolean searchBoxSubmit(final String query,
- final String fallbackUrl, final Map<String, String> fallbackHeaders) {
+ public boolean searchBoxSubmit(final String query, final String fallbackUrl,
+ final Map<String, String> fallbackHeaders, final PendingIntent onLoadCompleteIntent) {
final SearchBox sb = mTab.getWebView().getSearchBox();
if (sb == null) {
// no searchbox, cannot submit. Fallback to regular tab creation
if (LOGD_ENABLED) Log.d(LOGTAG, "No searchbox, cannot submit query");
return false;
}
- maybeSetQuery(query, sb);
+ final boolean newQuery = maybeSetQuery(query, sb);
if (LOGD_ENABLED) Log.d(LOGTAG, "Submitting query " + query);
final String currentUrl = mTab.getUrl();
sb.onsubmit(new SearchBox.SearchBoxListener() {
@@ -84,9 +87,14 @@
if (!called) {
if (LOGD_ENABLED) Log.d(LOGTAG, "Query not submitted; falling back");
loadUrl(fallbackUrl, fallbackHeaders);
+
// make sure that the failed, preloaded URL is cleared from the back stack
mTab.clearBackStackWhenItemAdded(Pattern.compile(
"^" + Pattern.quote(fallbackUrl) + "$"));
+ // When setting the search box query, preloadAttempted=true implies that the
+ // the query was prefetched using the searchbox API. This is the case if we
+ // the query is not new.
+ registerLoadCompleteListener(!newQuery, false, onLoadCompleteIntent);
} else {
// ignore the next fragment change, to avoid leaving a blank page in the browser
// after the query has been submitted.
@@ -100,11 +108,27 @@
Pattern.quote(currentWithoutFragment) +
"(\\#.*)?" +
"$"));
+ registerLoadCompleteListener(!newQuery, true, onLoadCompleteIntent);
}
}});
return true;
}
+ private void registerLoadCompleteListener(
+ final boolean queryPreloaded,
+ final boolean preloadSucceeded,
+ final PendingIntent pendingIntent) {
+ if (pendingIntent == null) {
+ return;
+ }
+ mTab.setOnPageLoadCompleteListener(null, new Tab.OnPageLoadCompleteListener(){
+ @Override
+ public void onPageLoadComplete() {
+ IntentHandler.sendPageLoadCompletePendingIntent(mTab.mContext, pendingIntent,
+ queryPreloaded, preloadSucceeded);
+ }});
+ }
+
public void searchBoxCancel() {
SearchBox sb = mTab.getWebView().getSearchBox();
if (sb != null) {