001package Torello.Browser.BrowserAPI;
002
003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
004// Java-HTML Imports
005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
006
007import Torello.Browser.*;
008import Torello.Browser.helper.*;
009import Torello.Browser.JavaScriptAPI.*;
010import Torello.JSON.*;
011
012import Torello.Java.ReadOnly.ReadOnlyList;
013import Torello.Java.ReadOnly.ReadOnlyArrayList;
014
015import Torello.JavaDoc.Annotations.StaticFunctional;
016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg;
017
018
019// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
020// JDK Imports
021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
022
023import javax.json.JsonObject;
024import javax.json.JsonValue;
025
026/**
027 * <SPAN CLASS=COPIEDJDK><B>Reporting of performance timeline events, as specified in
028 * https://w3c.github.io/performance-timeline/#dom-performanceobserver.</B></SPAN>
029 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE>
030 */
031@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE")
032public class PerformanceTimeline
033{
034    // No Pubic Constructors
035    private PerformanceTimeline() { }
036
037
038
039    // ********************************************************************************************
040    // ********************************************************************************************
041    // Basic Types
042    // ********************************************************************************************
043    // ********************************************************************************************
044
045
046    /**
047     * See https://github.com/WICG/LargestContentfulPaint and largest_contentful_paint.idl
048     * 
049     * <EMBED CLASS=globalDefs DATA-DOMAIN=PerformanceTimeline DATA-API=BrowserAPI>
050     */
051    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
052    public static class LargestContentfulPaint
053        extends BaseType<LargestContentfulPaint>
054        implements java.io.Serializable
055    {
056        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
057        protected static final long serialVersionUID = 1;
058
059        private static final NestedHelper<PerformanceTimeline.LargestContentfulPaint> singleton =
060            Torello.Browser.BrowserAPI.NestedHelpers.Types.
061                PerformanceTimeline$$LargestContentfulPaint$$.singleton;
062
063        /** <CODE>[No Description Provided by Google]</CODE> */
064        public final Number renderTime;
065
066        /** <CODE>[No Description Provided by Google]</CODE> */
067        public final Number loadTime;
068
069        /** The number of pixels being painted. */
070        public final Number size;
071
072        /**
073         * The id attribute of the element, if available.
074         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
075         */
076        public final String elementId;
077
078        /**
079         * The URL of the image (may be trimmed).
080         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
081         */
082        public final String url;
083
084        /**
085         * <CODE>[No Description Provided by Google]</CODE>
086         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
087         */
088        public final Integer nodeId;
089
090        /** Constructor.  Please review this class' fields for documentation. */
091        public LargestContentfulPaint(
092                ReadOnlyList<Boolean> isPresent, Number renderTime, Number loadTime, Number size,
093                String elementId, String url, Integer nodeId
094            )
095        {
096            super(singleton, Domains.PerformanceTimeline, "LargestContentfulPaint", 6);
097
098            this.renderTime = renderTime;
099            this.loadTime   = loadTime;
100            this.size       = size;
101            this.elementId  = elementId;
102            this.url        = url;
103            this.nodeId     = nodeId;
104
105            this.isPresent = (isPresent == null)
106                ? singleton.generateIsPresentList(this)
107                : THROWS.check(isPresent, 6, "PerformanceTimeline.LargestContentfulPaint");
108        }
109
110        /** Creates an instance of this class from a {@link JsonObject}.*/
111        public static LargestContentfulPaint fromJSON(JsonObject jo)
112        { return singleton.fromJSON(jo); }
113
114        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
115        public static NestedDescriptor<LargestContentfulPaint> descriptor()
116        { return singleton.descriptor(); }
117    }
118
119    /**
120     * See https://wicg.github.io/layout-instability/#sec-layout-shift and layout_shift.idl
121     * 
122     * <EMBED CLASS=globalDefs DATA-DOMAIN=PerformanceTimeline DATA-API=BrowserAPI>
123     */
124    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
125    public static class LayoutShift
126        extends BaseType<LayoutShift>
127        implements java.io.Serializable
128    {
129        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
130        protected static final long serialVersionUID = 1;
131
132        private static final NestedHelper<PerformanceTimeline.LayoutShift> singleton =
133            Torello.Browser.BrowserAPI.NestedHelpers.Types.
134                PerformanceTimeline$$LayoutShift$$.singleton;
135
136        /** Score increment produced by this event. */
137        public final Number value;
138
139        /** <CODE>[No Description Provided by Google]</CODE> */
140        public final boolean hadRecentInput;
141
142        /** <CODE>[No Description Provided by Google]</CODE> */
143        public final Number lastInputTime;
144
145        /** <CODE>[No Description Provided by Google]</CODE> */
146        public final PerformanceTimeline.LayoutShiftAttribution[] sources;
147
148        /** Constructor.  Please review this class' fields for documentation. */
149        public LayoutShift(
150                ReadOnlyList<Boolean> isPresent, Number value, boolean hadRecentInput,
151                Number lastInputTime, LayoutShiftAttribution[] sources
152            )
153        {
154            super(singleton, Domains.PerformanceTimeline, "LayoutShift", 4);
155
156            this.value          = value;
157            this.hadRecentInput = hadRecentInput;
158            this.lastInputTime  = lastInputTime;
159            this.sources        = sources;
160
161            this.isPresent = (isPresent == null)
162                ? singleton.generateIsPresentList(this)
163                : THROWS.check(isPresent, 4, "PerformanceTimeline.LayoutShift");
164        }
165
166        /** Creates an instance of this class from a {@link JsonObject}.*/
167        public static LayoutShift fromJSON(JsonObject jo)
168        { return singleton.fromJSON(jo); }
169
170        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
171        public static NestedDescriptor<LayoutShift> descriptor()
172        { return singleton.descriptor(); }
173    }
174
175    /**
176     * <CODE>[No Description Provided by Google]</CODE>
177     * 
178     * <EMBED CLASS=globalDefs DATA-DOMAIN=PerformanceTimeline DATA-API=BrowserAPI>
179     */
180    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
181    public static class LayoutShiftAttribution
182        extends BaseType<LayoutShiftAttribution>
183        implements java.io.Serializable
184    {
185        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
186        protected static final long serialVersionUID = 1;
187
188        private static final NestedHelper<PerformanceTimeline.LayoutShiftAttribution> singleton =
189            Torello.Browser.BrowserAPI.NestedHelpers.Types.
190                PerformanceTimeline$$LayoutShiftAttribution$$.singleton;
191
192        /** <CODE>[No Description Provided by Google]</CODE> */
193        public final DOM.Rect previousRect;
194
195        /** <CODE>[No Description Provided by Google]</CODE> */
196        public final DOM.Rect currentRect;
197
198        /**
199         * <CODE>[No Description Provided by Google]</CODE>
200         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
201         */
202        public final Integer nodeId;
203
204        /** Constructor.  Please review this class' fields for documentation. */
205        public LayoutShiftAttribution(
206                ReadOnlyList<Boolean> isPresent, DOM.Rect previousRect, DOM.Rect currentRect,
207                Integer nodeId
208            )
209        {
210            super(singleton, Domains.PerformanceTimeline, "LayoutShiftAttribution", 3);
211
212            this.previousRect   = previousRect;
213            this.currentRect    = currentRect;
214            this.nodeId         = nodeId;
215
216            this.isPresent = (isPresent == null)
217                ? singleton.generateIsPresentList(this)
218                : THROWS.check(isPresent, 3, "PerformanceTimeline.LayoutShiftAttribution");
219        }
220
221        /** Creates an instance of this class from a {@link JsonObject}.*/
222        public static LayoutShiftAttribution fromJSON(JsonObject jo)
223        { return singleton.fromJSON(jo); }
224
225        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
226        public static NestedDescriptor<LayoutShiftAttribution> descriptor()
227        { return singleton.descriptor(); }
228    }
229
230    /**
231     * <CODE>[No Description Provided by Google]</CODE>
232     * 
233     * <EMBED CLASS=globalDefs DATA-DOMAIN=PerformanceTimeline DATA-API=BrowserAPI>
234     */
235    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
236    public static class TimelineEvent
237        extends BaseType<TimelineEvent>
238        implements java.io.Serializable
239    {
240        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
241        protected static final long serialVersionUID = 1;
242
243        private static final NestedHelper<PerformanceTimeline.TimelineEvent> singleton =
244            Torello.Browser.BrowserAPI.NestedHelpers.Types.
245                PerformanceTimeline$$TimelineEvent$$.singleton;
246
247        /** Identifies the frame that this event is related to. Empty for non-frame targets. */
248        public final String frameId;
249
250        /**
251         * The event type, as specified in https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype
252         * This determines which of the optional "details" fields is present.
253         */
254        public final String type;
255
256        /** Name may be empty depending on the type. */
257        public final String name;
258
259        /** Time in seconds since Epoch, monotonically increasing within document lifetime. */
260        public final Number time;
261
262        /**
263         * Event duration, if applicable.
264         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
265         */
266        public final Number duration;
267
268        /**
269         * <CODE>[No Description Provided by Google]</CODE>
270         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
271         */
272        public final PerformanceTimeline.LargestContentfulPaint lcpDetails;
273
274        /**
275         * <CODE>[No Description Provided by Google]</CODE>
276         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
277         */
278        public final PerformanceTimeline.LayoutShift layoutShiftDetails;
279
280        /** Constructor.  Please review this class' fields for documentation. */
281        public TimelineEvent(
282                ReadOnlyList<Boolean> isPresent, String frameId, String type, String name,
283                Number time, Number duration, LargestContentfulPaint lcpDetails,
284                LayoutShift layoutShiftDetails
285            )
286        {
287            super(singleton, Domains.PerformanceTimeline, "TimelineEvent", 7);
288
289            this.frameId            = frameId;
290            this.type               = type;
291            this.name               = name;
292            this.time               = time;
293            this.duration           = duration;
294            this.lcpDetails         = lcpDetails;
295            this.layoutShiftDetails = layoutShiftDetails;
296
297            this.isPresent = (isPresent == null)
298                ? singleton.generateIsPresentList(this)
299                : THROWS.check(isPresent, 7, "PerformanceTimeline.TimelineEvent");
300        }
301
302        /** Creates an instance of this class from a {@link JsonObject}.*/
303        public static TimelineEvent fromJSON(JsonObject jo)
304        { return singleton.fromJSON(jo); }
305
306        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
307        public static NestedDescriptor<TimelineEvent> descriptor()
308        { return singleton.descriptor(); }
309    }
310
311
312    // ********************************************************************************************
313    // ********************************************************************************************
314    // Event Types
315    // ********************************************************************************************
316    // ********************************************************************************************
317
318
319    /**
320     * Sent when a performance timeline event is added. See reportPerformanceTimeline method.
321     * 
322     * <EMBED CLASS=globalDefs DATA-DOMAIN=PerformanceTimeline DATA-API=BrowserAPI>
323     */
324    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI")
325    public static class timelineEventAdded
326        extends BrowserEvent<timelineEventAdded>
327        implements java.io.Serializable
328    {
329        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
330        protected static final long serialVersionUID = 1;
331
332        private static final NestedHelper<PerformanceTimeline.timelineEventAdded> singleton =
333            Torello.Browser.BrowserAPI.NestedHelpers.Events.
334                PerformanceTimeline$$timelineEventAdded$$.singleton;
335
336        /** <CODE>[No Description Provided by Google]</CODE> */
337        public final PerformanceTimeline.TimelineEvent event;
338
339        /** Constructor.  Please review this class' fields for documentation. */
340        public timelineEventAdded(ReadOnlyList<Boolean> isPresent, TimelineEvent event)
341        {
342            super(singleton, Domains.PerformanceTimeline, "timelineEventAdded", 1);
343
344            this.event = event;
345
346            this.isPresent = (isPresent == null)
347                ? singleton.generateIsPresentList(this)
348                : THROWS.check(isPresent, 1, "PerformanceTimeline.timelineEventAdded");
349        }
350
351        /** Creates an instance of this class from a {@link JsonObject}.*/
352        public static timelineEventAdded fromJSON(JsonObject jo)
353        { return singleton.fromJSON(jo); }
354
355        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
356        public static NestedDescriptor<timelineEventAdded> descriptor()
357        { return singleton.descriptor(); }
358    }
359
360
361
362
363    // ********************************************************************************************
364    // ********************************************************************************************
365    // Commands
366    // ********************************************************************************************
367    // ********************************************************************************************
368
369
370    /**
371     * Previously buffered events would be reported before method returns.
372     * See also: timelineEventAdded
373     * 
374     * @param eventTypes 
375     * The types of event to report, as specified in
376     * https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype
377     * The specified filter overrides any previous filters, passing empty
378     * filter disables recording.
379     * Note that not all types exposed to the web platform are currently supported.
380     * 
381     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
382     *
383     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
384     * browser receives the invocation-request.
385     *
386     * <BR /><BR /><DIV CLASS=JDHint>
387     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
388     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
389     * the Browser Function has run to completion.
390     * </DIV>
391     */
392    public static Script<Void> enable(String[] eventTypes)
393    {
394        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
395        final String requestJSON = WriteJSON.get(
396            CDPTypes.STRING_ARRAY_1D, "eventTypes", false, "PerformanceTimeline.enable",
397            (Object) eventTypes
398        );
399
400        return Script.NO_RET(Domains.PerformanceTimeline, "enable", requestJSON);
401    }
402
403
404}