Bug 1434766 - Make nsIFileURL attributes readonly draft
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 26 Feb 2018 05:24:09 +0100
changeset 760478 8aed9c8819eed422bda5a295a7ada16309f0a49e
parent 760371 b184be59874080e96903183176c0f88dcbfafe25
child 760587 7687bc3fd6bd725fc8b2f0108d9644e92ae4fb82
push id100660
push uservalentin.gosu@gmail.com
push dateTue, 27 Feb 2018 18:14:14 +0000
bugs1434766
milestone60.0a1
Bug 1434766 - Make nsIFileURL attributes readonly MozReview-Commit-ID: AN5EzyuuKuJ
netwerk/base/nsIFileURL.idl
netwerk/base/nsStandardURL.cpp
netwerk/base/nsStandardURL.h
netwerk/protocol/file/nsFileProtocolHandler.cpp
--- a/netwerk/base/nsIFileURL.idl
+++ b/netwerk/base/nsIFileURL.idl
@@ -12,23 +12,23 @@ interface nsIURIMutator;
  * 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, builtinclass, uuid(e91ac988-27c2-448b-b1a1-3822e1ef1987)]
 interface nsIFileURL : nsIURL
 {
     /**
-     * Get/Set nsIFile corresponding to this URL.
+     * Get the nsIFile corresponding to this URL.
      *
-     *  - Getter returns a reference to an immutable object.  Callers must clone
+     *  - 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!!
      */
-    attribute nsIFile file;
+    readonly attribute nsIFile file;
 };
 
 [scriptable, builtinclass, uuid(a588b6f2-d2b9-4024-84c7-be3368546b57)]
 interface nsIFileURLMutator : nsISupports
 {
     /*
      *  - Setter clones the nsIFile object (allowing the caller to safely modify
      *    the nsIFile object after setting it on this interface).
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -3251,17 +3251,17 @@ nsStandardURL::GetFile(nsIFile **result)
     // XXX nsIFileURL.idl specifies that the consumer must _not_ modify the
     // nsIFile returned from this method; but it seems that some folks do
     // (see bug 161921). until we can be sure that all the consumers are
     // behaving themselves, we'll stay on the safe side and clone the file.
     // see bug 212724 about fixing the consumers.
     return mFile->Clone(result);
 }
 
-NS_IMETHODIMP
+nsresult
 nsStandardURL::SetFile(nsIFile *file)
 {
     ENSURE_MUTABLE();
 
     NS_ENSURE_ARG_POINTER(file);
 
     nsresult rv;
     nsAutoCString url;
--- a/netwerk/base/nsStandardURL.h
+++ b/netwerk/base/nsStandardURL.h
@@ -179,16 +179,17 @@ protected:
     // ensure that our mFile is initialized, if it's possible.
     // 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 SetFile(nsIFile *file);
 
     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);
--- a/netwerk/protocol/file/nsFileProtocolHandler.cpp
+++ b/netwerk/protocol/file/nsFileProtocolHandler.cpp
@@ -234,31 +234,26 @@ nsFileProtocolHandler::AllowPort(int32_t
     *result = false;
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // nsIFileProtocolHandler methods:
 
 NS_IMETHODIMP
-nsFileProtocolHandler::NewFileURI(nsIFile *file, nsIURI **result)
+nsFileProtocolHandler::NewFileURI(nsIFile *aFile, nsIURI **aResult)
 {
-    NS_ENSURE_ARG_POINTER(file);
-    nsresult rv;
+    NS_ENSURE_ARG_POINTER(aFile);
 
-    nsCOMPtr<nsIFileURL> url = new nsStandardURL(true);
-    if (!url)
-        return NS_ERROR_OUT_OF_MEMORY;
-
+    RefPtr<nsIFile> file(aFile);
     // NOTE: the origin charset is assigned the value of the platform
     // charset by the SetFile method.
-    rv = url->SetFile(file);
-    if (NS_FAILED(rv)) return rv;
-
-    return CallQueryInterface(url, result);
+    return NS_MutateURI(new nsStandardURL::Mutator())
+             .Apply(NS_MutatorMethod(&nsIFileURLMutator::SetFile, file))
+             .Finalize(aResult);
 }
 
 NS_IMETHODIMP
 nsFileProtocolHandler::NewFileURIMutator(nsIFile *aFile, nsIURIMutator **aResult)
 {
     NS_ENSURE_ARG_POINTER(aFile);
     nsresult rv;