Bug 1432320 - (Part 1) Add nsIURLMutator r=mayhemer
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 31 Jan 2018 02:32:27 +0100
changeset 401614 67185e1252ebe1dd66217f5290d23e8718941cda
parent 401613 6610a133bac659bd2f740447bee8691952c276c5
child 401615 f7e4fd351759898c90756fbb359759955e27f253
push id33350
push userbtara@mozilla.com
push dateWed, 31 Jan 2018 09:59:18 +0000
treeherdermozilla-central@e4df65201940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1432320
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 1432320 - (Part 1) Add nsIURLMutator r=mayhemer MozReview-Commit-ID: 8GYru46kFQE
modules/libjar/nsJARURI.cpp
modules/libjar/nsJARURI.h
netwerk/base/nsIURL.idl
netwerk/base/nsStandardURL.cpp
netwerk/base/nsStandardURL.h
netwerk/protocol/res/SubstitutingProtocolHandler.cpp
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -252,17 +252,56 @@ nsJARURI::GetHasRef(bool *result)
 }
 
 nsresult
 nsJARURI::SetSpecInternal(const nsACString& aSpec)
 {
     return SetSpecWithBase(aSpec, nullptr);
 }
 
-NS_IMPL_ISUPPORTS(nsJARURI::Mutator, nsIURISetters, nsIURIMutator)
+NS_IMPL_ISUPPORTS(nsJARURI::Mutator, nsIURISetters, nsIURIMutator, nsIURLMutator)
+
+NS_IMETHODIMP
+nsJARURI::Mutator::SetFileName(const nsACString& aFileName, nsIURIMutator** aMutator)
+{
+    if (!mURI) {
+        return NS_ERROR_NULL_POINTER;
+    }
+    if (aMutator) {
+        nsCOMPtr<nsIURIMutator> mutator = this;
+        mutator.forget(aMutator);
+    }
+    return mURI->SetFileName(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);
+}
+
+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);
+}
 
 NS_IMETHODIMP
 nsJARURI::Mutate(nsIURIMutator** aMutator)
 {
     RefPtr<nsJARURI::Mutator> mutator = new nsJARURI::Mutator();
     nsresult rv = mutator->InitFromURI(this);
     if (NS_FAILED(rv)) {
         return rv;
@@ -665,53 +704,66 @@ NS_IMETHODIMP
 nsJARURI::GetDirectory(nsACString& directory)
 {
     return mJAREntry->GetDirectory(directory);
 }
 
 NS_IMETHODIMP
 nsJARURI::SetDirectory(const nsACString& directory)
 {
-    return mJAREntry->SetDirectory(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)
 {
-    return mJAREntry->SetFileName(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)
 {
-    return mJAREntry->SetFileBaseName(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)
 {
-    return mJAREntry->SetFileExtension(fileExtension);
+    return NS_MutateURI(mJAREntry)
+             .Apply<nsIURLMutator>(&nsIURLMutator::SetFileExtension,
+                                   nsCString(fileExtension),
+                                   nullptr)
+             .Finalize(mJAREntry);
 }
 
 NS_IMETHODIMP
 nsJARURI::GetCommonBaseSpec(nsIURI* uriToCompare, nsACString& commonSpec)
 {
     commonSpec.Truncate();
 
     NS_ENSURE_ARG_POINTER(uriToCompare);
--- a/modules/libjar/nsJARURI.h
+++ b/modules/libjar/nsJARURI.h
@@ -97,20 +97,22 @@ protected:
     // like extensions, refs, etc.
     nsCOMPtr<nsIURL> mJAREntry;
     nsCString        mCharsetHint;
 
 public:
     class Mutator
         : public nsIURIMutator
         , public BaseURIMutator<nsJARURI>
+        , public nsIURLMutator
     {
         NS_DECL_ISUPPORTS
         NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
         NS_DEFINE_NSIMUTATOR_COMMON
+        NS_DECL_NSIURLMUTATOR
 
         explicit Mutator() { }
     private:
         virtual ~Mutator() { }
 
         friend class nsJARURI;
     };
 };
--- a/netwerk/base/nsIURL.idl
+++ b/netwerk/base/nsIURL.idl
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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/. */
 
 #include "nsIURI.idl"
+interface nsIURIMutator;
 
 /**
  * The nsIURL interface provides convenience methods that further
  * break down the path portion of nsIURI:
  *
  * http://host/directory/fileBaseName.fileExtension?query
  * http://host/directory/fileBaseName.fileExtension#ref
  *            \          \                       /
@@ -115,8 +116,16 @@ interface nsIURL : nsIURI
      * 2) http://mozilla.org/     http://www.mozilla.org    http://www.mozilla.org/
      * 3) http://foo.com/bar/     http://foo.com:80/bar/    ""
      * 4) http://foo.com/         http://foo.com/a.htm#b    a.html#b
      * 5) http://foo.com/a/b/     http://foo.com/c          ../../c
      */
     AUTF8String getRelativeSpec(in nsIURI aURIToCompare);
 
 };
+
+[scriptable, builtinclass, uuid(25072eb8-f1e6-482f-9ca9-eddd3d65169a)]
+interface nsIURLMutator : nsISupports
+{
+    [must_use] nsIURIMutator setFileName(in AUTF8String aFileName);
+    [must_use] nsIURIMutator setFileBaseName(in AUTF8String aFileBaseName);
+    [must_use] nsIURIMutator setFileExtension(in AUTF8String aFileExtension);
+};
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -2221,17 +2221,18 @@ nsStandardURL::SetPathQueryRef(const nsA
         mBasename.mLen = -1;
         mExtension.mLen = -1;
         mQuery.mLen = -1;
         mRef.mLen = -1;
     }
     return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS(nsStandardURL::Mutator, nsIURISetters, nsIURIMutator, nsIStandardURLMutator)
+// When updating this also update SubstitutingURL::Mutator
+NS_IMPL_ISUPPORTS(nsStandardURL::Mutator, nsIURISetters, nsIURIMutator, nsIStandardURLMutator, nsIURLMutator)
 
 NS_IMETHODIMP
 nsStandardURL::Mutate(nsIURIMutator** aMutator)
 {
     RefPtr<nsStandardURL::Mutator> mutator = new nsStandardURL::Mutator();
     nsresult rv = mutator->InitFromURI(this);
     if (NS_FAILED(rv)) {
         return rv;
--- a/netwerk/base/nsStandardURL.h
+++ b/netwerk/base/nsStandardURL.h
@@ -316,16 +316,17 @@ public:
 
     // We make this implementation a template so that we can avoid writing
     // the same code for SubstitutingURL (which extends nsStandardURL)
     template<class T>
     class TemplatedMutator
         : public nsIURIMutator
         , public BaseURIMutator<T>
         , public nsIStandardURLMutator
+        , public nsIURLMutator
     {
         NS_FORWARD_SAFE_NSIURISETTERS_RET(BaseURIMutator<T>::mURI)
 
         MOZ_MUST_USE NS_IMETHOD
         Deserialize(const mozilla::ipc::URIParams& aParams) override
         {
             return BaseURIMutator<T>::InitFromIPCParams(aParams);
         }
@@ -385,16 +386,56 @@ public:
             }
             if (aMutator) {
                 nsCOMPtr<nsIURIMutator> mutator = this;
                 mutator.forget(aMutator);
             }
             return BaseURIMutator<T>::mURI->SetDefaultPort(aNewDefaultPort);
         }
 
+        MOZ_MUST_USE NS_IMETHOD
+        SetFileName(const nsACString& aFileName, 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->SetFileName(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);
+        }
+
+        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);
+        }
+
+
         explicit TemplatedMutator() { }
     private:
         virtual ~TemplatedMutator() { }
 
         friend T;
     };
 
     class Mutator
--- a/netwerk/protocol/res/SubstitutingProtocolHandler.cpp
+++ b/netwerk/protocol/res/SubstitutingProtocolHandler.cpp
@@ -27,17 +27,17 @@ namespace net {
 static LazyLogModule gResLog("nsResProtocol");
 
 static NS_DEFINE_CID(kSubstitutingURLCID, NS_SUBSTITUTINGURL_CID);
 
 //---------------------------------------------------------------------------------
 // SubstitutingURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
 //---------------------------------------------------------------------------------
 
-NS_IMPL_ISUPPORTS(SubstitutingURL::Mutator, nsIURISetters, nsIURIMutator, nsIStandardURLMutator)
+NS_IMPL_ISUPPORTS(SubstitutingURL::Mutator, nsIURISetters, nsIURIMutator, nsIStandardURLMutator, nsIURLMutator)
 
 nsresult
 SubstitutingURL::EnsureFile()
 {
   nsAutoCString ourScheme;
   nsresult rv = GetScheme(ourScheme);
   NS_ENSURE_SUCCESS(rv, rv);