Index: Source/core/events/Event.cpp |
diff --git a/Source/core/events/Event.cpp b/Source/core/events/Event.cpp |
index c49e49e9f9641b5f33381901bf08b78aa697177b..7cd8010c7b578a590007cd2a8eecbd2f8d8b3a9c 100644 |
--- a/Source/core/events/Event.cpp |
+++ b/Source/core/events/Event.cpp |
@@ -33,6 +33,16 @@ |
namespace blink { |
+static const double millisPerSecond = 1000.0; |
+ |
+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.
|
+{ |
+ // Reduce the resolution to 5us similar to Performance.now() to prevent |
+ // precise timing attacks. |
+ static const double precision = 0.005 / millisPerSecond; // in seconds |
+ return floor(monotonicallyIncreasingTime() / precision) * precision; |
+} |
+ |
Event::Event() |
: Event("", false, false) |
{ |
@@ -51,7 +61,7 @@ Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableAr |
, m_eventPhase(0) |
, m_currentTarget(nullptr) |
, m_createTime(convertSecondsToDOMTimeStamp(currentTime())) |
- , m_uiCreateTime(0) |
+ , m_uiCreateTime(monotonicTimeWithSafePrecision()) |
{ |
} |
@@ -257,6 +267,30 @@ EventTarget* Event::currentTarget() const |
return m_currentTarget.get(); |
} |
+double Event::timeStamp() const |
+{ |
+ double timeStamp = 0; |
+ // TODO(majidvp): Get rid of m_createTime once the flag is enabled by default; |
+ if (UNLIKELY(RuntimeEnabledFeatures::hiResEventTimeStampEnabled())) { |
+ // Only expose monotonic time after changing its origin to its target |
+ // document's time origin. |
+ // TODO(majidvp): We do not reduce precision of user generated |
+ // events here but perhaps we should to avoid any accidental leakage of |
+ // 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
|
+ if (m_target && m_target->toNode()) |
+ timeStamp = m_target->toNode()->document().monotonicTimeToZeroBasedDocumentTime(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
|
+ } else { |
+ timeStamp = m_createTime; |
+ } |
+ |
+ return timeStamp; |
+} |
+ |
+double Event::timeStampForPlatformInSeconds() const |
+{ |
+ return RuntimeEnabledFeatures::hiResEventTimeStampEnabled() ? m_uiCreateTime : (m_createTime / millisPerSecond); |
+} |
+ |
DEFINE_TRACE(Event) |
{ |
visitor->trace(m_currentTarget); |