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

Side by Side Diff: Source/core/events/Event.cpp

Issue 1352523002: Use high precision timestamp for Event.timestamp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use m_target to find event document Created 5 years, 3 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) 2001 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 15 matching lines...) Expand all
26 #include "core/dom/StaticNodeList.h" 26 #include "core/dom/StaticNodeList.h"
27 #include "core/events/EventDispatchMediator.h" 27 #include "core/events/EventDispatchMediator.h"
28 #include "core/events/EventTarget.h" 28 #include "core/events/EventTarget.h"
29 #include "core/frame/OriginsUsingFeatures.h" 29 #include "core/frame/OriginsUsingFeatures.h"
30 #include "core/frame/UseCounter.h" 30 #include "core/frame/UseCounter.h"
31 #include "core/svg/SVGElement.h" 31 #include "core/svg/SVGElement.h"
32 #include "wtf/CurrentTime.h" 32 #include "wtf/CurrentTime.h"
33 33
34 namespace blink { 34 namespace blink {
35 35
36 static const double millisPerSecond = 1000.0;
37
38 static double monotonicTimeWithSafePrecision()
Rick Byers 2015/09/18 15:56:32 Can you share this logic with the usage in Perform
majidvp 2015/09/18 17:43:33 Acknowledged.
39 {
40 // Reduce the resolution to 5us similar to Performance.now() to prevent
41 // precise timing attacks.
42 static const double precision = 0.005 / millisPerSecond; // in seconds
43 return floor(monotonicallyIncreasingTime() / precision) * precision;
44 }
45
36 Event::Event() 46 Event::Event()
37 : Event("", false, false) 47 : Event("", false, false)
38 { 48 {
39 } 49 }
40 50
41 Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableAr g) 51 Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableAr g)
42 : m_type(eventType) 52 : m_type(eventType)
43 , m_canBubble(canBubbleArg) 53 , m_canBubble(canBubbleArg)
44 , m_cancelable(cancelableArg) 54 , m_cancelable(cancelableArg)
45 , m_propagationStopped(false) 55 , m_propagationStopped(false)
46 , m_immediatePropagationStopped(false) 56 , m_immediatePropagationStopped(false)
47 , m_defaultPrevented(false) 57 , m_defaultPrevented(false)
48 , m_defaultHandled(false) 58 , m_defaultHandled(false)
49 , m_cancelBubble(false) 59 , m_cancelBubble(false)
50 , m_isTrusted(false) 60 , m_isTrusted(false)
51 , m_eventPhase(0) 61 , m_eventPhase(0)
52 , m_currentTarget(nullptr) 62 , m_currentTarget(nullptr)
53 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 63 , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
54 , m_uiCreateTime(0) 64 , m_uiCreateTime(monotonicTimeWithSafePrecision())
55 { 65 {
56 } 66 }
57 67
58 Event::Event(const AtomicString& eventType, const EventInit& initializer) 68 Event::Event(const AtomicString& eventType, const EventInit& initializer)
59 : Event(eventType, initializer.bubbles(), initializer.cancelable()) 69 : Event(eventType, initializer.bubbles(), initializer.cancelable())
60 { 70 {
61 } 71 }
62 72
63 Event::~Event() 73 Event::~Event()
64 { 74 {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (!m_currentTarget) 260 if (!m_currentTarget)
251 return 0; 261 return 0;
252 Node* node = m_currentTarget->toNode(); 262 Node* node = m_currentTarget->toNode();
253 if (node && node->isSVGElement()) { 263 if (node && node->isSVGElement()) {
254 if (SVGElement* svgElement = toSVGElement(node)->correspondingElement()) 264 if (SVGElement* svgElement = toSVGElement(node)->correspondingElement())
255 return svgElement; 265 return svgElement;
256 } 266 }
257 return m_currentTarget.get(); 267 return m_currentTarget.get();
258 } 268 }
259 269
270 double Event::timeStamp() const
271 {
272 double timeStamp = 0;
273 // TODO(majidvp): Get rid of m_createTime once the flag is enabled by defaul t;
274 if (UNLIKELY(RuntimeEnabledFeatures::hiResEventTimeStampEnabled())) {
275 // Only expose monotonic time after changing its origin to its target
276 // document's time origin.
277 // TODO(majidvp): We do not reduce precision of user generated
278 // events here but perhaps we should to avoid any accidental leakage of
279 // hiResTime
Rick Byers 2015/09/18 16:17:29 By user-generated you mean real events, not script
majidvp 2015/09/18 17:43:33 User generated = real events. It will definitely b
Rick Byers 2015/09/21 15:44:37 5us is really short, in practice the variability i
280 if (m_target && m_target->toNode())
281 timeStamp = m_target->toNode()->document().monotonicTimeToZeroBased DocumentTime(m_uiCreateTime) * millisPerSecond;
dtapuska 2015/09/18 16:04:42 How does this work when the m_currentNode and the
Rick Byers 2015/09/18 16:17:29 Event::m_uiCreateTime is poorly defined (and perha
Rick Byers 2015/09/18 16:17:29 Does the conversion really have to be done based o
majidvp 2015/09/18 17:43:33 I agree that the target node's document may not be
Rick Byers 2015/09/21 15:44:37 Ah, sorry! I assumed EventInitDict had a timestam
282 } else {
283 timeStamp = m_createTime;
284 }
285
286 return timeStamp;
287 }
288
289 double Event::timeStampForPlatformInSeconds() const
290 {
291 return RuntimeEnabledFeatures::hiResEventTimeStampEnabled() ? m_uiCreateTime : (m_createTime / millisPerSecond);
292 }
293
260 DEFINE_TRACE(Event) 294 DEFINE_TRACE(Event)
261 { 295 {
262 visitor->trace(m_currentTarget); 296 visitor->trace(m_currentTarget);
263 visitor->trace(m_target); 297 visitor->trace(m_target);
264 visitor->trace(m_underlyingEvent); 298 visitor->trace(m_underlyingEvent);
265 visitor->trace(m_eventPath); 299 visitor->trace(m_eventPath);
266 } 300 }
267 301
268 } // namespace blink 302 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698