Bug 1432519 - Make nsIURL attributes readonly r=mayhemer
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 31 Jan 2018 03:06:58 +0100
changeset 402382 178575b934eac4fd983cc5237e119b10716a15c2
parent 402381 b5024605c7a3cc2719c5b1ec3050af79024cebab
child 402383 20f71f9dd68801c6507aad88f2adb096aed1cfd6
push id33389
push usernbeleuzu@mozilla.com
push dateTue, 06 Feb 2018 09:53:43 +0000
treeherdermozilla-central@25ceb97b5773 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1432519
milestone60.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 1432519 - Make nsIURL attributes readonly r=mayhemer MozReview-Commit-ID: KuPILT7rX6N
modules/libjar/nsJARURI.cpp
modules/libjar/nsJARURI.h
netwerk/base/nsIURL.idl
netwerk/base/nsStandardURL.cpp
netwerk/base/nsStandardURL.h
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -264,43 +264,43 @@ nsJARURI::Mutator::SetFileName(const nsA
 {
     if (!mURI) {
         return NS_ERROR_NULL_POINTER;
     }
     if (aMutator) {
         nsCOMPtr<nsIURIMutator> mutator = this;
         mutator.forget(aMutator);
     }
-    return mURI->SetFileName(aFileName);
+    return mURI->SetFileNameInternal(aFileName);
 }
 
 NS_IMETHODIMP
 nsJARURI::Mutator::SetFileBaseName(const nsACString& aFileBaseName, nsIURIMutator** aMutator)
 {
     if (!mURI) {
         return NS_ERROR_NULL_POINTER;
     }
     if (aMutator) {
         nsCOMPtr<nsIURIMutator> mutator = this;
         mutator.forget(aMutator);
     }
-    return mURI->SetFileBaseName(aFileBaseName);
+    return mURI->SetFileBaseNameInternal(aFileBaseName);
 }
 
 NS_IMETHODIMP
 nsJARURI::Mutator::SetFileExtension(const nsACString& aFileExtension, nsIURIMutator** aMutator)
 {
     if (!mURI) {
         return NS_ERROR_NULL_POINTER;
     }
     if (aMutator) {
         nsCOMPtr<nsIURIMutator> mutator = this;
         mutator.forget(aMutator);
     }
-    return mURI->SetFileExtension(aFileExtension);
+    return mURI->SetFileExtensionInternal(aFileExtension);
 }
 
 NS_IMETHODIMP
 nsJARURI::Mutate(nsIURIMutator** aMutator)
 {
     RefPtr<nsJARURI::Mutator> mutator = new nsJARURI::Mutator();
     nsresult rv = mutator->InitFromURI(this);
     if (NS_FAILED(rv)) {
@@ -702,62 +702,55 @@ nsJARURI::SetRef(const nsACString& ref)
 
 NS_IMETHODIMP
 nsJARURI::GetDirectory(nsACString& directory)
 {
     return mJAREntry->GetDirectory(directory);
 }
 
 NS_IMETHODIMP
-nsJARURI::SetDirectory(const nsACString& directory)
-{
-    MOZ_ASSERT_UNREACHABLE("SetDirectory");
-    return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
 nsJARURI::GetFileName(nsACString& fileName)
 {
     return mJAREntry->GetFileName(fileName);
 }
 
-NS_IMETHODIMP
-nsJARURI::SetFileName(const nsACString& fileName)
+nsresult
+nsJARURI::SetFileNameInternal(const nsACString& fileName)
 {
     return NS_MutateURI(mJAREntry)
              .Apply<nsIURLMutator>(&nsIURLMutator::SetFileName,
                                    nsCString(fileName),
                                    nullptr)
              .Finalize(mJAREntry);
 }
 
 NS_IMETHODIMP
 nsJARURI::GetFileBaseName(nsACString& fileBaseName)
 {
     return mJAREntry->GetFileBaseName(fileBaseName);
 }
 
-NS_IMETHODIMP
-nsJARURI::SetFileBaseName(const nsACString& fileBaseName)
+nsresult
+nsJARURI::SetFileBaseNameInternal(const nsACString& fileBaseName)
 {
     return NS_MutateURI(mJAREntry)
              .Apply<nsIURLMutator>(&nsIURLMutator::SetFileBaseName,
                                    nsCString(fileBaseName),
                                    nullptr)
              .Finalize(mJAREntry);
 }
 
 NS_IMETHODIMP
 nsJARURI::GetFileExtension(nsACString& fileExtension)
 {
     return mJAREntry->GetFileExtension(fileExtension);
 }
 
-NS_IMETHODIMP
-nsJARURI::SetFileExtension(const nsACString& fileExtension)
+nsresult
+nsJARURI::SetFileExtensionInternal(const nsACString& fileExtension)
 {
     return NS_MutateURI(mJAREntry)
              .Apply<nsIURLMutator>(&nsIURLMutator::SetFileExtension,
                                    nsCString(fileExtension),
                                    nullptr)
              .Finalize(mJAREntry);
 }
 
--- a/modules/libjar/nsJARURI.h
+++ b/modules/libjar/nsJARURI.h
@@ -75,16 +75,20 @@ protected:
 
     // enum used in a few places to specify how .ref attribute should be handled
     enum RefHandlingEnum {
         eIgnoreRef,
         eHonorRef,
         eReplaceRef
     };
 
+    nsresult SetFileNameInternal(const nsACString& fileName);
+    nsresult SetFileBaseNameInternal(const nsACString& fileBaseName);
+    nsresult SetFileExtensionInternal(const nsACString& fileExtension);
+
     // Helper to share code between Equals methods.
     virtual nsresult EqualsInternal(nsIURI* other,
                                     RefHandlingEnum refHandlingMode,
                                     bool* result);
 
     // Helpers to share code between Clone methods.
     nsresult CloneWithJARFileInternal(nsIURI *jarFile,
                                       RefHandlingEnum refHandlingMode,
--- a/netwerk/base/nsIURL.idl
+++ b/netwerk/base/nsIURL.idl
@@ -43,48 +43,47 @@ interface nsIURL : nsIURI
      * the empty string. If the trailing slash is omitted, then the Directory
      * is /foo/ and the file is bar (i.e. this is a syntactic, not a semantic
      * breakdown of the Path).  And hence don't rely on this for something to
      * be a definitely be a file. But you can get just the leading directory
      * portion for sure.
      *
      * Some characters may be escaped.
      */
-    attribute AUTF8String directory;
+    readonly attribute AUTF8String directory;
 
     /**
      * Returns the file name portion of a URL.  If the URL denotes a path to a
      * directory and not a file, e.g. http://host/foo/bar/, then the Directory
      * attribute accesses the complete /foo/bar/ portion, and the FileName is
      * the empty string. Note that this is purely based on searching for the
      * last trailing slash. And hence don't rely on this to be a definite file. 
      *
      * Some characters may be escaped.
      */
-    attribute AUTF8String fileName;
-
+    readonly attribute AUTF8String fileName;
 
     /*************************************************************************
      * The URL filename is broken down even further:
      */
 
     /**
      * Returns the file basename portion of a filename in a url.
      *
      * Some characters may be escaped.
      */
-    attribute AUTF8String fileBaseName;
+    readonly attribute AUTF8String fileBaseName;
 
     /**
      * Returns the file extension portion of a filename in a url.  If a file
      * extension does not exist, the empty string is returned.
      *
      * Some characters may be escaped.
      */
-    attribute AUTF8String fileExtension;
+    readonly attribute AUTF8String fileExtension;
 
     /**
      * This method takes a uri and compares the two.  The common uri portion
      * is returned as a string.  The minimum common uri portion is the 
      * protocol, and any of these if present:  login, password, host and port
      * If no commonality is found, "" is returned.  If they are identical, the
      * whole path with file/ref/etc. is returned.  For file uris, it is
      * expected that the common spec would be at least "file:///" since '/' is
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -3065,32 +3065,25 @@ nsStandardURL::SetRef(const nsACString &
     }
 
     int32_t shift = ReplaceSegment(mRef.mPos, mRef.mLen, ref, refLen);
     mPath.mLen += shift;
     mRef.mLen = refLen;
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsStandardURL::SetDirectory(const nsACString &input)
-{
-    MOZ_ASSERT_UNREACHABLE("SetDirectory");
-    return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsStandardURL::SetFileName(const nsACString &input)
+nsresult
+nsStandardURL::SetFileNameInternal(const nsACString &input)
 {
     ENSURE_MUTABLE();
 
     const nsPromiseFlatCString &flat = PromiseFlatCString(input);
     const char *filename = flat.get();
 
-    LOG(("nsStandardURL::SetFileName [filename=%s]\n", filename));
+    LOG(("nsStandardURL::SetFileNameInternal [filename=%s]\n", filename));
 
     if (mPath.mLen < 0)
         return SetPathQueryRef(flat);
 
     if (mSpec.Length() + input.Length() - Filename().Length() > (uint32_t) net_GetURLMaxLength()) {
         return NS_ERROR_MALFORMED_URI;
     }
 
@@ -3171,46 +3164,46 @@ nsStandardURL::SetFileName(const nsACStr
     if (shift) {
         ShiftFromQuery(shift);
         mFilepath.mLen += shift;
         mPath.mLen += shift;
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsStandardURL::SetFileBaseName(const nsACString &input)
+nsresult
+nsStandardURL::SetFileBaseNameInternal(const nsACString &input)
 {
     nsAutoCString extension;
     nsresult rv = GetFileExtension(extension);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoCString newFileName(input);
 
     if (!extension.IsEmpty()) {
         newFileName.Append('.');
         newFileName.Append(extension);
     }
 
-    return SetFileName(newFileName);
+    return SetFileNameInternal(newFileName);
 }
 
-NS_IMETHODIMP
-nsStandardURL::SetFileExtension(const nsACString &input)
+nsresult
+nsStandardURL::SetFileExtensionInternal(const nsACString &input)
 {
     nsAutoCString newFileName;
     nsresult rv = GetFileBaseName(newFileName);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!input.IsEmpty()) {
         newFileName.Append('.');
         newFileName.Append(input);
     }
 
-    return SetFileName(newFileName);
+    return SetFileNameInternal(newFileName);
 }
 
 //----------------------------------------------------------------------------
 // nsStandardURL::nsIFileURL
 //----------------------------------------------------------------------------
 
 nsresult
 nsStandardURL::EnsureFile()
--- a/netwerk/base/nsStandardURL.h
+++ b/netwerk/base/nsStandardURL.h
@@ -180,16 +180,20 @@ protected:
     // returns NS_ERROR_NO_INTERFACE if the url does not map to a file
     virtual nsresult EnsureFile();
 
 private:
     nsresult Init(uint32_t urlType, int32_t defaultPort, const nsACString &spec,
                   const char *charset, nsIURI *baseURI);
     nsresult SetDefaultPort(int32_t aNewDefaultPort);
 
+    nsresult SetFileNameInternal(const nsACString &input);
+    nsresult SetFileBaseNameInternal(const nsACString &input);
+    nsresult SetFileExtensionInternal(const nsACString &input);
+
     int32_t  Port() { return mPort == -1 ? mDefaultPort : mPort; }
 
     void     ReplacePortInSpec(int32_t aNewPort);
     void     Clear();
     void     InvalidateCache(bool invalidateCachedFile = true);
 
     bool     ValidIPv6orHostname(const char *host, uint32_t aLen);
     static bool     IsValidOfBase(unsigned char c, const uint32_t base);
@@ -401,43 +405,43 @@ public:
         {
             if (!BaseURIMutator<T>::mURI) {
                 return NS_ERROR_NULL_POINTER;
             }
             if (aMutator) {
                 nsCOMPtr<nsIURIMutator> mutator = this;
                 mutator.forget(aMutator);
             }
-            return BaseURIMutator<T>::mURI->SetFileName(aFileName);
+            return BaseURIMutator<T>::mURI->SetFileNameInternal(aFileName);
         }
 
         MOZ_MUST_USE NS_IMETHOD
         SetFileBaseName(const nsACString& aFileBaseName, nsIURIMutator** aMutator) override
         {
             if (!BaseURIMutator<T>::mURI) {
                 return NS_ERROR_NULL_POINTER;
             }
             if (aMutator) {
                 nsCOMPtr<nsIURIMutator> mutator = this;
                 mutator.forget(aMutator);
             }
-            return BaseURIMutator<T>::mURI->SetFileBaseName(aFileBaseName);
+            return BaseURIMutator<T>::mURI->SetFileBaseNameInternal(aFileBaseName);
         }
 
         MOZ_MUST_USE NS_IMETHOD
         SetFileExtension(const nsACString& aFileExtension, nsIURIMutator** aMutator) override
         {
             if (!BaseURIMutator<T>::mURI) {
                 return NS_ERROR_NULL_POINTER;
             }
             if (aMutator) {
                 nsCOMPtr<nsIURIMutator> mutator = this;
                 mutator.forget(aMutator);
             }
-            return BaseURIMutator<T>::mURI->SetFileExtension(aFileExtension);
+            return BaseURIMutator<T>::mURI->SetFileExtensionInternal(aFileExtension);
         }
 
         MOZ_MUST_USE NS_IMETHOD
         SetFile(nsIFile* aFile) override
         {
             RefPtr<T> uri;
             if (BaseURIMutator<T>::mURI) {
                 // We don't need a new URI object if we already have one
@@ -445,17 +449,17 @@ public:
             } else {
                 uri = new T(/* supportsFileURL = */ true);
             }
 
             nsresult rv = uri->SetFile(aFile);
             if (NS_FAILED(rv)) {
                 return rv;
             }
-            BaseURIMutator<T>::mURI = uri;
+            BaseURIMutator<T>::mURI.swap(uri);
             return NS_OK;
         }
 
         explicit TemplatedMutator() { }
     private:
         virtual ~TemplatedMutator() { }
 
         friend T;