Bug 752172 - Turn SiteIdentityPopup into a singleton. r=mbrubeck
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 07 May 2012 16:17:08 -0700
changeset 93411 4940a331b1471900664d9fe7012954be29d083ec
parent 93410 0a1435de2bd72d47d496c66313667ae974889713
child 93412 78e5d85cb6ac54fc50df3ceff471620a5243f22f
push id9131
push usermleibovic@mozilla.com
push dateMon, 07 May 2012 23:17:25 +0000
treeherdermozilla-inbound@4940a331b147 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs752172
milestone15.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 752172 - Turn SiteIdentityPopup into a singleton. r=mbrubeck
mobile/android/base/BrowserToolbar.java
mobile/android/base/GeckoApp.java
mobile/android/base/SiteIdentityPopup.java
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -176,17 +176,17 @@ public class BrowserToolbar {
         mSiteSecurity.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View view) {
                 int[] lockLocation = new int[2];
                 view.getLocationOnScreen(lockLocation);
                 LayoutParams lockLayoutParams = (LayoutParams) view.getLayoutParams();
 
                 // Calculate the left margin for the arrow based on the position of the lock icon.
                 int leftMargin = lockLocation[0] - lockLayoutParams.rightMargin;
-                GeckoApp.mSiteIdentityPopup.show(leftMargin);
+                SiteIdentityPopup.getInstance().show(leftMargin);
             }
         });
 
         mProgressSpinner = (AnimationDrawable) resources.getDrawable(R.drawable.progress_spinner);
         
         mStop = (ImageButton) mLayout.findViewById(R.id.stop);
         mStop.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -133,17 +133,16 @@ abstract public class GeckoApp
     public static boolean sIsGeckoReady = false;
     public static int mOrientation;
 
     private GeckoConnectivityReceiver mConnectivityReceiver;
     private GeckoBatteryManager mBatteryReceiver;
 
     public static BrowserToolbar mBrowserToolbar;
     public static DoorHangerPopup mDoorHangerPopup;
-    public static SiteIdentityPopup mSiteIdentityPopup;
     public static FormAssistPopup mFormAssistPopup;
     public Favicons mFavicons;
 
     private static LayerController mLayerController;
     private static GeckoLayerClient mLayerClient;
     private AboutHomeContent mAboutHomeContent;
     private static AbsoluteLayout mPluginContainer;
 
@@ -1653,17 +1652,16 @@ abstract public class GeckoApp
             v.setBackgroundColor(Color.WHITE);
 
             mGeckoLayout.addView(v, 0);
         }
 
         mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);
 
         mDoorHangerPopup = new DoorHangerPopup(this);
-        mSiteIdentityPopup = new SiteIdentityPopup(this);
         mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup);
 
         Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");
 
         //register for events
         GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
@@ -1944,18 +1942,17 @@ abstract public class GeckoApp
     public void onResume()
     {
         Log.i(LOGTAG, "resume");
 
         // After an onPause, the activity is back in the foreground.
         // Undo whatever we did in onPause.
         super.onResume();
 
-        if (mSiteIdentityPopup != null)
-            mSiteIdentityPopup.dismiss();
+        SiteIdentityPopup.getInstance().dismiss();
 
         int newOrientation = getResources().getConfiguration().orientation;
 
         if (mOrientation != newOrientation) {
             mOrientation = newOrientation;
             refreshActionBar();
         }
     }
@@ -2074,18 +2071,17 @@ abstract public class GeckoApp
         Log.i(LOGTAG, "configuration changed");
 
         super.onConfigurationChanged(newConfig);
 
         if (mOrientation != newConfig.orientation) {
             mOrientation = newConfig.orientation;
             if (mFormAssistPopup != null)
                 mFormAssistPopup.hide();
-            if (mSiteIdentityPopup != null)
-                mSiteIdentityPopup.dismiss();
+            SiteIdentityPopup.getInstance().dismiss();
             refreshActionBar();
         }
     }
 
     @Override
     public void onLowMemory()
     {
         Log.e(LOGTAG, "low memory");
@@ -2519,18 +2515,19 @@ abstract public class GeckoApp
 
     @Override
     public void onBackPressed() {
         if (mDoorHangerPopup.isShowing()) {
             mDoorHangerPopup.dismiss();
             return;
         }
 
-        if (mSiteIdentityPopup.isShowing()) {
-            mSiteIdentityPopup.dismiss();
+        SiteIdentityPopup identityPopup = SiteIdentityPopup.getInstance();
+        if (identityPopup.isShowing()) {
+            identityPopup.dismiss();
             return;
         }
 
         if (mDOMFullScreen) {
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FullScreen:Exit", null));
             return;
         }
 
--- a/mobile/android/base/SiteIdentityPopup.java
+++ b/mobile/android/base/SiteIdentityPopup.java
@@ -15,49 +15,60 @@ import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
 import android.widget.RelativeLayout.LayoutParams;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 import org.json.JSONObject;
 import org.json.JSONException;
 
+/**
+ * SiteIdentityPopup is a singleton class that displays site identity data in
+ * an arrow panel popup hanging from the lock icon in the browser toolbar.
+ */
 public class SiteIdentityPopup extends PopupWindow {
     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 Context mContext;
     private Resources mResources;
     private boolean mInflated;
 
     private TextView mHost;
     private TextView mOwner;
     private TextView mSupplemental;
     private TextView mVerifier;
     private TextView mEncrypted;
 
     private ImageView mLarry;
     private ImageView mArrow;
 
-    public SiteIdentityPopup(Context aContext) {
-        super(aContext);
-        mContext = aContext;
-        mResources = aContext.getResources();
+    private SiteIdentityPopup() {
+        super(GeckoApp.mAppContext);
+
+        mResources = GeckoApp.mAppContext.getResources();
         mInflated = false;
-   }
+    }
+
+    private static class InstanceHolder {
+        private static final SiteIdentityPopup INSTANCE = new SiteIdentityPopup();
+    }
+
+    public static SiteIdentityPopup getInstance() {
+       return SiteIdentityPopup.InstanceHolder.INSTANCE;
+    }
 
     private void init() {
         setBackgroundDrawable(new BitmapDrawable());
         setOutsideTouchable(true);
         setWindowLayoutMode(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
 
-        LayoutInflater inflater = LayoutInflater.from(mContext);
+        LayoutInflater inflater = LayoutInflater.from(GeckoApp.mAppContext);
         RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.site_identity_popup, null);
         setContentView(layout);
 
         mHost = (TextView) layout.findViewById(R.id.host);
         mOwner = (TextView) layout.findViewById(R.id.owner);
         mSupplemental = (TextView) layout.findViewById(R.id.supplemental);
         mVerifier = (TextView) layout.findViewById(R.id.verifier);
         mEncrypted = (TextView) layout.findViewById(R.id.encrypted);