001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013import Torello.Java.JSON.*;
014
015import static Torello.Java.JSON.JFlag.*;
016
017import Torello.Java.StrCmpr;
018import Torello.JavaDoc.StaticFunctional;
019import Torello.JavaDoc.JDHeaderBackgroundImg;
020import Torello.JavaDoc.Excuse;
021
022/**
023 * <SPAN CLASS=COPIEDJDK><B>DOM debugging allows setting breakpoints on particular DOM operations and events. JavaScript
024 * execution will stop on these operations as if there was a regular breakpoint set.</B></SPAN>
025 * 
026 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
027 */
028@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
029@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
030public class DOMDebugger
031{
032    // ********************************************************************************************
033    // ********************************************************************************************
034    // Class Header Stuff
035    // ********************************************************************************************
036    // ********************************************************************************************
037
038
039    // No Pubic Constructors
040    private DOMDebugger () { }
041
042    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
043    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
044    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
045    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
046
047    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
048    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
049    // offically, two empty-vectors.  One for String's, and the other for Classes.
050
051    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
052    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
053
054    static
055    {
056        for (Method m : DOMDebugger.class.getMethods())
057        {
058            // This doesn't work!  The parameter names are all "arg0" ... "argN"
059            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
060            //
061            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
062
063            Vector<Class<?>> parameterTypesList = new Vector<>();
064        
065            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
066
067            parameterTypes.put(
068                m.getName(),
069                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
070            );
071        }
072    }
073
074    static
075    {
076        Vector<String> v = null;
077
078        v = new Vector<String>(3);
079        parameterNames.put("getEventListeners", v);
080        Collections.addAll(v, new String[]
081        { "objectId", "depth", "pierce", });
082
083        v = new Vector<String>(2);
084        parameterNames.put("removeDOMBreakpoint", v);
085        Collections.addAll(v, new String[]
086        { "nodeId", "type", });
087
088        v = new Vector<String>(2);
089        parameterNames.put("removeEventListenerBreakpoint", v);
090        Collections.addAll(v, new String[]
091        { "eventName", "targetName", });
092
093        v = new Vector<String>(1);
094        parameterNames.put("removeInstrumentationBreakpoint", v);
095        Collections.addAll(v, new String[]
096        { "eventName", });
097
098        v = new Vector<String>(1);
099        parameterNames.put("removeXHRBreakpoint", v);
100        Collections.addAll(v, new String[]
101        { "url", });
102
103        v = new Vector<String>(1);
104        parameterNames.put("setBreakOnCSPViolation", v);
105        Collections.addAll(v, new String[]
106        { "violationTypes", });
107
108        v = new Vector<String>(2);
109        parameterNames.put("setDOMBreakpoint", v);
110        Collections.addAll(v, new String[]
111        { "nodeId", "type", });
112
113        v = new Vector<String>(2);
114        parameterNames.put("setEventListenerBreakpoint", v);
115        Collections.addAll(v, new String[]
116        { "eventName", "targetName", });
117
118        v = new Vector<String>(1);
119        parameterNames.put("setInstrumentationBreakpoint", v);
120        Collections.addAll(v, new String[]
121        { "eventName", });
122
123        v = new Vector<String>(1);
124        parameterNames.put("setXHRBreakpoint", v);
125        Collections.addAll(v, new String[]
126        { "url", });
127    }
128
129
130    // ********************************************************************************************
131    // ********************************************************************************************
132    // Types - Static Inner Classes
133    // ********************************************************************************************
134    // ********************************************************************************************
135
136    /** DOM breakpoint type. */
137    public static final String[] DOMBreakpointType =
138    { "subtree-modified", "attribute-modified", "node-removed", };
139    
140    /**
141     * CSP Violation type.
142     * <BR />
143     * <BR /><B>EXPERIMENTAL</B>
144     */
145    public static final String[] CSPViolationType =
146    { "trustedtype-sink-violation", "trustedtype-policy-violation", };
147    
148    /** Object event listener. */
149    public static class EventListener
150        extends BaseType
151        implements java.io.Serializable
152    {
153        /** For Object Serialization.  java.io.Serializable */
154        protected static final long serialVersionUID = 1;
155        
156        public boolean[] optionals()
157        { return new boolean[] { false, false, false, false, false, false, false, true, true, true, }; }
158        
159        /** <CODE>EventListener</CODE>'s type. */
160        public final String type;
161        
162        /** <CODE>EventListener</CODE>'s useCapture. */
163        public final boolean useCapture;
164        
165        /** <CODE>EventListener</CODE>'s passive flag. */
166        public final boolean passive;
167        
168        /** <CODE>EventListener</CODE>'s once flag. */
169        public final boolean once;
170        
171        /** Script id of the handler code. */
172        public final String scriptId;
173        
174        /** Line number in the script (0-based). */
175        public final int lineNumber;
176        
177        /** Column number in the script (0-based). */
178        public final int columnNumber;
179        
180        /**
181         * Event handler function value.
182         * <BR />
183         * <BR /><B>OPTIONAL</B>
184         */
185        public final RunTime.RemoteObject handler;
186        
187        /**
188         * Event original handler function value.
189         * <BR />
190         * <BR /><B>OPTIONAL</B>
191         */
192        public final RunTime.RemoteObject originalHandler;
193        
194        /**
195         * Node the listener is added to (if any).
196         * <BR />
197         * <BR /><B>OPTIONAL</B>
198         */
199        public final Integer backendNodeId;
200        
201        /**
202         * Constructor
203         *
204         * @param type <CODE>EventListener</CODE>'s type.
205         * 
206         * @param useCapture <CODE>EventListener</CODE>'s useCapture.
207         * 
208         * @param passive <CODE>EventListener</CODE>'s passive flag.
209         * 
210         * @param once <CODE>EventListener</CODE>'s once flag.
211         * 
212         * @param scriptId Script id of the handler code.
213         * 
214         * @param lineNumber Line number in the script (0-based).
215         * 
216         * @param columnNumber Column number in the script (0-based).
217         * 
218         * @param handler Event handler function value.
219         * <BR /><B>OPTIONAL</B>
220         * 
221         * @param originalHandler Event original handler function value.
222         * <BR /><B>OPTIONAL</B>
223         * 
224         * @param backendNodeId Node the listener is added to (if any).
225         * <BR /><B>OPTIONAL</B>
226         */
227        public EventListener(
228                String type, boolean useCapture, boolean passive, boolean once, String scriptId, 
229                int lineNumber, int columnNumber, RunTime.RemoteObject handler, 
230                RunTime.RemoteObject originalHandler, Integer backendNodeId
231            )
232        {
233            // Exception-Check(s) to ensure that if any parameters which are not declared as
234            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
235            
236            if (type == null)     THROWS.throwNPE("type");
237            if (scriptId == null) THROWS.throwNPE("scriptId");
238            
239            this.type             = type;
240            this.useCapture       = useCapture;
241            this.passive          = passive;
242            this.once             = once;
243            this.scriptId         = scriptId;
244            this.lineNumber       = lineNumber;
245            this.columnNumber     = columnNumber;
246            this.handler          = handler;
247            this.originalHandler  = originalHandler;
248            this.backendNodeId    = backendNodeId;
249        }
250        
251        /**
252         * JSON Object Constructor
253         * @param jo A Json-Object having data about an instance of {@code 'EventListener'}.
254         */
255        public EventListener (JsonObject jo)
256        {
257            this.type             = ReadJSON.getString(jo, "type", false, true);
258            this.useCapture       = ReadPrimJSON.getBoolean(jo, "useCapture");
259            this.passive          = ReadPrimJSON.getBoolean(jo, "passive");
260            this.once             = ReadPrimJSON.getBoolean(jo, "once");
261            this.scriptId         = ReadJSON.getString(jo, "scriptId", false, true);
262            this.lineNumber       = ReadPrimJSON.getInt(jo, "lineNumber");
263            this.columnNumber     = ReadPrimJSON.getInt(jo, "columnNumber");
264            this.handler          = ReadJSON.getObject(jo, "handler", RunTime.RemoteObject.class, true, false);
265            this.originalHandler  = ReadJSON.getObject(jo, "originalHandler", RunTime.RemoteObject.class, true, false);
266            this.backendNodeId    = ReadBoxedJSON.getInteger(jo, "backendNodeId", true);
267        }
268        
269        
270        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
271        public boolean equals(Object other)
272        {
273            if (this == other)                       return true;
274            if (other == null)                       return false;
275            if (other.getClass() != this.getClass()) return false;
276        
277            EventListener o = (EventListener) other;
278        
279            return
280                    Objects.equals(this.type, o.type)
281                &&  (this.useCapture == o.useCapture)
282                &&  (this.passive == o.passive)
283                &&  (this.once == o.once)
284                &&  Objects.equals(this.scriptId, o.scriptId)
285                &&  (this.lineNumber == o.lineNumber)
286                &&  (this.columnNumber == o.columnNumber)
287                &&  Objects.equals(this.handler, o.handler)
288                &&  Objects.equals(this.originalHandler, o.originalHandler)
289                &&  Objects.equals(this.backendNodeId, o.backendNodeId);
290        }
291        
292        /** Generates a Hash-Code for {@code 'this'} instance */
293        public int hashCode()
294        {
295            return
296                    Objects.hashCode(this.type)
297                +   (this.useCapture ? 1 : 0)
298                +   (this.passive ? 1 : 0)
299                +   (this.once ? 1 : 0)
300                +   Objects.hashCode(this.scriptId)
301                +   this.lineNumber
302                +   this.columnNumber
303                +   this.handler.hashCode()
304                +   this.originalHandler.hashCode()
305                +   Objects.hashCode(this.backendNodeId);
306        }
307    }
308    
309    
310    // Counter for keeping the WebSocket Request ID's distinct.
311    private static int counter = 1;
312    
313    /**
314     * Returns event listeners of the given object.
315     * 
316     * @param objectId Identifier of the object to return listeners for.
317     * 
318     * @param depth 
319     * The maximum depth at which Node children should be retrieved, defaults to 1. Use -1 for the
320     * entire subtree or provide an integer larger than 0.
321     * <BR /><B>OPTIONAL</B>
322     * 
323     * @param pierce 
324     * Whether or not iframes and shadow roots should be traversed when returning the subtree
325     * (default is false). Reports listeners for all contexts if pierce is enabled.
326     * <BR /><B>OPTIONAL</B>
327     * 
328     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
329     * {@link DOMDebugger.EventListener}[]&gt;</CODE>
330     * 
331     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
332     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
333     * {@link DOMDebugger.EventListener}[]&gt;</CODE> will be returned.
334     *
335     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
336     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
337      * may be retrieved.</I>
338     *
339     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
340     * <BR /><BR /><UL CLASS=JDUL>
341     * <LI><CODE>{@link DOMDebugger.EventListener}[] (<B>listeners</B></CODE>)
342     *     <BR />Array of relevant listeners.
343     * </LI>
344     * </UL> */
345    public static Script<String, JsonObject, DOMDebugger.EventListener[]> getEventListeners
346        (String objectId, Integer depth, Boolean pierce)
347    {
348        // Exception-Check(s) to ensure that if any parameters which are not declared as
349        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
350        
351        if (objectId == null) THROWS.throwNPE("objectId");
352        
353        final int       webSocketID = 16000000 + counter++;
354        final boolean[] optionals   = { false, true, true, };
355        
356        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
357        String requestJSON = WriteJSON.get(
358            parameterTypes.get("getEventListeners"),
359            parameterNames.get("getEventListeners"),
360            optionals, webSocketID,
361            "DOMDebugger.getEventListeners",
362            objectId, depth, pierce
363        );
364        
365        // 'JSON Binding' ... Converts Browser Response-JSON to 'DOMDebugger.EventListener[]'
366        Function<JsonObject, DOMDebugger.EventListener[]> responseProcessor = (JsonObject jo) ->
367            (jo.getJsonArray("listeners") == null)
368                ? null
369                : RJArrIntoStream.objArr(jo.getJsonArray("listeners"), null, 0, DOMDebugger.EventListener.class).toArray(DOMDebugger.EventListener[]::new);
370        
371        return new Script<>(webSocketID, requestJSON, responseProcessor);
372    }
373    
374    /**
375     * Removes DOM breakpoint that was set using <CODE>setDOMBreakpoint</CODE>.
376     * 
377     * @param nodeId Identifier of the node to remove breakpoint from.
378     * 
379     * @param type Type of the breakpoint to remove.
380     * 
381     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
382     * {@link Ret0}&gt;</CODE>
383     *
384     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
385     * browser receives the invocation-request.
386     *
387     * <BR /><BR />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 <JsonObject,} {@link Ret0}
389     * {@code >} to ensure the Browser Function has run to completion.
390     */
391    public static Script<String, JsonObject, Ret0> removeDOMBreakpoint(int nodeId, String type)
392    {
393        // Exception-Check(s) to ensure that if any parameters which are not declared as
394        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
395        
396        if (type == null) THROWS.throwNPE("type");
397        
398        // Exception-Check(s) to ensure that if any parameters which must adhere to a
399        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
400        
401        THROWS.checkIAE("type", type, "DOMDebugger.DOMBreakpointType", DOMDebugger.DOMBreakpointType);
402        
403        final int       webSocketID = 16001000 + counter++;
404        final boolean[] optionals   = { false, false, };
405        
406        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
407        String requestJSON = WriteJSON.get(
408            parameterTypes.get("removeDOMBreakpoint"),
409            parameterNames.get("removeDOMBreakpoint"),
410            optionals, webSocketID,
411            "DOMDebugger.removeDOMBreakpoint",
412            nodeId, type
413        );
414        
415        // This Remote Command does not have a Return-Value.
416        return new Script<>
417            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
418    }
419    
420    /**
421     * Removes breakpoint on particular DOM event.
422     * 
423     * @param eventName Event name.
424     * 
425     * @param targetName EventTarget interface name.
426     * <BR /><B>OPTIONAL</B>
427     * <BR /><B>EXPERIMENTAL</B>
428     * 
429     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
430     * {@link Ret0}&gt;</CODE>
431     *
432     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
433     * browser receives the invocation-request.
434     *
435     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
436     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
437     * {@code >} to ensure the Browser Function has run to completion.
438     */
439    public static Script<String, JsonObject, Ret0> removeEventListenerBreakpoint
440        (String eventName, String targetName)
441    {
442        // Exception-Check(s) to ensure that if any parameters which are not declared as
443        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
444        
445        if (eventName == null) THROWS.throwNPE("eventName");
446        
447        final int       webSocketID = 16002000 + counter++;
448        final boolean[] optionals   = { false, true, };
449        
450        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
451        String requestJSON = WriteJSON.get(
452            parameterTypes.get("removeEventListenerBreakpoint"),
453            parameterNames.get("removeEventListenerBreakpoint"),
454            optionals, webSocketID,
455            "DOMDebugger.removeEventListenerBreakpoint",
456            eventName, targetName
457        );
458        
459        // This Remote Command does not have a Return-Value.
460        return new Script<>
461            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
462    }
463    
464    /**
465     * Removes breakpoint on particular native event.
466     * <BR /><B>EXPERIMENTAL</B>
467     * 
468     * @param eventName Instrumentation name to stop on.
469     * 
470     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
471     * {@link Ret0}&gt;</CODE>
472     *
473     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
474     * browser receives the invocation-request.
475     *
476     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
477     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
478     * {@code >} to ensure the Browser Function has run to completion.
479     */
480    public static Script<String, JsonObject, Ret0> removeInstrumentationBreakpoint
481        (String eventName)
482    {
483        // Exception-Check(s) to ensure that if any parameters which are not declared as
484        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
485        
486        if (eventName == null) THROWS.throwNPE("eventName");
487        
488        final int       webSocketID = 16003000 + counter++;
489        final boolean[] optionals   = { false, };
490        
491        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
492        String requestJSON = WriteJSON.get(
493            parameterTypes.get("removeInstrumentationBreakpoint"),
494            parameterNames.get("removeInstrumentationBreakpoint"),
495            optionals, webSocketID,
496            "DOMDebugger.removeInstrumentationBreakpoint",
497            eventName
498        );
499        
500        // This Remote Command does not have a Return-Value.
501        return new Script<>
502            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
503    }
504    
505    /**
506     * Removes breakpoint from XMLHttpRequest.
507     * 
508     * @param url Resource URL substring.
509     * 
510     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
511     * {@link Ret0}&gt;</CODE>
512     *
513     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
514     * browser receives the invocation-request.
515     *
516     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
517     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
518     * {@code >} to ensure the Browser Function has run to completion.
519     */
520    public static Script<String, JsonObject, Ret0> removeXHRBreakpoint(String url)
521    {
522        // Exception-Check(s) to ensure that if any parameters which are not declared as
523        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
524        
525        if (url == null) THROWS.throwNPE("url");
526        
527        final int       webSocketID = 16004000 + counter++;
528        final boolean[] optionals   = { false, };
529        
530        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
531        String requestJSON = WriteJSON.get(
532            parameterTypes.get("removeXHRBreakpoint"),
533            parameterNames.get("removeXHRBreakpoint"),
534            optionals, webSocketID,
535            "DOMDebugger.removeXHRBreakpoint",
536            url
537        );
538        
539        // This Remote Command does not have a Return-Value.
540        return new Script<>
541            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
542    }
543    
544    /**
545     * Sets breakpoint on particular CSP violations.
546     * <BR /><B>EXPERIMENTAL</B>
547     * 
548     * @param violationTypes CSP Violations to stop upon.
549     * 
550     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
551     * {@link Ret0}&gt;</CODE>
552     *
553     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
554     * browser receives the invocation-request.
555     *
556     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
557     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
558     * {@code >} to ensure the Browser Function has run to completion.
559     */
560    public static Script<String, JsonObject, Ret0> setBreakOnCSPViolation
561        (String[] violationTypes)
562    {
563        // Exception-Check(s) to ensure that if any parameters which are not declared as
564        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
565        
566        if (violationTypes == null) THROWS.throwNPE("violationTypes");
567        
568        final int       webSocketID = 16005000 + counter++;
569        final boolean[] optionals   = { false, };
570        
571        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
572        String requestJSON = WriteJSON.get(
573            parameterTypes.get("setBreakOnCSPViolation"),
574            parameterNames.get("setBreakOnCSPViolation"),
575            optionals, webSocketID,
576            "DOMDebugger.setBreakOnCSPViolation",
577            (Object) violationTypes
578        );
579        
580        // This Remote Command does not have a Return-Value.
581        return new Script<>
582            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
583    }
584    
585    /**
586     * Sets breakpoint on particular operation with DOM.
587     * 
588     * @param nodeId Identifier of the node to set breakpoint on.
589     * 
590     * @param type Type of the operation to stop upon.
591     * 
592     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
593     * {@link Ret0}&gt;</CODE>
594     *
595     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
596     * browser receives the invocation-request.
597     *
598     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
599     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
600     * {@code >} to ensure the Browser Function has run to completion.
601     */
602    public static Script<String, JsonObject, Ret0> setDOMBreakpoint(int nodeId, String type)
603    {
604        // Exception-Check(s) to ensure that if any parameters which are not declared as
605        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
606        
607        if (type == null) THROWS.throwNPE("type");
608        
609        // Exception-Check(s) to ensure that if any parameters which must adhere to a
610        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
611        
612        THROWS.checkIAE("type", type, "DOMDebugger.DOMBreakpointType", DOMDebugger.DOMBreakpointType);
613        
614        final int       webSocketID = 16006000 + counter++;
615        final boolean[] optionals   = { false, false, };
616        
617        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
618        String requestJSON = WriteJSON.get(
619            parameterTypes.get("setDOMBreakpoint"),
620            parameterNames.get("setDOMBreakpoint"),
621            optionals, webSocketID,
622            "DOMDebugger.setDOMBreakpoint",
623            nodeId, type
624        );
625        
626        // This Remote Command does not have a Return-Value.
627        return new Script<>
628            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
629    }
630    
631    /**
632     * Sets breakpoint on particular DOM event.
633     * 
634     * @param eventName DOM Event name to stop on (any DOM event will do).
635     * 
636     * @param targetName 
637     * EventTarget interface name to stop on. If equal to <CODE>"*"</CODE> or not provided, will stop on any
638     * EventTarget.
639     * <BR /><B>OPTIONAL</B>
640     * <BR /><B>EXPERIMENTAL</B>
641     * 
642     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
643     * {@link Ret0}&gt;</CODE>
644     *
645     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
646     * browser receives the invocation-request.
647     *
648     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
649     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
650     * {@code >} to ensure the Browser Function has run to completion.
651     */
652    public static Script<String, JsonObject, Ret0> setEventListenerBreakpoint
653        (String eventName, String targetName)
654    {
655        // Exception-Check(s) to ensure that if any parameters which are not declared as
656        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
657        
658        if (eventName == null) THROWS.throwNPE("eventName");
659        
660        final int       webSocketID = 16007000 + counter++;
661        final boolean[] optionals   = { false, true, };
662        
663        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
664        String requestJSON = WriteJSON.get(
665            parameterTypes.get("setEventListenerBreakpoint"),
666            parameterNames.get("setEventListenerBreakpoint"),
667            optionals, webSocketID,
668            "DOMDebugger.setEventListenerBreakpoint",
669            eventName, targetName
670        );
671        
672        // This Remote Command does not have a Return-Value.
673        return new Script<>
674            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
675    }
676    
677    /**
678     * Sets breakpoint on particular native event.
679     * <BR /><B>EXPERIMENTAL</B>
680     * 
681     * @param eventName Instrumentation name to stop on.
682     * 
683     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
684     * {@link Ret0}&gt;</CODE>
685     *
686     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
687     * browser receives the invocation-request.
688     *
689     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
690     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
691     * {@code >} to ensure the Browser Function has run to completion.
692     */
693    public static Script<String, JsonObject, Ret0> setInstrumentationBreakpoint
694        (String eventName)
695    {
696        // Exception-Check(s) to ensure that if any parameters which are not declared as
697        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
698        
699        if (eventName == null) THROWS.throwNPE("eventName");
700        
701        final int       webSocketID = 16008000 + counter++;
702        final boolean[] optionals   = { false, };
703        
704        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
705        String requestJSON = WriteJSON.get(
706            parameterTypes.get("setInstrumentationBreakpoint"),
707            parameterNames.get("setInstrumentationBreakpoint"),
708            optionals, webSocketID,
709            "DOMDebugger.setInstrumentationBreakpoint",
710            eventName
711        );
712        
713        // This Remote Command does not have a Return-Value.
714        return new Script<>
715            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
716    }
717    
718    /**
719     * Sets breakpoint on XMLHttpRequest.
720     * 
721     * @param url Resource URL substring. All XHRs having this substring in the URL will get stopped upon.
722     * 
723     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
724     * {@link Ret0}&gt;</CODE>
725     *
726     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
727     * browser receives the invocation-request.
728     *
729     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
730     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
731     * {@code >} to ensure the Browser Function has run to completion.
732     */
733    public static Script<String, JsonObject, Ret0> setXHRBreakpoint(String url)
734    {
735        // Exception-Check(s) to ensure that if any parameters which are not declared as
736        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
737        
738        if (url == null) THROWS.throwNPE("url");
739        
740        final int       webSocketID = 16009000 + counter++;
741        final boolean[] optionals   = { false, };
742        
743        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
744        String requestJSON = WriteJSON.get(
745            parameterTypes.get("setXHRBreakpoint"),
746            parameterNames.get("setXHRBreakpoint"),
747            optionals, webSocketID,
748            "DOMDebugger.setXHRBreakpoint",
749            url
750        );
751        
752        // This Remote Command does not have a Return-Value.
753        return new Script<>
754            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
755    }
756    
757}