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

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

Issue 2000063005: [WIP] Speculatively launch Service Workers on mouse/touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
42 #include "wtf/CurrentTime.h"
40 43
41 namespace blink { 44 namespace blink {
42 45
43 using namespace HTMLNames; 46 using namespace HTMLNames;
44 47
48 class HTMLAnchorElement::NavigationHintSender : public GarbageCollected<HTMLAnch orElement::NavigationHintSender> {
49 public:
50 static NavigationHintSender* create(HTMLAnchorElement* anchorElement)
51 {
52 return new NavigationHintSender(anchorElement);
53 }
54 void handleEvent(Event*);
55
56 DECLARE_VIRTUAL_TRACE();
57 DECLARE_VIRTUAL_TRACE_WRAPPERS();
58
59 private:
60 explicit NavigationHintSender(HTMLAnchorElement*);
61 bool shouldSendNavigationHint() const;
62 void maybeSendNavigationHint(WebNavigationHintType);
63
64 Member<HTMLAnchorElement> m_anchorElement;
65 };
66
67 void HTMLAnchorElement::NavigationHintSender::handleEvent(Event* event)
68 {
69 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton)
70 maybeSendNavigationHint(WebNavigationHintType::LinkMouseDown);
71 else if (event->type() == EventTypeNames::gesturetapunconfirmed)
72 maybeSendNavigationHint(WebNavigationHintType::LinkTapUnconfirmed);
73 else if (event->type() == EventTypeNames::gestureshowpress)
74 maybeSendNavigationHint(WebNavigationHintType::LinkTapDown);
75 }
76
77 DEFINE_TRACE(HTMLAnchorElement::NavigationHintSender)
78 {
79 visitor->trace(m_anchorElement);
80 }
81
82 DEFINE_TRACE_WRAPPERS(HTMLAnchorElement::NavigationHintSender)
83 {
84 visitor->traceWrappers(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 if (!url.protocolIsInHTTPFamily())
96 return false;
97 Document& document = m_anchorElement->document();
98 if (!document.frame())
99 return false;
100 if (!document.getSecurityOrigin()->canDisplay(url))
101 return false;
102 if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(document. url(), url))
103 return false;
104
105 // If the opener is to be suppressed and the target frame name is set,
106 // WebContentsImpl::CreateNewWindow() will create a new process when the
107 // user click the anchor element. In such case we shouldn't start the
108 // Service Worker not to keep the current process running.
109 const bool openerSuppressed = m_anchorElement->hasRel(RelationNoReferrer) || m_anchorElement->hasRel(RelationNoOpener);
110 if (openerSuppressed && !m_anchorElement->getAttribute(targetAttr).isEmpty() )
111 return false;
112 return true;
113 }
114
115 void HTMLAnchorElement::NavigationHintSender::maybeSendNavigationHint(WebNavigat ionHintType type)
116 {
117 if (!shouldSendNavigationHint())
118 return;
119 blink::sendNavigationHint(m_anchorElement->href(), type);
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
145 DEFINE_TRACE_WRAPPERS(HTMLAnchorElement)
146 {
147 visitor->traceWrappers(m_navigationHintsender);
148 HTMLElement::traceWrappers(visitor);
149 }
150
62 bool HTMLAnchorElement::supportsFocus() const 151 bool HTMLAnchorElement::supportsFocus() const
63 { 152 {
64 if (hasEditableStyle()) 153 if (hasEditableStyle())
65 return HTMLElement::supportsFocus(); 154 return HTMLElement::supportsFocus();
66 // If not a link we should still be able to focus the element if it has tabI ndex. 155 // If not a link we should still be able to focus the element if it has tabI ndex.
67 return isLink() || HTMLElement::supportsFocus(); 156 return isLink() || HTMLElement::supportsFocus();
68 } 157 }
69 158
70 bool HTMLAnchorElement::matchesEnabledPseudoClass() const 159 bool HTMLAnchorElement::matchesEnabledPseudoClass() const
71 { 160 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 244
156 void HTMLAnchorElement::defaultEventHandler(Event* event) 245 void HTMLAnchorElement::defaultEventHandler(Event* event)
157 { 246 {
158 if (isLink()) { 247 if (isLink()) {
159 if (focused() && isEnterKeyKeydownEvent(event) && isLiveLink()) { 248 if (focused() && isEnterKeyKeydownEvent(event) && isLiveLink()) {
160 event->setDefaultHandled(); 249 event->setDefaultHandled();
161 dispatchSimulatedClick(event); 250 dispatchSimulatedClick(event);
162 return; 251 return;
163 } 252 }
164 253
254 if (RuntimeEnabledFeatures::speculativeLaunchServiceWorkerEnabled())
255 navigationHintSender()->handleEvent(event);
256
165 if (isLinkClick(event) && isLiveLink()) { 257 if (isLinkClick(event) && isLiveLink()) {
166 handleClick(event); 258 handleClick(event);
167 return; 259 return;
168 } 260 }
169 } 261 }
170 262
171 HTMLElement::defaultEventHandler(event); 263 HTMLElement::defaultEventHandler(event);
172 } 264 }
173 265
174 void HTMLAnchorElement::setActive(bool down) 266 void HTMLAnchorElement::setActive(bool down)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return isLink(); 481 return isLink();
390 } 482 }
391 483
392 Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode * insertionPoint) 484 Node::InsertionNotificationRequest HTMLAnchorElement::insertedInto(ContainerNode * insertionPoint)
393 { 485 {
394 InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPo int); 486 InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPo int);
395 logAddElementIfIsolatedWorldAndInDocument("a", hrefAttr); 487 logAddElementIfIsolatedWorldAndInDocument("a", hrefAttr);
396 return request; 488 return request;
397 } 489 }
398 490
491 HTMLAnchorElement::NavigationHintSender* HTMLAnchorElement::navigationHintSender ()
492 {
493 if (!m_navigationHintsender)
494 m_navigationHintsender = NavigationHintSender::create(this);
495 return m_navigationHintsender;
496 }
497
399 } // namespace blink 498 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLAnchorElement.h ('k') | third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698