summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/Tab.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/browser/Tab.java')
-rw-r--r--src/com/android/browser/Tab.java43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 907f7a1f3..ceacd4208 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -76,6 +76,7 @@ import com.android.browser.provider.SnapshotProvider.Snapshots;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.security.Principal;
@@ -161,6 +162,8 @@ class Tab implements PictureListener {
// before onPageFinsihed)
private boolean mInPageLoad;
private boolean mDisableOverrideUrlLoading;
+ // If true, the current page is the most visited page
+ private boolean mInMostVisitedPage;
// The last reported progress of the current page
private int mPageLoadProgress;
// The time the load started, used to find load page time
@@ -394,6 +397,16 @@ class Tab implements PictureListener {
}
syncCurrentState(view, url);
mWebViewController.onPageFinished(Tab.this);
+
+ if (view.getUrl().equals(HomeProvider.MOST_VISITED_URL)) {
+ if (!mInMostVisitedPage) {
+ loadUrl(HomeProvider.MOST_VISITED, null);
+ mInMostVisitedPage = true;
+ }
+ view.clearHistory();
+ } else {
+ mInMostVisitedPage = false;
+ }
}
// return true if want to hijack the url to let another app to handle it
@@ -1847,7 +1860,20 @@ class Tab implements PictureListener {
mInPageLoad = true;
mCurrentState = new PageState(mContext, false, url, null);
mWebViewController.onPageStarted(this, mMainView, null);
- mMainView.loadUrl(url, headers);
+ WebResourceResponse res = HomeProvider.shouldInterceptRequest(mContext, url);
+ if (res != null) {
+ try {
+ String data = readWebResource(res).toString();
+ mInMostVisitedPage = true;
+ mMainView.loadDataWithBaseURL(url, data, res.getMimeType(), res.getEncoding(),
+ HomeProvider.MOST_VISITED_URL);
+ } catch (IOException io) {
+ // Fallback to default load handling
+ mMainView.loadUrl(url, headers);
+ }
+ } else {
+ mMainView.loadUrl(url, headers);
+ }
}
}
@@ -2002,4 +2028,19 @@ class Tab implements PictureListener {
if (mSubView != null)
cookieManager.setAcceptThirdPartyCookies(mSubView, accept);
}
+
+ private StringBuilder readWebResource(WebResourceResponse response) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ InputStream is = response.getData();
+ try {
+ byte[] data = new byte[512];
+ int read = 0;
+ while ((read = is.read(data, 0, 512)) != -1) {
+ sb.append(new String(data, 0, read));
+ }
+ } finally {
+ is.close();
+ }
+ return sb;
+ }
}