RESOLVED FIXED 183768
Expose content attributes on _WKLinkIconParameters
https://bugs.webkit.org/show_bug.cgi?id=183768
Summary Expose content attributes on _WKLinkIconParameters
Ryosuke Niwa
Reported 2018-03-19 22:30:41 PDT
Some clients of WebKit may want to filter out icons based on link element's attributes. <rdar://problem/35442605>
Attachments
Patch (9.84 KB, patch)
2018-03-19 22:37 PDT, Ryosuke Niwa
no flags
Don't copy strings (10.24 KB, patch)
2018-03-20 15:03 PDT, Ryosuke Niwa
no flags
Use vector (10.36 KB, patch)
2018-03-20 16:00 PDT, Ryosuke Niwa
achristensen: review+
Ryosuke Niwa
Comment 1 2018-03-19 22:37:47 PDT
Alex Christensen
Comment 2 2018-03-20 10:51:41 PDT
Comment on attachment 336103 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=336103&action=review > Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm:66 > + _attributes.get()[[(NSString *)attribute.key copy]] = [(NSString *)attribute.value copy]; This looks like a memory leak. Why are you copying the NSStrings? WTF::String::operator NSString* returns an NSString you could probably just use without copying.
Ryosuke Niwa
Comment 3 2018-03-20 12:51:29 PDT
(In reply to Alex Christensen from comment #2) > Comment on attachment 336103 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=336103&action=review > > > Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm:66 > > + _attributes.get()[[(NSString *)attribute.key copy]] = [(NSString *)attribute.value copy]; > > This looks like a memory leak. Why are you copying the NSStrings? > WTF::String::operator NSString* returns an NSString you could probably just > use without copying. Presumably we want to be creating a different copy for each _WKLinkIconParameters. Why else are we making copies of linkIcon.url and linkIcon.mimeType? Either we need to make copies of keys & values here as well or copies of those values are also not needed.
Alex Christensen
Comment 4 2018-03-20 12:53:25 PDT
Comment on attachment 336103 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=336103&action=review >>> Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm:66 >>> + _attributes.get()[[(NSString *)attribute.key copy]] = [(NSString *)attribute.value copy]; >> >> This looks like a memory leak. Why are you copying the NSStrings? WTF::String::operator NSString* returns an NSString you could probably just use without copying. > > Presumably we want to be creating a different copy for each _WKLinkIconParameters. Why else are we making copies of linkIcon.url and linkIcon.mimeType? Either we need to make copies of keys & values here as well or copies of those values are also not needed. I'm not sure, but those copies are enclosed by adoptNS and these are not, making these memory leaks.
Ryosuke Niwa
Comment 5 2018-03-20 12:58:15 PDT
Brady says we don't need to make a copy of those either so let's just get rid of them all.
Ryosuke Niwa
Comment 6 2018-03-20 15:03:02 PDT
Created attachment 336157 [details] Don't copy strings
Darin Adler
Comment 7 2018-03-20 15:19:36 PDT
Comment on attachment 336157 [details] Don't copy strings Can we use a Vector instead of a HashMap?
Ryosuke Niwa
Comment 8 2018-03-20 15:45:30 PDT
(In reply to Darin Adler from comment #7) > Comment on attachment 336157 [details] > Don't copy strings > > Can we use a Vector instead of a HashMap? Like a pair of Strings? We can do that.
Ryosuke Niwa
Comment 9 2018-03-20 16:00:58 PDT
Created attachment 336162 [details] Use vector
Alex Christensen
Comment 10 2018-03-20 17:52:00 PDT
Comment on attachment 336162 [details] Use vector View in context: https://bugs.webkit.org/attachment.cgi?id=336162&action=review > Source/WebCore/html/LinkIconCollector.cpp:111 > + attributes.uncheckedAppend(std::make_pair(attribute.localName(), attribute.value())); Can we use an initializer list instead of make_pair? > Source/WebCore/html/LinkIconCollector.cpp:114 > + icons.append({ url, iconType, linkElement.type(), iconSize, attributes }); WTFMove(attributes). Otherwise this does an unnecessary Vector copy, right? > Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm:66 > + _attributes.get()[(NSString *)attributePair.first] = (NSString *)attributePair.second; Are the explicit (NSString *)s necessary?
Ryosuke Niwa
Comment 11 2018-03-20 19:09:26 PDT
(In reply to Alex Christensen from comment #10) > Comment on attachment 336162 [details] > Use vector > > View in context: > https://bugs.webkit.org/attachment.cgi?id=336162&action=review > > > Source/WebCore/html/LinkIconCollector.cpp:111 > > + attributes.uncheckedAppend(std::make_pair(attribute.localName(), attribute.value())); > > Can we use an initializer list instead of make_pair? Fixed. > > Source/WebCore/html/LinkIconCollector.cpp:114 > > + icons.append({ url, iconType, linkElement.type(), iconSize, attributes }); > > WTFMove(attributes). Otherwise this does an unnecessary Vector copy, right? Yup. Fixed. > > Source/WebKit/UIProcess/API/Cocoa/_WKLinkIconParameters.mm:66 > > + _attributes.get()[(NSString *)attributePair.first] = (NSString *)attributePair.second; > > Are the explicit (NSString *)s necessary? The key needs one but not the value so fixed that.
Ryosuke Niwa
Comment 12 2018-03-20 19:52:22 PDT
Note You need to log in before you can comment on or make changes to this bug.