Bug 1431204 - Make nsIURI.spec readonly draft
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 19 Jan 2018 15:26:07 +0100
changeset 722680 4dd86b893d6fa1901138f51e29f7331dd80171b6
parent 722679 80f378b91c09bde599473e3a22ac91ac71512156
child 722798 7948365cebb60ea389ad6d6e387d1bb07fc28b47
child 722803 efd8d0aa9d4bdccaa5205064ad5151c87adfafc8
push id96195
push uservalentin.gosu@gmail.com
push dateFri, 19 Jan 2018 14:28:43 +0000
bugs1431204
milestone59.0a1
Bug 1431204 - Make nsIURI.spec readonly MozReview-Commit-ID: 1l1CBUotIPh
caps/NullPrincipalURI.cpp
image/decoders/icon/nsIconURI.cpp
modules/libjar/nsJARURI.cpp
netwerk/base/nsIURI.idl
netwerk/base/nsIURIMutator.idl
netwerk/base/nsSimpleURI.cpp
netwerk/base/nsStandardURL.cpp
--- a/caps/NullPrincipalURI.cpp
+++ b/caps/NullPrincipalURI.cpp
@@ -252,18 +252,18 @@ NullPrincipalURI::GetSpecIgnoringRef(nsA
 
 NS_IMETHODIMP
 NullPrincipalURI::GetHasRef(bool* _result)
 {
   *_result = false;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-NullPrincipalURI::SetSpec(const nsACString& aSpec)
+nsresult
+NullPrincipalURI::SetSpecInternal(const nsACString& aSpec)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 NullPrincipalURI::GetUsername(nsACString& _username)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -199,18 +199,18 @@ extractAttributeValue(const char* aSearc
         } else {
           aResult.Assign(startOfAttribute);
         }
       } // if we have a attribute value
     } // if we have a attribute name
   } // if we got non-null search string and attribute name values
 }
 
-NS_IMETHODIMP
-nsMozIconURI::SetSpec(const nsACString& aSpec)
+nsresult
+nsMozIconURI::SetSpecInternal(const nsACString& aSpec)
 {
   // Reset everything to default values.
   mIconURL = nullptr;
   mSize = DEFAULT_IMAGE_SIZE;
   mContentType.Truncate();
   mFileName.Truncate();
   mStockIcon.Truncate();
   mIconSize = -1;
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -253,18 +253,18 @@ nsJARURI::GetDisplayHost(nsACString &aUn
 }
 
 NS_IMETHODIMP
 nsJARURI::GetHasRef(bool *result)
 {
     return mJAREntry->GetHasRef(result);
 }
 
-NS_IMETHODIMP
-nsJARURI::SetSpec(const nsACString& aSpec)
+nsresult
+nsJARURI::SetSpecInternal(const nsACString& aSpec)
 {
     return SetSpecWithBase(aSpec, nullptr);
 }
 
 NS_IMPL_ISUPPORTS(nsJARURI::Mutator, nsIURISetters, nsIURIMutator)
 
 NS_IMETHODIMP
 nsJARURI::Mutate(nsIURIMutator** aMutator)
--- a/netwerk/base/nsIURI.idl
+++ b/netwerk/base/nsIURI.idl
@@ -75,28 +75,36 @@ interface nsIURIMutator;
 [scriptable, builtinclass, uuid(92073a54-6d78-4f30-913a-b871813208c6)]
 interface nsIURI : nsISupports
 {
     /************************************************************************
      * The URI is broken down into the following principal components:
      */
 
     /**
-     * Returns a string representation of the URI. Setting the spec causes
+     * Returns a string representation of the URI.
+     *
+     * Some characters may be escaped.
+     */
+    readonly attribute AUTF8String spec;
+
+    /*
+     * This method should only be called by nsIURIMutator or C++ unit tests.
+     *
+     * Setting the spec causes
      * the new spec to be parsed per the rules for the scheme the URI
      * currently has.  In particular, setting the spec to a URI string with a
      * different scheme will generally produce incorrect results; no one
      * outside of a protocol handler implementation should be doing that.  If
      * the URI stores information from the nsIIOService.newURI call used to
      * create it other than just the parsed string, then behavior of this
      * information on setting the spec attribute is undefined.
-     *
-     * Some characters may be escaped.
      */
-    attribute AUTF8String spec;
+    [noscript,notxpcom,nostdcall]
+    nsresult setSpecInternal(in ACString aSpec);
 
 %{ C++
     // An infallible wrapper for GetSpec() that returns a failure indication
     // string if GetSpec() fails. It is most useful for creating
     // logging/warning/error messages produced for human consumption, and when
     // matching a URI spec against a fixed spec such as about:blank.
     nsCString GetSpecOrDefault()
     {
--- a/netwerk/base/nsIURIMutator.idl
+++ b/netwerk/base/nsIURIMutator.idl
@@ -70,17 +70,17 @@ protected:
     RefPtr<T> uri;
     if (mURI) {
       // This only works because all other Init methods create a new object
       mURI.swap(uri);
     } else {
       uri = new T();
     }
 
-    rv = uri->SetSpec(aSpec);
+    rv = uri->SetSpecInternal(aSpec);
     if (NS_FAILED(rv)) {
       return rv;
     }
     mURI = uri;
     return NS_OK;
   }
 
   RefPtr<T> mURI;
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -282,18 +282,18 @@ nsSimpleURI::GetDisplayPrePath(nsACStrin
 
 NS_IMETHODIMP
 nsSimpleURI::GetHasRef(bool *result)
 {
     *result = mIsRefValid;
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsSimpleURI::SetSpec(const nsACString &aSpec)
+nsresult
+nsSimpleURI::SetSpecInternal(const nsACString &aSpec)
 {
     NS_ENSURE_STATE(mMutable);
 
     nsresult rv = net_ExtractURLScheme(aSpec, mScheme);
     if (NS_FAILED(rv)) {
         return rv;
     }
     ToLowerCase(mScheme);
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1549,18 +1549,18 @@ IsSpecialProtocol(const nsACString &inpu
            protocol.LowerCaseEqualsLiteral("https") ||
            protocol.LowerCaseEqualsLiteral("ftp") ||
            protocol.LowerCaseEqualsLiteral("ws") ||
            protocol.LowerCaseEqualsLiteral("wss") ||
            protocol.LowerCaseEqualsLiteral("file") ||
            protocol.LowerCaseEqualsLiteral("gopher");
 }
 
-NS_IMETHODIMP
-nsStandardURL::SetSpec(const nsACString &input)
+nsresult
+nsStandardURL::SetSpecInternal(const nsACString &input)
 {
     return SetSpecWithEncoding(input, nullptr);
 }
 
 nsresult
 nsStandardURL::SetSpecWithEncoding(const nsACString &input,
                                    const Encoding* encoding)
 {
@@ -2204,17 +2204,17 @@ nsStandardURL::SetPathQueryRef(const nsA
     if (!path.IsEmpty()) {
         nsAutoCString spec;
 
         spec.Assign(mSpec.get(), mPath.mPos);
         if (path.First() != '/')
             spec.Append('/');
         spec.Append(path);
 
-        return SetSpec(spec);
+        return SetSpecInternal(spec);
     }
     else if (mPath.mLen >= 1) {
         mSpec.Cut(mPath.mPos + 1, mPath.mLen - 1);
         // these contain only a '/'
         mPath.mLen = 1;
         mDirectory.mLen = 1;
         mFilepath.mLen = 1;
         // these are no longer defined
@@ -2888,17 +2888,17 @@ nsStandardURL::SetFilePath(const nsACStr
 
         // compute the ending position of the current filepath
         if (mFilepath.mLen >= 0) {
             uint32_t end = mFilepath.mPos + mFilepath.mLen;
             if (mSpec.Length() > end)
                 spec.Append(mSpec.get() + end, mSpec.Length() - end);
         }
 
-        return SetSpec(spec);
+        return SetSpecInternal(spec);
     }
     else if (mPath.mLen > 1) {
         mSpec.Cut(mPath.mPos + 1, mFilepath.mLen - 1);
         // left shift query, and ref
         ShiftFromQuery(1 - mFilepath.mLen);
         // these contain only a '/'
         mPath.mLen = 1;
         mDirectory.mLen = 1;