Bug 751205 - (Part 2) Un-singleton-ify SiteIdentityPopup. r=wesj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Thu, 20 Jun 2013 08:06:15 -0700
changeset 147312 6b17a76cd79a0608b1b40e5590df222206d9bbae
parent 147311 bfe598caed730c316b1c393691a2ff0f2a93224f
child 147313 1433cdfd1a4342927432895d29ed5ae9702af84b
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs751205
milestone24.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 751205 - (Part 2) Un-singleton-ify SiteIdentityPopup. r=wesj
mobile/android/base/BrowserApp.java
mobile/android/base/BrowserToolbar.java
mobile/android/base/DoorHangerPopup.java
mobile/android/base/GeckoApp.java
mobile/android/base/SiteIdentityPopup.java
mobile/android/base/widget/ArrowPopup.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -147,16 +147,25 @@ abstract public class BrowserApp extends
     private static final String ABOUTHOME_TAG = "abouthome";
 
     private SharedPreferencesHelper mSharedPreferencesHelper;
 
     private OrderedBroadcastHelper mOrderedBroadcastHelper;
 
     private BrowserHealthReporter mBrowserHealthReporter;
 
+    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) {
         switch(msg) {
             case LOCATION_CHANGE:
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     maybeCancelFaviconLoad(tab);
                 }
                 // fall through
@@ -168,18 +177,18 @@ abstract public class BrowserApp extends
                         if (isDynamicToolbarEnabled()) {
                             // Show the toolbar.
                             mLayerView.getLayerMarginsAnimator().showMargins(false);
                         }
                     } else {
                         hideAboutHome();
                     }
 
-                    // Dismiss any SiteIdentity Popup
-                    SiteIdentityPopup.getInstance().dismiss();
+                    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
@@ -894,16 +903,29 @@ abstract public class BrowserApp extends
         });
     }
 
     @Override
     public void refreshChrome() {
         invalidateOptionsMenu();
         updateSideBarState();
         mTabsPanel.refresh();
+        if (mSiteIdentityPopup != null) {
+            mSiteIdentityPopup.dismiss();
+        }
+    }
+
+    @Override
+    public void onBackPressed() {
+        if (mSiteIdentityPopup != null && mSiteIdentityPopup.isShowing()) {
+            mSiteIdentityPopup.dismiss();
+            return;
+        }
+
+        super.onBackPressed();
     }
 
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         String url = null;
 
         // Don't update the url in the toolbar if the activity was cancelled.
         if (resultCode == Activity.RESULT_OK && data != null) {
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -286,17 +286,17 @@ public class BrowserToolbar implements T
         });
 
         Button.OnClickListener faviconListener = new Button.OnClickListener() {
             @Override
             public void onClick(View view) {
                 if (mSiteSecurity.getVisibility() != View.VISIBLE)
                     return;
 
-                SiteIdentityPopup.getInstance().show(mSiteSecurity);
+                mActivity.getSiteIdentityPopup().show(mSiteSecurity);
             }
         };
 
         mFavicon = (ImageButton) mLayout.findViewById(R.id.favicon);
         mFavicon.setOnClickListener(faviconListener);
         if (Build.VERSION.SDK_INT >= 16)
             mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
         mFaviconSize = Math.round(mActivity.getResources().getDimension(R.dimen.browser_toolbar_favicon_size));
--- a/mobile/android/base/DoorHangerPopup.java
+++ b/mobile/android/base/DoorHangerPopup.java
@@ -19,26 +19,24 @@ import android.view.View;
 import android.widget.RelativeLayout;
 
 import java.util.HashSet;
 
 public class DoorHangerPopup extends ArrowPopup
                              implements GeckoEventListener, Tabs.OnTabsChangedListener {
     private static final String LOGTAG = "GeckoDoorHangerPopup";
 
-    private GeckoApp mActivity;
     private View mAnchor;
 
     // Stores a set of all active DoorHanger notifications. A DoorHanger is
     // uniquely identified by its tabId and value.
     private HashSet<DoorHanger> mDoorHangers;
 
     DoorHangerPopup(GeckoApp aActivity, View aAnchor) {
         super(aActivity);
-        mActivity = aActivity;
         mAnchor = aAnchor;
 
         mDoorHangers = new HashSet<DoorHanger>();
 
         registerEventListener("Doorhanger:Add");
         registerEventListener("Doorhanger:Remove");
         Tabs.registerOnTabsChangedListener(this);
     }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1830,18 +1830,16 @@ abstract public class GeckoApp
 
     @Override
     public void onResume()
     {
         // After an onPause, the activity is back in the foreground.
         // Undo whatever we did in onPause.
         super.onResume();
 
-        SiteIdentityPopup.getInstance().dismiss();
-
         int newOrientation = getResources().getConfiguration().orientation;
 
         if (mOrientation != newOrientation) {
             mOrientation = newOrientation;
             refreshChrome();
         }
 
         GeckoScreenOrientationListener.getInstance().start();
@@ -1990,17 +1988,16 @@ abstract public class GeckoApp
         if (mDoorHangerPopup != null)
             mDoorHangerPopup.destroy();
         if (mFormAssistPopup != null)
             mFormAssistPopup.destroy();
         if (mPromptService != null)
             mPromptService.destroy();
         if (mTextSelection != null)
             mTextSelection.destroy();
-        SiteIdentityPopup.clearInstance();
         if (mNotificationHelper != null)
             mNotificationHelper.destroy();
 
         Tabs.getInstance().detachFromActivity(this);
 
         if (SmsManager.getInstance() != null) {
             SmsManager.getInstance().stop();
             if (isFinishing())
@@ -2054,17 +2051,16 @@ abstract public class GeckoApp
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
 
         if (mOrientation != newConfig.orientation) {
             mOrientation = newConfig.orientation;
             if (mFormAssistPopup != null)
                 mFormAssistPopup.hide();
-            SiteIdentityPopup.getInstance().dismiss();
             refreshChrome();
         }
     }
 
     @Override
     public Object onRetainCustomNonConfigurationInstance() {
         // Send a non-null value so that we can restart the application, 
         // when activity restarts due to configuration change.
@@ -2239,22 +2235,16 @@ abstract public class GeckoApp
         }
 
         if (mFullScreenPluginView != null) {
             GeckoAppShell.onFullScreenPluginHidden(mFullScreenPluginView);
             removeFullScreenPluginView(mFullScreenPluginView);
             return;
         }
 
-        SiteIdentityPopup identityPopup = SiteIdentityPopup.getInstance();
-        if (identityPopup.isShowing()) {
-            identityPopup.dismiss();
-            return;
-        }
-
         if (mLayerView != null && mLayerView.isFullScreen()) {
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FullScreen:Exit", null));
             return;
         }
 
         Tabs tabs = Tabs.getInstance();
         Tab tab = tabs.getSelectedTab();
         if (tab == null) {
--- a/mobile/android/base/SiteIdentityPopup.java
+++ b/mobile/android/base/SiteIdentityPopup.java
@@ -25,53 +25,41 @@ import android.widget.TextView;
  */
 public class SiteIdentityPopup extends ArrowPopup {
     private static final String LOGTAG = "GeckoSiteIdentityPopup";
 
     public static final String UNKNOWN = "unknown";
     public static final String VERIFIED = "verified";
     public static final String IDENTIFIED = "identified";
 
-    private static SiteIdentityPopup sInstance;
-
     private Resources mResources;
 
     private TextView mHost;
     private TextView mOwner;
     private TextView mSupplemental;
     private TextView mVerifier;
     private TextView mEncrypted;
     private ImageView mLarry;
 
-    private SiteIdentityPopup() {
-        super(GeckoAppShell.getContext());
-
-        mResources = GeckoAppShell.getContext().getResources();
-    }
+    SiteIdentityPopup(BrowserApp aActivity) {
+        super(aActivity);
 
-    public static synchronized SiteIdentityPopup getInstance() {
-        if (sInstance == null) {
-            sInstance = new SiteIdentityPopup();
-        }
-        return sInstance;
-    }
-
-    public static synchronized void clearInstance() {
-        sInstance = null;
+        mResources = aActivity.getResources();
     }
 
     @Override
     protected void init() {
         super.init();
 
         // Make the popup focusable so it doesn't inadvertently trigger click events elsewhere
         // which may reshow the popup (see bug 785156)
         setFocusable(true);
 
-        LinearLayout layout = (LinearLayout) mInflater.inflate(R.layout.site_identity, null);
+        LayoutInflater inflater = LayoutInflater.from(mActivity);
+        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.site_identity, null);
         mContent.addView(layout);
 
         mHost = (TextView) layout.findViewById(R.id.host);
         mOwner = (TextView) layout.findViewById(R.id.owner);
         mVerifier = (TextView) layout.findViewById(R.id.verifier);
         mLarry = (ImageView) layout.findViewById(R.id.larry);
     }
 
--- a/mobile/android/base/widget/ArrowPopup.java
+++ b/mobile/android/base/widget/ArrowPopup.java
@@ -1,57 +1,58 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.widget;
 
+import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.util.HardwareUtils;
 
-import android.content.Context;
 import android.graphics.drawable.BitmapDrawable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
 import android.widget.RelativeLayout;
 
 public class ArrowPopup extends PopupWindow {
-    protected LayoutInflater mInflater;
+    protected GeckoApp mActivity;
     protected boolean mInflated;
 
     protected LinearLayout mContent;
     protected ImageView mArrow;
 
     protected int mArrowWidth;
     protected int mYOffset;
 
-    public ArrowPopup(Context aContext) {
-        super(aContext);
-        mInflater = LayoutInflater.from(aContext);
+    public ArrowPopup(GeckoApp aActivity) {
+        super(aActivity);
+        mActivity = aActivity;
 
         mInflated = false;
-        mArrowWidth = aContext.getResources().getDimensionPixelSize(R.dimen.menu_popup_arrow_width);
-        mYOffset = aContext.getResources().getDimensionPixelSize(R.dimen.menu_popup_offset);
+        mArrowWidth = aActivity.getResources().getDimensionPixelSize(R.dimen.menu_popup_arrow_width);
+        mYOffset = aActivity.getResources().getDimensionPixelSize(R.dimen.menu_popup_offset);
 
         setAnimationStyle(R.style.PopupAnimation);
     }
 
     protected void init() {
         setBackgroundDrawable(new BitmapDrawable());
         setOutsideTouchable(true);
 
         setWindowLayoutMode(HardwareUtils.isTablet() ? ViewGroup.LayoutParams.WRAP_CONTENT : ViewGroup.LayoutParams.FILL_PARENT,
             ViewGroup.LayoutParams.WRAP_CONTENT);
 
-        RelativeLayout layout = (RelativeLayout) mInflater.inflate(R.layout.arrow_popup, null);
+        LayoutInflater inflater = LayoutInflater.from(mActivity);
+        RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.arrow_popup, null);
         setContentView(layout);
 
         mArrow = (ImageView) layout.findViewById(R.id.arrow);
         mContent = (LinearLayout) layout.findViewById(R.id.content);
 
         mInflated = true;
     }
 }