Bug 868342 - (Part 1) Fix NPE in BrowserToolbar.setTitle. r=wesj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 08 May 2013 15:53:24 -0400
changeset 138063 1c8df5e637a21782acfec5fc13d333b3eb489780
parent 138062 b61e721b78af92e7900112d59b8cb7490139cc8e
child 138064 a23eea95bf64672dcab5fedfad76339028c9593b
push id3752
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 17:21:10 +0000
treeherdermozilla-aurora@1580544aef0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs868342
milestone23.0a1
Bug 868342 - (Part 1) Fix NPE in BrowserToolbar.setTitle. r=wesj
mobile/android/base/BrowserToolbar.java
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -882,43 +882,45 @@ public class BrowserToolbar implements T
             mShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
         }
     }
 
     private void setTitle(String title) {
         Tab tab = Tabs.getInstance().getSelectedTab();
         CharSequence displayTitle = title;
 
-        // Keep the title unchanged if the tab is entering reader mode
-        if (tab != null && tab.isEnteringReaderMode())
-            return;
+        if (tab != null) {
+            // Keep the title unchanged if the tab is entering reader mode
+            if (tab.isEnteringReaderMode()) {
+                return;
+            }
 
-        // Setting a null title will ensure we just see the "Enter Search or Address"
-        // placeholder text. Because "about:home" and "about:privatebrowsing" don't
-        // have titles, their display titles will always match their URLs.
-        if (tab != null && ("about:home".equals(title) ||
-                            "about:privatebrowsing".equals(title))) {
-            displayTitle = null;
-        }
+            // Setting a null title will ensure we just see the "Enter Search or Address"
+            // placeholder text. Because "about:home" and "about:privatebrowsing" don't
+            // have titles, their display titles will always match their URLs.
+            if ("about:home".equals(title) || "about:privatebrowsing".equals(title)) {
+                displayTitle = null;
+            }
 
-        if (mShowUrl && displayTitle != null) {
-            title = StringUtils.stripScheme(tab.getURL());
-            title = StringUtils.stripCommonSubdomains(title);
-            displayTitle = title;
+            if (mShowUrl && displayTitle != null) {
+                title = StringUtils.stripScheme(tab.getURL());
+                title = StringUtils.stripCommonSubdomains(title);
+                displayTitle = title;
 
-            // highlight the domain name if we find one
-            String baseDomain = tab.getBaseDomain();
-            if (!TextUtils.isEmpty(baseDomain)) {
-                SpannableStringBuilder builder = new SpannableStringBuilder(title);
-                int index = title.indexOf(baseDomain);
-                if (index > -1) {
-                    builder.setSpan(mUrlColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
-                    builder.setSpan(tab.isPrivate() ? mPrivateDomainColor : mDomainColor, index, index+baseDomain.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+                // highlight the domain name if we find one
+                String baseDomain = tab.getBaseDomain();
+                if (!TextUtils.isEmpty(baseDomain)) {
+                    SpannableStringBuilder builder = new SpannableStringBuilder(title);
+                    int index = title.indexOf(baseDomain);
+                    if (index > -1) {
+                        builder.setSpan(mUrlColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+                        builder.setSpan(tab.isPrivate() ? mPrivateDomainColor : mDomainColor, index, index+baseDomain.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
 
-                    displayTitle = builder;
+                        displayTitle = builder;
+                    }
                 }
             }
         }
 
         mTitle.setText(displayTitle);
         mLayout.setContentDescription(title != null ? title : mTitle.getHint());
     }