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

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 DECLARE_VIRTUAL_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())
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))
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.
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
139 DEFINE_TRACE_WRAPPERS(HTMLAnchorElement)
kouhei (in TOK) 2016/06/09 08:01:19 ditto
horo 2016/06/09 08:20:46 Done.
140 {
141 visitor->traceWrappers(m_navigationHintsender);
142 HTMLElement::traceWrappers(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

Powered by Google App Engine
This is Rietveld 408576698