summaryrefslogtreecommitdiff
path: root/core/favicon.vala
diff options
context:
space:
mode:
Diffstat (limited to 'core/favicon.vala')
-rw-r--r--core/favicon.vala35
1 files changed, 19 insertions, 16 deletions
diff --git a/core/favicon.vala b/core/favicon.vala
index 0fab681e..6751301d 100644
--- a/core/favicon.vala
+++ b/core/favicon.vala
@@ -11,6 +11,14 @@
namespace Midori {
public class Favicon : Gtk.Image {
+ public new Cairo.Surface? surface { set {
+ var image = (Cairo.ImageSurface)value;
+ var pixbuf = image != null ? Gdk.pixbuf_get_from_surface (image, 0, 0, image.get_width (), image.get_height ()) : null;
+ int _icon_size = icon_size;
+ gicon = pixbuf != null ? (Icon)scale_to_icon_size (pixbuf) : null;
+ icon_size = _icon_size;
+ } }
+
string? _uri = null;
public string? uri { get { return _uri; } set {
// Reset icon without losing the size
@@ -22,24 +30,19 @@ namespace Midori {
load_icon.begin ();
} }
- construct {
- var database = WebKit.WebContext.get_default ().get_favicon_database ();
- database.favicon_changed.connect ((page_uri, favicon_uri) => {
- if (page_uri == uri) {
- load_icon.begin ();
- }
- });
- }
-
+ WebKit.FaviconDatabase? database;
async void load_icon (Cancellable? cancellable = null) {
- var database = WebKit.WebContext.get_default ().get_favicon_database ();
+ if (database == null) {
+ database = WebKit.WebContext.get_default ().get_favicon_database ();
+ database.favicon_changed.connect ((page_uri, favicon_uri) => {
+ if (page_uri == uri) {
+ load_icon.begin ();
+ }
+ });
+ }
+
try {
- var surface = yield database.get_favicon (uri, cancellable);
- if (surface != null) {
- var image = (Cairo.ImageSurface)surface;
- var pixbuf = Gdk.pixbuf_get_from_surface (image, 0, 0, image.get_width (), image.get_height ());
- gicon = (Icon)scale_to_icon_size (pixbuf);
- }
+ surface = yield database.get_favicon (uri, cancellable);
} catch (Error error) {
debug ("Icon failed to load: %s", error.message);
}