1 Description: Various fixes for nsGIOService
2 1) Don't use the unversioned devel so
3 2) Ensure nsGIOMimeApp::GetCommand returns the full command string
4 3) Fix nsGIOService::CreateAppFromCommand to match the correct GAppInfo
5 Author: Chris Coulson <chris.coulson@canonical.com>
6 Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=611953
7 Forwarded: https://bug611953.bugzilla.mozilla.org/attachment.cgi?id=491149
9 diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp
10 --- a/toolkit/system/gnome/nsGIOService.cpp
11 +++ b/toolkit/system/gnome/nsGIOService.cpp
12 @@ -101,25 +101,25 @@ nsGIOMimeApp::GetName(nsACString& aName)
17 nsGIOMimeApp::GetCommand(nsACString& aCommand)
19 get_commandline_t g_app_info_get_commandline_ptr;
21 - void *libHandle = dlopen("libgio-2.0.so", RTLD_LAZY);
22 + void *libHandle = dlopen("libgio-2.0.so.0", RTLD_LAZY);
24 return NS_ERROR_FAILURE;
26 dlerror(); /* clear any existing error */
27 g_app_info_get_commandline_ptr =
28 (get_commandline_t) dlsym(libHandle, "g_app_info_get_commandline");
29 - if (dlerror() != NULL) {
30 - const char cmd = *g_app_info_get_commandline_ptr(mApp);
31 + if (dlerror() == NULL) {
32 + const char *cmd = g_app_info_get_commandline_ptr(mApp);
35 return NS_ERROR_FAILURE;
41 @@ -414,75 +414,46 @@ nsGIOService::CreateAppFromCommand(nsACS
42 nsIGIOMimeApp** appInfo)
47 GAppInfo *app_info = NULL, *app_info_from_list = NULL;
48 GList *apps = g_app_info_get_all();
50 - get_commandline_t g_app_info_get_commandline_ptr;
52 - void *libHandle = dlopen("libgio-2.0.so", RTLD_LAZY);
54 - return NS_ERROR_FAILURE;
56 - dlerror(); /* clear any existing error */
57 - g_app_info_get_commandline_ptr =
58 - (get_commandline_t) dlsym(libHandle, "g_app_info_get_commandline");
59 - if (dlerror() != NULL) {
60 - g_app_info_get_commandline_ptr = NULL;
63 // Try to find relevant and existing GAppInfo in all installed application
64 + // We do this by comparing each GAppInfo's executable with out own
66 app_info_from_list = (GAppInfo*) apps_p->data;
67 - /* This is a silly test. It just compares app names but not
68 - * commands. This is due to old version of Glib/Gio. The required
69 - * function which allows to do a regular check of existence of desktop file
70 - * is possible by using function g_app_info_get_commandline. This function
71 - * has been introduced in Glib 2.20. */
72 - if (app_info_from_list && strcmp(g_app_info_get_name(app_info_from_list),
73 - PromiseFlatCString(appName).get()) == 0 )
75 - if (g_app_info_get_commandline_ptr)
77 - /* Following test is only possible with Glib >= 2.20.
78 - * Compare path only by using strncmp */
79 - if (strncmp(g_app_info_get_commandline_ptr(app_info_from_list),
80 - PromiseFlatCString(cmd).get(),
81 - strlen(PromiseFlatCString(cmd).get())) == 0)
83 - app_info = app_info_from_list;
86 - g_object_unref(app_info_from_list);
90 + // If the executable is not absolute, get it's full path
91 + char *executable = g_find_program_in_path(g_app_info_get_executable(app_info_from_list));
93 + if (executable && strcmp(executable, PromiseFlatCString(cmd).get()) == 0) {
94 + g_object_ref (app_info_from_list);
95 app_info = app_info_from_list;
99 - g_object_unref(app_info_from_list);
100 + g_free(executable);
103 + g_object_unref(app_info_from_list);
104 apps_p = apps_p->next;
109 app_info = g_app_info_create_from_commandline(PromiseFlatCString(cmd).get(),
110 PromiseFlatCString(appName).get(),
111 G_APP_INFO_CREATE_SUPPORTS_URIS,
116 g_warning("Cannot create application info from command: %s", error->message);
118 - dlclose(libHandle);
119 return NS_ERROR_FAILURE;
121 nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
122 NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
123 NS_ADDREF(*appInfo = mozApp);
124 - dlclose(libHandle);