Title: [229784] trunk
Revision
229784
Author
rn...@webkit.org
Date
2018-03-20 19:52:20 -0700 (Tue, 20 Mar 2018)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (229783 => 229784)


--- trunk/Source/WebCore/ChangeLog	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebCore/ChangeLog	2018-03-21 02:52:20 UTC (rev 229784)
@@ -1,3 +1,22 @@
+2018-03-19  Ryosuke Niwa  <rn...@webkit.org>
+
+        Expose content attributes on _WKLinkIconParameters
+        https://bugs.webkit.org/show_bug.cgi?id=183768
+
+        Reviewed by Alex Christensen.
+
+        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.
+
 2018-03-20  Zalan Bujtas  <za...@apple.com>
 
         RenderTreeNeedsLayoutChecker fails with absolutely positioned svg and <use>

Modified: trunk/Source/WebCore/html/LinkIconCollector.cpp (229783 => 229784)


--- trunk/Source/WebCore/html/LinkIconCollector.cpp	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebCore/html/LinkIconCollector.cpp	2018-03-21 02:52:20 UTC (rev 229784)
@@ -104,7 +104,14 @@
                 iconSize = size;
         }
 
-        icons.append({ url, iconType, linkElement.type(), iconSize });
+        Vector<std::pair<String, String>> attributes;
+        if (linkElement.hasAttributes()) {
+            attributes.reserveCapacity(linkElement.attributeCount());
+            for (const Attribute& attribute : linkElement.attributesIterator())
+                attributes.uncheckedAppend({ attribute.localName(), attribute.value() });
+        }
+
+        icons.append({ url, iconType, linkElement.type(), iconSize, WTFMove(attributes) });
     }
 
     std::sort(icons.begin(), icons.end(), [](auto& a, auto& b) {

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (229783 => 229784)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-03-21 02:52:20 UTC (rev 229784)
@@ -1870,7 +1870,7 @@
 
     auto findResult = m_linkIcons.findMatching([](auto& icon) { return icon.type == LinkIconType::Favicon; });
     if (findResult == notFound)
-        m_linkIcons.append({ document->completeURL(ASCIILiteral("/favicon.ico")), LinkIconType::Favicon, String(), std::nullopt });
+        m_linkIcons.append({ document->completeURL(ASCIILiteral("/favicon.ico")), LinkIconType::Favicon, String(), std::nullopt, { } });
 
     if (!m_linkIcons.size())
         return;

Modified: trunk/Source/WebCore/platform/LinkIcon.h (229783 => 229784)


--- trunk/Source/WebCore/platform/LinkIcon.h	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebCore/platform/LinkIcon.h	2018-03-21 02:52:20 UTC (rev 229784)
@@ -27,6 +27,7 @@
 
 #include "LinkIconType.h"
 #include "URL.h"
+#include <wtf/HashMap.h>
 #include <wtf/Optional.h>
 #include <wtf/text/WTFString.h>
 
@@ -37,6 +38,7 @@
     LinkIconType type;
     String mimeType;
     std::optional<unsigned> size;
+    Vector<std::pair<String, String>> attributes;
 
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static bool decode(Decoder&, LinkIcon&);
@@ -45,7 +47,7 @@
 template<class Encoder>
 void LinkIcon::encode(Encoder& encoder) const
 {
-    encoder << url << mimeType << size;
+    encoder << url << mimeType << size << attributes;
     encoder.encodeEnum(type);
 }
 
@@ -61,6 +63,9 @@
     if (!decoder.decode(result.size))
         return false;
 
+    if (!decoder.decode(result.attributes))
+        return false;
+
     if (!decoder.decodeEnum(result.type))
         return false;
 

Modified: trunk/Source/WebKit/ChangeLog (229783 => 229784)


--- trunk/Source/WebKit/ChangeLog	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebKit/ChangeLog	2018-03-21 02:52:20 UTC (rev 229784)
@@ -1,3 +1,20 @@
+2018-03-19  Ryosuke Niwa  <rn...@webkit.org>
+
+        Expose content attributes on _WKLinkIconParameters
+        https://bugs.webkit.org/show_bug.cgi?id=183768
+
+        Reviewed by Alex Christensen.
+
+        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.
+
 2018-03-20  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Add AssistedNodeInformation plumbing for form control placeholder text and label text

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.h (229783 => 229784)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.h	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.h	2018-03-21 02:52:20 UTC (rev 229784)
@@ -43,6 +43,8 @@
 @property (nonatomic, readonly, copy) NSString *mimeType;
 @property (nonatomic, readonly, copy) NSNumber *size;
 
+@property (nonatomic, readonly, copy) NSDictionary *attributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm (229783 => 229784)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm	2018-03-21 02:52:20 UTC (rev 229784)
@@ -35,6 +35,7 @@
     WKLinkIconType _iconType;
     RetainPtr<NSString> _mimeType;
     RetainPtr<NSNumber> _size;
+    RetainPtr<NSMutableDictionary> _attributes;
 }
 
 - (instancetype)_initWithLinkIcon:(const WebCore::LinkIcon&)linkIcon
@@ -42,8 +43,8 @@
     if (!(self = [super init]))
         return nil;
 
-    _url = adoptNS([(NSURL *)linkIcon.url copy]);
-    _mimeType = adoptNS([(NSString *)linkIcon.mimeType copy]);
+    _url = (NSURL *)linkIcon.url;
+    _mimeType = (NSString *)linkIcon.mimeType;
 
     if (linkIcon.size)
         _size = adoptNS([[NSNumber alloc] initWithUnsignedInt:linkIcon.size.value()]);
@@ -60,6 +61,10 @@
         break;
     }
 
+    _attributes = adoptNS([[NSMutableDictionary alloc] initWithCapacity:linkIcon.attributes.size()]);
+    for (auto& attributePair : linkIcon.attributes)
+        _attributes.get()[(NSString *)attributePair.first] = attributePair.second;
+
     return self;
 }
 
@@ -83,6 +88,11 @@
     return _iconType;
 }
 
+- (NSDictionary *)attributes
+{
+    return _attributes.get();
+}
+
 @end
 
 #endif // WK_API_ENABLED

Modified: trunk/Tools/ChangeLog (229783 => 229784)


--- trunk/Tools/ChangeLog	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Tools/ChangeLog	2018-03-21 02:52:20 UTC (rev 229784)
@@ -1,3 +1,15 @@
+2018-03-19  Ryosuke Niwa  <rn...@webkit.org>
+
+        Expose content attributes on _WKLinkIconParameters
+        https://bugs.webkit.org/show_bug.cgi?id=183768
+
+        Reviewed by Alex Christensen.
+
+        Expanded the basic test case for _WKLinkIconParameters's properties including newly added "attributes".
+
+        * TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm:
+        (IconLoading.DefaultFavicon):
+
 2018-03-20  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Add AssistedNodeInformation plumbing for form control placeholder text and label text

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm (229783 => 229784)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm	2018-03-21 02:28:29 UTC (rev 229783)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm	2018-03-21 02:52:20 UTC (rev 229784)
@@ -48,15 +48,15 @@
     bool shouldSaveCallback;
     bool didSaveCallback;
     void (^savedCallback)(void (^)(NSData*));
-}
-@end
 
-@implementation IconLoadingDelegate {
     RetainPtr<_WKLinkIconParameters> favicon;
     RetainPtr<_WKLinkIconParameters> touch;
     RetainPtr<_WKLinkIconParameters> touchPrecomposed;
 }
+@end
 
+@implementation IconLoadingDelegate
+
 - (void)webView:(WKWebView *)webView shouldLoadIconWithParameters:(_WKLinkIconParameters *)parameters completionHandler:(void (^)(void (^)(NSData*)))completionHandler
 {
     switch (parameters.iconType) {
@@ -156,7 +156,7 @@
 
 static const char mainBytes[] =
 "<head>" \
-"<link rel=\"apple-touch-icon\" sizes=\"57x57\" href="" \
+"<link rel=\"apple-touch-icon\" sizes=\"57x57\" non-standard-attribute href="" \
 "<link rel=\"apple-touch-icon-precomposed\" sizes=\"57x57\" href="" \
 "</head>";
 
@@ -177,6 +177,21 @@
 
     TestWebKitAPI::Util::run(&doneWithIcons);
     TestWebKitAPI::Util::run(&iconDelegate.get()->receivedFaviconDataCallback);
+
+    auto* faviconParameters = iconDelegate.get()->favicon.get();
+    EXPECT_WK_STREQ("testing:///favicon.ico", faviconParameters.url.absoluteString);
+    EXPECT_EQ(WKLinkIconTypeFavicon, faviconParameters.iconType);
+    EXPECT_EQ(static_cast<unsigned long>(0), faviconParameters.attributes.count);
+
+    auto* touchParameters = iconDelegate.get()->touch.get();
+    EXPECT_WK_STREQ("http://example.com/my-apple-touch-icon.png", touchParameters.url.absoluteString);
+    EXPECT_EQ(WKLinkIconTypeTouchIcon, touchParameters.iconType);
+    EXPECT_EQ(static_cast<unsigned long>(4), touchParameters.attributes.count);
+    EXPECT_WK_STREQ("apple-touch-icon", [touchParameters.attributes valueForKey:@"rel"]);
+    EXPECT_WK_STREQ("57x57", [touchParameters.attributes valueForKey:@"sizes"]);
+    EXPECT_WK_STREQ("http://example.com/my-apple-touch-icon.png", [touchParameters.attributes valueForKey:@"href"]);
+    EXPECT_TRUE([touchParameters.attributes.allKeys containsObject:@"non-standard-attribute"]);
+    EXPECT_FALSE([touchParameters.attributes.allKeys containsObject:@"nonexistent-attribute"]);
 }
 
 static const char mainBytes2[] =
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to