Overhaul handling tab data updates
Bug: 2127502, 3191165
Pushed some state tracking to the tab for URL, title, favicon,
and lock status. This allowed me to remove many duplicate methods
of updating that data, preventing the UI from getting out of sync
with the web view.
Change-Id: I995caa98068ad03ca37710207b5ab57bb9d801ab
diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java
index ea734a6..88209fe 100644
--- a/src/com/android/browser/TabBar.java
+++ b/src/com/android/browser/TabBar.java
@@ -73,10 +73,8 @@
private boolean mUserRequestedUrlbar;
private int mVisibleTitleHeight;
- private boolean mHasReceivedTitle;
private Drawable mGenericFavicon;
- private String mLoadingText;
private Drawable mActiveDrawable;
private Drawable mInactiveDrawable;
@@ -111,7 +109,6 @@
mNewTab = (ImageButton) findViewById(R.id.newtab);
mNewTab.setOnClickListener(this);
mGenericFavicon = res.getDrawable(R.drawable.app_web_browser_sm);
- mLoadingText = res.getString(R.string.title_bar_loading);
setChildrenDrawingOrderEnabled(true);
// TODO: Change enabled states based on whether you can go
@@ -346,19 +343,16 @@
private void updateFromData() {
mTabData.mTabView = this;
- if (mTabData.mUrl != null) {
- setDisplayTitle(mTabData.mUrl);
+ Tab tab = mTabData.mTab;
+ String displayTitle = tab.getTitle();
+ if (displayTitle == null) {
+ displayTitle = tab.getUrl();
}
- if (mTabData.mTitle != null) {
- setDisplayTitle(mTabData.mTitle);
- }
+ setDisplayTitle(displayTitle);
setProgress(mTabData.mProgress);
if (mTabData.mIcon != null) {
setFavicon(mTabData.mIcon);
}
- if (mTabData.mLock != null) {
- setLock(mTabData.mLock);
- }
if (mTabData.mTab != null) {
mIncognito.setVisibility(
mTabData.mTab.isPrivateBrowsingEnabled() ?
@@ -463,21 +457,13 @@
TabView mTabView;
int mProgress;
Drawable mIcon;
- Drawable mLock;
- String mTitle;
- String mUrl;
TabViewData(Tab tab) {
mTab = tab;
- WebView web = tab.getWebView();
- if (web != null) {
- setUrlAndTitle(web.getUrl(), web.getTitle());
- }
+ setUrlAndTitle(mTab.getUrl(), mTab.getTitle());
}
void setUrlAndTitle(String url, String title) {
- mUrl = url;
- mTitle = title;
if (mTabView != null) {
if (title != null) {
mTabView.setDisplayTitle(title);
@@ -562,31 +548,12 @@
}
public void onUrlAndTitle(Tab tab, String url, String title) {
- mHasReceivedTitle = true;
TabViewData tvd = mTabMap.get(tab);
if (tvd != null) {
tvd.setUrlAndTitle(url, title);
}
}
- public void onPageFinished(Tab tab) {
- if (!mHasReceivedTitle) {
- TabViewData tvd = mTabMap.get(tab);
- if (tvd != null) {
- tvd.setUrlAndTitle(tvd.mUrl, null);
- }
- }
- }
-
- public void onPageStarted(Tab tab, String url, Bitmap favicon) {
- mHasReceivedTitle = false;
- TabViewData tvd = mTabMap.get(tab);
- if (tvd != null) {
- tvd.setFavicon(favicon);
- tvd.setUrlAndTitle(url, mLoadingText);
- }
- }
-
private boolean isLoading() {
TabViewData tvd = mTabMap.get(mTabControl.getCurrentTab());
if ((tvd != null) && (tvd.mTabView != null)) {