Changeset 229784 in webkit


Ignore:
Timestamp:
Mar 20, 2018 7:52:20 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

Expose content attributes on _WKLinkIconParameters
https://bugs.webkit.org/show_bug.cgi?id=183768

Reviewed by Alex Christensen.

Source/WebCore:

Collect a vector of content attributes upon finding touch and fav-icons in order to expose it in a WebKit API.

Tests: IconLoading.DefaultFavicon

  • html/LinkIconCollector.cpp:

(WebCore::LinkIconCollector::iconsOfTypes): Collect attributes.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::startIconLoading): Use an empty vector for /favicon.ico.

  • platform/LinkIcon.h:

(WebCore::LinkIcon::encode const): Encode the vector of content attributes.
(WebCore::LinkIcon::decode): Ditto for decoding.

Source/WebKit:

Added _WKLinkIconParameters.attributes to expose content attributes of a link element
which defined a favicon, touch icon, or pre-compressed touch icon.

  • UIProcess/API/Cocoa/_WKLinkIconParameters.h:

(_WKLinkIconParameters.attributes): Added.

  • UIProcess/API/Cocoa/_WKLinkIconParameters.mm:

(_WKLinkIconParameters._attributes): Added.
(-[_WKLinkIconParameters _initWithLinkIcon:]): Convert the hash map from WebCore to a NSDictionary.
(-[_WKLinkIconParameters attributes]): Added.

Tools:

Expanded the basic test case for _WKLinkIconParameters's properties including newly added "attributes".

  • TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm:

(IconLoading.DefaultFavicon):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r229782 r229784  
     12018-03-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Expose content attributes on _WKLinkIconParameters
     4        https://bugs.webkit.org/show_bug.cgi?id=183768
     5
     6        Reviewed by Alex Christensen.
     7
     8        Collect a vector of content attributes upon finding touch and fav-icons in order to expose it in a WebKit API.
     9
     10        Tests: IconLoading.DefaultFavicon
     11
     12        * html/LinkIconCollector.cpp:
     13        (WebCore::LinkIconCollector::iconsOfTypes): Collect attributes.
     14        * loader/DocumentLoader.cpp:
     15        (WebCore::DocumentLoader::startIconLoading): Use an empty vector for /favicon.ico.
     16        * platform/LinkIcon.h:
     17        (WebCore::LinkIcon::encode const): Encode the vector of content attributes.
     18        (WebCore::LinkIcon::decode): Ditto for decoding.
     19
    1202018-03-20  Zalan Bujtas  <zalan@apple.com>
    221
  • trunk/Source/WebCore/html/LinkIconCollector.cpp

    r224390 r229784  
    105105        }
    106106
    107         icons.append({ url, iconType, linkElement.type(), iconSize });
     107        Vector<std::pair<String, String>> attributes;
     108        if (linkElement.hasAttributes()) {
     109            attributes.reserveCapacity(linkElement.attributeCount());
     110            for (const Attribute& attribute : linkElement.attributesIterator())
     111                attributes.uncheckedAppend({ attribute.localName(), attribute.value() });
     112        }
     113
     114        icons.append({ url, iconType, linkElement.type(), iconSize, WTFMove(attributes) });
    108115    }
    109116
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r229778 r229784  
    18711871    auto findResult = m_linkIcons.findMatching([](auto& icon) { return icon.type == LinkIconType::Favicon; });
    18721872    if (findResult == notFound)
    1873         m_linkIcons.append({ document->completeURL(ASCIILiteral("/favicon.ico")), LinkIconType::Favicon, String(), std::nullopt });
     1873        m_linkIcons.append({ document->completeURL(ASCIILiteral("/favicon.ico")), LinkIconType::Favicon, String(), std::nullopt, { } });
    18741874
    18751875    if (!m_linkIcons.size())
  • trunk/Source/WebCore/platform/LinkIcon.h

    r209640 r229784  
    2828#include "LinkIconType.h"
    2929#include "URL.h"
     30#include <wtf/HashMap.h>
    3031#include <wtf/Optional.h>
    3132#include <wtf/text/WTFString.h>
     
    3839    String mimeType;
    3940    std::optional<unsigned> size;
     41    Vector<std::pair<String, String>> attributes;
    4042
    4143    template<class Encoder> void encode(Encoder&) const;
     
    4648void LinkIcon::encode(Encoder& encoder) const
    4749{
    48     encoder << url << mimeType << size;
     50    encoder << url << mimeType << size << attributes;
    4951    encoder.encodeEnum(type);
    5052}
     
    6264        return false;
    6365
     66    if (!decoder.decode(result.attributes))
     67        return false;
     68
    6469    if (!decoder.decodeEnum(result.type))
    6570        return false;
  • trunk/Source/WebKit/ChangeLog

    r229783 r229784  
     12018-03-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Expose content attributes on _WKLinkIconParameters
     4        https://bugs.webkit.org/show_bug.cgi?id=183768
     5
     6        Reviewed by Alex Christensen.
     7
     8        Added _WKLinkIconParameters.attributes to expose content attributes of a link element
     9        which defined a favicon, touch icon, or pre-compressed touch icon.
     10
     11        * UIProcess/API/Cocoa/_WKLinkIconParameters.h:
     12        (_WKLinkIconParameters.attributes): Added.
     13        * UIProcess/API/Cocoa/_WKLinkIconParameters.mm:
     14        (_WKLinkIconParameters._attributes): Added.
     15        (-[_WKLinkIconParameters _initWithLinkIcon:]): Convert the hash map from WebCore to a NSDictionary.
     16        (-[_WKLinkIconParameters attributes]): Added.
     17
    1182018-03-20  Wenson Hsieh  <wenson_hsieh@apple.com>
    219
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.h

    r221930 r229784  
    4444@property (nonatomic, readonly, copy) NSNumber *size;
    4545
     46@property (nonatomic, readonly, copy) NSDictionary *attributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     47
    4648@end
    4749
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm

    r209640 r229784  
    3636    RetainPtr<NSString> _mimeType;
    3737    RetainPtr<NSNumber> _size;
     38    RetainPtr<NSMutableDictionary> _attributes;
    3839}
    3940
     
    4344        return nil;
    4445
    45     _url = adoptNS([(NSURL *)linkIcon.url copy]);
    46     _mimeType = adoptNS([(NSString *)linkIcon.mimeType copy]);
     46    _url = (NSURL *)linkIcon.url;
     47    _mimeType = (NSString *)linkIcon.mimeType;
    4748
    4849    if (linkIcon.size)
     
    6061        break;
    6162    }
     63
     64    _attributes = adoptNS([[NSMutableDictionary alloc] initWithCapacity:linkIcon.attributes.size()]);
     65    for (auto& attributePair : linkIcon.attributes)
     66        _attributes.get()[(NSString *)attributePair.first] = attributePair.second;
    6267
    6368    return self;
     
    8489}
    8590
     91- (NSDictionary *)attributes
     92{
     93    return _attributes.get();
     94}
     95
    8696@end
    8797
  • trunk/Tools/ChangeLog

    r229783 r229784  
     12018-03-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Expose content attributes on _WKLinkIconParameters
     4        https://bugs.webkit.org/show_bug.cgi?id=183768
     5
     6        Reviewed by Alex Christensen.
     7
     8        Expanded the basic test case for _WKLinkIconParameters's properties including newly added "attributes".
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm:
     11        (IconLoading.DefaultFavicon):
     12
    1132018-03-20  Wenson Hsieh  <wenson_hsieh@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm

    r218896 r229784  
    4949    bool didSaveCallback;
    5050    void (^savedCallback)(void (^)(NSData*));
    51 }
    52 @end
    53 
    54 @implementation IconLoadingDelegate {
     51
    5552    RetainPtr<_WKLinkIconParameters> favicon;
    5653    RetainPtr<_WKLinkIconParameters> touch;
    5754    RetainPtr<_WKLinkIconParameters> touchPrecomposed;
    5855}
     56@end
     57
     58@implementation IconLoadingDelegate
    5959
    6060- (void)webView:(WKWebView *)webView shouldLoadIconWithParameters:(_WKLinkIconParameters *)parameters completionHandler:(void (^)(void (^)(NSData*)))completionHandler
     
    157157static const char mainBytes[] =
    158158"<head>" \
    159 "<link rel=\"apple-touch-icon\" sizes=\"57x57\" href=\"http://example.com/my-apple-touch-icon.png\">" \
     159"<link rel=\"apple-touch-icon\" sizes=\"57x57\" non-standard-attribute href=\"http://example.com/my-apple-touch-icon.png\">" \
    160160"<link rel=\"apple-touch-icon-precomposed\" sizes=\"57x57\" href=\"http://example.com/my-apple-touch-icon-precomposed.png\">" \
    161161"</head>";
     
    178178    TestWebKitAPI::Util::run(&doneWithIcons);
    179179    TestWebKitAPI::Util::run(&iconDelegate.get()->receivedFaviconDataCallback);
     180
     181    auto* faviconParameters = iconDelegate.get()->favicon.get();
     182    EXPECT_WK_STREQ("testing:///favicon.ico", faviconParameters.url.absoluteString);
     183    EXPECT_EQ(WKLinkIconTypeFavicon, faviconParameters.iconType);
     184    EXPECT_EQ(static_cast<unsigned long>(0), faviconParameters.attributes.count);
     185
     186    auto* touchParameters = iconDelegate.get()->touch.get();
     187    EXPECT_WK_STREQ("http://example.com/my-apple-touch-icon.png", touchParameters.url.absoluteString);
     188    EXPECT_EQ(WKLinkIconTypeTouchIcon, touchParameters.iconType);
     189    EXPECT_EQ(static_cast<unsigned long>(4), touchParameters.attributes.count);
     190    EXPECT_WK_STREQ("apple-touch-icon", [touchParameters.attributes valueForKey:@"rel"]);
     191    EXPECT_WK_STREQ("57x57", [touchParameters.attributes valueForKey:@"sizes"]);
     192    EXPECT_WK_STREQ("http://example.com/my-apple-touch-icon.png", [touchParameters.attributes valueForKey:@"href"]);
     193    EXPECT_TRUE([touchParameters.attributes.allKeys containsObject:@"non-standard-attribute"]);
     194    EXPECT_FALSE([touchParameters.attributes.allKeys containsObject:@"nonexistent-attribute"]);
    180195}
    181196
Note: See TracChangeset for help on using the changeset viewer.