Bug 845051 - (Part 2) Handle tab events directly in BrowserToolbar, instead of going through BrowserApp. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 26 Feb 2013 14:38:38 -0800
changeset 123095 956f5c45646301c987f468a71c03bfc790138bd7
parent 123094 dc4f4e042b3f013020a59559cdcd154ab8afc556
child 123096 a5c27d24d2a560a2e282b23f2b7ab11e2a96b5a2
push id24372
push useremorley@mozilla.com
push dateWed, 27 Feb 2013 13:22:59 +0000
treeherdermozilla-central@0a91da5f5eab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs845051
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 845051 - (Part 2) Handle tab events directly in BrowserToolbar, instead of going through BrowserApp. r=mfinkle
mobile/android/base/BrowserApp.java
mobile/android/base/BrowserToolbar.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -132,41 +132,26 @@ abstract public class BrowserApp extends
                 // If tab is not loading and the favicon is updated, we
                 // want to load the image straight away. If tab is still
                 // loading, we only load the favicon once the page's content
                 // is fully loaded.
                 if (tab.getState() != Tab.STATE_LOADING) {
                     loadFavicon(tab);
                 }
                 break;
-            case SECURITY_CHANGE:
-                handleSecurityChange(tab);
-                break;
-            case READER_ENABLED:
-                handleReaderEnabled(tab);
-                break;
         }
         super.onTabChanged(tab, msg, data);
     }
 
     @Override
     void handleClearHistory() {
         super.handleClearHistory();
         updateAboutHomeTopSites();
     }
 
-    void handleSecurityChange(final Tab tab) {
-        mMainHandler.post(new Runnable() { 
-            public void run() {
-                if (Tabs.getInstance().isSelectedTab(tab))
-                    mBrowserToolbar.setSecurityMode(tab.getSecurityMode());
-            }
-        });
-    }
-
     void handleReaderAdded(boolean success, final String title, final String url) {
         if (!success) {
             showToast(R.string.reading_list_failed, Toast.LENGTH_SHORT);
             return;
         }
 
         GeckoAppShell.getHandler().post(new Runnable() {
             public void run() {
@@ -180,25 +165,16 @@ abstract public class BrowserApp extends
         GeckoAppShell.getHandler().post(new Runnable() {
             public void run() {
                 BrowserDB.removeReadingListItemWithURL(getContentResolver(), url);
                 showToast(R.string.reading_list_removed, Toast.LENGTH_SHORT);
             }
         });
     }
 
-    void handleReaderEnabled(final Tab tab) {
-        mMainHandler.post(new Runnable() {
-            public void run() {
-                if (Tabs.getInstance().isSelectedTab(tab))
-                    mBrowserToolbar.setReaderMode(tab.getReaderEnabled());
-            }
-        });
-    }
-
     @Override
     void onStatePurged() {
         mMainHandler.post(new Runnable() {
             public void run() {
                 if (mAboutHomeContent != null)
                     mAboutHomeContent.setLastTabsVisibility(false);
             }
         });
@@ -688,19 +664,16 @@ abstract public class BrowserApp extends
                 // The tab might be pointing to another URL by the time the
                 // favicon is finally loaded, in which case we simply ignore it.
                 if (!tab.getURL().equals(pageUrl))
                     return;
 
                 tab.updateFavicon(favicon);
                 tab.setFaviconLoadId(Favicons.NOT_LOADING);
 
-                if (Tabs.getInstance().isSelectedTab(tab))
-                    mBrowserToolbar.setFavicon(tab.getFavicon());
-
                 Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.FAVICON);
             }
         });
 
         tab.setFaviconLoadId(id);
     }
 
     private void maybeCancelFaviconLoad(Tab tab) {
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -416,16 +416,31 @@ public class BrowserToolbar implements V
             case CLOSED:
             case ADDED:
                 updateTabCountAndAnimate(Tabs.getInstance().getCount());
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     updateBackButton(tab.canDoBack());
                     updateForwardButton(tab.canDoForward());
                 }
                 break;
+            case FAVICON:
+                if (Tabs.getInstance().isSelectedTab(tab)) {
+                    setFavicon(tab.getFavicon());
+                }
+                break;
+            case SECURITY_CHANGE:
+                if (Tabs.getInstance().isSelectedTab(tab)) {
+                    setSecurityMode(tab.getSecurityMode());
+                }
+                break;
+            case READER_ENABLED:
+                if (Tabs.getInstance().isSelectedTab(tab)) {
+                    setReaderMode(tab.getReaderEnabled());
+                }
+                break;
         }
     }
 
     @Override
     public void onAnimationStart(Animation animation) {
         if (animation.equals(mLockFadeIn)) {
             if (mSiteSecurityVisible)
                 mSiteSecurity.setVisibility(View.VISIBLE);
@@ -975,44 +990,44 @@ public class BrowserToolbar implements V
         if (tab != null && ("about:home".equals(tab.getURL()) ||
                             "about:privatebrowsing".equals(tab.getURL())))
             title = null;
 
         mTitle.setText(title);
         mAwesomeBar.setContentDescription(title != null ? title : mTitle.getHint());
     }
 
-    public void setFavicon(Bitmap image) {
+    private void setFavicon(Bitmap image) {
         if (Tabs.getInstance().getSelectedTab().getState() == Tab.STATE_LOADING)
             return;
 
         if (image != null) {
             image = Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, false);
             mFavicon.setImageBitmap(image);
         } else {
             mFavicon.setImageResource(R.drawable.favicon);
         }
     }
     
-    public void setSecurityMode(String mode) {
+    private void setSecurityMode(String mode) {
         mShowSiteSecurity = true;
 
         if (mode.equals(SiteIdentityPopup.IDENTIFIED)) {
             mSiteSecurity.setImageLevel(1);
         } else if (mode.equals(SiteIdentityPopup.VERIFIED)) {
             mSiteSecurity.setImageLevel(2);
         } else {
             mSiteSecurity.setImageLevel(0);
             mShowSiteSecurity = false;
         }
 
         setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
     }
 
-    public void setReaderMode(boolean showReader) {
+    private void setReaderMode(boolean showReader) {
         mShowReader = showReader;
         setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
     }
 
     public void requestFocusFromTouch() {
         mLayout.requestFocusFromTouch();
     }