Bug 1434766 - Make nsIFileURL attributes readonly r=mayhemer
☠☠ backed out by d1c333aa68c5 ☠ ☠
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 26 Feb 2018 05:24:09 +0100
changeset 405579 56336c4873fea04e899159bbb3a97e07087af169
parent 405578 16f0fd2f54555220933709c293a7e17e1d7964cb
child 405580 765bfffce2b4c077d11c2c874f074e2cdda270d7
push id33525
push usernerli@mozilla.com
push dateWed, 28 Feb 2018 10:11:03 +0000
treeherdermozilla-central@9b1228043619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1434766
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 1434766 - Make nsIFileURL attributes readonly r=mayhemer 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
@@ -237,28 +237,22 @@ nsFileProtocolHandler::AllowPort(int32_t
 
 //-----------------------------------------------------------------------------
 // nsIFileProtocolHandler methods:
 
 NS_IMETHODIMP
 nsFileProtocolHandler::NewFileURI(nsIFile *file, nsIURI **result)
 {
     NS_ENSURE_ARG_POINTER(file);
-    nsresult rv;
-
-    nsCOMPtr<nsIFileURL> url = new nsStandardURL(true);
-    if (!url)
-        return NS_ERROR_OUT_OF_MEMORY;
 
     // 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(result);
 }
 
 NS_IMETHODIMP
 nsFileProtocolHandler::NewFileURIMutator(nsIFile *aFile, nsIURIMutator **aResult)
 {
     NS_ENSURE_ARG_POINTER(aFile);
     nsresult rv;