Chromium Code Reviews| Index: Source/core/html/HTMLAnchorElement.cpp |
| diff --git a/Source/core/html/HTMLAnchorElement.cpp b/Source/core/html/HTMLAnchorElement.cpp |
| index ad2524376d2764a9725c70eb8a93436c08ffed24..9b45843089256ad73129bf810a7411a346bfb8af 100644 |
| --- a/Source/core/html/HTMLAnchorElement.cpp |
| +++ b/Source/core/html/HTMLAnchorElement.cpp |
| @@ -24,6 +24,9 @@ |
| #include "config.h" |
| #include "core/html/HTMLAnchorElement.h" |
| +#include <public/Platform.h> |
| +#include <public/WebPrescientNetworking.h> |
| +#include <public/WebURL.h> |
| #include <wtf/text/StringBuilder.h> |
| #include "HTMLNames.h" |
| #include "core/dom/Attribute.h" |
| @@ -53,17 +56,31 @@ |
| namespace WebCore { |
| +namespace { |
| + |
| +void preconnectToURL(const KURL& url, WebKit::WebPreconnectMotivation motivation) |
| +{ |
| + WebKit::WebPrescientNetworking* prescientNetworking = |
| + WebKit::Platform::current()->prescientNetworking(); |
|
abarth-chromium
2013/05/24 05:58:12
There's no 80 col limit, so you can put this on on
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| + if (!prescientNetworking) |
| + return; |
| + |
| + prescientNetworking->preconnect(WebKit::WebURL(url), motivation); |
|
abarth-chromium
2013/05/24 05:58:12
No need to call WebKit::WebURL explicitly. The co
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| +} |
| + |
| +} |
| + |
| class HTMLAnchorElement::PrefetchEventHandler { |
| public: |
| - static PassOwnPtr<PrefetchEventHandler> create() |
| + static PassOwnPtr<PrefetchEventHandler> create(HTMLAnchorElement* anchorElement) |
| { |
| - return adoptPtr(new HTMLAnchorElement::PrefetchEventHandler()); |
| + return adoptPtr(new HTMLAnchorElement::PrefetchEventHandler(anchorElement)); |
| } |
| void handleEvent(Event* e); |
| private: |
| - PrefetchEventHandler(); |
| + PrefetchEventHandler(HTMLAnchorElement*); |
|
abarth-chromium
2013/05/24 05:58:12
Please use the "explicit" keyword for one-argument
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| void reset(); |
| @@ -74,10 +91,15 @@ private: |
| void handleGestureTapDown(Event*); |
| void handleClick(Event* event); |
| + bool shouldPrefetch(const KURL&); |
| + void prefetch(WebKit::WebPreconnectMotivation); |
| + |
| + HTMLAnchorElement* m_anchorElement; |
| double m_mouseOverTimestamp; |
| double m_mouseDownTimestamp; |
| double m_tapDownTimestamp; |
| bool m_hadTapUnconfirmed; |
| + bool m_hasIssuedPreconnect; |
| }; |
| using namespace HTMLNames; |
| @@ -648,13 +670,17 @@ void HTMLAnchorElement::setRootEditableElementForSelectionOnMouseDown(Element* e |
| HTMLAnchorElement::PrefetchEventHandler* HTMLAnchorElement::prefetchEventHandler() |
| { |
| if (!m_prefetchEventHandler) |
| - m_prefetchEventHandler = PrefetchEventHandler::create(); |
| + m_prefetchEventHandler = PrefetchEventHandler::create(this); |
| return m_prefetchEventHandler.get(); |
| } |
| -HTMLAnchorElement::PrefetchEventHandler::PrefetchEventHandler() |
| +HTMLAnchorElement::PrefetchEventHandler::PrefetchEventHandler( |
| + HTMLAnchorElement* anchorElement) |
|
abarth-chromium
2013/05/24 05:58:12
This line should be combined with the previous one
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| + : m_anchorElement(anchorElement) |
| { |
| + ASSERT(m_anchorElement); |
| + |
| reset(); |
| } |
| @@ -664,10 +690,14 @@ void HTMLAnchorElement::PrefetchEventHandler::reset() |
| m_mouseDownTimestamp = 0; |
| m_hadTapUnconfirmed = false; |
| m_tapDownTimestamp = 0; |
| + m_hasIssuedPreconnect = false; |
| } |
| void HTMLAnchorElement::PrefetchEventHandler::handleEvent(Event* event) |
| { |
| + if (!shouldPrefetch(m_anchorElement->href())) |
| + return; |
| + |
| if (event->type() == eventNames().mouseoverEvent) |
| handleMouseOver(event); |
| else if (event->type() == eventNames().mouseoutEvent) |
| @@ -688,6 +718,8 @@ void HTMLAnchorElement::PrefetchEventHandler::handleMouseOver(Event* event) |
| m_mouseOverTimestamp = event->timeStamp(); |
| HistogramSupport::histogramEnumeration("MouseEventPrefetch.MouseOvers", 0, 2); |
| + |
| + prefetch(WebKit::WebPreconnectMotivationLinkMouseOver); |
| } |
| } |
| @@ -706,6 +738,8 @@ void HTMLAnchorElement::PrefetchEventHandler::handleLeftMouseDown(Event* event) |
| m_mouseDownTimestamp = event->timeStamp(); |
| HistogramSupport::histogramEnumeration("MouseEventPrefetch.MouseDowns", 0, 2); |
| + |
| + prefetch(WebKit::WebPreconnectMotivationLinkMouseDown); |
| } |
| void HTMLAnchorElement::PrefetchEventHandler::handleGestureTapUnconfirmed(Event* event) |
| @@ -713,6 +747,8 @@ void HTMLAnchorElement::PrefetchEventHandler::handleGestureTapUnconfirmed(Event* |
| m_hadTapUnconfirmed = true; |
| HistogramSupport::histogramEnumeration("MouseEventPrefetch.TapUnconfirmeds", 0, 2); |
| + |
| + prefetch(WebKit::WebPreconnectMotivationLinkTapUnconfirmed); |
| } |
| void HTMLAnchorElement::PrefetchEventHandler::handleGestureTapDown(Event* event) |
| @@ -720,6 +756,8 @@ void HTMLAnchorElement::PrefetchEventHandler::handleGestureTapDown(Event* event) |
| m_tapDownTimestamp = event->timeStamp(); |
| HistogramSupport::histogramEnumeration("MouseEventPrefetch.TapDowns", 0, 2); |
| + |
| + prefetch(WebKit::WebPreconnectMotivationLinkTapDown); |
| } |
| void HTMLAnchorElement::PrefetchEventHandler::handleClick(Event* event) |
| @@ -753,4 +791,43 @@ void HTMLAnchorElement::PrefetchEventHandler::handleClick(Event* event) |
| reset(); |
| } |
| +bool HTMLAnchorElement::PrefetchEventHandler::shouldPrefetch(const KURL& url) |
| +{ |
| + Document* doc = m_anchorElement->document(); |
|
abarth-chromium
2013/05/24 05:58:12
doc -> document (please use complete words in vari
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| + if (!doc) |
| + return false; |
| + |
| + // is valid url? |
|
abarth-chromium
2013/05/24 05:58:12
We prefer skipping these sorts of comments. Good
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| + if (!doc->securityOrigin()->canDisplay(url)) |
| + return false; |
| + |
| + // is same url w/ fragment id? |
| + if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(doc->url(), url)) |
| + return false; |
| + |
| + Frame* frame = doc->frame(); |
| + if (!frame) |
| + return false; |
| + |
| + // is creating new window/tab? |
| + // Note: This is avoided because creating new window/tab |
| + // may require user approval interaction. |
| + String targetStr = m_anchorElement->target(); |
|
abarth-chromium
2013/05/24 05:58:12
targetStr -> target (The "str" postfix isn't a com
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| + if (!targetStr.isEmpty() && !frame->loader()->findFrameForNavigation(targetStr)) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +void HTMLAnchorElement::PrefetchEventHandler::prefetch( |
| + WebKit::WebPreconnectMotivation motivation) |
|
abarth-chromium
2013/05/24 05:58:12
Please combine this line with the previous line.
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| +{ |
| + KURL url = m_anchorElement->href(); |
|
abarth-chromium
2013/05/24 05:58:12
KURL -> const KURL&
kouhei (in TOK)
2013/05/24 06:17:10
Done.
|
| + |
| + if (!shouldPrefetch(url)) |
| + return; |
| + |
| + preconnectToURL(url, motivation); |
| +} |
| + |
| } |