Contents of /trunk/mozilla-firefox/patches/mozilla-firefox-1.0.7-uriloader.patch
Parent Directory | Revision Log
Revision 153 -
(show annotations)
(download)
Tue May 8 20:52:56 2007 UTC (17 years, 4 months ago) by niro
File size: 15096 byte(s)
Tue May 8 20:52:56 2007 UTC (17 years, 4 months ago) by niro
File size: 15096 byte(s)
-import
1 | Index: uriloader/exthandler/unix/nsGNOMERegistry.cpp |
2 | =================================================================== |
3 | RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp,v |
4 | retrieving revision 1.8 |
5 | diff -d -u -p -r1.8 nsGNOMERegistry.cpp |
6 | --- uriloader/exthandler/unix/nsGNOMERegistry.cpp 6 Mar 2004 14:41:00 -0000 1.8 |
7 | +++ uriloader/exthandler/unix/nsGNOMERegistry.cpp 3 May 2005 19:09:20 -0000 |
8 | @@ -42,7 +42,7 @@ |
9 | #include "nsString.h" |
10 | #include "nsIComponentManager.h" |
11 | #include "nsILocalFile.h" |
12 | -#include "nsMIMEInfoImpl.h" |
13 | +#include "nsMIMEInfoUnix.h" |
14 | #include "nsAutoPtr.h" |
15 | |
16 | #include <glib.h> |
17 | @@ -56,12 +56,12 @@ typedef struct _GConfClient GConfClient; |
18 | typedef struct _GnomeProgram GnomeProgram; |
19 | typedef struct _GnomeModuleInfo GnomeModuleInfo; |
20 | |
21 | -typedef struct { |
22 | +struct GnomeVFSMimeApplication { |
23 | char *id; |
24 | char *name; |
25 | char *command; |
26 | /* there is more here, but we don't need it */ |
27 | -} GnomeVFSMimeApplication; |
28 | +}; |
29 | |
30 | typedef GConfClient * (*_gconf_client_get_default_fn)(); |
31 | typedef gchar * (*_gconf_client_get_string_fn)(GConfClient *, |
32 | @@ -231,7 +231,7 @@ nsGNOMERegistry::LoadURL(nsIURI *aURL) |
33 | return NS_ERROR_FAILURE; |
34 | } |
35 | |
36 | -/* static */ already_AddRefed<nsMIMEInfoBase> |
37 | +/* static */ already_AddRefed<nsMIMEInfoUnix> |
38 | nsGNOMERegistry::GetFromExtension(const char *aFileExt) |
39 | { |
40 | if (!gconfLib) |
41 | @@ -253,7 +253,7 @@ nsGNOMERegistry::GetFromExtension(const |
42 | return GetFromType(mimeType); |
43 | } |
44 | |
45 | -/* static */ already_AddRefed<nsMIMEInfoBase> |
46 | +/* static */ already_AddRefed<nsMIMEInfoUnix> |
47 | nsGNOMERegistry::GetFromType(const char *aMIMEType) |
48 | { |
49 | if (!gconfLib) |
50 | @@ -263,10 +263,11 @@ nsGNOMERegistry::GetFromType(const char |
51 | if (!handlerApp) |
52 | return nsnull; |
53 | |
54 | - nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(); |
55 | + nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(); |
56 | NS_ENSURE_TRUE(mimeInfo, nsnull); |
57 | |
58 | mimeInfo->SetMIMEType(aMIMEType); |
59 | + mimeInfo->SetDefaultGnomeVFSMimeApplication(handlerApp); |
60 | |
61 | // Get the list of extensions and append then to the mimeInfo. |
62 | GList *extensions = _gnome_vfs_mime_get_extensions_list(aMIMEType); |
63 | @@ -289,11 +290,21 @@ nsGNOMERegistry::GetFromType(const char |
64 | return nsnull; |
65 | } |
66 | |
67 | - gchar *commandPath = g_find_program_in_path(nativeCommand); |
68 | + gchar **argv; |
69 | + gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL); |
70 | + if (!res) { |
71 | + NS_ERROR("Could not convert helper app command to filesystem encoding"); |
72 | + _gnome_vfs_mime_application_free(handlerApp); |
73 | + return nsnull; |
74 | + } |
75 | + |
76 | + gchar *commandPath = g_find_program_in_path(argv[0]); |
77 | |
78 | g_free(nativeCommand); |
79 | + g_strfreev(argv); |
80 | |
81 | if (!commandPath) { |
82 | + NS_WARNING("could not find command in path"); |
83 | _gnome_vfs_mime_application_free(handlerApp); |
84 | return nsnull; |
85 | } |
86 | @@ -311,7 +322,7 @@ nsGNOMERegistry::GetFromType(const char |
87 | |
88 | _gnome_vfs_mime_application_free(handlerApp); |
89 | |
90 | - nsMIMEInfoBase* retval; |
91 | + nsMIMEInfoUnix* retval; |
92 | NS_ADDREF((retval = mimeInfo)); |
93 | return retval; |
94 | } |
95 | Index: uriloader/exthandler/unix/nsGNOMERegistry.h |
96 | =================================================================== |
97 | RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.h,v |
98 | retrieving revision 1.2 |
99 | diff -d -u -p -r1.2 nsGNOMERegistry.h |
100 | --- uriloader/exthandler/unix/nsGNOMERegistry.h 23 Feb 2004 22:49:27 -0000 1.2 |
101 | +++ uriloader/exthandler/unix/nsGNOMERegistry.h 3 May 2005 18:21:35 -0000 |
102 | @@ -35,10 +35,13 @@ |
103 | * |
104 | * ***** END LICENSE BLOCK ***** */ |
105 | |
106 | +#ifndef nsGNOMERegistry_h__ |
107 | +#define nsGNOMERegistry_h__ |
108 | + |
109 | #include "nsIURI.h" |
110 | #include "nsCOMPtr.h" |
111 | |
112 | -class nsMIMEInfoBase; |
113 | +class nsMIMEInfoUnix; |
114 | |
115 | class nsGNOMERegistry |
116 | { |
117 | @@ -49,7 +52,9 @@ class nsGNOMERegistry |
118 | |
119 | static nsresult LoadURL(nsIURI *aURL); |
120 | |
121 | - static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt); |
122 | + static already_AddRefed<nsMIMEInfoUnix> GetFromExtension(const char *aFileExt); |
123 | |
124 | - static already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMIMEType); |
125 | + static already_AddRefed<nsMIMEInfoUnix> GetFromType(const char *aMIMEType); |
126 | }; |
127 | + |
128 | +#endif // nsGNOMERegistry_h__ |
129 | Index: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp |
130 | =================================================================== |
131 | RCS file: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp |
132 | diff -N uriloader/exthandler/unix/nsMIMEInfoUnix.cpp |
133 | --- /dev/null 1 Jan 1970 00:00:00 -0000 |
134 | +++ uriloader/exthandler/unix/nsMIMEInfoUnix.cpp 3 May 2005 18:21:35 -0000 |
135 | @@ -0,0 +1,196 @@ |
136 | +/* ***** BEGIN LICENSE BLOCK ***** |
137 | + * Version: MPL 1.1 |
138 | + * |
139 | + * The contents of this file are subject to the Mozilla Public License Version |
140 | + * 1.1 (the "License"); you may not use this file except in compliance with |
141 | + * the License. You may obtain a copy of the License at |
142 | + * http://www.mozilla.org/MPL/ |
143 | + * |
144 | + * Software distributed under the License is distributed on an "AS IS" basis, |
145 | + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
146 | + * for the specific language governing rights and limitations under the |
147 | + * License. |
148 | + * |
149 | + * The Original Code is mozilla.org Code. |
150 | + * |
151 | + * The Initial Developer of the Original Code is |
152 | + * Red Hat, Inc. |
153 | + * Portions created by the Initial Developer are Copyright (C) 2005 |
154 | + * the Initial Developer. All Rights Reserved. |
155 | + * |
156 | + * Contributor(s): |
157 | + * Christopher Aillon <caillon@redhat.com> (Original author) |
158 | + * |
159 | + * |
160 | + * ***** END LICENSE BLOCK ***** */ |
161 | + |
162 | +#include "nsMIMEInfoUnix.h" |
163 | +#include "prlink.h" |
164 | +#include "prmem.h" |
165 | +#include <glib.h> |
166 | +#include <glib-object.h> |
167 | + |
168 | +static PRLibrary *gnomeLib; |
169 | +static PRLibrary *vfsLib; |
170 | + |
171 | +typedef struct _GnomeProgram GnomeProgram; |
172 | +typedef struct _GnomeModuleInfo GnomeModuleInfo; |
173 | + |
174 | +typedef enum { |
175 | + GNOME_VFS_OK // there's more but we don't care about them. |
176 | +} GnomeVFSResult; |
177 | + |
178 | +typedef GnomeVFSResult (*_gnome_vfs_mime_application_launch_fn) |
179 | + (GnomeVFSMimeApplication *app, |
180 | + GList *uris); |
181 | +typedef void (*_gnome_vfs_mime_application_free_fn)(GnomeVFSMimeApplication *); |
182 | +typedef GnomeVFSMimeApplication * (*_gnome_vfs_mime_application_copy_fn)(GnomeVFSMimeApplication *); |
183 | +typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *, |
184 | + const GnomeModuleInfo *, int, |
185 | + char **, const char *, ...); |
186 | +typedef const char * (*_gnome_vfs_mime_application_get_name_fn)(GnomeVFSMimeApplication *); |
187 | +typedef const GnomeModuleInfo * (*_libgnome_module_info_get_fn)(); |
188 | +typedef GnomeProgram * (*_gnome_program_get_fn)(); |
189 | +typedef char * (*_gnome_vfs_make_uri_from_input_fn)(const char *); |
190 | + |
191 | +#define DECL_FUNC_PTR(func) static _##func##_fn _##func |
192 | + |
193 | +DECL_FUNC_PTR(gnome_vfs_mime_application_launch); |
194 | +DECL_FUNC_PTR(gnome_vfs_mime_application_free); |
195 | +DECL_FUNC_PTR(gnome_vfs_mime_application_copy); |
196 | +DECL_FUNC_PTR(gnome_vfs_mime_application_get_name); |
197 | +DECL_FUNC_PTR(gnome_program_init); |
198 | +DECL_FUNC_PTR(gnome_program_get); |
199 | +DECL_FUNC_PTR(libgnome_module_info_get); |
200 | +DECL_FUNC_PTR(gnome_vfs_make_uri_from_input); |
201 | + |
202 | +static PRLibrary * |
203 | +LoadVersionedLibrary(const char* libName, const char* libVersion) |
204 | +{ |
205 | + char *platformLibName = PR_GetLibraryName(nsnull, libName); |
206 | + nsCAutoString versionLibName(platformLibName); |
207 | + versionLibName.Append(libVersion); |
208 | + PR_Free(platformLibName); |
209 | + return PR_LoadLibrary(versionLibName.get()); |
210 | +} |
211 | + |
212 | +static void |
213 | +Cleanup() |
214 | +{ |
215 | + // Unload all libraries |
216 | + if (gnomeLib) |
217 | + PR_UnloadLibrary(gnomeLib); |
218 | + if (vfsLib) |
219 | + PR_UnloadLibrary(vfsLib); |
220 | + |
221 | + gnomeLib = vfsLib = nsnull; |
222 | +} |
223 | + |
224 | +static void |
225 | +InitGnomeVFS() |
226 | +{ |
227 | + static PRBool initialized = PR_FALSE; |
228 | + |
229 | + if (initialized) |
230 | + return; |
231 | + |
232 | + #define ENSURE_LIB(lib) \ |
233 | + PR_BEGIN_MACRO \ |
234 | + if (!lib) { \ |
235 | + Cleanup(); \ |
236 | + return; \ |
237 | + } \ |
238 | + PR_END_MACRO |
239 | + |
240 | + #define GET_LIB_FUNCTION(lib, func, failure) \ |
241 | + PR_BEGIN_MACRO \ |
242 | + _##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \ |
243 | + if (!_##func) { \ |
244 | + failure; \ |
245 | + } \ |
246 | + PR_END_MACRO |
247 | + |
248 | + // Attempt to open libgnome |
249 | + gnomeLib = LoadVersionedLibrary("gnome-2", ".0"); |
250 | + ENSURE_LIB(gnomeLib); |
251 | + |
252 | + GET_LIB_FUNCTION(gnome, gnome_program_init, return Cleanup()); |
253 | + GET_LIB_FUNCTION(gnome, libgnome_module_info_get, return Cleanup()); |
254 | + GET_LIB_FUNCTION(gnome, gnome_program_get, return Cleanup()); |
255 | + |
256 | + // Attempt to open libgnomevfs |
257 | + vfsLib = LoadVersionedLibrary("gnomevfs-2", ".0"); |
258 | + ENSURE_LIB(vfsLib); |
259 | + |
260 | + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_launch, /* do nothing */); |
261 | + GET_LIB_FUNCTION(vfs, gnome_vfs_make_uri_from_input, return Cleanup()); |
262 | + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_get_name, return Cleanup()); |
263 | + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_free, return Cleanup()); |
264 | + GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_copy, return Cleanup()); |
265 | + |
266 | + // Initialize GNOME, if it's not already initialized. It's not |
267 | + // necessary to tell GNOME about our actual command line arguments. |
268 | + |
269 | + if (!_gnome_program_get()) { |
270 | + char *argv[1] = { "gecko" }; |
271 | + _gnome_program_init("Gecko", "1.0", _libgnome_module_info_get(), |
272 | + 1, argv, NULL); |
273 | + } |
274 | + |
275 | + // Note: after GNOME has been initialized, do not ever unload these |
276 | + // libraries. They register atexit handlers, so if they are unloaded, we'll |
277 | + // crash on exit. |
278 | +} |
279 | + |
280 | +void |
281 | +nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication* app) |
282 | +{ |
283 | + if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) { |
284 | + mDefaultVFSApplication = _gnome_vfs_mime_application_copy(app); |
285 | + |
286 | + mPreferredAction = nsIMIMEInfo::useSystemDefault; |
287 | + |
288 | + const gchar * name = _gnome_vfs_mime_application_get_name(mDefaultVFSApplication); |
289 | + if (name) |
290 | + mDefaultAppDescription = NS_ConvertUTF8toUCS2(name); |
291 | + } |
292 | +} |
293 | + |
294 | +nsMIMEInfoUnix::~nsMIMEInfoUnix() |
295 | +{ |
296 | + if (mDefaultVFSApplication) |
297 | + _gnome_vfs_mime_application_free(mDefaultVFSApplication); |
298 | +} |
299 | + |
300 | +nsresult |
301 | +nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile* aFile) |
302 | +{ |
303 | + NS_ENSURE_ARG_POINTER(aFile); |
304 | + |
305 | + InitGnomeVFS(); |
306 | + |
307 | + if (_gnome_vfs_mime_application_launch && mDefaultVFSApplication) { |
308 | + nsCAutoString nativePath; |
309 | + aFile->GetNativePath(nativePath); |
310 | + |
311 | + gchar *uri = _gnome_vfs_make_uri_from_input(nativePath.get()); |
312 | + |
313 | + GList *uris = NULL; |
314 | + uris = g_list_append(uris, uri); |
315 | + |
316 | + GnomeVFSResult result = _gnome_vfs_mime_application_launch(mDefaultVFSApplication, uris); |
317 | + |
318 | + g_free(uri); |
319 | + g_list_free(uris); |
320 | + |
321 | + if (result != GNOME_VFS_OK) |
322 | + return NS_ERROR_FAILURE; |
323 | + |
324 | + return NS_OK; |
325 | + } |
326 | + |
327 | + if (!mDefaultApplication) |
328 | + return NS_ERROR_FILE_NOT_FOUND; |
329 | + |
330 | + return LaunchWithIProcess(mDefaultApplication, aFile); |
331 | +} |
332 | Index: uriloader/exthandler/unix/nsMIMEInfoUnix.h |
333 | =================================================================== |
334 | RCS file: uriloader/exthandler/unix/nsMIMEInfoUnix.h |
335 | diff -N uriloader/exthandler/unix/nsMIMEInfoUnix.h |
336 | --- /dev/null 1 Jan 1970 00:00:00 -0000 |
337 | +++ uriloader/exthandler/unix/nsMIMEInfoUnix.h 3 May 2005 18:21:35 -0000 |
338 | @@ -0,0 +1,48 @@ |
339 | +/* ***** BEGIN LICENSE BLOCK ***** |
340 | + * Version: MPL 1.1 |
341 | + * |
342 | + * The contents of this file are subject to the Mozilla Public License Version |
343 | + * 1.1 (the "License"); you may not use this file except in compliance with |
344 | + * the License. You may obtain a copy of the License at |
345 | + * http://www.mozilla.org/MPL/ |
346 | + * |
347 | + * Software distributed under the License is distributed on an "AS IS" basis, |
348 | + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
349 | + * for the specific language governing rights and limitations under the |
350 | + * License. |
351 | + * |
352 | + * The Original Code is mozilla.org Code. |
353 | + * |
354 | + * The Initial Developer of the Original Code is |
355 | + * Red Hat, Inc. |
356 | + * Portions created by the Initial Developer are Copyright (C) 2005 |
357 | + * the Initial Developer. All Rights Reserved. |
358 | + * |
359 | + * Contributor(s): |
360 | + * Christopher Aillon <caillon@redhat.com> (Original author) |
361 | + * |
362 | + * |
363 | + * ***** END LICENSE BLOCK ***** */ |
364 | + |
365 | +#ifndef nsMimeInfoUnix_h__ |
366 | +#define nsMimeInfoUnix_h__ |
367 | + |
368 | +#include "nsMIMEInfoImpl.h" |
369 | + |
370 | +struct GnomeVFSMimeApplication; |
371 | + |
372 | +class nsMIMEInfoUnix : public nsMIMEInfoImpl |
373 | +{ |
374 | +public: |
375 | + nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {} |
376 | + virtual ~nsMIMEInfoUnix(); |
377 | + |
378 | + void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app); |
379 | + |
380 | +protected: |
381 | + virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile); |
382 | + |
383 | + GnomeVFSMimeApplication *mDefaultVFSApplication; |
384 | +}; |
385 | + |
386 | +#endif // nsMimeInfoUnix_h__ |
387 | Index: uriloader/exthandler/unix/nsOSHelperAppService.cpp |
388 | =================================================================== |
389 | RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp,v |
390 | retrieving revision 1.50.6.2 |
391 | diff -d -u -p -r1.50.6.2 nsOSHelperAppService.cpp |
392 | --- uriloader/exthandler/unix/nsOSHelperAppService.cpp 20 Oct 2004 13:32:38 -0000 1.50.6.2 |
393 | +++ uriloader/exthandler/unix/nsOSHelperAppService.cpp 3 May 2005 18:21:35 -0000 |
394 | @@ -27,6 +27,7 @@ |
395 | #include "nsOSHelperAppService.h" |
396 | #ifdef MOZ_WIDGET_GTK2 |
397 | #include "nsGNOMERegistry.h" |
398 | +#include "nsMIMEInfoUnix.h" |
399 | #endif |
400 | #include "nsISupports.h" |
401 | #include "nsString.h" |
402 | @@ -1453,6 +1454,17 @@ nsOSHelperAppService::GetFromType(const |
403 | |
404 | LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType)); |
405 | |
406 | +#ifdef MOZ_WIDGET_GTK2 |
407 | + // Look in GNOME registry first since it is the preferred method in GNOME, |
408 | + // should trump the mailcap entry |
409 | + LOG(("Looking in GNOME registry\n")); |
410 | + nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType).get(); |
411 | + if (gnomeInfo) { |
412 | + LOG(("Got MIMEInfo from GNOME registry\n")); |
413 | + return gnomeInfo; |
414 | + } |
415 | +#endif |
416 | + |
417 | // extract the major and minor types |
418 | NS_ConvertASCIItoUTF16 mimeType(aMIMEType); |
419 | nsAString::const_iterator start_iter, end_iter, |
420 | @@ -1489,21 +1501,6 @@ nsOSHelperAppService::GetFromType(const |
421 | mozillaFlags, |
422 | PR_TRUE); |
423 | |
424 | - |
425 | - if (handler.IsEmpty() && extensions.IsEmpty() && |
426 | - mailcap_description.IsEmpty() && mime_types_description.IsEmpty()) { |
427 | - // No useful data yet |
428 | - |
429 | -#ifdef MOZ_WIDGET_GTK2 |
430 | - LOG(("Looking in GNOME registry\n")); |
431 | - nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType).get(); |
432 | - if (gnomeInfo) { |
433 | - LOG(("Got MIMEInfo from GNOME registry\n")); |
434 | - return gnomeInfo; |
435 | - } |
436 | -#endif |
437 | - } |
438 | - |
439 | if (handler.IsEmpty() && mailcap_description.IsEmpty()) { |
440 | DoLookUpHandlerAndDescription(majorType, |
441 | minorType, |
442 | Index: uriloader/exthandler/Makefile.in |
443 | =================================================================== |
444 | RCS file: /cvsroot/mozilla/uriloader/exthandler/Makefile.in,v |
445 | retrieving revision 1.60 |
446 | diff -d -u -p -r1.60 Makefile.in |
447 | --- uriloader/exthandler/Makefile.in 2 May 2005 16:30:03 -0000 1.60 |
448 | +++ uriloader/exthandler/Makefile.in 4 May 2005 05:49:19 -0000 |
449 | @@ -102,7 +102,7 @@ endif |
450 | LOCAL_INCLUDES = -I$(srcdir) |
451 | |
452 | ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2) |
453 | -OSHELPER += nsGNOMERegistry.cpp |
454 | +OSHELPER += nsMIMEInfoUnix.cpp nsGNOMERegistry.cpp |
455 | endif |
456 | |
457 | ifeq ($(MOZ_WIDGET_TOOLKIT),beos) |