Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp

Issue 2043863003: Speculatively launch Service Workers on mouse/touch events. [1/5] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use DECLARE_TRACE Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLAnchorElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Simon Hausmann <hausmann@kde.org> 4 * (C) 2000 Simon Hausmann <hausmann@kde.org>
5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
6 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 24 matching lines...) Expand all
35 #include "core/loader/FrameLoaderClient.h" 35 #include "core/loader/FrameLoaderClient.h"
36 #include "core/loader/PingLoader.h" 36 #include "core/loader/PingLoader.h"
37 #include "core/page/ChromeClient.h" 37 #include "core/page/ChromeClient.h"
38 #include "platform/network/NetworkHints.h" 38 #include "platform/network/NetworkHints.h"
39 #include "platform/weborigin/SecurityPolicy.h" 39 #include "platform/weborigin/SecurityPolicy.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 using namespace HTMLNames; 43 using namespace HTMLNames;
44 44
45 class HTMLAnchorElement::NavigationHintSender : public GarbageCollected<HTMLAnch orElement::NavigationHintSender> {
46 public:
47 // TODO(horo): Move WebNavigationHintType to public/ directory.
48 enum class WebNavigationHintType {
49 Unknown,
50 LinkMouseDown,
51 LinkTapUnconfirmed,
52 LinkTapDown,
53 Last = LinkTapDown
54 };
55
56 static NavigationHintSender* create(HTMLAnchorElement* anchorElement)
57 {
58 return new NavigationHintSender(anchorElement);
59 }
60 void handleEvent(Event*);
61
62 DECLARE_TRACE();
63
64 private:
65 explicit NavigationHintSender(HTMLAnchorElement*);
66 bool shouldSendNavigationHint() const;
67 void maybeSendNavigationHint(WebNavigationHintType);
68
69 Member<HTMLAnchorElement> m_anchorElement;
70 };
71
72 void HTMLAnchorElement::NavigationHintSender::handleEvent(Event* event)
73 {
74 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton)
75 maybeSendNavigationHint(WebNavigationHintType::LinkMouseDown);
76 else if (event->type() == EventTypeNames::gesturetapunconfirmed)
77 maybeSendNavigationHint(WebNavigationHintType::LinkTapUnconfirmed);
78 else if (event->type() == EventTypeNames::gestureshowpress)
79 maybeSendNavigationHint(WebNavigationHintType::LinkTapDown);
80 }
81
82 DEFINE_TRACE(HTMLAnchorElement::NavigationHintSender)
83 {
84 visitor->trace(m_anchorElement);
85 }
86
87 HTMLAnchorElement::NavigationHintSender::NavigationHintSender(HTMLAnchorElement* anchorElement)
88 : m_anchorElement(anchorElement)
89 {
90 }
91
92 bool HTMLAnchorElement::NavigationHintSender::shouldSendNavigationHint() const
93 {
94 const KURL& url = m_anchorElement->href();
95 // Currently the navigation hint only supports HTTP and HTTPS.
96 if (!url.protocolIsInHTTPFamily())
97 return false;
98
99 Document& document = m_anchorElement->document();
100 // If the element was detached from the frame, handleClick() doesn't cause
101 // the navigation.
102 if (!document.frame())
103 return false;
104
105 // When the user clicks a link which is to the current document with a hash,
106 // the network request is not fetched. So we don't send the navigation hint
107 // to the browser process.
108 if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(document. url(), url))
109 return false;
110
111 return true;
112 }
113
114 void HTMLAnchorElement::NavigationHintSender::maybeSendNavigationHint(WebNavigat ionHintType type)
115 {
116 if (!shouldSendNavigationHint())
117 return;
118
119 // TODO(horo): Send the navigation hint message to the browser process.
120 }
121
45 HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& doc ument) 122 HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& doc ument)
46 : HTMLElement(tagName, document) 123 : HTMLElement(tagName, document)
47 , m_linkRelations(0) 124 , m_linkRelations(0)
48 , m_cachedVisitedLinkHash(0) 125 , m_cachedVisitedLinkHash(0)
49 , m_wasFocusedByMouse(false) 126 , m_wasFocusedByMouse(false)
50 { 127 {
51 } 128 }
52 129
53 HTMLAnchorElement* HTMLAnchorElement::create(Document& document) 130 HTMLAnchorElement* HTMLAnchorElement::create(Document& document)
54 { 131 {
55 return new HTMLAnchorElement(aTag, document); 132 return new HTMLAnchorElement(aTag, document);
56 } 133 }
57 134
58 HTMLAnchorElement::~HTMLAnchorElement() 135 HTMLAnchorElement::~HTMLAnchorElement()
59 { 136 {
60 } 137 }
61 138
139 DEFINE_TRACE(HTMLAnchorElement)
140 {
141 visitor->trace(m_navigationHintSender);
142 HTMLElement::trace(visitor);
143 }
144
62 bool HTMLAnchorElement::supportsFocus() const 145 bool HTMLAnchorElement::supportsFocus() const
63 { 146 {
64 if (hasEditableStyle()) 147 if (hasEditableStyle())
65 return HTMLElement::supportsFocus(); 148 return HTMLElement::supportsFocus();
66 // If not a link we should still be able to focus the element if it has tabI ndex. 149 // If not a link we should still be able to focus the element if it has tabI ndex.
67 return isLink() || HTMLElement::supportsFocus(); 150 return isLink() || HTMLElement::supportsFocus();
68 } 151 }
69 152
70 bool HTMLAnchorElement::matchesEnabledPseudoClass() const 153 bool HTMLAnchorElement::matchesEnabledPseudoClass() const
71 { 154 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 238
156 void HTMLAnchorElement::defaultEventHandler(Event* event) 239 void HTMLAnchorElement::defaultEventHandler(Event* event)
157 { 240 {
158 if (isLink()) { 241 if (isLink()) {
159 if (focused() && isEnterKeyKeydownEvent(event) && isLiveLink()) { 242 if (focused() && isEnterKeyKeydownEvent(event) && isLiveLink()) {
160 event->setDefaultHandled(); 243 event->setDefaultHandled();
161 dispatchSimulatedClick(event); 244 dispatchSimulatedClick(event);
162 return; 245 return;
163 } 246 }
164 247
248 // TODO(horo): Call NavigationHintSender::handleEvent() when
249 // SpeculativeLaunchServiceWorker feature is enabled.
250 // ensureNavigationHintSender()->handleEvent(event);
251
165 if (isLinkClick(event) && isLiveLink()) { 252 if (isLinkClick(event) && isLiveLink()) {
166 handleClick(event); 253 handleClick(event);
167 return; 254 return;
168 } 255 }
169 } 256 }
170 257
171 HTMLElement::defaultEventHandler(event); 258 HTMLElement::defaultEventHandler(event);
172 } 259 }
173 260
174 void HTMLAnchorElement::setActive(bool down) 261 void HTMLAnchorElement::setActive(bool down)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return isLink(); 476 return isLink();
390 } 477 }
391 478
392 Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode * insertionPoint) 479 Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode * insertionPoint)
393 { 480 {
394 InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPo int); 481 InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPo int);
395 logAddElementIfIsolatedWorldAndInDocument("a", hrefAttr); 482 logAddElementIfIsolatedWorldAndInDocument("a", hrefAttr);
396 return request; 483 return request;
397 } 484 }
398 485
486 HTMLAnchorElement::NavigationHintSender* HTMLAnchorElement::ensureNavigationHint Sender()
487 {
488 if (!m_navigationHintSender)
489 m_navigationHintSender = NavigationHintSender::create(this);
490 return m_navigationHintSender;
491 }
492
399 } // namespace blink 493 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLAnchorElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698