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.java137
1 files changed, 61 insertions, 76 deletions
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 863fc95..e1dd1ca 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -88,6 +88,9 @@ class Tab {
Activity mActivity;
private WebViewController mWebViewController;
+ // The tab ID
+ private long mId;
+
// The Geolocation permissions prompt
private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
// Main WebView wrapper
@@ -104,12 +107,10 @@ class Tab {
private Bundle mSavedState;
// Parent Tab. This is the Tab that created this Tab, or null if the Tab was
// created by the UI
- private Tab mParentTab;
+ private Tab mParent;
// Tab that constructed by this Tab. This is used when this Tab is
// destroyed, it clears all mParentTab values in the children.
- private Vector<Tab> mChildTabs;
- // If true, the tab will be removed when back out of the first page.
- private boolean mCloseOnExit;
+ private Vector<Tab> mChildren;
// If true, the tab is in the foreground of the current activity.
private boolean mInForeground;
// If true, the tab is in page loading state (after onPageStarted,
@@ -139,6 +140,7 @@ class Tab {
DownloadTouchIcon mTouchIconLoader;
private Bitmap mScreenshot;
+ private BrowserSettings mSettings;
// All the state needed for a page
private static class PageState {
@@ -182,18 +184,11 @@ class Tab {
private PageState mCurrentState;
// Used for saving and restoring each Tab
- // TODO: Figure out who uses what and where
- // Some of these aren't use in this class, and some are only used in
- // restoring state but not saving it - FIX THIS
- static final String WEBVIEW = "webview";
- static final String NUMTABS = "numTabs";
- static final String CURRTAB = "currentTab";
+ static final String ID = "ID";
static final String CURRURL = "currentUrl";
static final String CURRTITLE = "currentTitle";
- static final String CLOSEONEXIT = "closeonexit";
static final String PARENTTAB = "parentTab";
static final String APPID = "appid";
- static final String ORIGINALURL = "originalUrl";
static final String INCOGNITO = "privateBrowsingEnabled";
static final String SCREENSHOT = "screenshot";
@@ -313,7 +308,9 @@ class Tab {
mVoiceSearchData.mLastVoiceSearchTitle
= mVoiceSearchData.mVoiceSearchResults.get(index);
if (mInForeground) {
- mWebViewController.activateVoiceSearchMode(mVoiceSearchData.mLastVoiceSearchTitle);
+ mWebViewController.activateVoiceSearchMode(
+ mVoiceSearchData.mLastVoiceSearchTitle,
+ mVoiceSearchData.mVoiceSearchResults);
}
if (mVoiceSearchData.mVoiceSearchHtmls != null) {
// When index was found it was already ensured that it was valid
@@ -709,7 +706,7 @@ class Tab {
setLockIconType(LockIcon.LOCK_ICON_UNSECURE);
return;
}
- if (BrowserSettings.getInstance().showSecurityWarnings()) {
+ if (mSettings.showSecurityWarnings()) {
final LayoutInflater factory =
LayoutInflater.from(mActivity);
final View warningsView =
@@ -856,9 +853,9 @@ class Tab {
mWebViewController.attachSubWindow(Tab.this);
transport.setWebView(mSubView);
} else {
- final Tab newTab = mWebViewController.openTabAndShow(
- Tab.this,
- IntentHandler.EMPTY_URL_DATA, false, null);
+ final Tab newTab = mWebViewController.openTab(null,
+ Tab.this.isPrivateBrowsingEnabled(),
+ true, true);
if (newTab != Tab.this) {
Tab.this.addChildTab(newTab);
}
@@ -935,18 +932,16 @@ class Tab {
@Override
public void onRequestFocus(WebView view) {
if (!mInForeground) {
- mWebViewController.switchToTab(mWebViewController.getTabControl().getTabIndex(
- Tab.this));
+ mWebViewController.switchToTab(Tab.this);
}
}
@Override
public void onCloseWindow(WebView window) {
- if (mParentTab != null) {
+ if (mParent != null) {
// JavaScript can only close popup window.
if (mInForeground) {
- mWebViewController.switchToTab(mWebViewController.getTabControl()
- .getTabIndex(mParentTab));
+ mWebViewController.switchToTab(mParent);
}
mWebViewController.closeTab(Tab.this);
}
@@ -1015,7 +1010,7 @@ class Tab {
public void onExceededDatabaseQuota(String url,
String databaseIdentifier, long currentQuota, long estimatedSize,
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
- BrowserSettings.getInstance().getWebStorageSizeManager()
+ mSettings.getWebStorageSizeManager()
.onExceededDatabaseQuota(url, databaseIdentifier,
currentQuota, estimatedSize, totalUsedQuota,
quotaUpdater);
@@ -1034,7 +1029,7 @@ class Tab {
@Override
public void onReachedMaxAppCacheSize(long spaceNeeded,
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
- BrowserSettings.getInstance().getWebStorageSizeManager()
+ mSettings.getWebStorageSizeManager()
.onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
quotaUpdater);
}
@@ -1172,10 +1167,7 @@ class Tab {
if (disableAutoFill.isChecked()) {
// Disable autofill and show a toast with how to turn it on again.
- BrowserSettings s = BrowserSettings.getInstance();
- s.addObserver(mMainView.getSettings());
- s.disableAutoFill(mActivity);
- s.update();
+ mSettings.setAutofillEnabled(false);
Toast.makeText(mActivity,
R.string.autofill_setup_dialog_negative_toast,
Toast.LENGTH_LONG).show();
@@ -1290,14 +1282,13 @@ class Tab {
// remove later
// Construct a new tab
- Tab(WebViewController wvcontroller, WebView w, boolean closeOnExit, String appId,
- String url) {
+ Tab(WebViewController wvcontroller, WebView w) {
mWebViewController = wvcontroller;
mActivity = mWebViewController.getActivity();
- mCloseOnExit = closeOnExit;
- mAppId = appId;
+ mSettings = BrowserSettings.getInstance();
mDataController = DataController.getInstance(mActivity);
- mCurrentState = new PageState(mActivity, w.isPrivateBrowsingEnabled());
+ mCurrentState = new PageState(mActivity, w != null
+ ? w.isPrivateBrowsingEnabled() : false);
mInPageLoad = false;
mInForeground = false;
@@ -1328,6 +1319,14 @@ class Tab {
setWebView(w);
}
+ public void setId(long id) {
+ mId = id;
+ }
+
+ public long getId() {
+ return mId;
+ }
+
/**
* Sets the WebView for this tab, correctly removing the old WebView from
* the container view.
@@ -1366,7 +1365,6 @@ class Tab {
void destroy() {
if (mMainView != null) {
dismissSubWindow();
- BrowserSettings.getInstance().deleteObserver(mMainView.getSettings());
// save the WebView to call destroy() after detach it from the tab
WebView webView = mMainView;
setWebView(null);
@@ -1379,14 +1377,14 @@ class Tab {
*/
void removeFromTree() {
// detach the children
- if (mChildTabs != null) {
- for(Tab t : mChildTabs) {
- t.setParentTab(null);
+ if (mChildren != null) {
+ for(Tab t : mChildren) {
+ t.setParent(null);
}
}
// remove itself from the parent list
- if (mParentTab != null) {
- mParentTab.mChildTabs.remove(this);
+ if (mParent != null) {
+ mParent.mChildren.remove(this);
}
}
@@ -1428,8 +1426,6 @@ class Tab {
void dismissSubWindow() {
if (mSubView != null) {
mWebViewController.endActionMode();
- BrowserSettings.getInstance().deleteObserver(
- mSubView.getSettings());
mSubView.destroy();
mSubView = null;
mSubViewContainer = null;
@@ -1440,37 +1436,45 @@ class Tab {
/**
* Set the parent tab of this tab.
*/
- void setParentTab(Tab parent) {
- mParentTab = parent;
+ void setParent(Tab parent) {
+ mParent = parent;
// This tab may have been freed due to low memory. If that is the case,
- // the parent tab index is already saved. If we are changing that index
+ // the parent tab id is already saved. If we are changing that id
// (most likely due to removing the parent tab) we must update the
- // parent tab index in the saved Bundle.
+ // parent tab id in the saved Bundle.
if (mSavedState != null) {
if (parent == null) {
mSavedState.remove(PARENTTAB);
} else {
- mSavedState.putInt(PARENTTAB, mWebViewController.getTabControl()
- .getTabIndex(parent));
+ mSavedState.putLong(PARENTTAB, parent.getId());
}
}
}
/**
+ * If this Tab was created through another Tab, then this method returns
+ * that Tab.
+ * @return the Tab parent or null
+ */
+ public Tab getParent() {
+ return mParent;
+ }
+
+ /**
* When a Tab is created through the content of another Tab, then we
* associate the Tabs.
* @param child the Tab that was created from this Tab
*/
void addChildTab(Tab child) {
- if (mChildTabs == null) {
- mChildTabs = new Vector<Tab>();
+ if (mChildren == null) {
+ mChildren = new Vector<Tab>();
}
- mChildTabs.add(child);
- child.setParentTab(this);
+ mChildren.add(child);
+ child.setParent(this);
}
- Vector<Tab> getChildTabs() {
- return mChildTabs;
+ Vector<Tab> getChildren() {
+ return mChildren;
}
void resume() {
@@ -1658,24 +1662,6 @@ class Tab {
return mErrorConsole;
}
- /**
- * If this Tab was created through another Tab, then this method returns
- * that Tab.
- * @return the Tab parent or null
- */
- public Tab getParentTab() {
- return mParentTab;
- }
-
- /**
- * Return whether this tab should be closed when it is backing out of the
- * first page.
- * @return TRUE if this tab should be closed when exit.
- */
- boolean closeOnExit() {
- return mCloseOnExit;
- }
-
private void setLockIconType(LockIcon icon) {
mCurrentState.mLockIcon = icon;
mWebViewController.onUpdatedLockIcon(this);
@@ -1740,16 +1726,15 @@ class Tab {
// Store some extra info for displaying the tab in the picker.
final WebHistoryItem item = list != null ? list.getCurrentItem() : null;
+ mSavedState.putLong(ID, mId);
mSavedState.putString(CURRURL, mCurrentState.mUrl);
mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
- mSavedState.putBoolean(CLOSEONEXIT, mCloseOnExit);
if (mAppId != null) {
mSavedState.putString(APPID, mAppId);
}
// Remember the parent tab so the relationship can be restored.
- if (mParentTab != null) {
- mSavedState.putInt(PARENTTAB, mWebViewController.getTabControl().getTabIndex(
- mParentTab));
+ if (mParent != null) {
+ mSavedState.putLong(PARENTTAB, mParent.mId);
}
if (mScreenshot != null) {
mSavedState.putParcelable(SCREENSHOT, mScreenshot);
@@ -1767,7 +1752,7 @@ class Tab {
// Restore the internal state even if the WebView fails to restore.
// This will maintain the app id, original url and close-on-exit values.
mSavedState = null;
- mCloseOnExit = b.getBoolean(CLOSEONEXIT);
+ mId = b.getLong(ID);
mAppId = b.getString(APPID);
mScreenshot = b.getParcelable(SCREENSHOT);