A question came up.  Can you create a standard-url, QI it to a nsIFileURI,
then call SetFile(nsIFile*), like:

nsCOMPtr<nsIFileURL>
fileURL(do_CreateInstance("@mozilla.org/network/standard-url;1"));
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
fileURL->SetFile(file);

I am leaning to say yes, but I would like some feedback please.


Doug Turner wrote:

> If you have a string which may or may not be a URL and you want to get a
> nsIURI for it, do not do this:
>
> // BAD!
> nsCOMPtr<nsIURL> uri;
> nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
>
>                                      nsnull,
>                                      NS_GET_IID(nsIURL),
>                                      getter_AddRefs(uri));
> uri->SetSpec(url);
> //
>
> This above code bypass necko's pluggable protocol architecture
> completely.  Furthermore, if you have a bad URL, not all of the getter
> attribute will be set properly.
>
> The proper thing to do is to call NS_NewURI:
>
> http://lxr.mozilla.org/seamonkey/source/netwerk/base/public/nsNetUtil.h#66
>
> This is in regards to bug
> http://bugzilla.mozilla.org/show_bug.cgi?id=73845
>
> The bug has a listing of call sites that I know about and will change
> (if I can).  If you are doing anything special, please contact me.

Reply via email to