Bug 677260: Add specIgnoringRef and hasRef for URIs. r=bz, sr=biesi
authorRandell Jesup <rjesup@wgate.com>
Mon, 15 Aug 2011 17:18:15 -0400
changeset 76077 a8e6a5bebe87cdea15237b872c84440c5b29a788
parent 76076 bd5215405aa91a51a9ca9987b9ab619c00dba57f
child 76078 f48880d25772c657a4f5781fd87da3c49dfb85af
push id235
push userbzbarsky@mozilla.com
push dateTue, 27 Sep 2011 17:13:04 +0000
treeherdermozilla-beta@2d1e082d176a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, biesi
bugs677260
milestone8.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 677260: Add specIgnoringRef and hasRef for URIs. r=bz, sr=biesi
caps/src/nsNullPrincipalURI.cpp
modules/libjar/nsIJARURI.idl
modules/libjar/nsJARURI.cpp
modules/libpr0n/decoders/icon/nsIIconURI.idl
modules/libpr0n/decoders/icon/nsIconURI.cpp
netwerk/base/public/nsIFileURL.idl
netwerk/base/public/nsIURI.idl
netwerk/base/public/nsIURL.idl
netwerk/base/src/nsSimpleURI.cpp
netwerk/base/src/nsStandardURL.cpp
netwerk/test/unit/test_URIs.js
--- a/caps/src/nsNullPrincipalURI.cpp
+++ b/caps/src/nsNullPrincipalURI.cpp
@@ -197,16 +197,30 @@ nsNullPrincipalURI::SetScheme(const nsAC
 
 NS_IMETHODIMP
 nsNullPrincipalURI::GetSpec(nsACString &_spec)
 {
   _spec = mScheme + NS_LITERAL_CSTRING(":") + mPath;
   return NS_OK;
 }
 
+// result may contain unescaped UTF-8 characters
+NS_IMETHODIMP
+nsNullPrincipalURI::GetSpecIgnoringRef(nsACString &result)
+{
+  return GetSpec(result);
+}
+
+NS_IMETHODIMP
+nsNullPrincipalURI::GetHasRef(PRBool *result)
+{
+  *result = PR_FALSE;
+  return NS_OK;
+}
+
 NS_IMETHODIMP
 nsNullPrincipalURI::SetSpec(const nsACString &aSpec)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsNullPrincipalURI::GetUsername(nsACString &_username)
--- a/modules/libjar/nsIJARURI.idl
+++ b/modules/libjar/nsIJARURI.idl
@@ -42,17 +42,17 @@
  * JAR URLs have the following syntax
  *
  * jar:<jar-file-uri>!/<jar-entry>
  *
  * EXAMPLE: jar:http://www.big.com/blue.jar!/ocean.html
  *
  * The nsIURL methods operate on the <jar-entry> part of the spec.
  */
-[scriptable, uuid(c95d481a-c0ec-43cc-8320-43842b1df597)]
+[scriptable, uuid(0d31634e-2fc9-4597-9d53-11fb3f05516a)]
 interface nsIJARURI : nsIURL {
 
     /**
      * Returns the root URI (the one for the actual JAR file) for this JAR
      * (e.g., http://www.big.com/blue.jar).
      */
     readonly attribute nsIURI JARFile;
 
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -243,16 +243,30 @@ NS_IMETHODIMP
 nsJARURI::GetSpec(nsACString &aSpec)
 {
     nsCAutoString entrySpec;
     mJAREntry->GetSpec(entrySpec);
     return FormatSpec(entrySpec, aSpec);
 }
 
 NS_IMETHODIMP
+nsJARURI::GetSpecIgnoringRef(nsACString &aSpec)
+{
+    nsCAutoString entrySpec;
+    mJAREntry->GetSpecIgnoringRef(entrySpec);
+    return FormatSpec(entrySpec, aSpec);
+}
+
+NS_IMETHODIMP
+nsJARURI::GetHasRef(PRBool *result)
+{
+    return mJAREntry->GetHasRef(result);
+}
+
+NS_IMETHODIMP
 nsJARURI::SetSpec(const nsACString& aSpec)
 {
     return SetSpecWithBase(aSpec, nsnull);
 }
 
 nsresult
 nsJARURI::SetSpecWithBase(const nsACString &aSpec, nsIURI* aBaseURL)
 {
--- a/modules/libpr0n/decoders/icon/nsIIconURI.idl
+++ b/modules/libpr0n/decoders/icon/nsIIconURI.idl
@@ -68,17 +68,17 @@
    *   Values:      [normal | disabled]
    *   Description: The state of the icon.
    *
    *   Parameter:   contentType
    *   Values:      <mime-type>
    *   Description: The mime type we want an icon for. This is ignored by stock images.
    */
 
-[scriptable, uuid(b6a47fa0-2f1e-4084-ae5f-bdebab4d1cc3)]
+[scriptable, uuid(da53adda-cbe3-41bc-a57d-fdd7a0ff448b)]
 interface nsIMozIconURI : nsIURI 
 {
   /**
    * iconFile
    *
    * the file URL contained within this moz-icon url, or null.
    */
   attribute nsIURL iconURL;
--- a/modules/libpr0n/decoders/icon/nsIconURI.cpp
+++ b/modules/libpr0n/decoders/icon/nsIconURI.cpp
@@ -140,16 +140,29 @@ nsMozIconURI::GetSpec(nsACString &aSpec)
   {
     aSpec += "&contentType=";
     aSpec += mContentType.get();
   }
   
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsMozIconURI::GetSpecIgnoringRef(nsACString &result)
+{
+  return GetSpec(result);
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetHasRef(PRBool *result)
+{
+  *result = PR_FALSE;
+  return NS_OK;
+}
+
 // takes a string like ?size=32&contentType=text/html and returns a new string 
 // containing just the attribute value. i.e you could pass in this string with
 // an attribute name of 'size=', this will return 32
 // Assumption: attribute pairs in the string are separated by '&'.
 void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& result)
 {
   //NS_ENSURE_ARG_POINTER(extractAttributeValue);
 
--- a/netwerk/base/public/nsIFileURL.idl
+++ b/netwerk/base/public/nsIFileURL.idl
@@ -40,17 +40,17 @@
 
 interface nsIFile;
 
 /**
  * nsIFileURL provides access to the underlying nsIFile object corresponding to
  * an URL.  The URL scheme need not be file:, since other local protocols may
  * map URLs to files (e.g., resource:).
  */
-[scriptable, uuid(44c14c16-07b4-48fb-b44b-0c8986697a17)]
+[scriptable, uuid(93a4f94e-1dae-4056-ac4e-08e13691ee8e)]
 interface nsIFileURL : nsIURL
 {
     /**
      * Get/Set nsIFile corresponding to this URL.
      *
      *  - Getter returns a reference to an immutable object.  Callers must clone
      *    before attempting to modify the returned nsIFile object.  NOTE: this
      *    constraint might not be enforced at runtime, so beware!!
--- a/netwerk/base/public/nsIURI.idl
+++ b/netwerk/base/public/nsIURI.idl
@@ -96,17 +96,17 @@
  * nsIIOService.newURI.
  *
  * NOTE: nsBinaryInputStream::ReadObject contains a hackaround to intercept the
  * old (pre-gecko6) nsIURI IID and swap in the current IID instead, in order
  * for sessionstore to work after an upgrade.  If this IID is revved further,
  * we will need to add additional checks there for all intermediate IIDs, until
  * nsPrincipal is fixed to serialize its URIs as nsISupports (bug 662693).
  */
-[scriptable, uuid(12120b20-0929-40e9-88cf-6e08766e8b23)]
+[scriptable, uuid(395fe045-7d18-4adb-a3fd-af98c8a1af11)]
 interface nsIURI : nsISupports
 {
     /************************************************************************
      * The URI is broken down into the following principal components:
      */
 
     /**
      * Returns a string representation of the URI. Setting the spec causes
@@ -267,9 +267,18 @@ interface nsIURI : nsISupports
      */
     boolean equalsExceptRef(in nsIURI other);
 
     /**
      * Clones the current URI, clearing the 'ref' attribute in the clone.
      */
     nsIURI cloneIgnoringRef();
 
+    /**
+     * returns a string for the current URI with the ref element cleared.
+     */
+   readonly attribute AUTF8String specIgnoringRef;
+
+    /**
+     * Returns if there is a reference portion (the part after the "#") of the URI.
+     */
+   readonly attribute boolean hasRef;
 };
--- a/netwerk/base/public/nsIURL.idl
+++ b/netwerk/base/public/nsIURL.idl
@@ -49,17 +49,17 @@
  *            \          \                       /
  *             \          -----------------------
  *              \                   |          /
  *               \               fileName     /
  *                ----------------------------
  *                            |
  *                        filePath
  */
-[scriptable, uuid(eab18ad5-e3be-4eb3-9c78-7d4e750200d6)]
+[scriptable, uuid(067d697a-c725-4293-9656-e658a75e6bcf)]
 interface nsIURL : nsIURI
 {
     /*************************************************************************
      * The URL path is broken down into the following principal components:
      */
 
     /**
      * Returns a path including the directory and file portions of a
--- a/netwerk/base/src/nsSimpleURI.cpp
+++ b/netwerk/base/src/nsSimpleURI.cpp
@@ -196,16 +196,31 @@ nsSimpleURI::GetSpec(nsACString &result)
     if (mIsRefValid) {
         result += NS_LITERAL_CSTRING("#") + mRef;
     } else {
         NS_ABORT_IF_FALSE(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
     }
     return NS_OK;
 }
 
+// result may contain unescaped UTF-8 characters
+NS_IMETHODIMP
+nsSimpleURI::GetSpecIgnoringRef(nsACString &result)
+{
+    result = mScheme + NS_LITERAL_CSTRING(":") + mPath;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsSimpleURI::GetHasRef(PRBool *result)
+{
+    *result = mIsRefValid;
+    return NS_OK;
+}
+
 NS_IMETHODIMP
 nsSimpleURI::SetSpec(const nsACString &aSpec)
 {
     NS_ENSURE_STATE(mMutable);
     
     const nsAFlatCString& flat = PromiseFlatCString(aSpec);
     const char* specPtr = flat.get();
 
--- a/netwerk/base/src/nsStandardURL.cpp
+++ b/netwerk/base/src/nsStandardURL.cpp
@@ -996,16 +996,31 @@ NS_IMETHODIMP
 nsStandardURL::GetSpec(nsACString &result)
 {
     result = mSpec;
     return NS_OK;
 }
 
 // result may contain unescaped UTF-8 characters
 NS_IMETHODIMP
+nsStandardURL::GetSpecIgnoringRef(nsACString &result)
+{
+    // URI without ref is 0 to one char before ref
+    if (mRef.mLen >= 0) {
+        URLSegment noRef(0, mRef.mPos - 1);
+
+        result = Segment(noRef);
+    } else {
+        result = mSpec;
+    }
+    return NS_OK;
+}
+
+// result may contain unescaped UTF-8 characters
+NS_IMETHODIMP
 nsStandardURL::GetPrePath(nsACString &result)
 {
     result = Prepath();
     return NS_OK;
 }
 
 // result is strictly US-ASCII
 NS_IMETHODIMP
@@ -2139,16 +2154,23 @@ nsStandardURL::GetQuery(nsACString &resu
 // result may contain unescaped UTF-8 characters
 NS_IMETHODIMP
 nsStandardURL::GetRef(nsACString &result)
 {
     result = Ref();
     return NS_OK;
 }
 
+NS_IMETHODIMP
+nsStandardURL::GetHasRef(PRBool *result)
+{
+    *result = (mRef.mLen >= 0);
+    return NS_OK;
+}
+
 // result may contain unescaped UTF-8 characters
 NS_IMETHODIMP
 nsStandardURL::GetDirectory(nsACString &result)
 {
     result = Directory();
     return NS_OK;
 }
 
--- a/netwerk/test/unit/test_URIs.js
+++ b/netwerk/test/unit/test_URIs.js
@@ -301,23 +301,27 @@ var gTests = [
     ref:     "",// fix
     nsIURL:  true, nsINestedURI: false },
   { spec:    "http://a/b/c/d;p?q",
     relativeURI: "g?y",
     scheme:  "http",
     prePath: "http://a",
     path:    "/b/c/g?y",
     ref:     "",// fix
+    specIgnoringRef: "http://a/b/c/g?y",
+    hasRef:  false,
     nsIURL:  true, nsINestedURI: false },
   { spec:    "http://a/b/c/d;p?q",
     relativeURI: "#s",
     scheme:  "http",
     prePath: "http://a",
     path:    "/b/c/d;p?q#s",
     ref:     "s",// fix
+    specIgnoringRef: "http://a/b/c/d;p?q",
+    hasRef:  true,
     nsIURL:  true, nsINestedURI: false },
   { spec:    "http://a/b/c/d;p?q",
     relativeURI: "g#s",
     scheme:  "http",
     prePath: "http://a",
     path:    "/b/c/g#s",
     ref:     "s",
     nsIURL:  true, nsINestedURI: false },
@@ -683,16 +687,21 @@ function do_test_uri_basic(aTest) {
   do_check_property(aTest, URI, "scheme");
   do_check_property(aTest, URI, "prePath");
   do_check_property(aTest, URI, "path");
   do_check_property(aTest, URI, "ref");
   do_check_property(aTest, URI, "port");
   do_check_property(aTest, URI, "username");
   do_check_property(aTest, URI, "password");
   do_check_property(aTest, URI, "host");
+  do_check_property(aTest, URI, "specIgnoringRef");
+  if ("hasRef" in aTest) {
+    do_info("testing hasref: " + aTest.hasRef + " vs " + URI.hasRef);
+    do_check_eq(aTest.hasRef, URI.hasRef);
+  }
 }
 
 // Test that a given URI parses correctly when we add a given ref to the end
 function do_test_uri_with_hash_suffix(aTest, aSuffix) {
   do_info("making sure caller is using suffix that starts with '#'");
   do_check_eq(aSuffix[0], "#");
 
   var origURI = NetUtil.newURI(aTest.spec);
@@ -723,16 +732,18 @@ function do_test_uri_with_hash_suffix(aT
           " doesn't equal self with '" + aSuffix + "' appended");
 
   do_check_false(origURI.equals(testURI));
 
   do_info("testing " + aTest.spec +
           " is equalExceptRef to self with '" + aSuffix + "' appended");
   do_check_uri_eqExceptRef(origURI, testURI);
 
+  do_check_eq(testURI.hasRef, true);
+
   if (!origURI.ref) {
     // These tests fail if origURI has a ref
     do_info("testing cloneIgnoringRef on " + testURI.spec +
             " is equal to no-ref version but not equal to ref version");
     var cloneNoRef = testURI.cloneIgnoringRef();
     do_check_uri_eq(cloneNoRef, origURI);
     do_check_false(cloneNoRef.equals(testURI));
   }