diff options
author | Brendan Long <self@brendanlong.com> | 2017-10-28 19:56:52 +0300 |
---|---|---|
committer | Brendan Long <self@brendanlong.com> | 2017-10-28 19:56:52 +0300 |
commit | 1e01c3c7994f79040866e30cd42d90e555af612d (patch) | |
tree | 51139753e69b8268e9fe284de34416c7a3ec3165 | |
parent | c3b7fc307bf6cdb49f8c513e36c4c1eafbe71471 (diff) |
Skip all the metadata and filesystem stuff when dealing with data URI favicons
-rw-r--r-- | src/FavIcon.vala | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/FavIcon.vala b/src/FavIcon.vala index 454b9e54..0b714d29 100644 --- a/src/FavIcon.vala +++ b/src/FavIcon.vala @@ -113,8 +113,39 @@ public class FeedReader.FavIcon : GLib.Object } } + private InputStream? try_load_data_uri(string? icon_url) + { + if(icon_url == null || !icon_url.has_prefix("data")) + return null; + + // LibSoup doesn't seem to handle data URI's properly, so handle them + // ourselves.. + int comma = icon_url.index_of_char(','); + if(comma == -1) + { + Logger.warning(@"Invalid data URI: $icon_url"); + return null; + } + int semicolon = icon_url.index_of_char(';'); + string data_str = icon_url[comma:icon_url.length]; + uint8[] data; + if(semicolon != -1 && semicolon < comma && icon_url[semicolon + 1:comma] == "base64") + { + data = Base64.decode(data_str); + } + else + { + data = data_str.data; + } + return new MemoryInputStream.from_data(data); + } + private async InputStream? downloadFavIcon(GLib.Cancellable? cancellable = null) throws GLib.Error { + var datastream = try_load_data_uri(m_feed.getIconURL()); + if(datastream != null) + return datastream; + string filename_prefix = m_icon_path + m_feed.getFeedFileName(); string local_filename = @"$filename_prefix.ico"; string metadata_filename = @"$filename_prefix.txt"; @@ -261,30 +292,6 @@ public class FeedReader.FavIcon : GLib.Object return null; } - if(icon_url.has_prefix("data:")) - { - // LibSoup doesn't seem to handle data URI's properly, so handle them - // ourselves.. - int comma = icon_url.index_of_char(','); - if(comma == -1) - { - Logger.warning(@"Invalid data URI: $icon_url"); - return null; - } - int semicolon = icon_url.index_of_char(';'); - string data_str = icon_url[comma:icon_url.length]; - uint8[] data; - if(semicolon != -1 && semicolon < comma && icon_url[semicolon + 1:comma] == "base64") - { - data = Base64.decode(data_str); - } - else - { - data = data_str.data; - } - return new MemoryInputStream.from_data(data); - } - string filename_prefix = m_icon_path + m_feed.getFeedFileName(); string local_filename = @"$filename_prefix.ico"; |