Bug 555816 - 'Start Page' preferences pane clean up [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Tue, 30 Mar 2010 13:27:03 -0400
changeset 66078 b4cc6d5dad4ddea134d2cd17d9c3dbe7eb5be16c
parent 66077 aa8d289017e6fb6c0bfae71638e49fd4d99a52b3
child 66079 cd520136470b09b4d2d7bc75c09ec68c88f73dad
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs555816
Bug 555816 - 'Start Page' preferences pane clean up [r=vingtetun]
mobile/chrome/content/browser.xul
mobile/chrome/content/preferences.js
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -398,17 +398,17 @@
                 &defaultBrowser.description;
               </setting>
 #endif
               <setting id="prefs-homepage" title="&homepage.title;" type="control">
                 <menulist id="prefs-homepage-options" oncommand="PreferencesView.updateHomePage();">
                   <menupopup>
                     <menuitem id="prefs-homepage-default" label="&homepage.default;" value="default"/>
                     <menuitem id="prefs-homepage-none" label="&homepage.none;" value="none"/>
-                    <menuitem id="prefs-homepage-currentpage" label="&homepage.currentpage;" value="custom"/>
+                    <menuitem id="prefs-homepage-currentpage" label="&homepage.currentpage;" value="currentpage"/>
                   </menupopup>
                 </menulist>
               </setting>
               <settings id="prefs-content" label="&content.title;">
                 <setting pref="permissions.default.image" title="&showImages.title;" type="boolint" on="1" off="2"/>
                 <setting pref="javascript.enabled" type="bool" title="&enableJavaScript.title;"/>
               </settings>
               <settings id="prefs-privacy" label="&privacy.title;">
--- a/mobile/chrome/content/preferences.js
+++ b/mobile/chrome/content/preferences.js
@@ -191,77 +191,102 @@ var PreferencesView = {
 
     // Show the restart notification, if needed
     if (this._currentLocale == newLocale)
       this.hideRestart();
     else
       this.showRestart();
   },
 
+  _showHomePageHint: function _showHomePageHint(aHint) {
+    if (aHint)
+      document.getElementById("prefs-homepage").setAttribute("desc", aHint);
+    else
+      document.getElementById("prefs-homepage").removeAttribute("desc");
+  },
+
   _loadHomePage: function _loadHomePage() {
     let url = Browser.getHomePage();
     let value = "default";
     let display = url;
+    try {
+      display = gPrefService.getComplexValue("browser.startup.homepage.title", Ci.nsIPrefLocalizedString).data;
+    } catch (e) { }
 
     switch (url) {
       case "about:blank":
         value = "none";
-        display = "";
+        display = null;
         break;
       case "about:home":
         value = "default";
-        display = "";
+        display = null;
         break;
       default:
         value = "custom";
         break;
     }
 
-    // Show or hide the URL of the custom homepage
-    document.getElementById("prefs-homepage").setAttribute("desc", display);
+    // Show or hide the title or URL of the custom homepage
+    this._showHomePageHint(display);
   
-    // Select the homepage option
+    // Add the helper "Custom Page" item in the menulist, if needed
     let options = document.getElementById("prefs-homepage-options");
     if (value == "custom") {
       // Make sure nothing is selected and just use a label to show the state
-      options.selectedIndex = -1;
-      options.setAttribute("label", Elements.browserBundle.getString("homepage.custom2"));
-    } else {
-      // Select the right menulist item
-      options.value = value;
+      options.appendItem(Elements.browserBundle.getString("homepage.custom2"), "custom");
     }
+
+    // Select the right menulist item
+    options.value = value;
   },
 
   updateHomePage: function updateHomePage() {
-    let url = "about:home";
     let options = document.getElementById("prefs-homepage-options");
     let value = options.selectedItem.value;
-    let display = "";
+
+    let url = "about:home";
+    let display = null;
 
     switch (value) {
       case "none":
         url = "about:blank";
         break;
       case "default":
         url = "about:home";
         break;
-      case "custom":
+      case "currentpage":
         url = Browser.selectedBrowser.currentURI.spec;
-        display = url;
+        display = Browser.selectedBrowser.contentDocument.title || url;
         break;
     }
 
-    // Show or hide the URL of the custom homepage
-    document.getElementById("prefs-homepage").setAttribute("desc", display);
+    // Show or hide the title or URL of the custom homepage
+    this._showHomePageHint(display);
+
+    // Is the helper already in the list
+    let helper = null;
+    let items = options.menupopup.getElementsByAttribute("value", "custom");
+    if (items && items.length)
+      helper = items[0];
 
-    let options = document.getElementById("prefs-homepage-options");
-    if (value == "custom") {
-      // Make sure nothing is selected and just use a label to show the state
-      options.selectedIndex = -1;
-      options.setAttribute("label", Elements.browserBundle.getString("homepage.custom2"));
+    // Update the helper "Custom Page" item in the menulist
+    if (value == "currentpage") {
+      // If the helper item is not already in the list, we need to put it there
+      // (this can happen when changing from one custom page to another)
+      if (!helper)
+        helper = options.appendItem(Elements.browserBundle.getString("homepage.custom2"), "custom");
+
+      options.selectedItem = helper;
+    } else {
+      options.menupopup.removeChild(helper);
     }
 
     // Save the homepage URL to a preference
     let pls = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(Ci.nsIPrefLocalizedString);
     pls.data = url;
     gPrefService.setComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString, pls);
+
+    // Save the homepage title to a preference
+    pls.data = display;
+    gPrefService.setComplexValue("browser.startup.homepage.title", Ci.nsIPrefLocalizedString, pls);
   }
 };