Bug 132509

Summary: [iOS][WK2] Prefetch DNS hostnames on tap highlight
Product: WebKit Reporter: Benjamin Poulain <benjamin>
Component: New BugsAssignee: Benjamin Poulain <benjamin>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, berto, cdumez, cgarcia, cmarcelo, commit-queue, danw, esprehn+autocc, galpeter, glenn, gustavo, gyuyoung.kim, japhet, kangil.han, kondapallykalyan, mrobinson
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Benjamin Poulain 2014-05-02 19:36:32 PDT
[iOS][WK2] Prefetch DNS hostnames on tap highlight
Comment 1 Benjamin Poulain 2014-05-02 19:36:48 PDT
Created attachment 230731 [details]
Patch
Comment 2 Ryosuke Niwa 2014-05-02 22:29:14 PDT
Comment on attachment 230731 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=230731&action=review

> Source/WebCore/dom/Document.cpp:4893
> +void Document::prefetchDNSFrom(const Node& node)
> +{
> +    if (node.isLink() && isElement(node)) {
> +        const Element& linkTypeElement = toElement(node);
> +
> +        AtomicString urlString;
> +        if (linkTypeElement.hasTagName(SVGNames::aTag))
> +            urlString = linkTypeElement.getAttribute(XLinkNames::hrefAttr);
> +        else
> +            urlString = linkTypeElement.getAttribute(HTMLNames::hrefAttr);
> +        if (!urlString.isEmpty()) {
> +            URL absoluteURL = linkTypeElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
> +            prefetchDNS(absoluteURL.host());
> +        }
> +    }
> +}

It would be nice if we could just make this a member function of Element instead.
And I guess we should share this code with HTMLAnchorElement::parseAttribute.
Comment 3 Benjamin Poulain 2014-05-04 13:36:55 PDT
Created attachment 230790 [details]
Patch
Comment 4 Benjamin Poulain 2014-05-04 16:05:22 PDT
Created attachment 230794 [details]
Patch
Comment 5 Alexey Proskuryakov 2014-05-04 18:12:39 PDT
Comment on attachment 230794 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=230794&action=review

> Source/WebCore/dom/Element.cpp:1168
> +void Element::prefetchDNSFrom(const Element& element)

It is unfortunate that this implementation is so different from what we have in Chrome::mouseDidMoveOverElement(). Can you make it similar? The situation is essentially the same, so having different solutions will be confusing.

> Source/WebCore/dom/Element.h:568
> +    static void prefetchDNSFrom(const Element&);

I don't think that we normally make Nodes or Elements const, so we?
Comment 6 Alexey Proskuryakov 2014-05-04 18:15:12 PDT
Comment on attachment 230794 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=230794&action=review

> Source/WebCore/dom/Element.cpp:1177
> +    if (element.hasTagName(SVGNames::aTag))
> +        urlString = element.getAttribute(XLinkNames::hrefAttr);
> +    else
> +        urlString = element.getAttribute(HTMLNames::hrefAttr);

It is a layering violation to make core DOM code know about HTML and SVG like here.
Comment 7 Benjamin Poulain 2014-05-04 18:37:38 PDT
(In reply to comment #6)
> (From update of attachment 230794 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=230794&action=review
> 
> > Source/WebCore/dom/Element.cpp:1177
> > +    if (element.hasTagName(SVGNames::aTag))
> > +        urlString = element.getAttribute(XLinkNames::hrefAttr);
> > +    else
> > +        urlString = element.getAttribute(HTMLNames::hrefAttr);
> 
> It is a layering violation to make core DOM code know about HTML and SVG like here.

Not sure to follow you. Element knows about SVG attributes in detail already.

Do you prefer if this is moved back to document?
Comment 8 Alexey Proskuryakov 2014-05-04 20:47:38 PDT
Prefetch on mouse move code path uses HitTestResult, which already has the url precomputed. So I would prefer this new code to not exist at all, and instead to use the same idiom as the existing solution.
Comment 9 Benjamin Poulain 2014-05-05 15:46:26 PDT
Created attachment 230862 [details]
Patch
Comment 10 Alexey Proskuryakov 2014-05-05 16:00:33 PDT
Comment on attachment 230862 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=230862&action=review

> Source/WebCore/dom/Element.cpp:1179
> +    if (linkAttribute.isEmpty())
> +        return document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkAttribute));
> +    return URL();

Looks like normal and early return statements are switched here.

> Source/WebCore/platform/network/DNS.h:34
> -void prefetchDNS(const String& hostname);
> +class URL;
> +
> +void prefetchDNS(const URL& absoluteURL);

I think that the original interface was superior, even though we had a bit of duplicated code. The new interface is misleading - this function logically takes a hostname, not a URL.
Comment 11 Benjamin Poulain 2014-05-05 17:02:12 PDT
Created attachment 230869 [details]
Patch
Comment 12 Benjamin Poulain 2014-05-05 18:14:27 PDT
Comment on attachment 230869 [details]
Patch

Clearing flags on attachment: 230869

Committed r168339: <http://trac.webkit.org/changeset/168339>
Comment 13 Benjamin Poulain 2014-05-05 18:14:37 PDT
All reviewed patches have been landed.  Closing bug.