Closed Bug 308305 Opened 19 years ago Closed 19 years ago

implement nsIFileProtocolHandler::ReadURLFile for GNOME

Categories

(Core :: Networking: File, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: chpe, Assigned: chpe)

References

()

Details

Attachments

(1 file, 2 obsolete files)

Bug 69114 added ReadURLFile to read windows link files, and bug 287603
implemented it for OS/2. What's missing is an implementation of ReadURLFile for
GNOME/KDE-style .desktop files
[http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.4.html].
What we're interested in here is .desktop files with Type=Link.

Steps to reproduce:
0) Open a web page in firefox
1) Drag a link to your GNOME desktop
2) Drag the newly created object from desktop into the browser

Results:
Tries to open the .desktop file with an external program, instead of loading the
link contained in the file.

Remaining problems with the patch:
- the URL bar will show the file:// URL of the dragged .desktop file instead of
the loaded page URL. This seems to be a problem somewhere in docshell?
- it only works if you drag .desktop from file:/// not from arbitrary gnome-vfs
locations
Attached patch proposed fix (obsolete) — Splinter Review
Comment on attachment 195856 [details] [diff] [review]
proposed fix

biesi: can you do first review on this?  thx!
Attachment #195856 - Flags: review?(cbiesinger)
Comment on attachment 195856 [details] [diff] [review]
proposed fix

+    nsresult rv;
+    nsCAutoString leafName;
+    rv = aFile->GetNativeLeafName(leafName);

please move the rv declaration to the line where it's first used

Hmm, I wonder why URLs are defined to be ASCII-only...

thanks for doing this. r=biesi
Attachment #195856 - Flags: review?(cbiesinger) → review+
Attachment #195856 - Attachment is obsolete: true
Comment on attachment 195881 [details] [diff] [review]
updated patch with change requested by the reviewer

>Index: netwerk/protocol/file/src/nsFileProtocolHandler.cpp

>+        !StringEndsWith(leafName, NS_LITERAL_CSTRING(".desktop"),
>+                        nsCaseInsensitiveCStringComparator()))

case insensitive really?  is there by chance a specification somewhere
that you can link to in the code?  a comment with an URL would be nice.


>+    nsCOMPtr<nsILocalFile> file(do_QueryInterface(aFile, &rv));
>+    if (NS_FAILED(rv))
>+        return NS_ERROR_NOT_AVAILABLE;
>+
>+    nsINIParser parser;
>+    rv = parser.Init(file);
>+    if (NS_FAILED(rv))
>+        return NS_ERROR_NOT_AVAILABLE;

It's generally better to propogate error codes unless there is good
reason to map them all to one error code like this.  The API says:

  * @throw NS_ERROR_NOT_AVAILABLE if the OS does not support such files.
  * @throw NS_ERROR_NOT_AVAILABLE if this file is not an internet shortcut.

I don't think failure for nsIFile to QI to nsILocalFile is covered
by either of those cases, so I would just propogate |rv|.  Same goes
for nsINIParser::Init failing.
Attachment #195881 - Flags: superreview-
(In reply to comment #5)
> (From update of attachment 195881 [details] [diff] [review] [edit])
> >Index: netwerk/protocol/file/src/nsFileProtocolHandler.cpp
> 
> >+        !StringEndsWith(leafName, NS_LITERAL_CSTRING(".desktop"),
> >+                        nsCaseInsensitiveCStringComparator()))
> 
> case insensitive really?  is there by chance a specification somewhere
> that you can link to in the code?  a comment with an URL would be nice.

http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.4.html#basic-format
says:
" These desktop entry files should have the extension .desktop. Determining file
type on basis of extension makes determining the file type very easy and quick.
When no file extension is present, the desktop system should fall back to
recognition via "magic detection"."

I talked with biesi about this on irc, and we agreed that it would be okay to
support only files with the extension, without doing the magic detection. I
could check it case insensitively though, if you think checking only lowercase
might be a problem? Like this:

    nsAutoString path;
    nsresult rv = aFile->GetPath(path);
    if (NS_FAILED(rv))
        return rv;
    if (path.Length() < 9)
        return NS_ERROR_NOT_AVAILABLE;
    if (!StringTail(path, 8).LowerCaseEqualsLiteral(".desktop"))
        return NS_ERROR_NOT_AVAILABLE;

> It's generally better to propogate error codes unless there is good
> reason to map them all to one error code like this.  The API says:
> 
>   * @throw NS_ERROR_NOT_AVAILABLE if the OS does not support such files.
>   * @throw NS_ERROR_NOT_AVAILABLE if this file is not an internet shortcut.
> 
> I don't think failure for nsIFile to QI to nsILocalFile is covered
> by either of those cases, so I would just propogate |rv|.  Same goes
> for nsINIParser::Init failing.

Fixed in my tree.

(In reply to comment #3)
> Hmm, I wonder why URLs are defined to be ASCII-only...

Interestingly, Nautilus already creates .desktop files with UTF-8 in the URL
field, for example when I drag a link to a non-punycoded IDN domain...
It could be an oversight, I'll ask the relevant list
[http://freedesktop.org/mailman/listinfo/xdg] . 

Attached patch updated patchSplinter Review
Changed to check for ".desktop" extension case-sensitively, and to propagate
return value. Add a link to the spec in a comment.
Attachment #195881 - Attachment is obsolete: true
Attachment #195917 - Flags: superreview?(darin)
Attachment #195917 - Flags: review?(cbiesinger)
Comment on attachment 195917 [details] [diff] [review]
updated patch

Looks good to me, sr=darin
Attachment #195917 - Flags: superreview?(darin) → superreview+
Attachment #195917 - Flags: review?(cbiesinger) → review+
Assignee: darin → chpe
Checking in netwerk/protocol/file/src/nsFileProtocolHandler.cpp;
/cvsroot/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.cpp,v  <-- 
nsFileProtocolHandler.cpp
new revision: 1.65; previous revision: 1.64
done
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
I filed bug 309781 as follow-up for the problem with the location bar that was
mentioned in comment 0.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: