Changeset 229784 in webkit
- Timestamp:
- Mar 20, 2018 7:52:20 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r229782 r229784 1 2018-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 1 20 2018-03-20 Zalan Bujtas <zalan@apple.com> 2 21 -
trunk/Source/WebCore/html/LinkIconCollector.cpp
r224390 r229784 105 105 } 106 106 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) }); 108 115 } 109 116 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r229778 r229784 1871 1871 auto findResult = m_linkIcons.findMatching([](auto& icon) { return icon.type == LinkIconType::Favicon; }); 1872 1872 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, { } }); 1874 1874 1875 1875 if (!m_linkIcons.size()) -
trunk/Source/WebCore/platform/LinkIcon.h
r209640 r229784 28 28 #include "LinkIconType.h" 29 29 #include "URL.h" 30 #include <wtf/HashMap.h> 30 31 #include <wtf/Optional.h> 31 32 #include <wtf/text/WTFString.h> … … 38 39 String mimeType; 39 40 std::optional<unsigned> size; 41 Vector<std::pair<String, String>> attributes; 40 42 41 43 template<class Encoder> void encode(Encoder&) const; … … 46 48 void LinkIcon::encode(Encoder& encoder) const 47 49 { 48 encoder << url << mimeType << size ;50 encoder << url << mimeType << size << attributes; 49 51 encoder.encodeEnum(type); 50 52 } … … 62 64 return false; 63 65 66 if (!decoder.decode(result.attributes)) 67 return false; 68 64 69 if (!decoder.decodeEnum(result.type)) 65 70 return false; -
trunk/Source/WebKit/ChangeLog
r229783 r229784 1 2018-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 1 18 2018-03-20 Wenson Hsieh <wenson_hsieh@apple.com> 2 19 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.h
r221930 r229784 44 44 @property (nonatomic, readonly, copy) NSNumber *size; 45 45 46 @property (nonatomic, readonly, copy) NSDictionary *attributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 47 46 48 @end 47 49 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm
r209640 r229784 36 36 RetainPtr<NSString> _mimeType; 37 37 RetainPtr<NSNumber> _size; 38 RetainPtr<NSMutableDictionary> _attributes; 38 39 } 39 40 … … 43 44 return nil; 44 45 45 _url = adoptNS([(NSURL *)linkIcon.url copy]);46 _mimeType = adoptNS([(NSString *)linkIcon.mimeType copy]);46 _url = (NSURL *)linkIcon.url; 47 _mimeType = (NSString *)linkIcon.mimeType; 47 48 48 49 if (linkIcon.size) … … 60 61 break; 61 62 } 63 64 _attributes = adoptNS([[NSMutableDictionary alloc] initWithCapacity:linkIcon.attributes.size()]); 65 for (auto& attributePair : linkIcon.attributes) 66 _attributes.get()[(NSString *)attributePair.first] = attributePair.second; 62 67 63 68 return self; … … 84 89 } 85 90 91 - (NSDictionary *)attributes 92 { 93 return _attributes.get(); 94 } 95 86 96 @end 87 97 -
trunk/Tools/ChangeLog
r229783 r229784 1 2018-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 1 13 2018-03-20 Wenson Hsieh <wenson_hsieh@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IconLoadingDelegate.mm
r218896 r229784 49 49 bool didSaveCallback; 50 50 void (^savedCallback)(void (^)(NSData*)); 51 } 52 @end 53 54 @implementation IconLoadingDelegate { 51 55 52 RetainPtr<_WKLinkIconParameters> favicon; 56 53 RetainPtr<_WKLinkIconParameters> touch; 57 54 RetainPtr<_WKLinkIconParameters> touchPrecomposed; 58 55 } 56 @end 57 58 @implementation IconLoadingDelegate 59 59 60 60 - (void)webView:(WKWebView *)webView shouldLoadIconWithParameters:(_WKLinkIconParameters *)parameters completionHandler:(void (^)(void (^)(NSData*)))completionHandler … … 157 157 static const char mainBytes[] = 158 158 "<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\">" \ 160 160 "<link rel=\"apple-touch-icon-precomposed\" sizes=\"57x57\" href=\"http://example.com/my-apple-touch-icon-precomposed.png\">" \ 161 161 "</head>"; … … 178 178 TestWebKitAPI::Util::run(&doneWithIcons); 179 179 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"]); 180 195 } 181 196
Note: See TracChangeset
for help on using the changeset viewer.