Bug 1118835 - Add back pref to show title in urlbar. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 07 Jan 2015 12:03:03 -0800
changeset 248436 cce47fbfe2fc2da35bae34f5def3cd1f08fc7768
parent 248435 c6b66f2272252f2f0b3b59e1df19be2b1ab32eb5
child 248437 6c10a8ad2e7b1cb518b8821fa721d539a126add3
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1118835
milestone37.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 1118835 - Add back pref to show title in urlbar. r=mfinkle
mobile/android/app/mobile.js
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/preferences/GeckoPreferences.java
mobile/android/base/resources/values/arrays.xml
mobile/android/base/resources/xml/preferences_display.xml
mobile/android/base/strings.xml.in
mobile/android/base/toolbar/ToolbarDisplayLayout.java
mobile/android/base/toolbar/ToolbarPrefs.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -731,16 +731,21 @@ pref("memory.free_dirty_pages", true);
 pref("layout.imagevisibility.numscrollportwidths", 1);
 pref("layout.imagevisibility.numscrollportheights", 1);
 
 pref("layers.enable-tiles", true);
 
 // Enable the dynamic toolbar
 pref("browser.chrome.dynamictoolbar", true);
 
+// The mode of browser titlebar
+// 0: Show a current page title.
+// 1: Show a current page url.
+pref("browser.chrome.titlebarMode", 1);
+
 // Hide common parts of URLs like "www." or "http://"
 pref("browser.urlbar.trimURLs", true);
 
 #ifdef MOZ_PKG_SPECIAL
 // Disable webgl on ARMv6 because running the reftests takes
 // too long for some reason (bug 843738)
 pref("webgl.disabled", true);
 #endif
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -332,16 +332,20 @@ size. -->
 <!ENTITY contextmenu_edit_bookmark "Edit">
 <!ENTITY contextmenu_subscribe "Subscribe to Page">
 <!ENTITY contextmenu_site_settings "Edit Site Settings">
 <!ENTITY contextmenu_top_sites_edit "Edit">
 <!ENTITY contextmenu_top_sites_pin "Pin Site">
 <!ENTITY contextmenu_top_sites_unpin "Unpin Site">
 <!ENTITY contextmenu_add_search_engine "Add a Search Engine">
 
+<!ENTITY pref_titlebar_mode "Title bar">
+<!ENTITY pref_titlebar_mode_title "Show page title">
+<!ENTITY pref_titlebar_mode_url "Show page address">
+
 <!-- Localization note (pref_scroll_title_bar2): Label for setting that controls
      whether or not the dynamic toolbar is enabled. -->
 <!ENTITY pref_scroll_title_bar2 "Full-screen browsing">
 <!ENTITY pref_scroll_title_bar_summary "Hide the &brandShortName; title bar when scrolling down a page">
 
 <!-- Localization note (page_removed): This string appears in a toast message when
      any page is removed frome about:home. This includes pages that are in history,
      bookmarks, or reading list. -->
--- a/mobile/android/base/preferences/GeckoPreferences.java
+++ b/mobile/android/base/preferences/GeckoPreferences.java
@@ -24,17 +24,16 @@ import org.mozilla.gecko.GeckoActivitySt
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoApplication;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.GuestSession;
 import org.mozilla.gecko.LocaleManager;
 import org.mozilla.gecko.Locales;
-import org.mozilla.gecko.NewTabletUI;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.RestrictedProfiles;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
 import org.mozilla.gecko.background.common.GlobalConstants;
 import org.mozilla.gecko.background.healthreport.HealthReportConstants;
@@ -116,16 +115,17 @@ OnSharedPreferenceChangeListener
     private static final String PREFS_MENU_CHAR_ENCODING = "browser.menu.showCharacterEncoding";
     private static final String PREFS_MP_ENABLED = "privacy.masterpassword.enabled";
     private static final String PREFS_UPDATER_AUTODOWNLOAD = "app.update.autodownload";
     private static final String PREFS_GEO_REPORTING = NON_PREF_PREFIX + "app.geo.reportdata";
     private static final String PREFS_GEO_LEARN_MORE = NON_PREF_PREFIX + "geo.learn_more";
     private static final String PREFS_HEALTHREPORT_LINK = NON_PREF_PREFIX + "healthreport.link";
     private static final String PREFS_DEVTOOLS_REMOTE_ENABLED = "devtools.debugger.remote-enabled";
     private static final String PREFS_DISPLAY_REFLOW_ON_ZOOM = "browser.zoom.reflowOnZoom";
+    private static final String PREFS_DISPLAY_TITLEBAR_MODE = "browser.chrome.titlebarMode";
     private static final String PREFS_SYNC = NON_PREF_PREFIX + "sync";
     private static final String PREFS_TRACKING_PROTECTION = "privacy.trackingprotection.enabled";
     private static final String PREFS_TRACKING_PROTECTION_LEARN_MORE = NON_PREF_PREFIX + "trackingprotection.learn_more";
 
     private static final String ACTION_STUMBLER_UPLOAD_PREF = AppConstants.ANDROID_PACKAGE_NAME + ".STUMBLER_PREF";
 
     // This isn't a Gecko pref, even if it looks like one.
     private static final String PREFS_BROWSER_LOCALE = "locale";
@@ -727,16 +727,22 @@ OnSharedPreferenceChangeListener
                     pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                         @Override
                         public boolean onPreferenceClick(Preference preference) {
                             GeckoPreferences.this.restoreDefaultSearchEngines();
                             Telemetry.sendUIEvent(TelemetryContract.Event.SEARCH_RESTORE_DEFAULTS, Method.LIST_ITEM);
                             return true;
                         }
                     });
+                } else if (PREFS_DISPLAY_TITLEBAR_MODE.equals(key) &&
+                           HardwareUtils.isTablet()) {
+                    // New tablet always shows URLS, not titles.
+                    preferences.removePreference(pref);
+                    i--;
+                    continue;
                 } else if (handlers.containsKey(key)) {
                     PrefHandler handler = handlers.get(key);
                     if (!handler.setupPref(this, pref)) {
                         preferences.removePreference(pref);
                         i--;
                         continue;
                     }
                 }
--- a/mobile/android/base/resources/values/arrays.xml
+++ b/mobile/android/base/resources/values/arrays.xml
@@ -133,17 +133,25 @@
         <item>@string/pref_update_autodownload_enabled</item>
         <item>@string/pref_update_autodownload_wifi</item>
         <item>@string/pref_update_autodownload_disabled</item>
     </string-array>
     <string-array name="pref_update_autodownload_values">
         <item>enabled</item>
         <item>wifi</item>
         <item>disabled</item>
-     </string-array>
+    </string-array>
+    <string-array name="pref_titlebar_mode_entries">
+        <item>@string/pref_titlebar_mode_title</item>
+        <item>@string/pref_titlebar_mode_url</item>
+    </string-array>
+    <string-array name="pref_titlebar_mode_values">
+        <item>0</item>
+        <item>1</item>
+    </string-array>
     <!-- This value is similar to config_longPressVibePattern in android frameworks/base/core/res/res/values/config.xml-->
     <integer-array name="long_press_vibrate_msec">
         <item>0</item>
         <item>1</item>
         <item>20</item>
         <item>21</item>
     </integer-array>
 </resources>
--- a/mobile/android/base/resources/xml/preferences_display.xml
+++ b/mobile/android/base/resources/xml/preferences_display.xml
@@ -10,16 +10,22 @@
 
     <org.mozilla.gecko.preferences.FontSizePreference
                     android:key="font.size.inflation.minTwips"
                     android:title="@string/pref_text_size"
                     android:positiveButtonText="@string/pref_font_size_set"
                     android:negativeButtonText="@string/button_cancel"
                     android:persistent="false" />
 
+    <ListPreference android:key="browser.chrome.titlebarMode"
+                    android:title="@string/pref_titlebar_mode"
+                    android:entries="@array/pref_titlebar_mode_entries"
+                    android:entryValues="@array/pref_titlebar_mode_values"
+                    android:persistent="false" />
+
     <CheckBoxPreference android:key="browser.chrome.dynamictoolbar"
                         android:title="@string/pref_scroll_title_bar2"
                         android:summary="@string/pref_scroll_title_bar_summary" />
 
     <CheckBoxPreference android:key="media.autoplay.enabled"
                         android:title="@string/pref_media_autoplay_enabled"
                         android:summary="@string/pref_media_autoplay_enabled_summary" />
 
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -312,16 +312,20 @@
   <string name="contextmenu_edit_bookmark">&contextmenu_edit_bookmark;</string>
   <string name="contextmenu_subscribe">&contextmenu_subscribe;</string>
   <string name="contextmenu_site_settings">&contextmenu_site_settings;</string>
   <string name="contextmenu_top_sites_edit">&contextmenu_top_sites_edit;</string>
   <string name="contextmenu_top_sites_pin">&contextmenu_top_sites_pin;</string>
   <string name="contextmenu_top_sites_unpin">&contextmenu_top_sites_unpin;</string>
   <string name="contextmenu_add_search_engine">&contextmenu_add_search_engine;</string>
 
+  <string name="pref_titlebar_mode">&pref_titlebar_mode;</string>
+  <string name="pref_titlebar_mode_title">&pref_titlebar_mode_title;</string>
+  <string name="pref_titlebar_mode_url">&pref_titlebar_mode_url;</string>
+
   <string name="pref_scroll_title_bar2">&pref_scroll_title_bar2;</string>
   <string name="pref_scroll_title_bar_summary">&pref_scroll_title_bar_summary;</string>
 
   <string name="page_removed">&page_removed;</string>
 
   <string name="bookmark_edit_title">&bookmark_edit_title;</string>
   <string name="bookmark_edit_name">&bookmark_edit_name;</string>
   <string name="bookmark_edit_location">&bookmark_edit_location;</string>
--- a/mobile/android/base/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/toolbar/ToolbarDisplayLayout.java
@@ -352,16 +352,22 @@ public class ToolbarDisplayLayout extend
 
             final SpannableStringBuilder builder = new SpannableStringBuilder(title);
             builder.setSpan(mBlockedColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
 
             setTitle(builder);
             return;
         }
 
+        // If the pref to show the title is set, use the tab's display title.
+        if (!mPrefs.shouldShowUrl(mActivity) || url == null) {
+            setTitle(tab.getDisplayTitle());
+            return;
+        }
+
         CharSequence title = url;
         if (mPrefs.shouldTrimUrls()) {
             title = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url));
         }
 
         final String baseDomain = tab.getBaseDomain();
         if (!TextUtils.isEmpty(baseDomain)) {
             final SpannableStringBuilder builder = new SpannableStringBuilder(title);
--- a/mobile/android/base/toolbar/ToolbarPrefs.java
+++ b/mobile/android/base/toolbar/ToolbarPrefs.java
@@ -10,41 +10,48 @@ import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.content.Context;
 
 class ToolbarPrefs {
     private static final String PREF_AUTOCOMPLETE_ENABLED = "browser.urlbar.autocomplete.enabled";
+    private static final String PREF_TITLEBAR_MODE = "browser.chrome.titlebarMode";
     private static final String PREF_TRIM_URLS = "browser.urlbar.trimURLs";
 
     private static final String[] PREFS = {
         PREF_AUTOCOMPLETE_ENABLED,
+        PREF_TITLEBAR_MODE,
         PREF_TRIM_URLS
     };
 
     private final TitlePrefsHandler HANDLER = new TitlePrefsHandler();
 
     private volatile boolean enableAutocomplete;
+    private volatile boolean showUrl;
     private volatile boolean trimUrls;
 
     private Integer prefObserverId;
 
     ToolbarPrefs() {
         // Skip autocompletion while Gecko is loading.
         // We will get the correct pref value once Gecko is loaded.
         enableAutocomplete = false;
         trimUrls = true;
     }
 
     boolean shouldAutocomplete() {
         return enableAutocomplete;
     }
 
+    boolean shouldShowUrl(final Context context) {
+        return showUrl || NewTabletUI.isEnabled(context);
+    }
+
     boolean shouldTrimUrls() {
         return trimUrls;
     }
 
     void open() {
         if (prefObserverId == null) {
             prefObserverId = PrefsHelper.getPrefs(PREFS, HANDLER);
         }
@@ -67,16 +74,30 @@ class ToolbarPrefs {
                     tabs.notifyListeners(tab, Tabs.TabEvents.TITLE);
                 }
             }
         });
     }
 
     private class TitlePrefsHandler extends PrefsHelper.PrefHandlerBase {
         @Override
+        public void prefValue(String pref, String str) {
+            if (PREF_TITLEBAR_MODE.equals(pref)) {
+                // Handles PREF_TITLEBAR_MODE, which is always a string.
+                int value = Integer.parseInt(str);
+                boolean shouldShowUrl = (value == 1);
+
+                if (shouldShowUrl != showUrl) {
+                    showUrl = shouldShowUrl;
+                    triggerTitleChangeListener();
+                }
+            }
+        }
+
+        @Override
         public void prefValue(String pref, boolean value) {
             if (PREF_AUTOCOMPLETE_ENABLED.equals(pref)) {
                 enableAutocomplete = value;
 
             } else if (PREF_TRIM_URLS.equals(pref)) {
                 // Handles PREF_TRIM_URLS, which should usually be a boolean.
                 if (value != trimUrls) {
                     trimUrls = value;
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1375,16 +1375,17 @@ var BrowserApp = {
 
       // Some Gecko preferences use integers or strings to reference
       // state instead of directly representing the value.
       // Since the Java UI uses the type to determine which ui elements
       // to show and how to handle them, we need to normalize these
       // preferences to the correct type.
       switch (prefName) {
         // (string) index for determining which multiple choice value to display.
+        case "browser.chrome.titlebarMode":
         case "network.cookie.cookieBehavior":
         case "font.size.inflation.minTwips":
         case "home.sync.updateMode":
           pref.type = "string";
           pref.value = pref.value.toString();
           break;
       }
 
@@ -1425,16 +1426,17 @@ var BrowserApp = {
       // Crash reporter preference is in a service; set and return.
       case "datareporting.crashreporter.submitEnabled":
         CrashReporter.submitReports = json.value;
         return;
 #endif
       // When sending to Java, we normalized special preferences that use
       // integers and strings to represent booleans. Here, we convert them back
       // to their actual types so we can store them.
+      case "browser.chrome.titlebarMode":
       case "network.cookie.cookieBehavior":
       case "font.size.inflation.minTwips":
       case "home.sync.updateMode":
         json.type = "int";
         json.value = parseInt(json.value);
         break;
     }