Merge lp:~gue5t/midori/icon-pixbuf into lp:midori

Proposed by gue5t gue5t
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 7108
Merged at revision: 7109
Proposed branch: lp:~gue5t/midori/icon-pixbuf
Merge into: lp:midori
Diff against target: 94 lines (+61/-1)
1 file modified
midori/midori-view.c (+61/-1)
To merge this branch: bzr merge lp:~gue5t/midori/icon-pixbuf
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+287704@code.launchpad.net

Commit message

Fix segfaults and type errors introduced in r7105 by incorrect downcasts from GIcon to GdkPixbuf in midori-view.c

Description of the change

Fix segfaults and type errors introduced in r7105 by incorrect downcasts from GIcon to GdkPixbuf in midori-view.c

Specifically, midori-view.c was downcasting a GIcon (which is an interface implemented by both GdkPixbuf and GThemedIcon) to a GdkPixbuf in several places where it isn't always true that the icon actually is a GdkPixbuf—for example, there's no pixbuf underlying GThemedIcons. This led to GObject cast failures and segfaults.

This adds code that explicitly converts GThemedIcon instances to GdkPixbufs to allow storing them in the GdkPixbuf* icon field of MidoriView. I've checked it against GTK2/GTK3 to make sure our scaling behavior for icons is unchanged and checked that extensions work without crashes again.

To post a comment you must log in.
Revision history for this message
Paweł Forysiuk (tuxator) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-view.c'
2--- midori/midori-view.c 2016-02-20 17:48:39 +0000
3+++ midori/midori-view.c 2016-03-01 20:59:33 +0000
4@@ -396,6 +396,14 @@
5 katze_item_set_name (view->item, view->title);
6 }
7
8+/**
9+ * midori_view_apply_icon
10+ * @view: a #MidoriView
11+ * @icon: (transfer none): the icon to apply, either a #GThemedIcon or a #GdkPixbuf
12+ * @icon_name: a string corresponding to the icon to apply, or %NULL.
13+ *
14+ * Obtains a #GdkPixbuf from the given #GIcon and sets it as @view's icon.
15+ */
16 static void
17 midori_view_apply_icon (MidoriView* view,
18 GIcon* icon,
19@@ -403,8 +411,57 @@
20 {
21 g_return_if_fail (icon != NULL);
22
23+ GdkPixbuf* pixbuf = NULL;
24+
25+ /* If the GIcon is a GdkPixbuf (since GdkPixbuf implements the GIcon interface), just use it */
26+ if (GDK_IS_PIXBUF (icon))
27+ {
28+ pixbuf = g_object_ref (GDK_PIXBUF (icon));
29+ }
30+ else if (G_IS_THEMED_ICON (icon)) /* The icon is a GThemedIcon; we must use a GtkIconTheme to render it */
31+ {
32+ GtkIconTheme* icon_theme;
33+ GtkIconInfo* icon_info;
34+ gchar** icon_names = NULL;
35+ GError* error = NULL;
36+
37+ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (view)));
38+ g_object_get (icon, "names", &icon_names, NULL);
39+
40+ icon_info =
41+#if GTK_CHECK_VERSION (3, 0, 0)
42+ gtk_icon_theme_choose_icon_for_scale (
43+#else
44+ gtk_icon_theme_choose_icon (
45+#endif
46+ icon_theme,
47+ (const char **)icon_names,
48+ 16, /* Favicon-sized */
49+#if GTK_CHECK_VERSION (3, 0, 0)
50+ gtk_widget_get_scale_factor (GTK_WIDGET (view)),
51+#endif
52+ 0);
53+
54+ pixbuf = gtk_icon_info_load_icon (icon_info, &error);
55+ g_strfreev (icon_names);
56+ if (pixbuf == NULL) {
57+ g_warning ("Could not load pixbuf for icon '%s': %s\n", icon_name, error->message);
58+ g_clear_error (&error);
59+
60+ /* view->icon cannot be set to NULL, so we simply leave it as-is */
61+ return;
62+ }
63+
64+ gtk_icon_info_free (icon_info);
65+ }
66+ else /* The icon is some other implementation of the GIcon interface, which should be impossible
67+ since this is internal API and its only callers pass GdkPixbufs or GThemedIcons */
68+ {
69+ g_warning ("Could not load pixbuf for icon '%s': unknown GIcon implementation", icon_name);
70+ }
71+
72 katze_item_set_icon (view->item, icon_name);
73- katze_object_assign (view->icon, g_object_ref (icon));
74+ katze_object_assign (view->icon, pixbuf);
75 g_object_notify (G_OBJECT (view), "icon");
76
77 if (view->menu_item)
78@@ -414,6 +471,8 @@
79 }
80 }
81
82+/* Resets the view's icon from a WebKit-provided pixbuf for a certain page to a
83+generic filetype-based icon */
84 static void
85 midori_view_unset_icon (MidoriView* view)
86 {
87@@ -432,6 +491,7 @@
88 midori_view_apply_icon (view, icon, NULL);
89 }
90
91+/* Sets the view's icon pixbuf to the one WebKit provides for the current page */
92 static void
93 _midori_web_view_load_icon (MidoriView* view)
94 {

Subscribers

People subscribed via source and target branches

to all changes: