Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / performance / PerformanceEventTiming.h
blob3f7bf7e3092287799d2cf7c729b407d6b26edfd2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PerformanceEventTiming_h___
8 #define mozilla_dom_PerformanceEventTiming_h___
10 #include "mozilla/dom/PerformanceEntry.h"
11 #include "mozilla/EventForwards.h"
12 #include "nsRFPService.h"
13 #include "Performance.h"
14 #include "nsIWeakReferenceUtils.h"
15 #include "nsINode.h"
17 namespace mozilla {
18 class WidgetEvent;
19 namespace dom {
21 class PerformanceEventTiming final
22 : public PerformanceEntry,
23 public LinkedListElement<RefPtr<PerformanceEventTiming>> {
24 public:
25 NS_DECL_ISUPPORTS_INHERITED
27 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PerformanceEventTiming,
28 PerformanceEntry)
30 static already_AddRefed<PerformanceEventTiming> TryGenerateEventTiming(
31 const EventTarget* aTarget, const WidgetEvent* aEvent);
33 already_AddRefed<PerformanceEventTiming> Clone() {
34 RefPtr<PerformanceEventTiming> eventTiming =
35 new PerformanceEventTiming(*this);
36 return eventTiming.forget();
39 JSObject* WrapObject(JSContext* cx,
40 JS::Handle<JSObject*> aGivenProto) override;
42 DOMHighResTimeStamp ProcessingStart() const {
43 if (mCachedProcessingStart.isNothing()) {
44 mCachedProcessingStart.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
45 mProcessingStart, mPerformance->GetRandomTimelineSeed(),
46 mPerformance->IsSystemPrincipal(),
47 mPerformance->CrossOriginIsolated()));
49 return mCachedProcessingStart.value();
52 DOMHighResTimeStamp ProcessingEnd() const {
53 if (mCachedProcessingEnd.isNothing()) {
54 mCachedProcessingEnd.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
55 mProcessingEnd, mPerformance->GetRandomTimelineSeed(),
56 mPerformance->IsSystemPrincipal(),
57 mPerformance->CrossOriginIsolated()));
59 return mCachedProcessingEnd.value();
62 bool Cancelable() const { return mCancelable; }
64 nsINode* GetTarget() const;
66 void SetDuration(const DOMHighResTimeStamp aDuration) {
67 mDuration = aDuration;
70 // nsRFPService::ReduceTimePrecisionAsMSecs might causes
71 // some memory overhead, using the raw timestamp internally
72 // to avoid calling in unnecessarily.
73 DOMHighResTimeStamp RawDuration() const { return mDuration; }
75 DOMHighResTimeStamp Duration() const override {
76 if (mCachedDuration.isNothing()) {
77 mCachedDuration.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
78 mDuration, mPerformance->GetRandomTimelineSeed(),
79 mPerformance->IsSystemPrincipal(),
80 mPerformance->CrossOriginIsolated()));
82 return mCachedDuration.value();
85 // Similar as RawDuration; Used to avoid calling
86 // nsRFPService::ReduceTimePrecisionAsMSecs unnecessarily.
87 DOMHighResTimeStamp RawStartTime() const { return mStartTime; }
89 DOMHighResTimeStamp StartTime() const override {
90 if (mCachedStartTime.isNothing()) {
91 mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
92 mStartTime, mPerformance->GetRandomTimelineSeed(),
93 mPerformance->IsSystemPrincipal(),
94 mPerformance->CrossOriginIsolated()));
96 return mCachedStartTime.value();
99 bool ShouldAddEntryToBuffer(double aDuration) const;
100 bool ShouldAddEntryToObserverBuffer(PerformanceObserverInit&) const override;
102 void BufferEntryIfNeeded() override;
104 void FinalizeEventTiming(EventTarget* aTarget);
106 EventMessage GetMessage() const { return mMessage; }
108 private:
109 PerformanceEventTiming(Performance* aPerformance, const nsAString& aName,
110 const TimeStamp& aStartTime, bool aIsCacelable,
111 EventMessage aMessage);
113 PerformanceEventTiming(const PerformanceEventTiming& aEventTimingEntry);
115 ~PerformanceEventTiming() = default;
117 // Perform the get an element algorithm
118 nsINode* GetAnElement(nsINode* aTarget, const Document* aDocument);
120 RefPtr<Performance> mPerformance;
122 DOMHighResTimeStamp mProcessingStart;
123 mutable Maybe<DOMHighResTimeStamp> mCachedProcessingStart;
125 DOMHighResTimeStamp mProcessingEnd;
126 mutable Maybe<DOMHighResTimeStamp> mCachedProcessingEnd;
128 nsWeakPtr mTarget;
130 DOMHighResTimeStamp mStartTime;
131 mutable Maybe<DOMHighResTimeStamp> mCachedStartTime;
133 DOMHighResTimeStamp mDuration;
134 mutable Maybe<DOMHighResTimeStamp> mCachedDuration;
136 bool mCancelable;
138 EventMessage mMessage;
140 } // namespace dom
141 } // namespace mozilla
143 #endif