1 Index: uriloader/exthandler/Makefile.in
2 ===================================================================
3 RCS file: /cvsroot/mozilla/uriloader/exthandler/Makefile.in,v
4 retrieving revision 1.60
5 diff -d -u -p -r1.60 Makefile.in
6 --- uriloader/exthandler/Makefile.in 2 May 2005 16:30:03 -0000 1.60
7 +++ uriloader/exthandler/Makefile.in 21 Jul 2005 03:07:39 -0000
8 @@ -102,7 +102,7 @@ endif
9 LOCAL_INCLUDES = -I$(srcdir)
11 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
12 -OSHELPER += nsGNOMERegistry.cpp
13 +OSHELPER += nsMIMEInfoUnix.cpp nsGNOMERegistry.cpp
16 ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
17 Index: uriloader/exthandler/unix/nsGNOMERegistry.cpp
18 ===================================================================
19 RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp,v
20 retrieving revision 1.10
21 diff -d -u -p -r1.10 nsGNOMERegistry.cpp
22 --- uriloader/exthandler/unix/nsGNOMERegistry.cpp 16 Oct 2004 13:46:17 -0000 1.10
23 +++ uriloader/exthandler/unix/nsGNOMERegistry.cpp 21 Jul 2005 03:07:40 -0000
26 #include "nsIComponentManager.h"
27 #include "nsILocalFile.h"
28 -#include "nsMIMEInfoImpl.h"
29 +#include "nsMIMEInfoUnix.h"
30 #include "nsAutoPtr.h"
33 @@ -56,12 +56,12 @@ typedef struct _GConfClient GConfClient;
34 typedef struct _GnomeProgram GnomeProgram;
35 typedef struct _GnomeModuleInfo GnomeModuleInfo;
38 +struct GnomeVFSMimeApplication {
42 /* there is more here, but we don't need it */
43 -} GnomeVFSMimeApplication;
46 typedef GConfClient * (*_gconf_client_get_default_fn)();
47 typedef gchar * (*_gconf_client_get_string_fn)(GConfClient *,
48 @@ -264,7 +264,7 @@ nsGNOMERegistry::GetAppDescForScheme(con
52 -/* static */ already_AddRefed<nsMIMEInfoBase>
53 +/* static */ already_AddRefed<nsMIMEInfoUnix>
54 nsGNOMERegistry::GetFromExtension(const char *aFileExt)
57 @@ -286,7 +286,7 @@ nsGNOMERegistry::GetFromExtension(const
58 return GetFromType(mimeType);
61 -/* static */ already_AddRefed<nsMIMEInfoBase>
62 +/* static */ already_AddRefed<nsMIMEInfoUnix>
63 nsGNOMERegistry::GetFromType(const char *aMIMEType)
66 @@ -296,9 +296,11 @@ nsGNOMERegistry::GetFromType(const char
70 - nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(aMIMEType);
71 + nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType);
72 NS_ENSURE_TRUE(mimeInfo, nsnull);
74 + mimeInfo->SetDefaultGnomeVFSMimeApplication(handlerApp);
76 // Get the list of extensions and append then to the mimeInfo.
77 GList *extensions = _gnome_vfs_mime_get_extensions_list(aMIMEType);
78 for (GList *extension = extensions; extension; extension = extension->next)
79 @@ -320,11 +322,21 @@ nsGNOMERegistry::GetFromType(const char
83 - gchar *commandPath = g_find_program_in_path(nativeCommand);
85 + gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL);
87 + NS_ERROR("Could not convert helper app command to filesystem encoding");
88 + _gnome_vfs_mime_application_free(handlerApp);
92 + gchar *commandPath = g_find_program_in_path(argv[0]);
94 g_free(nativeCommand);
98 + NS_WARNING("could not find command in path");
99 _gnome_vfs_mime_application_free(handlerApp);
102 @@ -342,7 +354,7 @@ nsGNOMERegistry::GetFromType(const char
104 _gnome_vfs_mime_application_free(handlerApp);
106 - nsMIMEInfoBase* retval;
107 + nsMIMEInfoUnix* retval;
108 NS_ADDREF((retval = mimeInfo));
111 Index: uriloader/exthandler/unix/nsGNOMERegistry.h
112 ===================================================================
113 RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.h,v
114 retrieving revision 1.3
115 diff -d -u -p -r1.3 nsGNOMERegistry.h
116 --- uriloader/exthandler/unix/nsGNOMERegistry.h 16 Oct 2004 13:46:17 -0000 1.3
117 +++ uriloader/exthandler/unix/nsGNOMERegistry.h 21 Jul 2005 03:07:40 -0000
120 * ***** END LICENSE BLOCK ***** */
122 +#ifndef nsGNOMERegistry_h__
123 +#define nsGNOMERegistry_h__
126 #include "nsCOMPtr.h"
128 -class nsMIMEInfoBase;
129 +class nsMIMEInfoUnix;
131 class nsGNOMERegistry
133 @@ -52,7 +55,9 @@ class nsGNOMERegistry
134 static void GetAppDescForScheme(const nsACString& aScheme,
137 - static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
138 + static already_AddRefed<nsMIMEInfoUnix> GetFromExtension(const char *aFileExt);
140 - static already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMIMEType);
141 + static already_AddRefed<nsMIMEInfoUnix> GetFromType(const char *aMIMEType);
144 +#endif // nsGNOMERegistry_h__
145 Index: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
146 ===================================================================
147 RCS file: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
148 diff -N uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
149 --- /dev/null 1 Jan 1970 00:00:00 -0000
150 +++ uriloader/exthandler/unix/nsMIMEInfoUnix.cpp 21 Jul 2005 03:07:40 -0000
152 +/* ***** BEGIN LICENSE BLOCK *****
155 + * The contents of this file are subject to the Mozilla Public License Version
156 + * 1.1 (the "License"); you may not use this file except in compliance with
157 + * the License. You may obtain a copy of the License at
158 + * http://www.mozilla.org/MPL/
160 + * Software distributed under the License is distributed on an "AS IS" basis,
161 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
162 + * for the specific language governing rights and limitations under the
165 + * The Original Code is mozilla.org Code.
167 + * The Initial Developer of the Original Code is
169 + * Portions created by the Initial Developer are Copyright (C) 2005
170 + * the Initial Developer. All Rights Reserved.
173 + * Christopher Aillon <caillon@redhat.com> (Original author)
176 + * ***** END LICENSE BLOCK ***** */
178 +#include "nsMIMEInfoUnix.h"
182 +#include <glib-object.h>
184 +static PRLibrary *gnomeLib;
185 +static PRLibrary *vfsLib;
187 +typedef struct _GnomeProgram GnomeProgram;
188 +typedef struct _GnomeModuleInfo GnomeModuleInfo;
191 + GNOME_VFS_OK // there's more but we don't care about them.
194 +typedef GnomeVFSResult (*_gnome_vfs_mime_application_launch_fn)
195 + (GnomeVFSMimeApplication *app,
197 +typedef void (*_gnome_vfs_mime_application_free_fn)(GnomeVFSMimeApplication *);
198 +typedef GnomeVFSMimeApplication * (*_gnome_vfs_mime_application_copy_fn)(GnomeVFSMimeApplication *);
199 +typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *,
200 + const GnomeModuleInfo *, int,
201 + char **, const char *, ...);
202 +typedef const char * (*_gnome_vfs_mime_application_get_name_fn)(GnomeVFSMimeApplication *);
203 +typedef const GnomeModuleInfo * (*_libgnome_module_info_get_fn)();
204 +typedef GnomeProgram * (*_gnome_program_get_fn)();
205 +typedef char * (*_gnome_vfs_make_uri_from_input_fn)(const char *);
207 +#define DECL_FUNC_PTR(func) static _##func##_fn _##func
209 +DECL_FUNC_PTR(gnome_vfs_mime_application_launch);
210 +DECL_FUNC_PTR(gnome_vfs_mime_application_free);
211 +DECL_FUNC_PTR(gnome_vfs_mime_application_copy);
212 +DECL_FUNC_PTR(gnome_vfs_mime_application_get_name);
213 +DECL_FUNC_PTR(gnome_program_init);
214 +DECL_FUNC_PTR(gnome_program_get);
215 +DECL_FUNC_PTR(libgnome_module_info_get);
216 +DECL_FUNC_PTR(gnome_vfs_make_uri_from_input);
219 +LoadVersionedLibrary(const char* libName, const char* libVersion)
221 + char *platformLibName = PR_GetLibraryName(nsnull, libName);
222 + nsCAutoString versionLibName(platformLibName);
223 + versionLibName.Append(libVersion);
224 + PR_Free(platformLibName);
225 + return PR_LoadLibrary(versionLibName.get());
231 + // Unload all libraries
233 + PR_UnloadLibrary(gnomeLib);
235 + PR_UnloadLibrary(vfsLib);
237 + gnomeLib = vfsLib = nsnull;
243 + static PRBool initialized = PR_FALSE;
248 + #define ENSURE_LIB(lib) \
256 + #define GET_LIB_FUNCTION(lib, func, failure) \
258 + _##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \
264 + // Attempt to open libgnome
265 + gnomeLib = LoadVersionedLibrary("gnome-2", ".0");
266 + ENSURE_LIB(gnomeLib);
268 + GET_LIB_FUNCTION(gnome, gnome_program_init, return Cleanup());
269 + GET_LIB_FUNCTION(gnome, libgnome_module_info_get, return Cleanup());
270 + GET_LIB_FUNCTION(gnome, gnome_program_get, return Cleanup());
272 + // Attempt to open libgnomevfs
273 + vfsLib = LoadVersionedLibrary("gnomevfs-2", ".0");
274 + ENSURE_LIB(vfsLib);
276 + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_launch, /* do nothing */);
277 + GET_LIB_FUNCTION(vfs, gnome_vfs_make_uri_from_input, return Cleanup());
278 + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_get_name, return Cleanup());
279 + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_free, return Cleanup());
280 + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_copy, return Cleanup());
282 + // Initialize GNOME, if it's not already initialized. It's not
283 + // necessary to tell GNOME about our actual command line arguments.
285 + if (!_gnome_program_get()) {
286 + char *argv[1] = { "gecko" };
287 + _gnome_program_init("Gecko", "1.0", _libgnome_module_info_get(),
291 + // Note: after GNOME has been initialized, do not ever unload these
292 + // libraries. They register atexit handlers, so if they are unloaded, we'll
297 +nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication* app)
299 + if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) {
300 + mDefaultVFSApplication = _gnome_vfs_mime_application_copy(app);
302 + mPreferredAction = nsIMIMEInfo::useSystemDefault;
304 + const gchar * name = _gnome_vfs_mime_application_get_name(mDefaultVFSApplication);
306 + mDefaultAppDescription = NS_ConvertUTF8toUCS2(name);
310 +nsMIMEInfoUnix::~nsMIMEInfoUnix()
312 + if (mDefaultVFSApplication)
313 + _gnome_vfs_mime_application_free(mDefaultVFSApplication);
317 +nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile* aFile)
319 + NS_ENSURE_ARG_POINTER(aFile);
323 + if (_gnome_vfs_mime_application_launch && mDefaultVFSApplication) {
324 + nsCAutoString nativePath;
325 + aFile->GetNativePath(nativePath);
327 + gchar *uri = _gnome_vfs_make_uri_from_input(nativePath.get());
329 + GList *uris = NULL;
330 + uris = g_list_append(uris, uri);
332 + GnomeVFSResult result = _gnome_vfs_mime_application_launch(mDefaultVFSApplication, uris);
337 + if (result != GNOME_VFS_OK)
338 + return NS_ERROR_FAILURE;
343 + if (!mDefaultApplication)
344 + return NS_ERROR_FILE_NOT_FOUND;
346 + return LaunchWithIProcess(mDefaultApplication, aFile);
348 Index: uriloader/exthandler/unix/nsMIMEInfoUnix.h
349 ===================================================================
350 RCS file: uriloader/exthandler/unix/nsMIMEInfoUnix.h
351 diff -N uriloader/exthandler/unix/nsMIMEInfoUnix.h
352 --- /dev/null 1 Jan 1970 00:00:00 -0000
353 +++ uriloader/exthandler/unix/nsMIMEInfoUnix.h 21 Jul 2005 03:07:40 -0000
355 +/* ***** BEGIN LICENSE BLOCK *****
358 + * The contents of this file are subject to the Mozilla Public License Version
359 + * 1.1 (the "License"); you may not use this file except in compliance with
360 + * the License. You may obtain a copy of the License at
361 + * http://www.mozilla.org/MPL/
363 + * Software distributed under the License is distributed on an "AS IS" basis,
364 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
365 + * for the specific language governing rights and limitations under the
368 + * The Original Code is mozilla.org Code.
370 + * The Initial Developer of the Original Code is
372 + * Portions created by the Initial Developer are Copyright (C) 2005
373 + * the Initial Developer. All Rights Reserved.
376 + * Christopher Aillon <caillon@redhat.com> (Original author)
379 + * ***** END LICENSE BLOCK ***** */
381 +#ifndef nsMimeInfoUnix_h__
382 +#define nsMimeInfoUnix_h__
384 +#include "nsMIMEInfoImpl.h"
386 +struct GnomeVFSMimeApplication;
388 +class nsMIMEInfoUnix : public nsMIMEInfoImpl
391 + nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {}
392 + nsMIMEInfoUnix(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {};
394 + virtual ~nsMIMEInfoUnix();
396 + void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app);
399 + virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
401 + GnomeVFSMimeApplication *mDefaultVFSApplication;
404 +#endif // nsMimeInfoUnix_h__
405 Index: uriloader/exthandler/unix/nsOSHelperAppService.cpp
406 ===================================================================
407 RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp,v
408 retrieving revision 1.58
409 diff -d -u -p -r1.58 nsOSHelperAppService.cpp
410 --- uriloader/exthandler/unix/nsOSHelperAppService.cpp 25 Oct 2004 07:46:01 -0000 1.58
411 +++ uriloader/exthandler/unix/nsOSHelperAppService.cpp 21 Jul 2005 03:07:40 -0000
413 #include "nsOSHelperAppService.h"
414 #ifdef MOZ_WIDGET_GTK2
415 #include "nsGNOMERegistry.h"
416 +#include "nsMIMEInfoUnix.h"
418 #include "nsISupports.h"
419 #include "nsString.h"
420 @@ -1486,6 +1487,17 @@ nsOSHelperAppService::GetFromType(const
422 LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType.get()));
424 +#ifdef MOZ_WIDGET_GTK2
425 + // Look in GNOME registry first since it is the preferred method in GNOME,
426 + // should trump the mailcap entry
427 + LOG(("Looking in GNOME registry\n"));
428 + nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
430 + LOG(("Got MIMEInfo from GNOME registry\n"));
435 // extract the major and minor types
436 NS_ConvertASCIItoUTF16 mimeType(aMIMEType);
437 nsAString::const_iterator start_iter, end_iter,
438 @@ -1522,21 +1534,6 @@ nsOSHelperAppService::GetFromType(const
443 - if (handler.IsEmpty() && extensions.IsEmpty() &&
444 - mailcap_description.IsEmpty() && mime_types_description.IsEmpty()) {
445 - // No useful data yet
447 -#ifdef MOZ_WIDGET_GTK2
448 - LOG(("Looking in GNOME registry\n"));
449 - nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
451 - LOG(("Got MIMEInfo from GNOME registry\n"));
457 if (handler.IsEmpty() && mailcap_description.IsEmpty()) {
458 DoLookUpHandlerAndDescription(majorType,