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

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: remove TRACE_WRAPPERS 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
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 17 matching lines...) Expand all
28 #include "core/frame/FrameHost.h" 28 #include "core/frame/FrameHost.h"
29 #include "core/frame/Settings.h" 29 #include "core/frame/Settings.h"
30 #include "core/frame/UseCounter.h" 30 #include "core/frame/UseCounter.h"
31 #include "core/html/HTMLImageElement.h" 31 #include "core/html/HTMLImageElement.h"
32 #include "core/html/parser/HTMLParserIdioms.h" 32 #include "core/html/parser/HTMLParserIdioms.h"
33 #include "core/layout/LayoutBox.h" 33 #include "core/layout/LayoutBox.h"
34 #include "core/loader/FrameLoadRequest.h" 34 #include "core/loader/FrameLoadRequest.h"
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/RuntimeEnabledFeatures.h"
38 #include "platform/network/NetworkHints.h" 39 #include "platform/network/NetworkHints.h"
39 #include "platform/weborigin/SecurityPolicy.h" 40 #include "platform/weborigin/SecurityPolicy.h"
41 #include "public/platform/WebNavigationHintType.h"
40 42
41 namespace blink { 43 namespace blink {
42 44
43 using namespace HTMLNames; 45 using namespace HTMLNames;
44 46
47 class HTMLAnchorElement::NavigationHintSender : public GarbageCollected<HTMLAnch orElement::NavigationHintSender> {
48 public:
49 static NavigationHintSender* create(HTMLAnchorElement* anchorElement)
50 {
51 return new NavigationHintSender(anchorElement);
52 }
53 void handleEvent(Event*);
54
55 DECLARE_VIRTUAL_TRACE();
56
57 private:
58 explicit NavigationHintSender(HTMLAnchorElement*);
59 bool shouldSendNavigationHint() const;
60 void maybeSendNavigationHint(WebNavigationHintType);
61
62 Member<HTMLAnchorElement> m_anchorElement;
63 };
64
65 void HTMLAnchorElement::NavigationHintSender::handleEvent(Event* event)
66 {
67 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton)
68 maybeSendNavigationHint(WebNavigationHintType::LinkMouseDown);
69 else if (event->type() == EventTypeNames::gesturetapunconfirmed)
70 maybeSendNavigationHint(WebNavigationHintType::LinkTapUnconfirmed);
71 else if (event->type() == EventTypeNames::gestureshowpress)
72 maybeSendNavigationHint(WebNavigationHintType::LinkTapDown);
73 }
74
75 DEFINE_TRACE(HTMLAnchorElement::NavigationHintSender)
76 {
77 visitor->trace(m_anchorElement);
78 }
79
80 HTMLAnchorElement::NavigationHintSender::NavigationHintSender(HTMLAnchorElement* anchorElement)
81 : m_anchorElement(anchorElement)
82 {
83 }
84
85 bool HTMLAnchorElement::NavigationHintSender::shouldSendNavigationHint() const
86 {
87 const KURL& url = m_anchorElement->href();
88 if (!url.protocolIsInHTTPFamily())
falken 2016/06/09 13:24:16 Why is it restricted to HTTP? Is this because the
horo 2016/06/14 11:03:14 Done.
89 return false;
90 Document& document = m_anchorElement->document();
91 if (!document.frame())
92 return false;
93 if (!document.getSecurityOrigin()->canDisplay(url))
94 return false;
95 if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(document. url(), url))
falken 2016/06/09 13:24:16 Is this avoiding the hint if the link is to curren
horo 2016/06/14 11:03:14 When the user clicks a link which is to the curren
96 return false;
97
98 // If the opener is to be suppressed and the target frame name is set,
99 // WebContentsImpl::CreateNewWindow() will create a new process when the
100 // user click the anchor element. In such case we shouldn't start the
101 // Service Worker not to keep the current process running.
falken 2016/06/09 13:24:16 Ah yes this code is pretty SW-specific but the nam
102 const bool openerSuppressed = m_anchorElement->hasRel(RelationNoReferrer) || m_anchorElement->hasRel(RelationNoOpener);
103 if (openerSuppressed && !m_anchorElement->getAttribute(targetAttr).isEmpty() )
104 return false;
105 return true;
106 }
107
108 void HTMLAnchorElement::NavigationHintSender::maybeSendNavigationHint(WebNavigat ionHintType type)
109 {
110 if (!shouldSendNavigationHint())
111 return;
112
113 // TODO(horo): Send the navigation hint message to the browser process.
114 }
115
45 HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& doc ument) 116 HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& doc ument)
46 : HTMLElement(tagName, document) 117 : HTMLElement(tagName, document)
47 , m_linkRelations(0) 118 , m_linkRelations(0)
48 , m_cachedVisitedLinkHash(0) 119 , m_cachedVisitedLinkHash(0)
49 , m_wasFocusedByMouse(false) 120 , m_wasFocusedByMouse(false)
50 { 121 {
51 } 122 }
52 123
53 HTMLAnchorElement* HTMLAnchorElement::create(Document& document) 124 HTMLAnchorElement* HTMLAnchorElement::create(Document& document)
54 { 125 {
55 return new HTMLAnchorElement(aTag, document); 126 return new HTMLAnchorElement(aTag, document);
56 } 127 }
57 128
58 HTMLAnchorElement::~HTMLAnchorElement() 129 HTMLAnchorElement::~HTMLAnchorElement()
59 { 130 {
60 } 131 }
61 132
133 DEFINE_TRACE(HTMLAnchorElement)
134 {
135 visitor->trace(m_navigationHintsender);
136 HTMLElement::trace(visitor);
137 }
138
62 bool HTMLAnchorElement::supportsFocus() const 139 bool HTMLAnchorElement::supportsFocus() const
63 { 140 {
64 if (hasEditableStyle()) 141 if (hasEditableStyle())
65 return HTMLElement::supportsFocus(); 142 return HTMLElement::supportsFocus();
66 // If not a link we should still be able to focus the element if it has tabI ndex. 143 // If not a link we should still be able to focus the element if it has tabI ndex.
67 return isLink() || HTMLElement::supportsFocus(); 144 return isLink() || HTMLElement::supportsFocus();
68 } 145 }
69 146
70 bool HTMLAnchorElement::matchesEnabledPseudoClass() const 147 bool HTMLAnchorElement::matchesEnabledPseudoClass() const
71 { 148 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 232
156 void HTMLAnchorElement::defaultEventHandler(Event* event) 233 void HTMLAnchorElement::defaultEventHandler(Event* event)
157 { 234 {
158 if (isLink()) { 235 if (isLink()) {
159 if (focused() && isEnterKeyKeydownEvent(event) && isLiveLink()) { 236 if (focused() && isEnterKeyKeydownEvent(event) && isLiveLink()) {
160 event->setDefaultHandled(); 237 event->setDefaultHandled();
161 dispatchSimulatedClick(event); 238 dispatchSimulatedClick(event);
162 return; 239 return;
163 } 240 }
164 241
242 // TODO(horo): Call NavigationHintSender::handleEvent() when
243 // SpeculativeLaunchServiceWorker feature is enabled.
244 // ensureNavigationHintSender()->handleEvent(event);
245
165 if (isLinkClick(event) && isLiveLink()) { 246 if (isLinkClick(event) && isLiveLink()) {
166 handleClick(event); 247 handleClick(event);
167 return; 248 return;
168 } 249 }
169 } 250 }
170 251
171 HTMLElement::defaultEventHandler(event); 252 HTMLElement::defaultEventHandler(event);
172 } 253 }
173 254
174 void HTMLAnchorElement::setActive(bool down) 255 void HTMLAnchorElement::setActive(bool down)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return isLink(); 470 return isLink();
390 } 471 }
391 472
392 Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode * insertionPoint) 473 Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode * insertionPoint)
393 { 474 {
394 InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPo int); 475 InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPo int);
395 logAddElementIfIsolatedWorldAndInDocument("a", hrefAttr); 476 logAddElementIfIsolatedWorldAndInDocument("a", hrefAttr);
396 return request; 477 return request;
397 } 478 }
398 479
480 HTMLAnchorElement::NavigationHintSender* HTMLAnchorElement::ensureNavigationHint Sender()
481 {
482 if (!m_navigationHintsender)
483 m_navigationHintsender = NavigationHintSender::create(this);
484 return m_navigationHintsender;
485 }
486
399 } // namespace blink 487 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698