Bug 571598: Allow XUL documents loaded in about urls to persist attributes. r=bz
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 29 Jul 2010 22:08:50 -0700
changeset 48394 92c3a3a024057b65a4b6a4b9b42335f320c01a1a
parent 48393 1ac135c8a4847ea3739228efdf0f430932dbf7cb
child 48395 e1161df6af197e9ac4ac337b74a020b31f59459f
push id14711
push userdtownsend@mozilla.com
push dateFri, 30 Jul 2010 05:18:14 +0000
treeherderautoland@92c3a3a02405 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs571598
milestone2.0b3pre
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 571598: Allow XUL documents loaded in about urls to persist attributes. r=bz
content/xul/templates/src/nsXULContentUtils.cpp
toolkit/mozapps/extensions/test/browser/Makefile.in
toolkit/mozapps/extensions/test/browser/browser_bug567137.js
--- a/content/xul/templates/src/nsXULContentUtils.cpp
+++ b/content/xul/templates/src/nsXULContentUtils.cpp
@@ -85,16 +85,17 @@
 #include "nsIDateTimeFormat.h"
 #include "nsDateTimeFormatCID.h"
 #include "nsIScriptableDateFormat.h"
 #include "nsICollation.h"
 #include "nsCollationCID.h"
 #include "nsILocale.h"
 #include "nsILocaleService.h"
 #include "nsIConsoleService.h"
+#include "nsEscape.h"
 
 static NS_DEFINE_CID(kRDFServiceCID,        NS_RDFSERVICE_CID);
 
 //------------------------------------------------------------------------
 
 nsIRDFService* nsXULContentUtils::gRDF;
 nsIDateTimeFormat* nsXULContentUtils::gFormat;
 nsICollation *nsXULContentUtils::gCollation;
@@ -330,16 +331,30 @@ nsXULContentUtils::MakeElementURI(nsIDoc
     nsIURI *docURL = aDocument->GetDocumentURI();
     NS_ENSURE_TRUE(docURL, NS_ERROR_UNEXPECTED);
 
     nsCOMPtr<nsIURI> docURIClone;
     nsresult rv = docURL->Clone(getter_AddRefs(docURIClone));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIURL> mutableURL(do_QueryInterface(docURIClone));
+    if (!mutableURL) {
+        nsCString uri;
+        rv = docURL->GetSpec(aURI);
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        nsCAutoString ref;
+        NS_EscapeURL(NS_ConvertUTF16toUTF8(aElementID), esc_FilePath | esc_AlwaysCopy, ref);
+
+        aURI.Append('#');
+        aURI.Append(ref);
+
+        return NS_OK;
+    }
+
     NS_ENSURE_TRUE(mutableURL, NS_ERROR_NOT_AVAILABLE);
 
     rv = mutableURL->SetRef(NS_ConvertUTF16toUTF8(aElementID));
     NS_ENSURE_SUCCESS(rv, rv);
 
     return mutableURL->GetSpec(aURI);
 }
 
@@ -376,16 +391,29 @@ nsXULContentUtils::MakeElementID(nsIDocu
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
     if (url) {
         nsCAutoString ref;
         url->GetRef(ref);
         CopyUTF8toUTF16(ref, aElementID);
     } else {
+        const char* start = aURI.BeginReading();
+        const char* end = aURI.EndReading();
+        const char* chr = end;
+
+        while (--chr >= start) {
+            if (*chr == '#') {
+                nsDependentCSubstring ref = Substring(chr + 1, end);
+                nsCAutoString unescaped;
+                CopyUTF8toUTF16(NS_UnescapeURL(ref, esc_FilePath, unescaped), aElementID);
+                return NS_OK;
+            }
+        }
+
         aElementID.Truncate();
     }
 
     return NS_OK;
 }
 
 nsresult
 nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult)
--- a/toolkit/mozapps/extensions/test/browser/Makefile.in
+++ b/toolkit/mozapps/extensions/test/browser/Makefile.in
@@ -45,16 +45,17 @@ TESTXPI = $(CURDIR)/$(DEPTH)/_tests/test
 
 include $(DEPTH)/config/autoconf.mk
 
 _TEST_FILES = \
   head.js \
   browser_bug562890.js \
   browser_bug562899.js \
   browser_bug562992.js \
+  browser_bug567137.js \
   browser_bug572561.js \
   browser_dragdrop.js \
   browser_searching.js \
   browser_searching.xml \
   browser_searching_empty.xml \
   browser_sorting.js \
   browser_uninstalling.js \
   browser_updatessl.js \
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug567137.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Test that the selected category is persisted across loads of the manager
+
+function test() {
+  waitForExplicitFinish();
+
+  open_manager(null, function(aWindow) {
+    let utils = new CategoryUtilities(aWindow);
+
+    // Open the plugins category
+    utils.openType("plugin", function() {
+
+      // Re-open the manager
+      close_manager(aWindow, function() {
+        open_manager(null, function(aWindow) {
+          utils = new CategoryUtilities(aWindow);
+
+          is(utils.selectedCategory, "plugin", "Should have shown the plugins category");
+
+          // Open the extensions category
+          utils.openType("extension", function() {
+
+            // Re-open the manager
+            close_manager(aWindow, function() {
+              open_manager(null, function(aWindow) {
+                utils = new CategoryUtilities(aWindow);
+
+                is(utils.selectedCategory, "extension", "Should have shown the extensions category");
+                close_manager(aWindow, finish);
+              });
+            });
+          });
+        });
+      });
+    });
+  });
+}