Merge lp:~3v1n0/bamf/javaws-ignore-desktop-0.3 into lp:bamf/0.3

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: 506
Merged at revision: 498
Proposed branch: lp:~3v1n0/bamf/javaws-ignore-desktop-0.3
Merge into: lp:bamf/0.3
Diff against target: 477 lines (+243/-22)
8 files modified
src/bamf-legacy-window-test.c (+21/-0)
src/bamf-legacy-window-test.h (+1/-0)
src/bamf-legacy-window.c (+47/-0)
src/bamf-legacy-window.h (+4/-0)
src/bamf-matcher-private.h (+1/-0)
src/bamf-matcher.c (+50/-19)
tests/bamfdaemon/data/icedtea-netx-javaws.desktop (+12/-0)
tests/bamfdaemon/test-matcher.c (+107/-3)
To merge this branch: bzr merge lp:~3v1n0/bamf/javaws-ignore-desktop-0.3
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
Review via email: mp+145294@code.launchpad.net

Commit message

BamfMatcher: ignore the javaws windows when setting the window hint

Description of the change

Backport to Bamf-0.3 of lp:~3v1n0/bamf/javaws-ignore-desktop/+merge/145289

We need to avoid that a Java Web Application is associated with the default "Java Web Start" .desktop file provided by java as the default opener for jnlp files, or the bug #1098186 will show again.

Test added.

To post a comment you must log in.
500. By Marco Trevisan (Treviño)

Tests: add the missing icedtea-netx-javaws.desktop file

501. By Marco Trevisan (Treviño)

TestMatcher: fix javawm class names

502. By Marco Trevisan (Treviño)

BamfLegacyWindow: add a function to fetch the process name

503. By Marco Trevisan (Treviño)

BamfLegacyWindowTest: implement the get_process_name function

504. By Marco Trevisan (Treviño)

BamfMatcher: add bamf_matcher_is_valid_process_prefix to check for bad prefix process

Now we ignore the bad process prefixes also when using the
fallback process-name comparison. In this way the .desktop files
that they may provide to load files are ignored.

505. By Marco Trevisan (Treviño)

TestMatcher: added one more test to ensure javaws matching

506. By Marco Trevisan (Treviño)

BamfMatcher: fix compilation issues

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-legacy-window-test.c'
2--- src/bamf-legacy-window-test.c 2012-10-10 17:18:56 +0000
3+++ src/bamf-legacy-window-test.c 2013-01-29 17:52:22 +0000
4@@ -194,6 +194,16 @@
5 }
6
7 char *
8+bamf_legacy_window_test_get_process_name (BamfLegacyWindow *legacy_window)
9+{
10+ BamfLegacyWindowTest *self;
11+
12+ self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
13+
14+ return g_strdup (self->process_name);
15+}
16+
17+char *
18 bamf_legacy_window_test_get_app_id (BamfLegacyWindow *legacy_window)
19 {
20 BamfLegacyWindowTest *self;
21@@ -371,6 +381,7 @@
22 g_free (self->wm_class_name);
23 g_free (self->wm_class_instance);
24 g_free (self->exec);
25+ g_free (self->process_name);
26 g_free (self->application_id);
27 g_free (self->unique_bus_name);
28 g_free (self->dbus_menu_object_path);
29@@ -390,6 +401,7 @@
30 win_class->get_class_name = bamf_legacy_window_test_get_class_name;
31 win_class->get_class_instance_name = bamf_legacy_window_test_get_class_instance_name;
32 win_class->get_exec_string = bamf_legacy_window_test_get_exec_string;
33+ win_class->get_process_name = bamf_legacy_window_test_get_process_name;
34 win_class->get_xid = bamf_legacy_window_test_get_xid;
35 win_class->get_pid = bamf_legacy_window_test_get_pid;
36 win_class->needs_attention = bamf_legacy_window_test_needs_attention;
37@@ -431,6 +443,7 @@
38 copy->wm_class_name = g_strdup (self->wm_class_name);
39 copy->wm_class_instance = g_strdup (self->wm_class_instance);
40 copy->exec = g_strdup (self->exec);
41+ copy->process_name = g_strdup (self->process_name);
42 copy->application_id = g_strdup (self->application_id);
43 copy->unique_bus_name = g_strdup (self->unique_bus_name);
44 copy->dbus_menu_object_path = g_strdup (self->dbus_menu_object_path);
45@@ -459,5 +472,13 @@
46 self->wm_class_name = g_strdup (wmclass_name);
47 self->exec = g_strdup (exec);
48
49+ if (self->exec)
50+ {
51+ gchar **splitted_exec = g_strsplit (exec, " ", 2);
52+ gchar *tmp = g_utf8_strrchr (splitted_exec[0], -1, G_DIR_SEPARATOR);
53+ self->process_name = g_strdup (tmp ? tmp + 1 : splitted_exec[0]);
54+ g_strfreev (splitted_exec);
55+ }
56+
57 return self;
58 }
59
60=== modified file 'src/bamf-legacy-window-test.h'
61--- src/bamf-legacy-window-test.h 2012-10-10 17:18:56 +0000
62+++ src/bamf-legacy-window-test.h 2013-01-29 17:52:22 +0000
63@@ -57,6 +57,7 @@
64 char * wm_class_name;
65 char * wm_class_instance;
66 char * exec;
67+ char * process_name;
68 char * application_id;
69 char * unique_bus_name;
70 char * dbus_menu_object_path;
71
72=== modified file 'src/bamf-legacy-window.c'
73--- src/bamf-legacy-window.c 2013-01-10 00:23:28 +0000
74+++ src/bamf-legacy-window.c 2013-01-29 17:52:22 +0000
75@@ -186,6 +186,51 @@
76 }
77
78 char *
79+bamf_legacy_window_get_process_name (BamfLegacyWindow *self)
80+{
81+ gchar *stat_path;
82+ gchar *contents;
83+ gchar **lines;
84+ gchar **sections;
85+ gchar *result = NULL;
86+ guint pid;
87+
88+ g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
89+
90+ if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_process_name)
91+ return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_process_name (self);
92+
93+ pid = bamf_legacy_window_get_pid (self);
94+
95+ if (pid <= 0)
96+ return NULL;
97+
98+ stat_path = g_strdup_printf ("/proc/%i/status", pid);
99+
100+ if (g_file_get_contents (stat_path, &contents, NULL, NULL))
101+ {
102+ lines = g_strsplit (contents, "\n", 2);
103+
104+ if (lines && g_strv_length (lines) > 0)
105+ {
106+ sections = g_strsplit (lines[0], "\t", 0);
107+ if (sections)
108+ {
109+ if (g_strv_length (sections) > 1)
110+ result = g_strdup (sections[1]);
111+
112+ g_strfreev (sections);
113+ }
114+ g_strfreev (lines);
115+ }
116+ g_free (contents);
117+ }
118+ g_free (stat_path);
119+
120+ return result;
121+}
122+
123+char *
124 bamf_legacy_window_get_exec_string (BamfLegacyWindow *self)
125 {
126 gchar *result = NULL;
127@@ -223,6 +268,8 @@
128 return result;
129 }
130
131+
132+
133 const char *
134 bamf_legacy_window_save_mini_icon (BamfLegacyWindow *self)
135 {
136
137=== modified file 'src/bamf-legacy-window.h'
138--- src/bamf-legacy-window.h 2012-10-09 09:13:30 +0000
139+++ src/bamf-legacy-window.h 2013-01-29 17:52:22 +0000
140@@ -74,6 +74,7 @@
141 const char * (*get_class_name) (BamfLegacyWindow *legacy_window);
142 const char * (*get_class_instance_name) (BamfLegacyWindow *legacy_window);
143 char * (*get_exec_string) (BamfLegacyWindow *legacy_window);
144+ char * (*get_process_name) (BamfLegacyWindow *legacy_window);
145 char * (*get_app_id) (BamfLegacyWindow *legacy_window);
146 char * (*get_unique_bus_name) (BamfLegacyWindow *legacy_window);
147 char * (*get_menu_object_path) (BamfLegacyWindow *legacy_window);
148@@ -142,6 +143,8 @@
149
150 char * bamf_legacy_window_get_exec_string (BamfLegacyWindow *self);
151
152+char * bamf_legacy_window_get_process_name (BamfLegacyWindow *self);
153+
154 BamfLegacyWindow * bamf_legacy_window_get_transient (BamfLegacyWindow *self);
155
156 char * bamf_legacy_window_get_hint (BamfLegacyWindow *self,
157@@ -158,3 +161,4 @@
158 BamfLegacyWindow * bamf_legacy_window_new (WnckWindow *legacy_window);
159
160 #endif
161+
162
163=== modified file 'src/bamf-matcher-private.h'
164--- src/bamf-matcher-private.h 2013-01-10 00:23:28 +0000
165+++ src/bamf-matcher-private.h 2013-01-29 17:52:22 +0000
166@@ -50,5 +50,6 @@
167 BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file);
168 BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid);
169 char * bamf_matcher_get_trimmed_exec (BamfMatcher *self, const char *exec);
170+gboolean bamf_matcher_is_valid_process_prefix (BamfMatcher *self, const char *exec);
171
172 #endif
173
174=== modified file 'src/bamf-matcher.c'
175--- src/bamf-matcher.c 2013-01-10 00:23:28 +0000
176+++ src/bamf-matcher.c 2013-01-29 17:52:22 +0000
177@@ -58,7 +58,8 @@
178 "^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$",
179 "^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d.\\d)?$", "^(ba)?sh$",
180 "^perl$", "^env$", "^xdg-open$",
181- /* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt.jar$"
182+ /* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt\\.jar$",
183+ "^com\\.sun\\.javaws\\.Main$", "^deploy\\.jar$"
184 };
185
186 // Prefixes that must be considered starting point of exec strings
187@@ -511,6 +512,30 @@
188 return (l ? (char *) l->data : NULL);
189 }
190
191+gboolean
192+bamf_matcher_is_valid_process_prefix (BamfMatcher *self, const char *process_name)
193+{
194+ GRegex *regex;
195+ gint i;
196+
197+ g_return_val_if_fail (BAMF_IS_MATCHER (self), TRUE);
198+
199+ if (!process_name || *process_name == '\0')
200+ return FALSE;
201+
202+ for (i = 0; i < self->priv->bad_prefixes->len; ++i)
203+ {
204+ regex = g_array_index (self->priv->bad_prefixes, GRegex *, i);
205+
206+ if (g_regex_match (regex, process_name, 0, NULL))
207+ {
208+ return FALSE;
209+ }
210+ }
211+
212+ return TRUE;
213+}
214+
215 /* Attempts to return the binary name for a particular execution string */
216 char *
217 bamf_matcher_get_trimmed_exec (BamfMatcher * self, const char * exec_string)
218@@ -566,16 +591,7 @@
219 if (good_prefix)
220 continue;
221
222- bad_prefix = FALSE;
223- for (j = 0; j < self->priv->bad_prefixes->len; j++)
224- {
225- regex = g_array_index (self->priv->bad_prefixes, GRegex *, j);
226- if (g_regex_match (regex, part, 0, NULL))
227- {
228- bad_prefix = TRUE;
229- break;
230- }
231- }
232+ bad_prefix = !bamf_matcher_is_valid_process_prefix (self, part);
233
234 if (!bad_prefix)
235 {
236@@ -1504,9 +1520,10 @@
237 result = g_list_reverse (result);
238 return result;
239 }
240-
241+
242 proc_name = process_name (pid);
243- if (proc_name)
244+
245+ if (bamf_matcher_is_valid_process_prefix (self, proc_name))
246 {
247 table_list = g_hash_table_lookup (priv->desktop_file_table, proc_name);
248
249@@ -1514,15 +1531,15 @@
250 {
251 result = g_list_prepend (result, g_strdup (l->data));
252 }
253- g_free (proc_name);
254 }
255-
256+ g_free (proc_name);
257+
258 result = g_list_reverse (result);
259 return result;
260 }
261
262 static gboolean
263-is_web_app_window (BamfMatcher *self, BamfLegacyWindow *window)
264+is_web_app_window (BamfLegacyWindow *window)
265 {
266 const char *window_class = bamf_legacy_window_get_class_name (window);
267 const char *instance_name = bamf_legacy_window_get_class_instance_name (window);
268@@ -1557,12 +1574,26 @@
269 }
270
271 static gboolean
272+is_javaws_window (BamfLegacyWindow *window)
273+{
274+ const char *window_class = bamf_legacy_window_get_class_name (window);
275+
276+ if (g_strcmp0 (window_class, "net-sourceforge-jnlp-runtime-Boot") == 0 ||
277+ g_strcmp0 (window_class, "com-sun-javaws-Main") == 0)
278+ {
279+ return TRUE;
280+ }
281+
282+ return FALSE;
283+}
284+
285+static gboolean
286 bamf_matcher_window_skips_hint_set (BamfMatcher *self, BamfLegacyWindow *window)
287 {
288- gboolean skip_hint_set = FALSE;
289+ gboolean skip_hint_set;
290 g_return_val_if_fail (BAMF_IS_MATCHER (self), TRUE);
291
292- skip_hint_set = is_web_app_window (self, window);
293+ skip_hint_set = is_web_app_window (window) || is_javaws_window (window);
294
295 return skip_hint_set;
296 }
297@@ -1644,7 +1675,7 @@
298
299 if (!filter_by_wmclass)
300 {
301- if (is_web_app_window (self, window))
302+ if (is_web_app_window (window))
303 {
304 // This ensures that a new application is created even for unknown webapps
305 filter_by_wmclass = TRUE;
306
307=== added file 'tests/bamfdaemon/data/icedtea-netx-javaws.desktop'
308--- tests/bamfdaemon/data/icedtea-netx-javaws.desktop 1970-01-01 00:00:00 +0000
309+++ tests/bamfdaemon/data/icedtea-netx-javaws.desktop 2013-01-29 17:52:22 +0000
310@@ -0,0 +1,12 @@
311+[Desktop Entry]
312+Name=IcedTea Java Web Start
313+Name[fi]=IcedTea Java - Web Start
314+Comment=IcedTea Java Web Start
315+Comment[fi]=IcedTea Java - Web Start
316+Exec=/usr/bin/javaws %u
317+Terminal=false
318+Type=Application
319+Icon=javaws
320+Categories=Application;Network;
321+MimeType=application/x-java-jnlp-file;
322+NoDisplay=true
323
324=== modified file 'tests/bamfdaemon/test-matcher.c'
325--- tests/bamfdaemon/test-matcher.c 2013-01-10 00:23:28 +0000
326+++ tests/bamfdaemon/test-matcher.c 2013-01-29 17:52:22 +0000
327@@ -34,6 +34,8 @@
328 static void test_match_libreoffice_windows (void);
329 static void test_match_gnome_control_center_panels (void);
330 static void test_match_javaws_windows (void);
331+static void test_match_javaws_windows_hint_ignored (void);
332+static void test_match_javaws_windows_no_desktop_match (void);
333 static void test_new_desktop_matches_unmatched_windows (void);
334 static void test_trim_exec_string (void);
335
336@@ -56,6 +58,8 @@
337 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);
338 g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels);
339 g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows);
340+ g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart/HintIngored", test_match_javaws_windows_hint_ignored);
341+ g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart/NoDesktopMatch", test_match_javaws_windows_no_desktop_match);
342 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);
343 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
344 }
345@@ -569,7 +573,7 @@
346
347 screen = bamf_legacy_screen_get_default ();
348 matcher = bamf_matcher_get_default ();
349- const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
350+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
351 "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
352 "-Xms8m -Djava.security.manager " \
353 "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
354@@ -577,8 +581,8 @@
355 "-Dicedtea-web.bin.name=javaws " \
356 "-Dicedtea-web.bin.location=/usr/bin/javaws "\
357 "net.sourceforge.jnlp.runtime.Boot";
358- const char *class_name = "sun-awt-X11-XFramePeer";
359- const char *class_instance = "net-sourceforge-jnlp-runtime-Boot";
360+ const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
361+ const char *class_instance = "sun-awt-X11-XFramePeer";
362
363 cleanup_matcher_tables (matcher);
364 export_matcher_on_bus (matcher);
365@@ -626,6 +630,93 @@
366 }
367
368 static void
369+test_match_javaws_windows_hint_ignored (void)
370+{
371+ BamfMatcher *matcher;
372+ BamfLegacyScreen *screen;
373+ BamfLegacyWindowTest *test_win;
374+ BamfApplication *app;
375+
376+ screen = bamf_legacy_screen_get_default ();
377+ matcher = bamf_matcher_get_default ();
378+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
379+ "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
380+ "-Xms8m -Djava.security.manager " \
381+ "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
382+ "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
383+ "-Dicedtea-web.bin.name=javaws " \
384+ "-Dicedtea-web.bin.location=/usr/bin/javaws "\
385+ "net.sourceforge.jnlp.runtime.Boot ";
386+ const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
387+ const char *class_instance = "sun-awt-X11-XFramePeer";
388+
389+ cleanup_matcher_tables (matcher);
390+ export_matcher_on_bus (matcher);
391+
392+ guint xid = g_random_int ();
393+ guint pid = g_random_int ();
394+ char *exec = g_strconcat (exec_prefix, "Notepad.jnlp", NULL);
395+ test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
396+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
397+ test_win->pid = pid;
398+ _bamf_legacy_screen_open_test_window (screen, test_win);
399+ g_free (exec);
400+
401+ bamf_matcher_register_desktop_file_for_pid (matcher, DATA_DIR"/icedtea-netx-javaws.desktop", pid);
402+
403+ char *hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE);
404+ g_assert (hint == NULL);
405+
406+ app = bamf_matcher_get_application_by_xid (matcher, xid);
407+ g_assert (BAMF_IS_APPLICATION (app));
408+ g_assert (bamf_application_get_desktop_file (app) == NULL);
409+
410+ g_object_unref (matcher);
411+ g_object_unref (screen);
412+}
413+
414+static void
415+test_match_javaws_windows_no_desktop_match (void)
416+{
417+ BamfMatcher *matcher;
418+ BamfLegacyScreen *screen;
419+ BamfLegacyWindowTest *test_win;
420+ BamfApplication *app;
421+
422+ screen = bamf_legacy_screen_get_default ();
423+ matcher = bamf_matcher_get_default ();
424+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
425+ "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
426+ "-Xms8m -Djava.security.manager " \
427+ "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
428+ "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
429+ "-Dicedtea-web.bin.name=javaws " \
430+ "-Dicedtea-web.bin.location=/usr/bin/javaws "\
431+ "net.sourceforge.jnlp.runtime.Boot ";
432+ const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
433+ const char *class_instance = "sun-awt-X11-XFramePeer";
434+
435+ cleanup_matcher_tables (matcher);
436+ export_matcher_on_bus (matcher);
437+
438+ bamf_matcher_load_desktop_file (matcher, DATA_DIR"/icedtea-netx-javaws.desktop");
439+
440+ guint xid = g_random_int ();
441+ char *exec = g_strconcat (exec_prefix, "Notepad.jnlp", NULL);
442+ test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
443+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
444+ _bamf_legacy_screen_open_test_window (screen, test_win);
445+ g_free (exec);
446+
447+ app = bamf_matcher_get_application_by_xid (matcher, xid);
448+ g_assert (BAMF_IS_APPLICATION (app));
449+ g_assert (bamf_application_get_desktop_file (app) == NULL);
450+
451+ g_object_unref (matcher);
452+ g_object_unref (screen);
453+}
454+
455+static void
456 test_trim_exec_string (void)
457 {
458 BamfMatcher *matcher;
459@@ -692,5 +783,18 @@
460 g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
461 g_free (trimmed);
462
463+ exec = "/usr/lib/jvm/java-7-oracle/jre/bin/java " \
464+ "-classpath /usr/lib/jvm/java-7-oracle/jre/lib/deploy.jar " \
465+ "-Djava.security.policy=file:/usr/lib/jvm/java-7-oracle/jre/lib/security/javaws.policy " \
466+ "-DtrustProxy=true -Xverify:remote " \
467+ "-Djnlpx.home=/usr/lib/jvm/java-7-oracle/jre/bin " \
468+ "-Djnlpx.remove=true -Dsun.awt.warmup=true " \
469+ "-Xbootclasspath/a:/usr/lib/jvm/java-7-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-7-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-7-oracle/jre/lib/plugin.jar " \
470+ "-Xms12m -Xmx384m -Djnlpx.jvm=/usr/lib/jvm/java-7-oracle/jre/bin/java " \
471+ "com.sun.javaws.Main Notepad.jnlp";
472+ trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
473+ g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
474+ g_free (trimmed);
475+
476 g_object_unref (matcher);
477 }

Subscribers

People subscribed via source and target branches