Bug 943915 - Encapsulate SiteIdentityPopup into BrowserToolbar (r=wesj)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 12 Dec 2013 00:28:14 +0000
changeset 160129 371cd009024b6196997d3bf70c0b4cebe4ee3a98
parent 160128 547f2316b28038bb7979d5a87c3e7fce294060c4
child 160130 d6f749a28b3df7d28b1f016fe1285f699d2654be
push id1672
push userkvijayan@mozilla.com
push dateThu, 12 Dec 2013 20:08:00 +0000
reviewerswesj
bugs943915
milestone29.0a1
Bug 943915 - Encapsulate SiteIdentityPopup into BrowserToolbar (r=wesj)
mobile/android/base/BrowserApp.java
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -22,17 +22,16 @@ import org.mozilla.gecko.home.BrowserSea
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.home.SearchEngine;
 import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.prompts.Prompt;
 import org.mozilla.gecko.toolbar.AutocompleteHandler;
 import org.mozilla.gecko.toolbar.BrowserToolbar;
-import org.mozilla.gecko.toolbar.SiteIdentityPopup;
 import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.GamepadUtils;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UiAsyncTask;
 import org.mozilla.gecko.widget.GeckoActionProvider;
 import org.mozilla.gecko.widget.ButtonToast;
@@ -183,25 +182,16 @@ abstract public class BrowserApp extends
     private Integer mTargetTabForEditingMode = null;
 
     // The animator used to toggle HomePager visibility has a race where if the HomePager is shown
     // (starting the animation), the HomePager is hidden, and the HomePager animation completes,
     // both the web content and the HomePager will be hidden. This flag is used to prevent the
     // race by determining if the web content should be hidden at the animation's end.
     private boolean mHideWebContentOnAnimationEnd = false;
 
-    private SiteIdentityPopup mSiteIdentityPopup;
-
-    public SiteIdentityPopup getSiteIdentityPopup() {
-        if (mSiteIdentityPopup == null)
-            mSiteIdentityPopup = new SiteIdentityPopup(this);
-
-        return mSiteIdentityPopup;
-    }
-
     @Override
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
         if (tab == null) {
             // Only RESTORED is allowed a null tab: it's the only event that
             // isn't tied to a specific tab.
             if (msg != Tabs.TabEvents.RESTORED) {
                 throw new IllegalArgumentException("onTabChanged:" + msg + " must specify a tab.");
             }
@@ -214,19 +204,16 @@ abstract public class BrowserApp extends
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     maybeCancelFaviconLoad(tab);
                 }
                 // fall through
             case SELECTED:
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     updateHomePagerForTab(tab);
 
-                    if (mSiteIdentityPopup != null)
-                        mSiteIdentityPopup.dismiss();
-
                     final TabsPanel.Panel panel = tab.isPrivate()
                                                 ? TabsPanel.Panel.PRIVATE_TABS
                                                 : TabsPanel.Panel.NORMAL_TABS;
                     // Delay calling showTabs so that it does not modify the mTabsChangedListeners
                     // array while we are still iterating through the array.
                     ThreadUtils.postToUiThread(new Runnable() {
                         @Override
                         public void run() {
@@ -613,18 +600,17 @@ abstract public class BrowserApp extends
             super.onBackPressed();
             return;
         }
 
         if (dismissEditingMode()) {
             return;
         }
 
-        if (mSiteIdentityPopup != null && mSiteIdentityPopup.isShowing()) {
-            mSiteIdentityPopup.dismiss();
+        if (mBrowserToolbar.onBackPressed()) {
             return;
         }
 
         if (mActionMode != null) {
             endActionModeCompat();
             return;
         }
 
@@ -1043,19 +1029,17 @@ abstract public class BrowserApp extends
         });
     }
 
     @Override
     public void refreshChrome() {
         invalidateOptionsMenu();
         updateSideBarState();
         mTabsPanel.refresh();
-        if (mSiteIdentityPopup != null) {
-            mSiteIdentityPopup.dismiss();
-        }
+        mBrowserToolbar.refresh();
     }
 
     @Override
     public boolean hasTabsSideBar() {
         return (mTabsPanel != null && mTabsPanel.isSideBar());
     }
 
     private void updateSideBarState() {
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -136,16 +136,18 @@ public class BrowserToolbar extends Geck
 
     private OnActivateListener mActivateListener;
     private OnCommitListener mCommitListener;
     private OnDismissListener mDismissListener;
     private OnFilterListener mFilterListener;
     private OnStartEditingListener mStartEditingListener;
     private OnStopEditingListener mStopEditingListener;
 
+    private SiteIdentityPopup mSiteIdentityPopup;
+
     final private BrowserApp mActivity;
     private boolean mHasSoftMenuButton;
 
     private boolean mShowSiteSecurity;
     private boolean mSpinnerVisible;
 
     private boolean mIsEditing;
     private boolean mAnimatingEntry;
@@ -290,17 +292,19 @@ public class BrowserToolbar extends Geck
                 mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
             }
             mFavicon.setLayerType(View.LAYER_TYPE_HARDWARE, null);
         }
         mFaviconSize = Math.round(res.getDimension(R.dimen.browser_toolbar_favicon_size));
 
         mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
         mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);
-        mActivity.getSiteIdentityPopup().setAnchor(mSiteSecurity);
+
+        mSiteIdentityPopup = new SiteIdentityPopup(mActivity);
+        mSiteIdentityPopup.setAnchor(mSiteSecurity);
 
         mProgressSpinner = AnimationUtils.loadAnimation(mActivity, R.anim.progress_spinner);
 
         mStop = (ImageButton) findViewById(R.id.stop);
         mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
 
         mMenu = (GeckoImageButton) findViewById(R.id.menu);
         mMenuIcon = (GeckoImageView) findViewById(R.id.menu_icon);
@@ -424,19 +428,19 @@ public class BrowserToolbar extends Geck
                 if (mSiteSecurity.getVisibility() != View.VISIBLE)
                     return;
 
                 JSONObject identityData = Tabs.getInstance().getSelectedTab().getIdentityData();
                 if (identityData == null) {
                     Log.e(LOGTAG, "Selected tab has no identity data");
                     return;
                 }
-                SiteIdentityPopup siteIdentityPopup = mActivity.getSiteIdentityPopup();
-                siteIdentityPopup.updateIdentity(identityData);
-                siteIdentityPopup.show();
+
+                mSiteIdentityPopup.updateIdentity(identityData);
+                mSiteIdentityPopup.show();
             }
         };
 
         mFavicon.setOnClickListener(faviconListener);
         mSiteSecurity.setOnClickListener(faviconListener);
 
         mStop.setOnClickListener(new Button.OnClickListener() {
             @Override
@@ -476,16 +480,24 @@ public class BrowserToolbar extends Geck
                 @Override
                 public void onClick(View view) {
                     mActivity.openOptionsMenu();
                 }
             });
         }
     }
 
+    public void refresh() {
+        dismissSiteIdentityPopup();
+    }
+
+    public boolean onBackPressed() {
+        return dismissSiteIdentityPopup();
+    }
+
     public boolean onKey(int keyCode, KeyEvent event) {
         if (event.getAction() != KeyEvent.ACTION_DOWN) {
             return false;
         }
 
         // Galaxy Note sends key events for the stylus that are outside of the
         // valid keyCode range (see bug 758427)
         if (keyCode > KeyEvent.getMaxKeyCode()) {
@@ -552,16 +564,17 @@ public class BrowserToolbar extends Geck
         switch (msg) {
             case ADDED:
             case CLOSED:
                 updateTabCount(tabs.getDisplayCount());
                 break;
             case RESTORED:
                 // TabCount fixup after OOM
             case SELECTED:
+                dismissSiteIdentityPopup();
                 updateTabCount(tabs.getDisplayCount());
                 mSwitchingTabs = true;
                 // Fall through.
         }
 
         if (tabs.isSelectedTab(tab)) {
             switch (msg) {
                 case TITLE:
@@ -588,17 +601,17 @@ public class BrowserToolbar extends Geck
 
                 case SELECTED:
                 case LOAD_ERROR:
                     updateTitle();
                     // Fall through.
                 case LOCATION_CHANGE:
                     // A successful location change will cause Tab to notify
                     // us of a title change, so we don't update the title here.
-                    refresh();
+                    refreshState();
                     break;
 
                 case CLOSED:
                 case ADDED:
                     updateBackButton(tab);
                     updateForwardButton(tab);
                     break;
 
@@ -663,16 +676,25 @@ public class BrowserToolbar extends Geck
 
     @Override
     public void onAnimationEnd(Animation animation) {
         if (animation.equals(mTitleSlideRight)) {
             mSiteSecurity.startAnimation(mLockFadeIn);
         }
     }
 
+    private boolean dismissSiteIdentityPopup() {
+        if (mSiteIdentityPopup != null && mSiteIdentityPopup.isShowing()) {
+            mSiteIdentityPopup.dismiss();
+            return true;
+        }
+
+        return false;
+    }
+
     private int getUrlBarEntryTranslation() {
         return getWidth() - mUrlBarEntry.getRight();
     }
 
     private int getUrlBarCurveTranslation() {
         return getWidth() - mTabs.getLeft();
     }
 
@@ -1528,17 +1550,17 @@ public class BrowserToolbar extends Geck
     public void show() {
         setVisibility(View.VISIBLE);
     }
 
     public void hide() {
         setVisibility(View.GONE);
     }
 
-    private void refresh() {
+    private void refreshState() {
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab != null) {
             setFavicon(tab.getFavicon());
             setProgressVisibility(tab.getState() == Tab.STATE_LOADING);
             setSecurityMode(tab.getSecurityMode());
             setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
             updateBackButton(tab);
             updateForwardButton(tab);