Changeset 95593 in webkit


Ignore:
Timestamp:
Sep 20, 2011 6:49:03 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Support for multiple <link rel="icon"> favicon elements.
https://bugs.webkit.org/show_bug.cgi?id=65564

Patch by Rachel Blum <groby@chromium.org> on 2011-09-20
Reviewed by Darin Fisher.

No tests - purely an API change. (And API is not exposed to LayoutTests)

  • dom/Document.cpp:

(WebCore::Document::iconURLs):
(WebCore::Document::addIconURL):

  • dom/Document.h:
  • dom/IconURL.cpp:

(WebCore::toIconIndex):

  • dom/IconURL.h:

(WebCore::IconURL::IconURL):

  • html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::process):

  • loader/LinkLoader.cpp:

(WebCore::LinkLoader::loadLink):

  • loader/LinkLoader.h:
  • loader/icon/IconController.cpp:

(WebCore::IconController::urlsForTypes):
(WebCore::IconController::appendToIconURLs):
(WebCore::IconController::defaultURL):

Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r95591 r95593  
     12011-09-20  Rachel Blum  <groby@chromium.org>
     2
     3        Support for multiple <link rel="icon"> favicon elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=65564
     5
     6        Reviewed by Darin Fisher.
     7
     8        No tests - purely an API change. (And API is not exposed to LayoutTests)
     9
     10        * dom/Document.cpp:
     11        (WebCore::Document::iconURLs):
     12        (WebCore::Document::addIconURL):
     13        * dom/Document.h:
     14        * dom/IconURL.cpp:
     15        (WebCore::toIconIndex):
     16        * dom/IconURL.h:
     17        (WebCore::IconURL::IconURL):
     18        * html/HTMLLinkElement.cpp:
     19        (WebCore::HTMLLinkElement::process):
     20        * loader/LinkLoader.cpp:
     21        (WebCore::LinkLoader::loadLink):
     22        * loader/LinkLoader.h:
     23        * loader/icon/IconController.cpp:
     24        (WebCore::IconController::urlsForTypes):
     25        (WebCore::IconController::appendToIconURLs):
     26        (WebCore::IconController::defaultURL):
     27
    1282011-09-20  Ojan Vafai  <ojan@chromium.org>
    229
  • trunk/Source/WebCore/dom/Document.cpp

    r95535 r95593  
    66 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
    77 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
    8  * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
     8 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
    99 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
    1010 *
     
    44314431}
    44324432
    4433 IconURL Document::iconURL(IconType iconType) const
    4434 {
    4435     return m_iconURLs[toIconIndex(iconType)];
    4436 }
    4437 
    4438 void Document::setIconURL(const String& url, const String& mimeType, IconType iconType)
    4439 {
     4433const Vector<IconURL>& Document::iconURLs() const
     4434{
     4435    return m_iconURLs;
     4436}
     4437
     4438void Document::addIconURL(const String& url, const String& mimeType, const String& sizes, IconType iconType)
     4439{
     4440    if (url.isEmpty())
     4441        return;
     4442
    44404443    // FIXME - <rdar://problem/4727645> - At some point in the future, we might actually honor the "mimeType"
    4441     IconURL newURL(KURL(ParsedURLString, url), iconType);
    4442     if (iconURL(iconType).m_iconURL.isEmpty())
    4443         setIconURL(newURL);
    4444     else if (!mimeType.isEmpty())
    4445         setIconURL(newURL);
    4446     if (Frame* f = frame())
    4447         f->loader()->icon()->setURL(newURL);
    4448 }
    4449 
    4450 void Document::setIconURL(const IconURL& iconURL)
    4451 {
    4452     m_iconURLs[toIconIndex(iconURL.m_iconType)] = iconURL;
     4444    IconURL newURL(KURL(ParsedURLString, url), sizes, mimeType, iconType);
     4445    m_iconURLs.append(newURL);
     4446
     4447    if (Frame* f = frame()) {
     4448        IconURL iconURL = f->loader()->icon()->iconURL(iconType);
     4449        if (iconURL == newURL)
     4450            f->loader()->didChangeIcons(iconType);
     4451    }
    44534452}
    44544453
  • trunk/Source/WebCore/dom/Document.h

    r95271 r95593  
    77 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
    88 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
     9 * Copyright (C) 2011 Google Inc. All rights reserved.
    910 *
    1011 * This library is free software; you can redistribute it and/or
     
    918919    void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
    919920
    920     IconURL iconURL(IconType) const;
    921     void setIconURL(const String&, const String&, IconType);
    922     void setIconURL(const IconURL&);
     921    const Vector<IconURL>& iconURLs() const;
     922    void addIconURL(const String& url, const String& mimeType, const String& size, IconType);
    923923
    924924    void setUseSecureKeyboardEntryWhenActive(bool);
     
    13501350    bool m_createRenderers;
    13511351    bool m_inPageCache;
    1352     IconURL m_iconURLs[ICON_COUNT];
     1352    Vector<IconURL> m_iconURLs;
    13531353
    13541354    HashSet<Element*> m_documentActivationCallbackElements;
  • trunk/Source/WebCore/dom/IconURL.cpp

    r85785 r95593  
    5555}
    5656
     57IconURL IconURL::defaultIconURL(const KURL& url, IconType type)
     58{
     59    IconURL result(url, emptyString(), emptyString(), type);
     60    result.m_isDefaultIcon = true;
     61    return result;
    5762}
    5863
     64bool operator==(const IconURL& lhs, const IconURL& rhs)
     65{
     66    return lhs.m_iconType == rhs.m_iconType
     67           && lhs.m_isDefaultIcon == rhs.m_isDefaultIcon
     68           && lhs.m_iconURL == rhs.m_iconURL
     69           && lhs.m_sizes == rhs.m_sizes
     70           && lhs.m_mimeType == rhs.m_mimeType;
     71}
     72
     73}
     74
  • trunk/Source/WebCore/dom/IconURL.h

    r85785 r95593  
    4646    Favicon = 1,
    4747    TouchIcon = 1 << 1,
    48     TouchPrecomposedIcon = 1 << 2
     48    TouchPrecomposedIcon = 1 << 2,
    4949};
    5050
    5151struct IconURL {
    5252    IconType m_iconType;
     53    String m_sizes;
     54    String m_mimeType;
    5355    KURL m_iconURL;
     56    bool m_isDefaultIcon;
    5457
    5558    IconURL()
    5659        : m_iconType(InvalidIcon)
     60        , m_isDefaultIcon(false)
    5761    {
    5862    }
    5963
    60     IconURL(const KURL& url, IconType type)
     64    IconURL(const KURL& url, const String& sizes, const String& mimeType, IconType type)
    6165        : m_iconType(type)
     66        , m_sizes(sizes)
     67        , m_mimeType(mimeType)
    6268        , m_iconURL(url)
     69        , m_isDefaultIcon(false)
    6370    {
    6471    }
     72   
     73    static IconURL defaultIconURL(const KURL&, IconType);
    6574};
     75
     76bool operator==(const IconURL&, const IconURL&);
    6677
    6778typedef Vector<IconURL, ICON_COUNT> IconURLs;
  • trunk/Source/WebCore/html/HTMLLinkElement.cpp

    r94427 r95593  
    180180    String type = m_type.lower();
    181181
    182     if (!m_linkLoader.loadLink(m_relAttribute, type, m_url, document()))
     182    if (!m_linkLoader.loadLink(m_relAttribute, type, m_sizes->toString(), m_url, document()))
    183183        return;
    184184
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r93066 r95593  
    11/*
    22 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    683684}
    684685
    685 IconURL DocumentLoader::iconURL(IconType iconType) const
    686 {
    687     return m_iconURLs[toIconIndex(iconType)];
    688 }
    689 
    690 void DocumentLoader::setIconURL(const IconURL& url)
    691 {
    692     if (url.m_iconURL.isEmpty())
    693         return;
    694 
    695     if (iconURL(url.m_iconType).m_iconURL != url.m_iconURL) {
    696         m_iconURLs[toIconIndex(url.m_iconType)] = url;
    697         frameLoader()->didChangeIcons(this, url.m_iconType);
    698     }
    699 }
    700 
    701686KURL DocumentLoader::urlForHistory() const
    702687{
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r91600 r95593  
    11/*
    22 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334#include "DocumentWriter.h"
    3435#include "IconDatabaseBase.h"
    35 #include "IconURL.h"
    3636#include "NavigationAction.h"
    3737#include "ResourceError.h"
     
    129129        void setPrimaryLoadComplete(bool);
    130130        void setTitle(const StringWithDirection&);
    131         void setIconURL(const IconURL&);
    132131        const String& overrideEncoding() const { return m_overrideEncoding; }
    133132
     
    176175        void stopRecordingResponses();
    177176        const StringWithDirection& title() const { return m_pageTitle; }
    178         IconURL iconURL(IconType) const;
    179177
    180178        KURL urlForHistory() const;
     
    315313
    316314        StringWithDirection m_pageTitle;
    317         IconURL m_iconURLs[ICON_COUNT];
    318315
    319316        String m_overrideEncoding;
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r95271 r95593  
    66 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
    77 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
     8 * Copyright (C) 2011 Google Inc. All rights reserved.
    89 *
    910 * Redistribution and use in source and binary forms, with or without
     
    32293230}
    32303231
    3231 void FrameLoader::didChangeIcons(DocumentLoader* loader, IconType type)
    3232 {
    3233     if (loader == m_documentLoader)
    3234         m_client->dispatchDidChangeIcons(type);
     3232void FrameLoader::didChangeIcons(IconType type)
     3233{
     3234    m_client->dispatchDidChangeIcons(type);
    32353235}
    32363236
  • trunk/Source/WebCore/loader/FrameLoader.h

    r93886 r95593  
    33 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
    44 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
     5 * Copyright (C) 2011 Google Inc. All rights reserved.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    170171    void willChangeTitle(DocumentLoader*);
    171172    void didChangeTitle(DocumentLoader*);
    172     void didChangeIcons(DocumentLoader*, IconType);
     173    void didChangeIcons(IconType);
    173174
    174175    FrameLoadType loadType() const;
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r89719 r95593  
    8686
    8787bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const String& type,
    88                           const KURL& href, Document* document)
     88                          const String& sizes, const KURL& href, Document* document)
    8989{
    9090    // We'll record this URL per document, even if we later only use it in top level frames
     
    9292        if (!m_client->shouldLoadLink())
    9393            return false;
    94         document->setIconURL(href.string(), type, relAttribute.m_iconType);
     94        document->addIconURL(href.string(), type, sizes, relAttribute.m_iconType);
    9595    }
    9696
  • trunk/Source/WebCore/loader/LinkLoader.h

    r89719 r95593  
    5151    virtual void notifyFinished(CachedResource*);
    5252   
    53     bool loadLink(const LinkRelAttribute&, const String& type, const KURL&, Document*);
     53    bool loadLink(const LinkRelAttribute&, const String& type, const String& sizes, const KURL&, Document*);
    5454
    5555private:
  • trunk/Source/WebCore/loader/icon/IconController.cpp

    r92551 r95593  
    66 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
    77 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
     8 * Copyright (C) 2011 Google Inc. All rights reserved.
    89 *
    910 * Redistribution and use in source and binary forms, with or without
     
    6566}
    6667
     68IconURL IconController::iconURL(IconType iconType) const
     69{
     70    IconURL result;
     71    const Vector<IconURL>& iconURLs = m_frame->document()->iconURLs();
     72    Vector<IconURL>::const_iterator iter(iconURLs.begin());
     73    for (; iter != iconURLs.end(); ++iter) {
     74        if (iter->m_iconType == iconType) {
     75            if (result.m_iconURL.isEmpty() || !iter->m_mimeType.isEmpty())
     76                result = *iter;
     77        }
     78    }
     79
     80    return result;
     81}
     82
    6783IconURLs IconController::urlsForTypes(int iconTypes)
    6884{
     
    7086    if (m_frame->tree() && m_frame->tree()->parent())
    7187        return iconURLs;
    72 
     88       
    7389    if (iconTypes & Favicon && !appendToIconURLs(Favicon, &iconURLs))
    7490        iconURLs.append(defaultURL(Favicon));
    7591
    7692#if ENABLE(TOUCH_ICON_LOADING)
    77     bool havePrecomposedIcon = false;
     93    int missedIcons = 0;
    7894    if (iconTypes & TouchPrecomposedIcon)
    79         havePrecomposedIcon = appendToIconURLs(TouchPrecomposedIcon, &iconURLs);
    80 
    81     bool haveTouchIcon = false;
     95        missedIcons += appendToIconURLs(TouchPrecomposedIcon, &iconURLs) ? 0:1;
     96
    8297    if (iconTypes & TouchIcon)
    83         haveTouchIcon = appendToIconURLs(TouchIcon, &iconURLs);
     98      missedIcons += appendToIconURLs(TouchIcon, &iconURLs) ? 0:1;
    8499
    85100    // Only return the default touch icons when the both were required and neither was gotten.
    86     if (iconTypes & TouchPrecomposedIcon && iconTypes & TouchIcon && !havePrecomposedIcon && !haveTouchIcon) {
     101    if (missedIcons == 2) {
    87102        iconURLs.append(defaultURL(TouchPrecomposedIcon));
    88103        iconURLs.append(defaultURL(TouchIcon));
    89104    }
    90105#endif
     106
     107    // Finally, append all remaining icons of this type.
     108    const Vector<IconURL>& allIconURLs = m_frame->document()->iconURLs();
     109    for (Vector<IconURL>::const_iterator iter = allIconURLs.begin(); iter != allIconURLs.end(); ++iter) {
     110        if (!(iter->m_iconType & iconTypes))
     111            continue;
     112
     113        int i;
     114        int iconCount = iconURLs.size();
     115        for (i = 0; i < iconCount; ++i) {
     116            if (*iter == iconURLs.at(i))
     117                break;
     118        }
     119        if (i == iconCount)
     120            iconURLs.append(*iter);
     121    }
     122
    91123    return iconURLs;
    92124}
     
    97129    iconDatabase().setIconURLForPageURL(icon.string(), m_frame->document()->url().string());
    98130    iconDatabase().setIconURLForPageURL(icon.string(), m_frame->loader()->initialRequest().url().string());
    99 }
    100 
    101 void IconController::setURL(const IconURL& iconURL)
    102 {
    103     m_frame->loader()->documentLoader()->setIconURL(iconURL);
    104131}
    105132
     
    219246bool IconController::appendToIconURLs(IconType iconType, IconURLs* iconURLs)
    220247{
    221     IconURL url = m_frame->document()->iconURL(iconType);
    222     if (url.m_iconURL.isEmpty())
     248    IconURL faviconURL = iconURL(iconType);
     249    if (faviconURL.m_iconURL.isEmpty())
    223250        return false;
    224251
    225     iconURLs->append(url);
     252    iconURLs->append(faviconURL);
    226253    return true;
    227254}
     
    240267    if (documentURL.hasPort())
    241268        url.setPort(documentURL.port());
     269
    242270    if (iconType == Favicon) {
    243271        url.setPath("/favicon.ico");
    244         return IconURL(url, Favicon);
     272        return IconURL::defaultIconURL(url, Favicon);
    245273    }
    246274#if ENABLE(TOUCH_ICON_LOADING)
    247275    if (iconType == TouchPrecomposedIcon) {
    248276        url.setPath("/apple-touch-icon-precomposed.png");
    249         return IconURL(url, TouchPrecomposedIcon);
     277        return IconURL::defaultIconURL(url, TouchPrecomposedIcon);
    250278    }
    251279    if (iconType == TouchIcon) {
    252280        url.setPath("/apple-touch-icon.png");
    253         return IconURL(url, TouchIcon);
     281        return IconURL::defaultIconURL(url, TouchIcon);
    254282    }
    255283#endif
  • trunk/Source/WebCore/loader/icon/IconController.h

    r88682 r95593  
    5050    KURL url();
    5151    IconURLs urlsForTypes(int iconTypes);
    52 
    53     // FIXME: We should inline this function into its one caller!
    54     void setURL(const IconURL&);
     52    IconURL iconURL(IconType) const;
    5553
    5654    void startLoader();
Note: See TracChangeset for help on using the changeset viewer.