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

Proposed by Marco Trevisan (Treviño) on 2013-01-29
Status: Merged
Approved by: Brandon Schaefer on 2013-01-29
Approved revision: 498
Merged at revision: 491
Proposed branch: lp:~3v1n0/bamf/javaws-ignore-desktop-0.2
Merge into: lp:bamf/0.2
Diff against target: 473 lines (+241/-21)
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 (+48/-18)
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.2
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) 2013-01-29 Approve on 2013-01-29
Review via email: mp+145291@code.launchpad.net

Commit message

BamfMatcher: ignore the javaws windows when setting the window hint

Description of the change

Backport to Bamf-0.2 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.
493. By Marco Trevisan (Treviño) on 2013-01-29

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

494. By Marco Trevisan (Treviño) on 2013-01-29

TestMatcher: fix javawm class names

495. By Marco Trevisan (Treviño) on 2013-01-29

BamfLegacyWindow: add a function to fetch the process name

496. By Marco Trevisan (Treviño) on 2013-01-29

BamfLegacyWindowTest: implement the get_process_name function

497. By Marco Trevisan (Treviño) on 2013-01-29

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.

498. By Marco Trevisan (Treviño) on 2013-01-29

TestMatcher: added one more test to ensure javaws matching

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:36:21 +0000
3+++ src/bamf-legacy-window-test.c 2013-01-29 18:22:23 +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:36:21 +0000
62+++ src/bamf-legacy-window-test.h 2013-01-29 18:22:23 +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-09 19:49:06 +0000
74+++ src/bamf-legacy-window.c 2013-01-29 18:22:23 +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-10 17:36:21 +0000
139+++ src/bamf-legacy-window.h 2013-01-29 18:22:23 +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-09 19:48:18 +0000
165+++ src/bamf-matcher-private.h 2013-01-29 18:22:23 +0000
166@@ -47,5 +47,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-09 22:37:21 +0000
176+++ src/bamf-matcher.c 2013-01-29 18:22:23 +0000
177@@ -54,7 +54,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@@ -507,6 +508,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@@ -562,16 +587,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@@ -1502,7 +1518,7 @@
237 }
238
239 proc_name = process_name (pid);
240- if (proc_name)
241+ if (bamf_matcher_is_valid_process_prefix (self, proc_name))
242 {
243 table_list = g_hash_table_lookup (priv->desktop_file_table, proc_name);
244
245@@ -1510,15 +1526,15 @@
246 {
247 result = g_list_prepend (result, g_strdup (l->data));
248 }
249- g_free (proc_name);
250 }
251-
252+ g_free (proc_name);
253+
254 result = g_list_reverse (result);
255 return result;
256 }
257
258 static gboolean
259-is_web_app_window (BamfMatcher *self, BamfLegacyWindow *window)
260+is_web_app_window (BamfLegacyWindow *window)
261 {
262 const char *window_class = bamf_legacy_window_get_class_name (window);
263 const char *instance_name = bamf_legacy_window_get_class_instance_name (window);
264@@ -1553,12 +1569,26 @@
265 }
266
267 static gboolean
268+is_javaws_window (BamfLegacyWindow *window)
269+{
270+ const char *window_class = bamf_legacy_window_get_class_name (window);
271+
272+ if (g_strcmp0 (window_class, "net-sourceforge-jnlp-runtime-Boot") == 0 ||
273+ g_strcmp0 (window_class, "com-sun-javaws-Main") == 0)
274+ {
275+ return TRUE;
276+ }
277+
278+ return FALSE;
279+}
280+
281+static gboolean
282 bamf_matcher_window_skips_hint_set (BamfMatcher *self, BamfLegacyWindow *window)
283 {
284- gboolean skip_hint_set = FALSE;
285+ gboolean skip_hint_set;
286 g_return_val_if_fail (BAMF_IS_MATCHER (self), TRUE);
287
288- skip_hint_set = is_web_app_window (self, window);
289+ skip_hint_set = is_web_app_window (window) || is_javaws_window (window);
290
291 return skip_hint_set;
292 }
293@@ -1640,7 +1670,7 @@
294
295 if (!filter_by_wmclass)
296 {
297- if (is_web_app_window (self, window))
298+ if (is_web_app_window (window))
299 {
300 // This ensures that a new application is created even for unknown webapps
301 filter_by_wmclass = TRUE;
302
303=== added file 'tests/bamfdaemon/data/icedtea-netx-javaws.desktop'
304--- tests/bamfdaemon/data/icedtea-netx-javaws.desktop 1970-01-01 00:00:00 +0000
305+++ tests/bamfdaemon/data/icedtea-netx-javaws.desktop 2013-01-29 18:22:23 +0000
306@@ -0,0 +1,12 @@
307+[Desktop Entry]
308+Name=IcedTea Java Web Start
309+Name[fi]=IcedTea Java - Web Start
310+Comment=IcedTea Java Web Start
311+Comment[fi]=IcedTea Java - Web Start
312+Exec=/usr/bin/javaws %u
313+Terminal=false
314+Type=Application
315+Icon=javaws
316+Categories=Application;Network;
317+MimeType=application/x-java-jnlp-file;
318+NoDisplay=true
319
320=== modified file 'tests/bamfdaemon/test-matcher.c'
321--- tests/bamfdaemon/test-matcher.c 2013-01-09 22:37:58 +0000
322+++ tests/bamfdaemon/test-matcher.c 2013-01-29 18:22:23 +0000
323@@ -34,6 +34,8 @@
324 static void test_match_libreoffice_windows (void);
325 static void test_match_gnome_control_center_panels (void);
326 static void test_match_javaws_windows (void);
327+static void test_match_javaws_windows_hint_ignored (void);
328+static void test_match_javaws_windows_no_desktop_match (void);
329 static void test_new_desktop_matches_unmatched_windows (void);
330 static void test_trim_exec_string (void);
331
332@@ -56,6 +58,8 @@
333 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);
334 g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels);
335 g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows);
336+ g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart/HintIngored", test_match_javaws_windows_hint_ignored);
337+ g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart/NoDesktopMatch", test_match_javaws_windows_no_desktop_match);
338 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);
339 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
340 }
341@@ -569,7 +573,7 @@
342
343 screen = bamf_legacy_screen_get_default ();
344 matcher = bamf_matcher_get_default ();
345- const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
346+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
347 "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
348 "-Xms8m -Djava.security.manager " \
349 "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
350@@ -577,8 +581,8 @@
351 "-Dicedtea-web.bin.name=javaws " \
352 "-Dicedtea-web.bin.location=/usr/bin/javaws "\
353 "net.sourceforge.jnlp.runtime.Boot";
354- const char *class_name = "sun-awt-X11-XFramePeer";
355- const char *class_instance = "net-sourceforge-jnlp-runtime-Boot";
356+ const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
357+ const char *class_instance = "sun-awt-X11-XFramePeer";
358
359 cleanup_matcher_tables (matcher);
360 export_matcher_on_bus (matcher);
361@@ -626,6 +630,93 @@
362 }
363
364 static void
365+test_match_javaws_windows_hint_ignored (void)
366+{
367+ BamfMatcher *matcher;
368+ BamfLegacyScreen *screen;
369+ BamfLegacyWindowTest *test_win;
370+ BamfApplication *app;
371+
372+ screen = bamf_legacy_screen_get_default ();
373+ matcher = bamf_matcher_get_default ();
374+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
375+ "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
376+ "-Xms8m -Djava.security.manager " \
377+ "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
378+ "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
379+ "-Dicedtea-web.bin.name=javaws " \
380+ "-Dicedtea-web.bin.location=/usr/bin/javaws "\
381+ "net.sourceforge.jnlp.runtime.Boot ";
382+ const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
383+ const char *class_instance = "sun-awt-X11-XFramePeer";
384+
385+ cleanup_matcher_tables (matcher);
386+ export_matcher_on_bus (matcher);
387+
388+ guint xid = g_random_int ();
389+ guint pid = g_random_int ();
390+ char *exec = g_strconcat (exec_prefix, "Notepad.jnlp", NULL);
391+ test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
392+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
393+ test_win->pid = pid;
394+ _bamf_legacy_screen_open_test_window (screen, test_win);
395+ g_free (exec);
396+
397+ bamf_matcher_register_desktop_file_for_pid (matcher, DATA_DIR"/icedtea-netx-javaws.desktop", pid);
398+
399+ char *hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE);
400+ g_assert (hint == NULL);
401+
402+ app = bamf_matcher_get_application_by_xid (matcher, xid);
403+ g_assert (BAMF_IS_APPLICATION (app));
404+ g_assert (bamf_application_get_desktop_file (app) == NULL);
405+
406+ g_object_unref (matcher);
407+ g_object_unref (screen);
408+}
409+
410+static void
411+test_match_javaws_windows_no_desktop_match (void)
412+{
413+ BamfMatcher *matcher;
414+ BamfLegacyScreen *screen;
415+ BamfLegacyWindowTest *test_win;
416+ BamfApplication *app;
417+
418+ screen = bamf_legacy_screen_get_default ();
419+ matcher = bamf_matcher_get_default ();
420+ const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
421+ "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
422+ "-Xms8m -Djava.security.manager " \
423+ "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
424+ "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
425+ "-Dicedtea-web.bin.name=javaws " \
426+ "-Dicedtea-web.bin.location=/usr/bin/javaws "\
427+ "net.sourceforge.jnlp.runtime.Boot ";
428+ const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
429+ const char *class_instance = "sun-awt-X11-XFramePeer";
430+
431+ cleanup_matcher_tables (matcher);
432+ export_matcher_on_bus (matcher);
433+
434+ bamf_matcher_load_desktop_file (matcher, DATA_DIR"/icedtea-netx-javaws.desktop");
435+
436+ guint xid = g_random_int ();
437+ char *exec = g_strconcat (exec_prefix, "Notepad.jnlp", NULL);
438+ test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
439+ bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
440+ _bamf_legacy_screen_open_test_window (screen, test_win);
441+ g_free (exec);
442+
443+ app = bamf_matcher_get_application_by_xid (matcher, xid);
444+ g_assert (BAMF_IS_APPLICATION (app));
445+ g_assert (bamf_application_get_desktop_file (app) == NULL);
446+
447+ g_object_unref (matcher);
448+ g_object_unref (screen);
449+}
450+
451+static void
452 test_trim_exec_string (void)
453 {
454 BamfMatcher *matcher;
455@@ -692,5 +783,18 @@
456 g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
457 g_free (trimmed);
458
459+ exec = "/usr/lib/jvm/java-7-oracle/jre/bin/java " \
460+ "-classpath /usr/lib/jvm/java-7-oracle/jre/lib/deploy.jar " \
461+ "-Djava.security.policy=file:/usr/lib/jvm/java-7-oracle/jre/lib/security/javaws.policy " \
462+ "-DtrustProxy=true -Xverify:remote " \
463+ "-Djnlpx.home=/usr/lib/jvm/java-7-oracle/jre/bin " \
464+ "-Djnlpx.remove=true -Dsun.awt.warmup=true " \
465+ "-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 " \
466+ "-Xms12m -Xmx384m -Djnlpx.jvm=/usr/lib/jvm/java-7-oracle/jre/bin/java " \
467+ "com.sun.javaws.Main Notepad.jnlp";
468+ trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
469+ g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
470+ g_free (trimmed);
471+
472 g_object_unref (matcher);
473 }

Subscribers

People subscribed via source and target branches