Last Comment Bug 675466 - [Linux] Download manager disregards user's configured default handler apps in recent Gnome versions, due to use of deprecated GnomeVFS APIs (instead of GIO)
: [Linux] Download manager disregards user's configured default handler apps in...
Status: RESOLVED DUPLICATE of bug 713802
[workaround in comment 4]
Product: Core Graveyard
Classification: Graveyard
Component: File Handling (show other bugs)
: Trunk
: All Linux
-- normal (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
Depends on: 713802
  Show dependency treegraph
Reported: 2011-07-30 17:11 PDT by Daniel Holbert [:dholbert]
Modified: 2016-06-22 12:16 PDT (History)
3 users (show)
See Also:
QA Whiteboard:
Iteration: ---
Points: ---


Description User image Daniel Holbert [:dholbert] 2011-07-30 17:11:44 PDT
 0. Be running Ubuntu. (I'm on v11.04). Install VLC or another non-default ogg video player.
 1. Run "wget " to save that file to your desktop.
 2. Right-click on that file, and choose "Properties", and then "Open With" tab, and click the radiobutton for VLC instead of Totem.
 3. Now start Firefox.  Visit the above URL.  Right-click the video and choose "Save As", and save it somewhere.
 4. When the download completes, double-click the file *in the download manager.*

ACTUAL RESULTS: Totem opens.

Digging into this a bit, it appears we end up with this stack after I've chosen "Save As":
#0  nsGnomeVFSService::GetAppForMimeType (this=0x7fbb76cd4560, aMimeType=..., aApp=0x7fffa10252e0) at ../../../../mozilla/toolkit/system/gnome/nsGnomeVFSService.cpp:212
#1  0x00007fbb886a7a1d in nsGNOMERegistry::GetFromType (aMIMEType=...) at ../../../mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp:196
#2  0x00007fbb886a8aba in nsMIMEInfoUnix::GetHasDefaultHandler (this=0x7fbb64905dc0, _retval=0x7fffa10256b4) at ../../../mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp:103
#3  0x00007fbb886a64db in nsOSHelperAppService::GetMIMEInfoFromOS (this=0x7fbb738ac7a0, aType=..., aFileExt=..., aFound=0x7fffa10258bc) at ../../../mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp:1541
#4  0x00007fbb886992b3 in nsExternalHelperAppService::GetFromTypeAndExtension (this=0x7fbb738ac7a0, aMIMEType=..., aFileExt=..., _retval=0x7fffa1025c30) at ../../../mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp:2583
#5  0x00007fbb88692b89 in nsExternalHelperAppService::DoContent (this=0x7fbb738ac7a0, aMimeContentType=..., aRequest=0x7fbb6386a858, aWindowContext=0x7fbb6aea44b0, aForceSave=1, aStreamListener=0x7fffa10260a0) at ../../../mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp:834

Level 0 in that backtrace is this function:
> 204 nsGnomeVFSService::GetAppForMimeType(const nsACString &aMimeType,
> 205                                      nsIGnomeVFSMimeApp** aApp)
> 206 {
> 207   *aApp = nsnull;
> 208   GnomeVFSMimeApplication *app =
> 209    gnome_vfs_mime_get_default_application(PromiseFlatCString(aMimeType).get());
> 210 
> 211   if (app) {
> 212     nsGnomeVFSMimeApp *mozApp = new nsGnomeVFSMimeApp(app);
> 214 
> 215     NS_ADDREF(*aApp = mozApp);
> 216   }
> 217 
> 218   return NS_OK;
> 219 }

...and "app" returned by gnome_vfs_mime_get_default_application is:
$26 = {
  id = 0x7fbb64b46340 "totem.desktop", 
  name = 0x7fbb64b58170 "Movie Player", 
  command = 0x7fbb64b46440 "totem", 
  can_open_multiple_files = 1, 
  supported_uri_schemes = 0x7fbb6513e200, 
  requires_terminal = 0, 
  reserved1 = 0x0, 
  priv = 0x7fbb64d06ac0
Comment 1 User image Daniel Holbert [:dholbert] 2011-07-30 17:40:00 PDT
Here's the API documentation for gnome_vfs_mime_get_default_application():

Snippets from that documentation:
> Query the MIME database for the application to be executed on files of MIME type mime_type by default.
> Returns: a GnomeVFSMimeApplication representing the default handler of mime_type.

I'm not sure if "default" there means the global default, or if it includes the user's chosen default app.

Also -- FWIW, after step 2 of the STR, this appears in ~/.local/share/applications/mimeapps.list :
> [Default Applications]
> audio/ogg=vlc.desktop
Comment 2 User image Daniel Holbert [:dholbert] 2011-07-30 17:41:57 PDT
See also this "Ask Ubuntu" (stackexchange) page on this issue:
Comment 3 User image Daniel Holbert [:dholbert] 2011-07-30 18:08:37 PDT
Nautilus appears to use "GAppInfo" instead of "GnomeVFSMimeApplication" to represent apps in this case, and it calls "g_app_info_get_default_for_type" to look up the default app.

This struct & method appear to be part of GIO as opposed to GnomeVFS  (and IIUC, GIO is a replacement for GnomeVFS).

Source reference, from nautilus-  (obtained via "apt-get source nautilus"):
> GAppInfo *
> nautilus_mime_get_default_application_for_file (NautilusFile *file)
> {
>	GAppInfo *app;
>	char *mime_type;
>	mime_type = nautilus_file_get_mime_type (file);
>	app = g_app_info_get_default_for_type (mime_type, !file_has_local_path (file));
Comment 4 User image Daniel Holbert [:dholbert] 2011-07-30 18:48:47 PDT
(In reply to comment #1)
> Also -- FWIW, after step 2 of the STR, this appears in
> ~/.local/share/applications/mimeapps.list :
> > [Default Applications]
> > audio/ogg=vlc.desktop

Aha! So GIO apparently uses that file ("mimeapps.list") to store user-configured default apps.  However, GnomeVFS expects this file to have a different name -- "defaults.list"[1]. The files appear to have the same format, though, so you can fake out GnomeVFS by providing it with GIO's file, like so:
  cd .local/share/applications/
  ln -s mimeapps.list defaults.list
  [and then restart Firefox]
That effectively works around this bug, at least on my Ubuntu 11.04 system. 

Comment 5 User image Daniel Holbert [:dholbert] 2011-07-30 18:57:47 PDT
Also, FWIW, you can use the "gnomevfs-info" tool (in package "libgnomevfs2-bin") to see what app GnomeVFS thinks should open a particular file.

That tool is just as confused as Firefox after this bug's original STR, and it gets faked out just as effectively as Firefox by the workaround in comment 4.
Comment 6 User image Daniel Holbert [:dholbert] 2011-07-30 19:13:30 PDT
It appears that we do have code to provide GIO support, added in bug 402892.  You have to explicitly add a build flag to get it, though. (--enable-gio)
Comment 7 User image :Ehsan Akhgari 2012-01-09 16:14:37 PST
(In reply to Daniel Holbert [:dholbert] from comment #6)
> It appears that we do have code to provide GIO support, added in bug 402892.
> You have to explicitly add a build flag to get it, though. (--enable-gio)

Is there any downsides to just make that the default?
Comment 8 User image Daniel Holbert [:dholbert] 2012-01-09 16:22:44 PST
I think it doesn't work on old GTK versions.  But as those become deprecated / unused, that becomes less of an issue.

In any case, it looks like that's covered in bug 713802.  Duping to that bug.

*** This bug has been marked as a duplicate of bug 713802 ***

Note You need to log in before you can comment on or make changes to this bug.