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
=== modified file 'midori/midori-view.c'
--- midori/midori-view.c 2016-02-20 17:48:39 +0000
+++ midori/midori-view.c 2016-03-01 20:59:33 +0000
@@ -396,6 +396,14 @@
396 katze_item_set_name (view->item, view->title);396 katze_item_set_name (view->item, view->title);
397}397}
398398
399/**
400 * midori_view_apply_icon
401 * @view: a #MidoriView
402 * @icon: (transfer none): the icon to apply, either a #GThemedIcon or a #GdkPixbuf
403 * @icon_name: a string corresponding to the icon to apply, or %NULL.
404 *
405 * Obtains a #GdkPixbuf from the given #GIcon and sets it as @view's icon.
406 */
399static void407static void
400midori_view_apply_icon (MidoriView* view,408midori_view_apply_icon (MidoriView* view,
401 GIcon* icon,409 GIcon* icon,
@@ -403,8 +411,57 @@
403{411{
404 g_return_if_fail (icon != NULL);412 g_return_if_fail (icon != NULL);
405413
414 GdkPixbuf* pixbuf = NULL;
415
416 /* If the GIcon is a GdkPixbuf (since GdkPixbuf implements the GIcon interface), just use it */
417 if (GDK_IS_PIXBUF (icon))
418 {
419 pixbuf = g_object_ref (GDK_PIXBUF (icon));
420 }
421 else if (G_IS_THEMED_ICON (icon)) /* The icon is a GThemedIcon; we must use a GtkIconTheme to render it */
422 {
423 GtkIconTheme* icon_theme;
424 GtkIconInfo* icon_info;
425 gchar** icon_names = NULL;
426 GError* error = NULL;
427
428 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (view)));
429 g_object_get (icon, "names", &icon_names, NULL);
430
431 icon_info =
432#if GTK_CHECK_VERSION (3, 0, 0)
433 gtk_icon_theme_choose_icon_for_scale (
434#else
435 gtk_icon_theme_choose_icon (
436#endif
437 icon_theme,
438 (const char **)icon_names,
439 16, /* Favicon-sized */
440#if GTK_CHECK_VERSION (3, 0, 0)
441 gtk_widget_get_scale_factor (GTK_WIDGET (view)),
442#endif
443 0);
444
445 pixbuf = gtk_icon_info_load_icon (icon_info, &error);
446 g_strfreev (icon_names);
447 if (pixbuf == NULL) {
448 g_warning ("Could not load pixbuf for icon '%s': %s\n", icon_name, error->message);
449 g_clear_error (&error);
450
451 /* view->icon cannot be set to NULL, so we simply leave it as-is */
452 return;
453 }
454
455 gtk_icon_info_free (icon_info);
456 }
457 else /* The icon is some other implementation of the GIcon interface, which should be impossible
458 since this is internal API and its only callers pass GdkPixbufs or GThemedIcons */
459 {
460 g_warning ("Could not load pixbuf for icon '%s': unknown GIcon implementation", icon_name);
461 }
462
406 katze_item_set_icon (view->item, icon_name);463 katze_item_set_icon (view->item, icon_name);
407 katze_object_assign (view->icon, g_object_ref (icon));464 katze_object_assign (view->icon, pixbuf);
408 g_object_notify (G_OBJECT (view), "icon");465 g_object_notify (G_OBJECT (view), "icon");
409466
410 if (view->menu_item)467 if (view->menu_item)
@@ -414,6 +471,8 @@
414 }471 }
415}472}
416473
474/* Resets the view's icon from a WebKit-provided pixbuf for a certain page to a
475generic filetype-based icon */
417static void476static void
418midori_view_unset_icon (MidoriView* view)477midori_view_unset_icon (MidoriView* view)
419{478{
@@ -432,6 +491,7 @@
432 midori_view_apply_icon (view, icon, NULL);491 midori_view_apply_icon (view, icon, NULL);
433}492}
434493
494/* Sets the view's icon pixbuf to the one WebKit provides for the current page */
435static void495static void
436_midori_web_view_load_icon (MidoriView* view)496_midori_web_view_load_icon (MidoriView* view)
437{497{

Subscribers

People subscribed via source and target branches

to all changes: