Preloading support in browser
Apps like the QSB can request the browser to preload a
web page.
- preloaded pages are not added to the browser history
if they'r not seen by the user
- when a request is received, a new tab is created for the
preloaded page, but not added to the tab list
- upon receiving the view intent for the preloaded page
the tab is added to the tab list, and shown
- if several pages are preloaded consecutively in the same tab,
the back stack is cleared before it is displayed
- preloaded pages use the main browser cookie jar, so pages that
have never been viewed by the user can drop cookies
Change-Id: I9ed21f2c9560fda0ed042b460b73bb33988a2e8a
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 447e61b..9046745 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -229,6 +229,7 @@
mTabControl = new TabControl(this);
mSettings.setController(this);
mCrashRecoveryHandler = CrashRecoveryHandler.initialize(this);
+ mFactory = new BrowserWebViewFactory(browser);
mUrlHandler = new UrlHandler(this);
mIntentHandler = new IntentHandler(mActivity, this);
@@ -312,7 +313,7 @@
// If the intent is ACTION_VIEW and data is not null, the Browser is
// invoked to view the content by another application. In this case,
// the tab will be close when exit.
- UrlData urlData = mIntentHandler.getUrlDataFromIntent(intent);
+ UrlData urlData = IntentHandler.getUrlDataFromIntent(intent);
Tab t = null;
if (urlData.isEmpty()) {
t = openTabToHomePage();
@@ -356,10 +357,6 @@
}
}
- void setWebViewFactory(WebViewFactory factory) {
- mFactory = factory;
- }
-
@Override
public WebViewFactory getWebViewFactory() {
return mFactory;
@@ -381,6 +378,11 @@
}
@Override
+ public Context getContext() {
+ return mActivity;
+ }
+
+ @Override
public Activity getActivity() {
return mActivity;
}
@@ -1637,6 +1639,7 @@
return id;
}
+ @Override
protected void onPostExecute(Long id) {
if (id > 0) {
createNewSnapshotTab(id, true);
@@ -2247,11 +2250,19 @@
// open a non inconito tab with the given url data
// and set as active tab
public Tab openTab(UrlData urlData) {
- Tab tab = createNewTab(false, true, true);
- if ((tab != null) && !urlData.isEmpty()) {
- loadUrlDataIn(tab, urlData);
+ if (urlData.isPreloaded()) {
+ Tab tab = urlData.getPreloadedTab();
+ tab.getWebView().clearHistory();
+ mTabControl.addPreloadedTab(tab);
+ setActiveTab(tab);
+ return tab;
+ } else {
+ Tab tab = createNewTab(false, true, true);
+ if ((tab != null) && !urlData.isEmpty()) {
+ loadUrlDataIn(tab, urlData);
+ }
+ return tab;
}
- return tab;
}
@Override
@@ -2417,6 +2428,8 @@
if (data != null) {
if (data.mVoiceIntent != null) {
t.activateVoiceSearchMode(data.mVoiceIntent);
+ } else if (data.isPreloaded()) {
+ // this isn't called for preloaded tabs
} else {
loadUrl(t, data.mUrl, data.mHeaders);
}