updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / xulrunner-1.8 / gnome_helpers_with_params.patch
blob32c292675a1c22996452b2fa2394fd6831bef81c
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 125_gnome_helpers_with_params.dpatch by Mike Hommey <glandium@debian.org>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Make helper applications with parameters work. Adapted patch from
6 ## DP: bz#273524
8 @DPATCH@
10 === uriloader/exthandler/Makefile.in
11 ==================================================================
12 --- xulrunner/uriloader/exthandler/Makefile.in (revision 116)
13 +++ xulrunner/uriloader/exthandler/Makefile.in (local)
14 @@ -102,7 +102,7 @@
15 LOCAL_INCLUDES = -I$(srcdir)
17 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
18 -OSHELPER += nsGNOMERegistry.cpp
19 +OSHELPER += nsMIMEInfoUnix.cpp nsGNOMERegistry.cpp
20 endif
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)
27 @@ -42,7 +42,7 @@
28 #include "nsString.h"
29 #include "nsIComponentManager.h"
30 #include "nsILocalFile.h"
31 -#include "nsMIMEInfoImpl.h"
32 +#include "nsMIMEInfoUnix.h"
33 #include "nsAutoPtr.h"
35 #include <glib.h>
36 @@ -56,12 +56,12 @@
37 typedef struct _GnomeProgram GnomeProgram;
38 typedef struct _GnomeModuleInfo GnomeModuleInfo;
40 -typedef struct {
41 +struct GnomeVFSMimeApplication {
42 char *id;
43 char *name;
44 char *command;
45 /* there is more here, but we don't need it */
46 -} GnomeVFSMimeApplication;
47 +};
49 typedef GConfClient * (*_gconf_client_get_default_fn)();
50 typedef gchar * (*_gconf_client_get_string_fn)(GConfClient *,
51 @@ -264,7 +264,7 @@
55 -/* static */ already_AddRefed<nsMIMEInfoBase>
56 +/* static */ already_AddRefed<nsMIMEInfoUnix>
57 nsGNOMERegistry::GetFromExtension(const char *aFileExt)
59 if (!gconfLib)
60 @@ -286,7 +286,7 @@
61 return GetFromType(mimeType);
64 -/* static */ already_AddRefed<nsMIMEInfoBase>
65 +/* static */ already_AddRefed<nsMIMEInfoUnix>
66 nsGNOMERegistry::GetFromType(const char *aMIMEType)
68 if (!gconfLib)
69 @@ -296,7 +296,7 @@
70 if (!handlerApp)
71 return nsnull;
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.
78 @@ -320,11 +320,21 @@
79 return nsnull;
82 - gchar *commandPath = g_find_program_in_path(nativeCommand);
83 + gchar **argv;
84 + gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL);
85 + if (!res) {
86 + NS_ERROR("Could not convert helper app command to filesystem encoding");
87 + _gnome_vfs_mime_application_free(handlerApp);
88 + return nsnull;
89 + }
91 + gchar *commandPath = g_find_program_in_path(argv[0]);
93 g_free(nativeCommand);
94 + g_strfreev(argv);
96 if (!commandPath) {
97 + NS_WARNING("could not find command in path");
98 _gnome_vfs_mime_application_free(handlerApp);
99 return nsnull;
101 @@ -342,7 +352,7 @@
103 _gnome_vfs_mime_application_free(handlerApp);
105 - nsMIMEInfoBase* retval;
106 + nsMIMEInfoUnix* retval;
107 NS_ADDREF((retval = mimeInfo));
108 return retval;
110 === uriloader/exthandler/unix/nsGNOMERegistry.h
111 ==================================================================
112 --- xulrunner/uriloader/exthandler/unix/nsGNOMERegistry.h (revision 116)
113 +++ xulrunner/uriloader/exthandler/unix/nsGNOMERegistry.h (local)
114 @@ -35,10 +35,13 @@
116 * ***** END LICENSE BLOCK ***** */
118 +#ifndef nsGNOMERegistry_h__
119 +#define nsGNOMERegistry_h__
121 #include "nsIURI.h"
122 #include "nsCOMPtr.h"
124 -class nsMIMEInfoBase;
125 +class nsMIMEInfoUnix;
127 class nsGNOMERegistry
129 @@ -52,7 +55,9 @@
130 static void GetAppDescForScheme(const nsACString& aScheme,
131 nsAString& aDesc);
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)
145 @@ -44,11 +44,13 @@
146 #include "nsOSHelperAppService.h"
147 #ifdef MOZ_WIDGET_GTK2
148 #include "nsGNOMERegistry.h"
149 +#include "nsMIMEInfoUnix.h"
150 #endif
151 #include "nsISupports.h"
152 #include "nsString.h"
153 #include "nsReadableUtils.h"
154 #include "nsUnicharUtils.h"
155 +#include "nsIStringEnumerator.h"
156 #include "nsXPIDLString.h"
157 #include "nsIURL.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();
168 + if (gnomeInfo) {
169 + LOG(("Got MIMEInfo from GNOME registry\n"));
170 + nsCOMPtr<nsIUTF8StringEnumerator> extensions;
171 + gnomeInfo->GetFileExtensions(getter_AddRefs(extensions));
172 + PRBool hasMore;
173 + extensions->HasMore(&hasMore);
174 + if (hasMore)
175 + return gnomeInfo;
177 +#endif
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"));
197 - return gnomeInfo;
200 -#endif
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)
208 @@ -0,0 +1,196 @@
209 +/* ***** BEGIN LICENSE BLOCK *****
210 + * Version: MPL 1.1
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
220 + * License.
222 + * The Original Code is mozilla.org Code.
224 + * The Initial Developer of the Original Code is
225 + * Red Hat, Inc.
226 + * Portions created by the Initial Developer are Copyright (C) 2005
227 + * the Initial Developer. All Rights Reserved.
229 + * Contributor(s):
230 + * Christopher Aillon <caillon@redhat.com> (Original author)
233 + * ***** END LICENSE BLOCK ***** */
235 +#include "nsMIMEInfoUnix.h"
236 +#include "prlink.h"
237 +#include "prmem.h"
238 +#include <glib.h>
239 +#include <glib-object.h>
241 +static PRLibrary *gnomeLib;
242 +static PRLibrary *vfsLib;
244 +typedef struct _GnomeProgram GnomeProgram;
245 +typedef struct _GnomeModuleInfo GnomeModuleInfo;
247 +typedef enum {
248 + GNOME_VFS_OK // there's more but we don't care about them.
249 +} GnomeVFSResult;
251 +typedef GnomeVFSResult (*_gnome_vfs_mime_application_launch_fn)
252 + (GnomeVFSMimeApplication *app,
253 + GList *uris);
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);
275 +static PRLibrary *
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());
285 +static void
286 +Cleanup()
288 + // Unload all libraries
289 + if (gnomeLib)
290 + PR_UnloadLibrary(gnomeLib);
291 + if (vfsLib)
292 + PR_UnloadLibrary(vfsLib);
294 + gnomeLib = vfsLib = nsnull;
297 +static void
298 +InitGnomeVFS()
300 + static PRBool initialized = PR_FALSE;
302 + if (initialized)
303 + return;
305 + #define ENSURE_LIB(lib) \
306 + PR_BEGIN_MACRO \
307 + if (!lib) { \
308 + Cleanup(); \
309 + return; \
310 + } \
311 + PR_END_MACRO
313 + #define GET_LIB_FUNCTION(lib, func, failure) \
314 + PR_BEGIN_MACRO \
315 + _##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \
316 + if (!_##func) { \
317 + failure; \
318 + } \
319 + PR_END_MACRO
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(),
345 + 1, argv, NULL);
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
350 + // crash on exit.
353 +void
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);
362 + if (name)
363 + mDefaultAppDescription = NS_ConvertUTF8toUCS2(name);
367 +nsMIMEInfoUnix::~nsMIMEInfoUnix()
369 + if (mDefaultVFSApplication)
370 + _gnome_vfs_mime_application_free(mDefaultVFSApplication);
373 +nsresult
374 +nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile* aFile)
376 + NS_ENSURE_ARG_POINTER(aFile);
378 + InitGnomeVFS();
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);
391 + g_free(uri);
392 + g_list_free(uris);
394 + if (result != GNOME_VFS_OK)
395 + return NS_ERROR_FAILURE;
397 + return NS_OK;
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)
409 @@ -0,0 +1,48 @@
410 +/* ***** BEGIN LICENSE BLOCK *****
411 + * Version: MPL 1.1
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
421 + * License.
423 + * The Original Code is mozilla.org Code.
425 + * The Initial Developer of the Original Code is
426 + * Red Hat, Inc.
427 + * Portions created by the Initial Developer are Copyright (C) 2005
428 + * the Initial Developer. All Rights Reserved.
430 + * Contributor(s):
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
445 +public:
446 + nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {}
447 + virtual ~nsMIMEInfoUnix();
449 + void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app);
451 +protected:
452 + virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
454 + GnomeVFSMimeApplication *mDefaultVFSApplication;
457 +#endif // nsMimeInfoUnix_h__