Bug 1442242 - Make the constructor of nsJARURI private r=mayhemer
☠☠ backed out by daef726185bb ☠ ☠
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 20 Mar 2018 12:52:47 +0100
changeset 409002 65b8727bfe7632fda2aa8f2652529d24e722d1df
parent 409001 88130a542fb3041239eb0a257f1e6db411e35f5c
child 409003 9f37df3c62e1c821d646cde969a278357741ba2b
push id33671
push usercsabou@mozilla.com
push dateTue, 20 Mar 2018 22:23:32 +0000
treeherdermozilla-central@e2e874ceae78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1442242
milestone61.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 1442242 - Make the constructor of nsJARURI private r=mayhemer MozReview-Commit-ID: 2X1mu5576u1
modules/libjar/nsIJARURI.idl
modules/libjar/nsJARProtocolHandler.cpp
modules/libjar/nsJARURI.cpp
modules/libjar/nsJARURI.h
--- a/modules/libjar/nsIJARURI.idl
+++ b/modules/libjar/nsIJARURI.idl
@@ -31,8 +31,17 @@ interface nsIJARURI : nsIURL {
     readonly attribute AUTF8String JAREntry;
 
     /**
      * Create a clone of the JAR URI with a new root URI (the URI for the
      * actual JAR file).
      */
     nsIJARURI cloneWithJARFile(in nsIURI jarFile);
 };
+
+[builtinclass, uuid(d66df117-eda7-4324-b4e4-1f670ff6718e)]
+interface nsIJARURIMutator : nsISupports
+{
+    /**
+     * Will initalize a URI using the passed spec, baseURI and charset.
+     */
+    void setSpecBaseCharset(in AUTF8String aSpec, in nsIURI aBase, in string aCharset);
+};
--- a/modules/libjar/nsJARProtocolHandler.cpp
+++ b/modules/libjar/nsJARProtocolHandler.cpp
@@ -113,31 +113,21 @@ nsJARProtocolHandler::GetProtocolFlags(u
 }
 
 NS_IMETHODIMP
 nsJARProtocolHandler::NewURI(const nsACString &aSpec,
                              const char *aCharset,
                              nsIURI *aBaseURI,
                              nsIURI **result)
 {
-    nsresult rv = NS_OK;
-
-    RefPtr<nsJARURI> jarURI = new nsJARURI();
-    if (!jarURI)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    rv = jarURI->Init(aCharset);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = jarURI->SetSpecWithBase(aSpec, aBaseURI);
-    if (NS_FAILED(rv))
-        return rv;
-
-    NS_ADDREF(*result = jarURI);
-    return rv;
+    nsCOMPtr<nsIURI> base(aBaseURI);
+    return NS_MutateURI(new nsJARURI::Mutator())
+             .Apply(NS_MutatorMethod(&nsIJARURIMutator::SetSpecBaseCharset,
+                                     nsCString(aSpec), base, aCharset))
+             .Finalize(result);
 }
 
 NS_IMETHODIMP
 nsJARProtocolHandler::NewChannel2(nsIURI* uri,
                                   nsILoadInfo* aLoadInfo,
                                   nsIChannel** result)
 {
     nsJARChannel *chan = new nsJARChannel();
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -263,17 +263,18 @@ nsJARURI::SetSpecInternal(const nsACStri
     return SetSpecWithBase(aSpec, nullptr);
 }
 
 // Queries this list of interfaces. If none match, it queries mURI.
 NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsJARURI::Mutator,
                                 nsIURISetters,
                                 nsIURIMutator,
                                 nsIURLMutator,
-                                nsISerializable)
+                                nsISerializable,
+                                nsIJARURIMutator)
 
 NS_IMETHODIMP
 nsJARURI::Mutator::SetFileName(const nsACString& aFileName, nsIURIMutator** aMutator)
 {
     if (!mURI) {
         return NS_ERROR_NULL_POINTER;
     }
     if (aMutator) {
--- a/modules/libjar/nsJARURI.h
+++ b/modules/libjar/nsJARURI.h
@@ -54,29 +54,28 @@ public:
     NS_DECL_NSISERIALIZABLE
     NS_DECL_NSICLASSINFO
     NS_DECL_NSINESTEDURI
     NS_DECL_NSIIPCSERIALIZABLEURI
 
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_JARURI_IMPL_CID)
 
     // nsJARURI
-    nsJARURI();
-
-    nsresult Init(const char *charsetHint);
     nsresult FormatSpec(const nsACString &entryPath, nsACString &result,
                         bool aIncludeScheme = true);
     nsresult CreateEntryURL(const nsACString& entryFilename,
                             const char* charset,
                             nsIURL** url);
-    nsresult SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL);
 
 protected:
+    nsJARURI();
     virtual ~nsJARURI();
     nsresult SetJAREntry(const nsACString &entryPath);
+    nsresult Init(const char *charsetHint);
+    nsresult SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL);
 
     // enum used in a few places to specify how .ref attribute should be handled
     enum RefHandlingEnum {
         eIgnoreRef,
         eHonorRef,
         eReplaceRef
     };
 
@@ -121,16 +120,17 @@ private:
     nsresult SetFileExtensionInternal(const nsACString& fileExtension);
 
 public:
     class Mutator final
         : public nsIURIMutator
         , public BaseURIMutator<nsJARURI>
         , public nsIURLMutator
         , public nsISerializable
+        , public nsIJARURIMutator
     {
         NS_DECL_ISUPPORTS
         NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
         NS_DEFINE_NSIMUTATOR_COMMON
         NS_DECL_NSIURLMUTATOR
 
         NS_IMETHOD
         Write(nsIObjectOutputStream *aOutputStream) override
@@ -139,16 +139,40 @@ public:
         }
 
         MOZ_MUST_USE NS_IMETHOD
         Read(nsIObjectInputStream* aStream) override
         {
             return InitFromInputStream(aStream);
         }
 
+        NS_IMETHOD
+        SetSpecBaseCharset(const nsACString& aSpec,
+                           nsIURI* aBaseURI,
+                           const char* aCharset) override
+        {
+            RefPtr<nsJARURI> uri;
+            if (mURI) {
+                mURI.swap(uri);
+            } else {
+                uri = new nsJARURI();
+            }
+
+            nsresult rv = uri->Init(aCharset);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            rv = uri->SetSpecWithBase(aSpec, aBaseURI);
+            if (NS_FAILED(rv)) {
+                return rv;
+            }
+
+            mURI.swap(uri);
+            return NS_OK;
+        }
+
         explicit Mutator() { }
     private:
         virtual ~Mutator() { }
 
         friend class nsJARURI;
     };
 
     friend BaseURIMutator<nsJARURI>;