waffle

How To Make Safari 3’s WebKit Start Handing You Favicons (Site Icons) Again

Needless to say, when WebKit in Leopard (and, it turned out, WebKit in any system where Safari 3 exists) stopped doling out “hey, you have a favicon” delegate messages (webView:didReceiveIcon:forFrame:), and you make a search tool whose only form of distinguishing between different search engines are in many places by icon and color, you get pretty pissed.

The WebKit ticket is #16296, and it turns out that the backing icon database was disabled by default since driving WebKit into multithreading for the sake of the few apps that want to use icons was deemed unsavory. The fix in WebKit itself is to start the requisite icon database engine if the delegate method is being implemented, but until this bubbles up to Safari-level distribution, one has to call +[WebIconDatabase sharedIconDatabase] to force the database to allocate a singleton instance and thus start itself. Here’s how:

@try {
    Class webIconDatabaseClass = NSClassFromString(@"WebIconDatabase");
    // Since this is private API, it may go away; only call if the class exists.
    if (webIconDatabaseClass != Nil) {
        [webIconDatabaseClass performSelector:@selector(sharedIconDatabase)];
    }
} @catch (NSException *exc) {
#pragma unused(exc)
}

Comments [+]

  1. [...] Jesper says that, due to a bug in Web Kit, if you want your application to receive the -webView:didReceiveIcon:forFrame: delegate method, you have to start up the (private) shared icon database. [...]

    By Michael Tsai - Blog - Safari 3 Favicons · 2007.12.31 16:41

Leave a comment

Your e-mail address is never shown. If you type a line break in the comment, it will show up as a line break (naturally). The following HTML is allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)


Please note: Your comment will not show up at once. Unless you're spamming or being abusive, you have nothing to worry about. (Read the full policy.)