Bug 735471 - Add a pref to switch between window'd preferences and in-content preferences. r=jaws,bmcbride
authorDevan Sayles <saylesd1@msu.edu>
Tue, 08 May 2012 19:31:51 -0700
changeset 93589 9b4f86c85565c3da346592d86a2c65a4bfc2c481
parent 93588 0fbf6059c2937ea5ce1c2f7dc140daf90bf2437b
child 93590 8b195889f55cc8feb0517352261e46afbd32218c
push id22646
push useremorley@mozilla.com
push dateWed, 09 May 2012 14:40:08 +0000
treeherdermozilla-central@d3f81d81f664 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, bmcbride
bugs735471
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 735471 - Add a pref to switch between window'd preferences and in-content preferences. r=jaws,bmcbride
browser/app/profile/firefox.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug735471.js
browser/base/content/utilityOverlay.js
browser/components/nsBrowserContentHandler.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -626,16 +626,19 @@ pref("browser.preferences.instantApply",
 pref("browser.preferences.instantApply", true);
 #endif
 #ifdef XP_MACOSX
 pref("browser.preferences.animateFadeIn", true);
 #else
 pref("browser.preferences.animateFadeIn", false);
 #endif
 
+// Toggles between the two Preferences implementations, pop-up window and in-content
+pref("browser.preferences.inContent", false);
+
 pref("browser.download.show_plugins_in_list", true);
 pref("browser.download.hide_plugins_without_extensions", true);
 
 // Backspace and Shift+Backspace behavior
 // 0 goes Back/Forward
 // 1 act like PgUp/PgDown
 // 2 and other values, nothing
 #ifdef UNIX_BUT_NOT_MAC
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -176,16 +176,17 @@ endif
                  browser_bug623155.js \
                  browser_bug623893.js \
                  browser_bug624734.js \
                  browser_bug647886.js \
                  browser_bug655584.js \
                  browser_bug664672.js \
                  browser_bug710878.js \
                  browser_bug719271.js \
+                 browser_bug735471.js \
                  browser_bug743421.js \
                  browser_bug749738.js \
                  browser_canonizeURL.js \
                  browser_findbarClose.js \
                  browser_homeDrop.js \
                  browser_keywordBookmarklets.js \
                  browser_contextSearchTabPosition.js \
                  browser_ctrlTab.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug735471.js
@@ -0,0 +1,59 @@
+/*
+ * 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/.
+ */
+
+
+function test() {
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    // Reset pref to its default
+    Services.prefs.clearUserPref("browser.preferences.inContent");
+  });
+  
+  // Verify that about:preferences tab is displayed when
+  // browser.preferences.inContent is set to true
+  Services.prefs.setBoolPref("browser.preferences.inContent", true);
+    
+  gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
+    
+    gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true);
+    let browser = aEvent.originalTarget.linkedBrowser;
+    browser.addEventListener("load", function(aEvent) {
+      browser.removeEventListener("load", arguments.callee, true);
+      
+      is(Services.prefs.getBoolPref("browser.preferences.inContent"), true, "In-content prefs are enabled");
+      is(browser.contentWindow.location.href, "about:preferences", "Checking if the preferences tab was opened");
+      
+      gBrowser.removeCurrentTab();
+      Services.prefs.setBoolPref("browser.preferences.inContent", false);
+      openPreferences();
+      
+    }, true);
+  }, true);
+  
+  
+  let observer = {
+    observe: function(aSubject, aTopic, aData) {
+      if (aTopic == "domwindowopened") {
+        windowWatcher.unregisterNotification(observer);
+        
+        let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
+        win.addEventListener("load", function() {
+          win.removeEventListener("load", arguments.callee, false);
+          is(Services.prefs.getBoolPref("browser.preferences.inContent"), false, "In-content prefs are disabled");
+          is(win.location.href, "chrome://browser/content/preferences/preferences.xul", "Checking if the preferences window was opened");
+          win.close();
+          finish();
+        }, false);
+      }
+    }
+  }
+  
+  var windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
+                        .getService(Components.interfaces.nsIWindowWatcher);
+  windowWatcher.registerNotification(observer);
+  
+  openPreferences();
+}
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -490,37 +490,41 @@ function openAboutDialog() {
 #else
   var features = "chrome,centerscreen,dependent,dialog=no";
 #endif
   window.openDialog("chrome://browser/content/aboutDialog.xul", "", features);
 }
 
 function openPreferences(paneID, extraArgs)
 {
-  var instantApply = getBoolPref("browser.preferences.instantApply", false);
-  var features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
+  if (Services.prefs.getBoolPref("browser.preferences.inContent")) {  
+    openUILinkIn("about:preferences", "tab");
+  } else {
+    var instantApply = getBoolPref("browser.preferences.instantApply", false);
+    var features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
 
-  var win = Services.wm.getMostRecentWindow("Browser:Preferences");
-  if (win) {
-    win.focus();
-    if (paneID) {
-      var pane = win.document.getElementById(paneID);
-      win.document.documentElement.showPane(pane);
+    var win = Services.wm.getMostRecentWindow("Browser:Preferences");
+    if (win) {
+      win.focus();
+      if (paneID) {
+        var pane = win.document.getElementById(paneID);
+        win.document.documentElement.showPane(pane);
+      }
+
+      if (extraArgs && extraArgs["advancedTab"]) {
+        var advancedPaneTabs = win.document.getElementById("advancedPrefs");
+        advancedPaneTabs.selectedTab = win.document.getElementById(extraArgs["advancedTab"]);
+      }
+
+     return win;
     }
 
-    if (extraArgs && extraArgs["advancedTab"]) {
-      var advancedPaneTabs = win.document.getElementById("advancedPrefs");
-      advancedPaneTabs.selectedTab = win.document.getElementById(extraArgs["advancedTab"]);
-    }
-
-    return win;
+    return openDialog("chrome://browser/content/preferences/preferences.xul",
+                      "Preferences", features, paneID, extraArgs);
   }
-
-  return openDialog("chrome://browser/content/preferences/preferences.xul",
-                    "Preferences", features, paneID, extraArgs);
 }
 
 function openAdvancedPreferences(tabID)
 {
   return openPreferences("paneAdvanced", { "advancedTab" : tabID });
 }
 
 /**
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -285,24 +285,43 @@ function openWindow(parent, url, target,
   argArray.AppendElement(null); // referer
   argArray.AppendElement(null); // postData
   argArray.AppendElement(null); // allowThirdPartyFixup
 
   return wwatch.openWindow(parent, url, target, features, argArray);
 }
 
 function openPreferences() {
-  var features = "chrome,titlebar,toolbar,centerscreen,dialog=no";
-  var url = "chrome://browser/content/preferences/preferences.xul";
+  if (Services.prefs.getBoolPref("browser.preferences.inContent")) { 
+    var sa = Components.classes["@mozilla.org/supports-array;1"]
+                       .createInstance(Components.interfaces.nsISupportsArray);
+
+    var wuri = Components.classes["@mozilla.org/supports-string;1"]
+                         .createInstance(Components.interfaces.nsISupportsString);
+    wuri.data = "about:preferences";
+
+    sa.AppendElement(wuri);
+
+    var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
+                           .getService(nsIWindowWatcher);
 
-  var win = getMostRecentWindow("Browser:Preferences");
-  if (win) {
-    win.focus();
+    wwatch.openWindow(null, gBrowserContentHandler.chromeURL,
+                      "_blank",
+                      "chrome,dialog=no,all",
+                      sa);
   } else {
-    openWindow(null, url, "_blank", features);
+    var features = "chrome,titlebar,toolbar,centerscreen,dialog=no";
+    var url = "chrome://browser/content/preferences/preferences.xul";
+    
+    var win = getMostRecentWindow("Browser:Preferences");
+    if (win) {
+      win.focus();
+    } else {
+      openWindow(null, url, "_blank", features);
+    }
   }
 }
 
 function getMostRecentWindow(aType) {
   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                      .getService(nsIWindowMediator);
   return wm.getMostRecentWindow(aType);
 }