|
1 From: Wolfgang Rosenauer <wr@rosenauer.org> |
|
2 Subject: no helper app for application/octet-stream but recognized extensions |
|
3 References: |
|
4 https://bugzilla.novell.com/show_bug.cgi?id=406979 |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=327323 |
|
6 |
|
7 |
|
8 diff --git a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp |
|
9 --- a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp |
|
10 +++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp |
|
11 @@ -47,6 +47,7 @@ |
|
12 #include "nsMIMEInfoUnix.h" |
|
13 #include "nsGNOMERegistry.h" |
|
14 #include "nsIGnomeVFSService.h" |
|
15 +#include "nsAutoPtr.h" |
|
16 #ifdef MOZ_ENABLE_DBUS |
|
17 #include "nsDBusHandlerApp.h" |
|
18 #endif |
|
19 @@ -74,13 +75,16 @@ NS_IMETHODIMP |
|
20 nsMIMEInfoUnix::GetHasDefaultHandler(PRBool *_retval) |
|
21 { |
|
22 *_retval = PR_FALSE; |
|
23 - nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); |
|
24 - if (vfs) { |
|
25 - nsCOMPtr<nsIGnomeVFSMimeApp> app; |
|
26 - if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app) |
|
27 - *_retval = PR_TRUE; |
|
28 + nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromType(mType); |
|
29 + if (!mimeInfo) { |
|
30 + nsCAutoString ext; |
|
31 + GetPrimaryExtension(ext); |
|
32 + mimeInfo = nsGNOMERegistry::GetFromExtension(ext); |
|
33 } |
|
34 |
|
35 + if (mimeInfo) |
|
36 + *_retval = PR_TRUE; |
|
37 + |
|
38 if (*_retval) |
|
39 return NS_OK; |
|
40 |
|
41 @@ -113,6 +117,16 @@ nsMIMEInfoUnix::LaunchDefaultWithFile(ns |
|
42 nsCOMPtr<nsIGnomeVFSMimeApp> app; |
|
43 if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app) |
|
44 return app->Launch(nativePath); |
|
45 + |
|
46 + // If we haven't got an app we try to get a valid one by searching for the |
|
47 + // extension mapped type |
|
48 + nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromExtension(nativePath); |
|
49 + if (mimeInfo) { |
|
50 + nsCAutoString type; |
|
51 + mimeInfo->GetType(type); |
|
52 + if (NS_SUCCEEDED(vfs->GetAppForMimeType(type, getter_AddRefs(app))) && app) |
|
53 + return app->Launch(nativePath); |
|
54 + } |
|
55 } |
|
56 |
|
57 if (!mDefaultApplication) |
|
58 diff --git a/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/uriloader/exthandler/unix/nsOSHelperAppService.cpp |
|
59 --- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp |
|
60 +++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp |
|
61 @@ -1580,8 +1580,16 @@ nsOSHelperAppService::GetMIMEInfoFromOS( |
|
62 return retval; |
|
63 } |
|
64 |
|
65 - // Copy the attributes of retval onto miByExt, to return it |
|
66 + // Copy the attributes of retval (mimeinfo from type) onto miByExt, to |
|
67 + // return it |
|
68 + // but reset to just collected mDefaultAppDescription (from ext) |
|
69 + // and preserve the primary extension as well |
|
70 + nsAutoString byExtDefault; |
|
71 + miByExt->GetDefaultDescription(byExtDefault); |
|
72 + retval->SetDefaultDescription(byExtDefault); |
|
73 retval->CopyBasicDataTo(miByExt); |
|
74 + if (!aFileExt.IsEmpty()) |
|
75 + miByExt->SetPrimaryExtension(aFileExt); |
|
76 |
|
77 miByExt.swap(retval); |
|
78 } |