1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 125_gnome_helpers_with_params.dpatch by Mike Hommey <glandium@debian.org>
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Make helper applications with parameters work. Adapted patch from
10 === uriloader
/exthandler
/Makefile.
in
11 ==================================================================
12 --- xulrunner
/uriloader
/exthandler
/Makefile.
in (revision
116)
13 +++ xulrunner
/uriloader
/exthandler
/Makefile.
in (local)
15 LOCAL_INCLUDES
= -I$
(srcdir
)
17 ifeq
($
(MOZ_WIDGET_TOOLKIT
),gtk2
)
18 -OSHELPER += nsGNOMERegistry.cpp
19 +OSHELPER
+= nsMIMEInfoUnix.cpp nsGNOMERegistry.cpp
22 ifeq
($
(MOZ_WIDGET_TOOLKIT
),beos
)
23 === uriloader
/exthandler
/unix
/nsGNOMERegistry.cpp
24 ==================================================================
25 --- xulrunner
/uriloader
/exthandler
/unix
/nsGNOMERegistry.cpp
(revision
116)
26 +++ xulrunner
/uriloader
/exthandler
/unix
/nsGNOMERegistry.cpp
(local)
29 #include "nsIComponentManager.h"
30 #include "nsILocalFile.h"
31 -#include "nsMIMEInfoImpl.h"
32 +#include "nsMIMEInfoUnix.h"
33 #include "nsAutoPtr.h"
37 typedef struct _GnomeProgram GnomeProgram
;
38 typedef struct _GnomeModuleInfo GnomeModuleInfo
;
41 +struct GnomeVFSMimeApplication
{
45 /* there is
more here
, but we don
't need it */
46 -} GnomeVFSMimeApplication;
49 typedef GConfClient * (*_gconf_client_get_default_fn)();
50 typedef gchar * (*_gconf_client_get_string_fn)(GConfClient *,
55 -/* static */ already_AddRefed<nsMIMEInfoBase>
56 +/* static */ already_AddRefed<nsMIMEInfoUnix>
57 nsGNOMERegistry::GetFromExtension(const char *aFileExt)
61 return GetFromType(mimeType);
64 -/* static */ already_AddRefed<nsMIMEInfoBase>
65 +/* static */ already_AddRefed<nsMIMEInfoUnix>
66 nsGNOMERegistry::GetFromType(const char *aMIMEType)
73 - nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(aMIMEType);
74 + nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType);
75 NS_ENSURE_TRUE(mimeInfo, nsnull);
77 // Get the list of extensions and append then to the mimeInfo.
82 - gchar *commandPath = g_find_program_in_path(nativeCommand);
84 + gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL);
86 + NS_ERROR("Could not convert helper app command to filesystem encoding");
87 + _gnome_vfs_mime_application_free(handlerApp);
91 + gchar *commandPath = g_find_program_in_path(argv[0]);
93 g_free(nativeCommand);
97 + NS_WARNING("could not find command in path");
98 _gnome_vfs_mime_application_free(handlerApp);
103 _gnome_vfs_mime_application_free(handlerApp);
105 - nsMIMEInfoBase* retval;
106 + nsMIMEInfoUnix* retval;
107 NS_ADDREF((retval = mimeInfo));
110 === uriloader/exthandler/unix/nsGNOMERegistry.h
111 ==================================================================
112 --- xulrunner/uriloader/exthandler/unix/nsGNOMERegistry.h (revision 116)
113 +++ xulrunner/uriloader/exthandler/unix/nsGNOMERegistry.h (local)
116 * ***** END LICENSE BLOCK ***** */
118 +#ifndef nsGNOMERegistry_h__
119 +#define nsGNOMERegistry_h__
122 #include "nsCOMPtr.h"
124 -class nsMIMEInfoBase;
125 +class nsMIMEInfoUnix;
127 class nsGNOMERegistry
130 static void GetAppDescForScheme(const nsACString& aScheme,
133 - static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
134 + static already_AddRefed<nsMIMEInfoUnix> GetFromExtension(const char *aFileExt);
136 - static already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMIMEType);
137 + static already_AddRefed<nsMIMEInfoUnix> GetFromType(const char *aMIMEType);
140 +#endif // nsGNOMERegistry_h__
141 === uriloader/exthandler/unix/nsOSHelperAppService.cpp
142 ==================================================================
143 --- xulrunner/uriloader/exthandler/unix/nsOSHelperAppService.cpp (revision 175)
144 +++ xulrunner/uriloader/exthandler/unix/nsOSHelperAppService.cpp (local)
146 #include "nsOSHelperAppService.h"
147 #ifdef MOZ_WIDGET_GTK2
148 #include "nsGNOMERegistry.h"
149 +#include "nsMIMEInfoUnix.h"
151 #include "nsISupports.h"
152 #include "nsString.h"
153 #include "nsReadableUtils.h"
154 #include "nsUnicharUtils.h"
155 +#include "nsIStringEnumerator.h"
156 #include "nsXPIDLString.h"
158 #include "nsIFileStreams.h"
159 @@ -1486,6 +1488,22 @@
161 LOG(("Here we do a mimetype lookup for '%s
'\n", aMIMEType.get()));
163 +#ifdef MOZ_WIDGET_GTK2
164 + // Look in GNOME registry first since it is the preferred method in GNOME,
165 + // should trump the mailcap entry
166 + LOG(("Looking in GNOME registry\n"));
167 + nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
169 + LOG(("Got MIMEInfo from GNOME registry\n"));
170 + nsCOMPtr<nsIUTF8StringEnumerator> extensions;
171 + gnomeInfo->GetFileExtensions(getter_AddRefs(extensions));
173 + extensions->HasMore(&hasMore);
179 // extract the major and minor types
180 NS_ConvertASCIItoUTF16 mimeType(aMIMEType);
181 nsAString::const_iterator start_iter, end_iter,
182 @@ -1521,21 +1539,6 @@
183 NS_LossyConvertUTF16toASCII(handler).get(),
184 NS_LossyConvertUTF16toASCII(mailcap_description).get()));
186 -#ifdef MOZ_WIDGET_GTK2
187 - nsMIMEInfoBase *gnomeInfo = nsnull;
188 - if (handler.IsEmpty()) {
189 - // No useful data yet. Check the GNOME registry. Unfortunately, newer
190 - // GNOME versions no longer have type-to-extension mappings, so we might
191 - // get back a MIMEInfo without any extensions set. In that case we'll have
192 - // to
look in our mime.types files
for the extensions.
193 - LOG
(("Looking in GNOME registry\n"));
194 - gnomeInfo
= nsGNOMERegistry
::GetFromType
(aMIMEType.get
()).get
();
195 - if (gnomeInfo
&& gnomeInfo-
>HasExtensions
()) {
196 - LOG
(("Got MIMEInfo from GNOME registry, and it has extensions set\n"));
202 // Now
look up our extensions
203 nsAutoString extensions
, mime_types_description
;
204 === uriloader
/exthandler
/unix
/nsMIMEInfoUnix.cpp
205 ==================================================================
206 --- xulrunner
/uriloader
/exthandler
/unix
/nsMIMEInfoUnix.cpp
(revision
116)
207 +++ xulrunner
/uriloader
/exthandler
/unix
/nsMIMEInfoUnix.cpp
(local)
209 +/* ***** BEGIN LICENSE BLOCK
*****
212 + * The contents of this
file are subject to the Mozilla Public License Version
213 + * 1.1 (the
"License"); you may not use this
file except
in compliance with
214 + * the License. You may obtain a copy of the License
at
215 + * http
://www.mozilla.org
/MPL
/
217 + * Software distributed under the License is distributed on an
"AS IS" basis
,
218 + * WITHOUT WARRANTY OF ANY KIND
, either express or implied. See the License
219 + * for the specific language governing rights and limitations under the
222 + * The Original Code is mozilla.org Code.
224 + * The Initial Developer of the Original Code is
226 + * Portions created by the Initial Developer are Copyright
(C
) 2005
227 + * the Initial Developer. All Rights Reserved.
230 + * Christopher Aillon
<caillon@redhat.com
> (Original author
)
233 + * ***** END LICENSE BLOCK
***** */
235 +#include "nsMIMEInfoUnix.h"
239 +#include <glib-object.h>
241 +static PRLibrary
*gnomeLib
;
242 +static PRLibrary
*vfsLib
;
244 +typedef struct _GnomeProgram GnomeProgram
;
245 +typedef struct _GnomeModuleInfo GnomeModuleInfo
;
248 + GNOME_VFS_OK
// there
's more but we don't care about them.
251 +typedef GnomeVFSResult
(*_gnome_vfs_mime_application_launch_fn
)
252 + (GnomeVFSMimeApplication
*app
,
254 +typedef void
(*_gnome_vfs_mime_application_free_fn
)(GnomeVFSMimeApplication
*);
255 +typedef GnomeVFSMimeApplication
* (*_gnome_vfs_mime_application_copy_fn
)(GnomeVFSMimeApplication
*);
256 +typedef GnomeProgram
* (*_gnome_program_init_fn
)(const char
*, const char
*,
257 + const GnomeModuleInfo
*, int
,
258 + char
**, const char
*, ...
);
259 +typedef const char
* (*_gnome_vfs_mime_application_get_name_fn
)(GnomeVFSMimeApplication
*);
260 +typedef const GnomeModuleInfo
* (*_libgnome_module_info_get_fn
)();
261 +typedef GnomeProgram
* (*_gnome_program_get_fn
)();
262 +typedef char
* (*_gnome_vfs_make_uri_from_input_fn
)(const char
*);
264 +#define DECL_FUNC_PTR(func) static _##func##_fn _##func
266 +DECL_FUNC_PTR
(gnome_vfs_mime_application_launch
);
267 +DECL_FUNC_PTR
(gnome_vfs_mime_application_free
);
268 +DECL_FUNC_PTR
(gnome_vfs_mime_application_copy
);
269 +DECL_FUNC_PTR
(gnome_vfs_mime_application_get_name
);
270 +DECL_FUNC_PTR
(gnome_program_init
);
271 +DECL_FUNC_PTR
(gnome_program_get
);
272 +DECL_FUNC_PTR
(libgnome_module_info_get
);
273 +DECL_FUNC_PTR
(gnome_vfs_make_uri_from_input
);
276 +LoadVersionedLibrary
(const char
* libName
, const char
* libVersion
)
278 + char
*platformLibName
= PR_GetLibraryName
(nsnull
, libName
);
279 + nsCAutoString versionLibName
(platformLibName
);
280 + versionLibName.Append
(libVersion
);
281 + PR_Free
(platformLibName
);
282 + return PR_LoadLibrary
(versionLibName.get
());
288 + // Unload all libraries
290 + PR_UnloadLibrary
(gnomeLib
);
292 + PR_UnloadLibrary
(vfsLib
);
294 + gnomeLib
= vfsLib
= nsnull
;
300 + static PRBool initialized
= PR_FALSE
;
305 + #define ENSURE_LIB(lib) \
313 + #define GET_LIB_FUNCTION(lib, func, failure) \
315 + _
##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \
321 + // Attempt to open libgnome
322 + gnomeLib
= LoadVersionedLibrary
("gnome-2", ".0");
323 + ENSURE_LIB
(gnomeLib
);
325 + GET_LIB_FUNCTION
(gnome
, gnome_program_init
, return Cleanup
());
326 + GET_LIB_FUNCTION
(gnome
, libgnome_module_info_get
, return Cleanup
());
327 + GET_LIB_FUNCTION
(gnome
, gnome_program_get
, return Cleanup
());
329 + // Attempt to open libgnomevfs
330 + vfsLib
= LoadVersionedLibrary
("gnomevfs-2", ".0");
331 + ENSURE_LIB
(vfsLib
);
333 + GET_LIB_FUNCTION
(vfs
, gnome_vfs_mime_application_launch
, /* do nothing
*/);
334 + GET_LIB_FUNCTION
(vfs
, gnome_vfs_make_uri_from_input
, return Cleanup
());
335 + GET_LIB_FUNCTION
(vfs
, gnome_vfs_mime_application_get_name
, return Cleanup
());
336 + GET_LIB_FUNCTION
(vfs
, gnome_vfs_mime_application_free
, return Cleanup
());
337 + GET_LIB_FUNCTION
(vfs
, gnome_vfs_mime_application_copy
, return Cleanup
());
339 + // Initialize GNOME
, if it
's not already initialized. It's not
340 + // necessary to tell GNOME about our actual
command line arguments.
342 + if (!_gnome_program_get
()) {
343 + char
*argv
[1] = { "gecko" };
344 + _gnome_program_init
("Gecko", "1.0", _libgnome_module_info_get
(),
348 + // Note
: after GNOME has been initialized
, do not ever unload these
349 + // libraries. They register atexit handlers
, so
if they are unloaded
, we
'll
354 +nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication* app)
356 + if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) {
357 + mDefaultVFSApplication = _gnome_vfs_mime_application_copy(app);
359 + mPreferredAction = nsIMIMEInfo::useSystemDefault;
361 + const gchar * name = _gnome_vfs_mime_application_get_name(mDefaultVFSApplication);
363 + mDefaultAppDescription = NS_ConvertUTF8toUCS2(name);
367 +nsMIMEInfoUnix::~nsMIMEInfoUnix()
369 + if (mDefaultVFSApplication)
370 + _gnome_vfs_mime_application_free(mDefaultVFSApplication);
374 +nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile* aFile)
376 + NS_ENSURE_ARG_POINTER(aFile);
380 + if (_gnome_vfs_mime_application_launch && mDefaultVFSApplication) {
381 + nsCAutoString nativePath;
382 + aFile->GetNativePath(nativePath);
384 + gchar *uri = _gnome_vfs_make_uri_from_input(nativePath.get());
386 + GList *uris = NULL;
387 + uris = g_list_append(uris, uri);
389 + GnomeVFSResult result = _gnome_vfs_mime_application_launch(mDefaultVFSApplication, uris);
394 + if (result != GNOME_VFS_OK)
395 + return NS_ERROR_FAILURE;
400 + if (!mDefaultApplication)
401 + return NS_ERROR_FILE_NOT_FOUND;
403 + return LaunchWithIProcess(mDefaultApplication, aFile);
405 === uriloader/exthandler/unix/nsMIMEInfoUnix.h
406 ==================================================================
407 --- xulrunner/uriloader/exthandler/unix/nsMIMEInfoUnix.h (revision 116)
408 +++ xulrunner/uriloader/exthandler/unix/nsMIMEInfoUnix.h (local)
410 +/* ***** BEGIN LICENSE BLOCK *****
413 + * The contents of this file are subject to the Mozilla Public License Version
414 + * 1.1 (the "License"); you may not use this file except in compliance with
415 + * the License. You may obtain a copy of the License at
416 + * http://www.mozilla.org/MPL/
418 + * Software distributed under the License is distributed on an "AS IS" basis,
419 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
420 + * for the specific language governing rights and limitations under the
423 + * The Original Code is mozilla.org Code.
425 + * The Initial Developer of the Original Code is
427 + * Portions created by the Initial Developer are Copyright (C) 2005
428 + * the Initial Developer. All Rights Reserved.
431 + * Christopher Aillon <caillon@redhat.com> (Original author)
434 + * ***** END LICENSE BLOCK ***** */
436 +#ifndef nsMimeInfoUnix_h__
437 +#define nsMimeInfoUnix_h__
439 +#include "nsMIMEInfoImpl.h"
441 +struct GnomeVFSMimeApplication;
443 +class nsMIMEInfoUnix : public nsMIMEInfoImpl
446 + nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {}
447 + virtual ~nsMIMEInfoUnix();
449 + void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app);
452 + virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
454 + GnomeVFSMimeApplication *mDefaultVFSApplication;
457 +#endif // nsMimeInfoUnix_h__