Index: third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp b/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp |
index e74548006ea6219402dacb1a555a086e67eb9440..5fa836fd6d81ccb2a32b28453c8872075cf7a1e7 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp |
@@ -35,13 +35,83 @@ |
#include "core/loader/FrameLoaderClient.h" |
#include "core/loader/PingLoader.h" |
#include "core/page/ChromeClient.h" |
+#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/network/NetworkHints.h" |
+#include "platform/weborigin/SchemeRegistry.h" |
#include "platform/weborigin/SecurityPolicy.h" |
+#include "public/platform/WebNavigationHintType.h" |
namespace blink { |
using namespace HTMLNames; |
+class HTMLAnchorElement::NavigationHintSender : public GarbageCollected<HTMLAnchorElement::NavigationHintSender> { |
kinuko
2016/06/16 06:14:31
Now it looks this class seems to exist primarily f
horo
2016/06/16 07:02:14
Added "ForServiceWorkerSender".
|
+public: |
+ static NavigationHintSender* create(HTMLAnchorElement* anchorElement) |
+ { |
+ return new NavigationHintSender(anchorElement); |
+ } |
+ void handleEvent(Event*); |
+ |
+ DECLARE_VIRTUAL_TRACE(); |
+ |
+private: |
+ explicit NavigationHintSender(HTMLAnchorElement*); |
+ bool shouldSendNavigationHintForServiceWorker() const; |
+ void maybeSendNavigationHintForServiceWorker(WebNavigationHintType); |
+ |
+ Member<HTMLAnchorElement> m_anchorElement; |
+}; |
+ |
+void HTMLAnchorElement::NavigationHintSender::handleEvent(Event* event) |
+{ |
+ if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) |
+ maybeSendNavigationHintForServiceWorker(WebNavigationHintType::LinkMouseDown); |
+ else if (event->type() == EventTypeNames::gesturetapunconfirmed) |
+ maybeSendNavigationHintForServiceWorker(WebNavigationHintType::LinkTapUnconfirmed); |
+ else if (event->type() == EventTypeNames::gestureshowpress) |
+ maybeSendNavigationHintForServiceWorker(WebNavigationHintType::LinkTapDown); |
+} |
+ |
+DEFINE_TRACE(HTMLAnchorElement::NavigationHintSender) |
+{ |
+ visitor->trace(m_anchorElement); |
+} |
+ |
+HTMLAnchorElement::NavigationHintSender::NavigationHintSender(HTMLAnchorElement* anchorElement) |
+ : m_anchorElement(anchorElement) |
+{ |
+} |
+ |
+bool HTMLAnchorElement::NavigationHintSender::shouldSendNavigationHintForServiceWorker() const |
+{ |
+ const KURL& url = m_anchorElement->href(); |
+ if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(url.protocol())) |
+ return false; |
+ |
+ Document& document = m_anchorElement->document(); |
+ // If the element was detached from the frame, handleClick() doesn't cause |
+ // the navigation. |
+ if (!document.frame()) |
+ return false; |
+ |
+ // When the user clicks a link which is to the current document with a hash, |
+ // the network request is not fetched. So we don't need to start the Service |
+ // Worker. |
+ if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(document.url(), url)) |
+ return false; |
+ |
+ return true; |
+} |
+ |
+void HTMLAnchorElement::NavigationHintSender::maybeSendNavigationHintForServiceWorker(WebNavigationHintType type) |
+{ |
+ if (!shouldSendNavigationHintForServiceWorker()) |
+ return; |
+ |
+ // TODO(horo): Send the navigation hint message to the browser process. |
+} |
+ |
HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& document) |
: HTMLElement(tagName, document) |
, m_linkRelations(0) |
@@ -59,6 +129,12 @@ HTMLAnchorElement::~HTMLAnchorElement() |
{ |
} |
+DEFINE_TRACE(HTMLAnchorElement) |
+{ |
+ visitor->trace(m_navigationHintsender); |
+ HTMLElement::trace(visitor); |
+} |
+ |
bool HTMLAnchorElement::supportsFocus() const |
{ |
if (hasEditableStyle()) |
@@ -162,6 +238,10 @@ void HTMLAnchorElement::defaultEventHandler(Event* event) |
return; |
} |
+ // TODO(horo): Call NavigationHintSender::handleEvent() when |
+ // SpeculativeLaunchServiceWorker feature is enabled. |
+ // ensureNavigationHintSender()->handleEvent(event); |
+ |
if (isLinkClick(event) && isLiveLink()) { |
handleClick(event); |
return; |
@@ -396,4 +476,11 @@ Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode |
return request; |
} |
+HTMLAnchorElement::NavigationHintSender* HTMLAnchorElement::ensureNavigationHintSender() |
+{ |
+ if (!m_navigationHintSender) |
+ m_navigationHintSender = NavigationHintSender::create(this); |
+ return m_navigationHintSender; |
+} |
+ |
} // namespace blink |