Magellan Linux

Contents of /trunk/mozilla-firefox/patches/mozilla-firefox-1.5.0-uriloader.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations) (download)
Tue May 8 20:52:56 2007 UTC (17 years ago) by niro
File size: 15300 byte(s)
-import

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)
10
11 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
12 -OSHELPER += nsGNOMERegistry.cpp
13 +OSHELPER += nsMIMEInfoUnix.cpp nsGNOMERegistry.cpp
14 endif
15
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
24 @@ -42,7 +42,7 @@
25 #include "nsString.h"
26 #include "nsIComponentManager.h"
27 #include "nsILocalFile.h"
28 -#include "nsMIMEInfoImpl.h"
29 +#include "nsMIMEInfoUnix.h"
30 #include "nsAutoPtr.h"
31
32 #include <glib.h>
33 @@ -56,12 +56,12 @@ typedef struct _GConfClient GConfClient;
34 typedef struct _GnomeProgram GnomeProgram;
35 typedef struct _GnomeModuleInfo GnomeModuleInfo;
36
37 -typedef struct {
38 +struct GnomeVFSMimeApplication {
39 char *id;
40 char *name;
41 char *command;
42 /* there is more here, but we don't need it */
43 -} GnomeVFSMimeApplication;
44 +};
45
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
49 }
50
51
52 -/* static */ already_AddRefed<nsMIMEInfoBase>
53 +/* static */ already_AddRefed<nsMIMEInfoUnix>
54 nsGNOMERegistry::GetFromExtension(const char *aFileExt)
55 {
56 if (!gconfLib)
57 @@ -286,7 +286,7 @@ nsGNOMERegistry::GetFromExtension(const
58 return GetFromType(mimeType);
59 }
60
61 -/* static */ already_AddRefed<nsMIMEInfoBase>
62 +/* static */ already_AddRefed<nsMIMEInfoUnix>
63 nsGNOMERegistry::GetFromType(const char *aMIMEType)
64 {
65 if (!gconfLib)
66 @@ -296,9 +296,11 @@ nsGNOMERegistry::GetFromType(const char
67 if (!handlerApp)
68 return nsnull;
69
70 - nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(aMIMEType);
71 + nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType);
72 NS_ENSURE_TRUE(mimeInfo, nsnull);
73
74 + mimeInfo->SetDefaultGnomeVFSMimeApplication(handlerApp);
75 +
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
80 return nsnull;
81 }
82
83 - gchar *commandPath = g_find_program_in_path(nativeCommand);
84 + gchar **argv;
85 + gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL);
86 + if (!res) {
87 + NS_ERROR("Could not convert helper app command to filesystem encoding");
88 + _gnome_vfs_mime_application_free(handlerApp);
89 + return nsnull;
90 + }
91 +
92 + gchar *commandPath = g_find_program_in_path(argv[0]);
93
94 g_free(nativeCommand);
95 + g_strfreev(argv);
96
97 if (!commandPath) {
98 + NS_WARNING("could not find command in path");
99 _gnome_vfs_mime_application_free(handlerApp);
100 return nsnull;
101 }
102 @@ -342,7 +354,7 @@ nsGNOMERegistry::GetFromType(const char
103
104 _gnome_vfs_mime_application_free(handlerApp);
105
106 - nsMIMEInfoBase* retval;
107 + nsMIMEInfoUnix* retval;
108 NS_ADDREF((retval = mimeInfo));
109 return retval;
110 }
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
118 @@ -35,10 +35,13 @@
119 *
120 * ***** END LICENSE BLOCK ***** */
121
122 +#ifndef nsGNOMERegistry_h__
123 +#define nsGNOMERegistry_h__
124 +
125 #include "nsIURI.h"
126 #include "nsCOMPtr.h"
127
128 -class nsMIMEInfoBase;
129 +class nsMIMEInfoUnix;
130
131 class nsGNOMERegistry
132 {
133 @@ -52,7 +55,9 @@ class nsGNOMERegistry
134 static void GetAppDescForScheme(const nsACString& aScheme,
135 nsAString& aDesc);
136
137 - static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
138 + static already_AddRefed<nsMIMEInfoUnix> GetFromExtension(const char *aFileExt);
139
140 - static already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMIMEType);
141 + static already_AddRefed<nsMIMEInfoUnix> GetFromType(const char *aMIMEType);
142 };
143 +
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
151 @@ -0,0 +1,196 @@
152 +/* ***** BEGIN LICENSE BLOCK *****
153 + * Version: MPL 1.1
154 + *
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/
159 + *
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
163 + * License.
164 + *
165 + * The Original Code is mozilla.org Code.
166 + *
167 + * The Initial Developer of the Original Code is
168 + * Red Hat, Inc.
169 + * Portions created by the Initial Developer are Copyright (C) 2005
170 + * the Initial Developer. All Rights Reserved.
171 + *
172 + * Contributor(s):
173 + * Christopher Aillon <caillon@redhat.com> (Original author)
174 + *
175 + *
176 + * ***** END LICENSE BLOCK ***** */
177 +
178 +#include "nsMIMEInfoUnix.h"
179 +#include "prlink.h"
180 +#include "prmem.h"
181 +#include <glib.h>
182 +#include <glib-object.h>
183 +
184 +static PRLibrary *gnomeLib;
185 +static PRLibrary *vfsLib;
186 +
187 +typedef struct _GnomeProgram GnomeProgram;
188 +typedef struct _GnomeModuleInfo GnomeModuleInfo;
189 +
190 +typedef enum {
191 + GNOME_VFS_OK // there's more but we don't care about them.
192 +} GnomeVFSResult;
193 +
194 +typedef GnomeVFSResult (*_gnome_vfs_mime_application_launch_fn)
195 + (GnomeVFSMimeApplication *app,
196 + GList *uris);
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 *);
206 +
207 +#define DECL_FUNC_PTR(func) static _##func##_fn _##func
208 +
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);
217 +
218 +static PRLibrary *
219 +LoadVersionedLibrary(const char* libName, const char* libVersion)
220 +{
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());
226 +}
227 +
228 +static void
229 +Cleanup()
230 +{
231 + // Unload all libraries
232 + if (gnomeLib)
233 + PR_UnloadLibrary(gnomeLib);
234 + if (vfsLib)
235 + PR_UnloadLibrary(vfsLib);
236 +
237 + gnomeLib = vfsLib = nsnull;
238 +}
239 +
240 +static void
241 +InitGnomeVFS()
242 +{
243 + static PRBool initialized = PR_FALSE;
244 +
245 + if (initialized)
246 + return;
247 +
248 + #define ENSURE_LIB(lib) \
249 + PR_BEGIN_MACRO \
250 + if (!lib) { \
251 + Cleanup(); \
252 + return; \
253 + } \
254 + PR_END_MACRO
255 +
256 + #define GET_LIB_FUNCTION(lib, func, failure) \
257 + PR_BEGIN_MACRO \
258 + _##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \
259 + if (!_##func) { \
260 + failure; \
261 + } \
262 + PR_END_MACRO
263 +
264 + // Attempt to open libgnome
265 + gnomeLib = LoadVersionedLibrary("gnome-2", ".0");
266 + ENSURE_LIB(gnomeLib);
267 +
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());
271 +
272 + // Attempt to open libgnomevfs
273 + vfsLib = LoadVersionedLibrary("gnomevfs-2", ".0");
274 + ENSURE_LIB(vfsLib);
275 +
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());
281 +
282 + // Initialize GNOME, if it's not already initialized. It's not
283 + // necessary to tell GNOME about our actual command line arguments.
284 +
285 + if (!_gnome_program_get()) {
286 + char *argv[1] = { "gecko" };
287 + _gnome_program_init("Gecko", "1.0", _libgnome_module_info_get(),
288 + 1, argv, NULL);
289 + }
290 +
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
293 + // crash on exit.
294 +}
295 +
296 +void
297 +nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication* app)
298 +{
299 + if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) {
300 + mDefaultVFSApplication = _gnome_vfs_mime_application_copy(app);
301 +
302 + mPreferredAction = nsIMIMEInfo::useSystemDefault;
303 +
304 + const gchar * name = _gnome_vfs_mime_application_get_name(mDefaultVFSApplication);
305 + if (name)
306 + mDefaultAppDescription = NS_ConvertUTF8toUCS2(name);
307 + }
308 +}
309 +
310 +nsMIMEInfoUnix::~nsMIMEInfoUnix()
311 +{
312 + if (mDefaultVFSApplication)
313 + _gnome_vfs_mime_application_free(mDefaultVFSApplication);
314 +}
315 +
316 +nsresult
317 +nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile* aFile)
318 +{
319 + NS_ENSURE_ARG_POINTER(aFile);
320 +
321 + InitGnomeVFS();
322 +
323 + if (_gnome_vfs_mime_application_launch && mDefaultVFSApplication) {
324 + nsCAutoString nativePath;
325 + aFile->GetNativePath(nativePath);
326 +
327 + gchar *uri = _gnome_vfs_make_uri_from_input(nativePath.get());
328 +
329 + GList *uris = NULL;
330 + uris = g_list_append(uris, uri);
331 +
332 + GnomeVFSResult result = _gnome_vfs_mime_application_launch(mDefaultVFSApplication, uris);
333 +
334 + g_free(uri);
335 + g_list_free(uris);
336 +
337 + if (result != GNOME_VFS_OK)
338 + return NS_ERROR_FAILURE;
339 +
340 + return NS_OK;
341 + }
342 +
343 + if (!mDefaultApplication)
344 + return NS_ERROR_FILE_NOT_FOUND;
345 +
346 + return LaunchWithIProcess(mDefaultApplication, aFile);
347 +}
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
354 @@ -0,0 +1,50 @@
355 +/* ***** BEGIN LICENSE BLOCK *****
356 + * Version: MPL 1.1
357 + *
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/
362 + *
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
366 + * License.
367 + *
368 + * The Original Code is mozilla.org Code.
369 + *
370 + * The Initial Developer of the Original Code is
371 + * Red Hat, Inc.
372 + * Portions created by the Initial Developer are Copyright (C) 2005
373 + * the Initial Developer. All Rights Reserved.
374 + *
375 + * Contributor(s):
376 + * Christopher Aillon <caillon@redhat.com> (Original author)
377 + *
378 + *
379 + * ***** END LICENSE BLOCK ***** */
380 +
381 +#ifndef nsMimeInfoUnix_h__
382 +#define nsMimeInfoUnix_h__
383 +
384 +#include "nsMIMEInfoImpl.h"
385 +
386 +struct GnomeVFSMimeApplication;
387 +
388 +class nsMIMEInfoUnix : public nsMIMEInfoImpl
389 +{
390 +public:
391 + nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {}
392 + nsMIMEInfoUnix(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {};
393 +
394 + virtual ~nsMIMEInfoUnix();
395 +
396 + void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app);
397 +
398 +protected:
399 + virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
400 +
401 + GnomeVFSMimeApplication *mDefaultVFSApplication;
402 +};
403 +
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
412 @@ -44,6 +44,7 @@
413 #include "nsOSHelperAppService.h"
414 #ifdef MOZ_WIDGET_GTK2
415 #include "nsGNOMERegistry.h"
416 +#include "nsMIMEInfoUnix.h"
417 #endif
418 #include "nsISupports.h"
419 #include "nsString.h"
420 @@ -1535,6 +1551,17 @@ nsOSHelperAppService::GetFromType(const
421
422 LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType.get()));
423
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();
429 + if (gnomeInfo) {
430 + LOG(("Got MIMEInfo from GNOME registry\n"));
431 + return gnomeInfo;
432 + }
433 +#endif
434 +
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
439 mozillaFlags,
440 PR_TRUE);
441
442 -
443 - if (handler.IsEmpty() && extensions.IsEmpty() &&
444 - mailcap_description.IsEmpty() && mime_types_description.IsEmpty()) {
445 - // No useful data yet
446 -
447 -#ifdef MOZ_WIDGET_GTK2
448 - LOG(("Looking in GNOME registry\n"));
449 - nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
450 - if (gnomeInfo) {
451 - LOG(("Got MIMEInfo from GNOME registry\n"));
452 - return gnomeInfo;
453 - }
454 -#endif
455 - }
456 -
457 if (handler.IsEmpty() && mailcap_description.IsEmpty()) {
458 DoLookUpHandlerAndDescription(majorType,
459 minorType,