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>The Browser domain defines methods and events for browser managing.</B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class Browser
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private Browser () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : Browser.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        v = new Vector<String>(4);
078        parameterNames.put("setPermission", v);
079        Collections.addAll(v, new String[]
080        { "permission", "setting", "origin", "browserContextId", });
081
082        v = new Vector<String>(3);
083        parameterNames.put("grantPermissions", v);
084        Collections.addAll(v, new String[]
085        { "permissions", "origin", "browserContextId", });
086
087        v = new Vector<String>(1);
088        parameterNames.put("resetPermissions", v);
089        Collections.addAll(v, new String[]
090        { "browserContextId", });
091
092        v = new Vector<String>(4);
093        parameterNames.put("setDownloadBehavior", v);
094        Collections.addAll(v, new String[]
095        { "behavior", "browserContextId", "downloadPath", "eventsEnabled", });
096
097        v = new Vector<String>(2);
098        parameterNames.put("cancelDownload", v);
099        Collections.addAll(v, new String[]
100        { "guid", "browserContextId", });
101
102        parameterNames.put("close", EMPTY_VEC_STR);
103
104        parameterNames.put("crash", EMPTY_VEC_STR);
105
106        parameterNames.put("crashGpuProcess", EMPTY_VEC_STR);
107
108        parameterNames.put("getVersion", EMPTY_VEC_STR);
109
110        parameterNames.put("getBrowserCommandLine", EMPTY_VEC_STR);
111
112        v = new Vector<String>(2);
113        parameterNames.put("getHistograms", v);
114        Collections.addAll(v, new String[]
115        { "query", "delta", });
116
117        v = new Vector<String>(2);
118        parameterNames.put("getHistogram", v);
119        Collections.addAll(v, new String[]
120        { "name", "delta", });
121
122        v = new Vector<String>(1);
123        parameterNames.put("getWindowBounds", v);
124        Collections.addAll(v, new String[]
125        { "windowId", });
126
127        v = new Vector<String>(1);
128        parameterNames.put("getWindowForTarget", v);
129        Collections.addAll(v, new String[]
130        { "targetId", });
131
132        v = new Vector<String>(2);
133        parameterNames.put("setWindowBounds", v);
134        Collections.addAll(v, new String[]
135        { "windowId", "bounds", });
136
137        v = new Vector<String>(2);
138        parameterNames.put("setDockTile", v);
139        Collections.addAll(v, new String[]
140        { "badgeLabel", "image", });
141
142        v = new Vector<String>(1);
143        parameterNames.put("executeBrowserCommand", v);
144        Collections.addAll(v, new String[]
145        { "commandId", });
146    }
147
148
149    // ********************************************************************************************
150    // ********************************************************************************************
151    // Types - Static Inner Classes
152    // ********************************************************************************************
153    // ********************************************************************************************
154
155    // public static class BrowserContextID => String
156    
157    // public static class WindowID => Integer
158    
159    /**
160     * The state of the browser window.
161     * <BR />
162     * <BR /><B>EXPERIMENTAL</B>
163     */
164    public static final String[] WindowState =
165    { "normal", "minimized", "maximized", "fullscreen", };
166    
167    /**
168     * <CODE>[No Description Provided by Google]</CODE>
169     * <BR />
170     * <BR /><B>EXPERIMENTAL</B>
171     */
172    public static final String[] PermissionType =
173    { 
174        "accessibilityEvents", "audioCapture", "backgroundSync", "backgroundFetch", 
175        "clipboardReadWrite", "clipboardSanitizedWrite", "displayCapture", "durableStorage", 
176        "flash", "geolocation", "midi", "midiSysex", "nfc", "notifications", "paymentHandler", 
177        "periodicBackgroundSync", "protectedMediaIdentifier", "sensors", "videoCapture", 
178        "videoCapturePanTiltZoom", "idleDetection", "wakeLockScreen", "wakeLockSystem", 
179    };
180    
181    /**
182     * <CODE>[No Description Provided by Google]</CODE>
183     * <BR />
184     * <BR /><B>EXPERIMENTAL</B>
185     */
186    public static final String[] PermissionSetting =
187    { "granted", "denied", "prompt", };
188    
189    /**
190     * Browser command ids used by executeBrowserCommand.
191     * <BR />
192     * <BR /><B>EXPERIMENTAL</B>
193     */
194    public static final String[] BrowserCommandId =
195    { "openTabSearch", "closeTabSearch", };
196    
197    /**
198     * Browser window bounds information
199     * <BR />
200     * <BR /><B>EXPERIMENTAL</B>
201     */
202    public static class Bounds
203        extends BaseType
204        implements java.io.Serializable
205    {
206        /** For Object Serialization.  java.io.Serializable */
207        protected static final long serialVersionUID = 1;
208        
209        public boolean[] optionals()
210        { return new boolean[] { true, true, true, true, true, }; }
211        
212        /**
213         * The offset from the left edge of the screen to the window in pixels.
214         * <BR />
215         * <BR /><B>OPTIONAL</B>
216         */
217        public final Integer left;
218        
219        /**
220         * The offset from the top edge of the screen to the window in pixels.
221         * <BR />
222         * <BR /><B>OPTIONAL</B>
223         */
224        public final Integer top;
225        
226        /**
227         * The window width in pixels.
228         * <BR />
229         * <BR /><B>OPTIONAL</B>
230         */
231        public final Integer width;
232        
233        /**
234         * The window height in pixels.
235         * <BR />
236         * <BR /><B>OPTIONAL</B>
237         */
238        public final Integer height;
239        
240        /**
241         * The window state. Default to normal.
242         * <BR />
243         * <BR /><B>OPTIONAL</B>
244         */
245        public final String windowState;
246        
247        /**
248         * Constructor
249         *
250         * @param left The offset from the left edge of the screen to the window in pixels.
251         * <BR /><B>OPTIONAL</B>
252         * 
253         * @param top The offset from the top edge of the screen to the window in pixels.
254         * <BR /><B>OPTIONAL</B>
255         * 
256         * @param width The window width in pixels.
257         * <BR /><B>OPTIONAL</B>
258         * 
259         * @param height The window height in pixels.
260         * <BR /><B>OPTIONAL</B>
261         * 
262         * @param windowState The window state. Default to normal.
263         * <BR /><B>OPTIONAL</B>
264         */
265        public Bounds
266            (Integer left, Integer top, Integer width, Integer height, String windowState)
267        {
268            // Exception-Check(s) to ensure that if any parameters which must adhere to a
269            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
270            
271            BRDPC.checkIAE("windowState", windowState, "Browser.WindowState", Browser.WindowState);
272            
273            this.left         = left;
274            this.top          = top;
275            this.width        = width;
276            this.height       = height;
277            this.windowState  = windowState;
278        }
279        
280        /**
281         * JSON Object Constructor
282         * @param jo A Json-Object having data about an instance of {@code 'Bounds'}.
283         */
284        public Bounds (JsonObject jo)
285        {
286            this.left         = ReadBoxedJSON.getInteger(jo, "left", true);
287            this.top          = ReadBoxedJSON.getInteger(jo, "top", true);
288            this.width        = ReadBoxedJSON.getInteger(jo, "width", true);
289            this.height       = ReadBoxedJSON.getInteger(jo, "height", true);
290            this.windowState  = ReadJSON.getString(jo, "windowState", true, false);
291        }
292        
293        
294        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
295        public boolean equals(Object other)
296        {
297            if (other == null)                       return false;
298            if (other.getClass() != this.getClass()) return false;
299        
300            Bounds o = (Bounds) other;
301        
302            return
303                    Objects.equals(this.left, o.left)
304                &&  Objects.equals(this.top, o.top)
305                &&  Objects.equals(this.width, o.width)
306                &&  Objects.equals(this.height, o.height)
307                &&  Objects.equals(this.windowState, o.windowState);
308        }
309        
310        /** Generates a Hash-Code for {@code 'this'} instance */
311        public int hashCode()
312        {
313            return
314                    Objects.hashCode(this.left)
315                +   Objects.hashCode(this.top)
316                +   Objects.hashCode(this.width)
317                +   Objects.hashCode(this.height)
318                +   Objects.hashCode(this.windowState);
319        }
320    }
321    
322    /**
323     * Definition of PermissionDescriptor defined in the Permissions API:
324     * https://w3c.github.io/permissions/#dictdef-permissiondescriptor.
325     * <BR />
326     * <BR /><B>EXPERIMENTAL</B>
327     */
328    public static class PermissionDescriptor
329        extends BaseType
330        implements java.io.Serializable
331    {
332        /** For Object Serialization.  java.io.Serializable */
333        protected static final long serialVersionUID = 1;
334        
335        public boolean[] optionals()
336        { return new boolean[] { false, true, true, true, true, }; }
337        
338        /**
339         * Name of permission.
340         * See https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl for valid permission names.
341         */
342        public final String name;
343        
344        /**
345         * For "midi" permission, may also specify sysex control.
346         * <BR />
347         * <BR /><B>OPTIONAL</B>
348         */
349        public final Boolean sysex;
350        
351        /**
352         * For "push" permission, may specify userVisibleOnly.
353         * Note that userVisibleOnly = true is the only currently supported type.
354         * <BR />
355         * <BR /><B>OPTIONAL</B>
356         */
357        public final Boolean userVisibleOnly;
358        
359        /**
360         * For "clipboard" permission, may specify allowWithoutSanitization.
361         * <BR />
362         * <BR /><B>OPTIONAL</B>
363         */
364        public final Boolean allowWithoutSanitization;
365        
366        /**
367         * For "camera" permission, may specify panTiltZoom.
368         * <BR />
369         * <BR /><B>OPTIONAL</B>
370         */
371        public final Boolean panTiltZoom;
372        
373        /**
374         * Constructor
375         *
376         * @param name 
377         * Name of permission.
378         * See https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl for valid permission names.
379         * 
380         * @param sysex For "midi" permission, may also specify sysex control.
381         * <BR /><B>OPTIONAL</B>
382         * 
383         * @param userVisibleOnly 
384         * For "push" permission, may specify userVisibleOnly.
385         * Note that userVisibleOnly = true is the only currently supported type.
386         * <BR /><B>OPTIONAL</B>
387         * 
388         * @param allowWithoutSanitization For "clipboard" permission, may specify allowWithoutSanitization.
389         * <BR /><B>OPTIONAL</B>
390         * 
391         * @param panTiltZoom For "camera" permission, may specify panTiltZoom.
392         * <BR /><B>OPTIONAL</B>
393         */
394        public PermissionDescriptor(
395                String name, Boolean sysex, Boolean userVisibleOnly, 
396                Boolean allowWithoutSanitization, Boolean panTiltZoom
397            )
398        {
399            // Exception-Check(s) to ensure that if any parameters which are not declared as
400            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
401            
402            if (name == null) BRDPC.throwNPE("name");
403            
404            this.name                      = name;
405            this.sysex                     = sysex;
406            this.userVisibleOnly           = userVisibleOnly;
407            this.allowWithoutSanitization  = allowWithoutSanitization;
408            this.panTiltZoom               = panTiltZoom;
409        }
410        
411        /**
412         * JSON Object Constructor
413         * @param jo A Json-Object having data about an instance of {@code 'PermissionDescriptor'}.
414         */
415        public PermissionDescriptor (JsonObject jo)
416        {
417            this.name                      = ReadJSON.getString(jo, "name", false, true);
418            this.sysex                     = ReadBoxedJSON.getBoolean(jo, "sysex", true);
419            this.userVisibleOnly           = ReadBoxedJSON.getBoolean(jo, "userVisibleOnly", true);
420            this.allowWithoutSanitization  = ReadBoxedJSON.getBoolean(jo, "allowWithoutSanitization", true);
421            this.panTiltZoom               = ReadBoxedJSON.getBoolean(jo, "panTiltZoom", true);
422        }
423        
424        
425        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
426        public boolean equals(Object other)
427        {
428            if (other == null)                       return false;
429            if (other.getClass() != this.getClass()) return false;
430        
431            PermissionDescriptor o = (PermissionDescriptor) other;
432        
433            return
434                    Objects.equals(this.name, o.name)
435                &&  Objects.equals(this.sysex, o.sysex)
436                &&  Objects.equals(this.userVisibleOnly, o.userVisibleOnly)
437                &&  Objects.equals(this.allowWithoutSanitization, o.allowWithoutSanitization)
438                &&  Objects.equals(this.panTiltZoom, o.panTiltZoom);
439        }
440        
441        /** Generates a Hash-Code for {@code 'this'} instance */
442        public int hashCode()
443        {
444            return
445                    Objects.hashCode(this.name)
446                +   Objects.hashCode(this.sysex)
447                +   Objects.hashCode(this.userVisibleOnly)
448                +   Objects.hashCode(this.allowWithoutSanitization)
449                +   Objects.hashCode(this.panTiltZoom);
450        }
451    }
452    
453    /**
454     * Chrome histogram bucket.
455     * <BR />
456     * <BR /><B>EXPERIMENTAL</B>
457     */
458    public static class Bucket
459        extends BaseType
460        implements java.io.Serializable
461    {
462        /** For Object Serialization.  java.io.Serializable */
463        protected static final long serialVersionUID = 1;
464        
465        public boolean[] optionals()
466        { return new boolean[] { false, false, false, }; }
467        
468        /** Minimum value (inclusive). */
469        public final int low;
470        
471        /** Maximum value (exclusive). */
472        public final int high;
473        
474        /** Number of samples. */
475        public final int count;
476        
477        /**
478         * Constructor
479         *
480         * @param low Minimum value (inclusive).
481         * 
482         * @param high Maximum value (exclusive).
483         * 
484         * @param count Number of samples.
485         */
486        public Bucket(int low, int high, int count)
487        {
488            this.low    = low;
489            this.high   = high;
490            this.count  = count;
491        }
492        
493        /**
494         * JSON Object Constructor
495         * @param jo A Json-Object having data about an instance of {@code 'Bucket'}.
496         */
497        public Bucket (JsonObject jo)
498        {
499            this.low    = ReadPrimJSON.getInt(jo, "low");
500            this.high   = ReadPrimJSON.getInt(jo, "high");
501            this.count  = ReadPrimJSON.getInt(jo, "count");
502        }
503        
504        
505        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
506        public boolean equals(Object other)
507        {
508            if (other == null)                       return false;
509            if (other.getClass() != this.getClass()) return false;
510        
511            Bucket o = (Bucket) other;
512        
513            return
514                    (this.low == o.low)
515                &&  (this.high == o.high)
516                &&  (this.count == o.count);
517        }
518        
519        /** Generates a Hash-Code for {@code 'this'} instance */
520        public int hashCode()
521        {
522            return
523                    this.low
524                +   this.high
525                +   this.count;
526        }
527    }
528    
529    /**
530     * Chrome histogram.
531     * <BR />
532     * <BR /><B>EXPERIMENTAL</B>
533     */
534    public static class Histogram
535        extends BaseType
536        implements java.io.Serializable
537    {
538        /** For Object Serialization.  java.io.Serializable */
539        protected static final long serialVersionUID = 1;
540        
541        public boolean[] optionals()
542        { return new boolean[] { false, false, false, false, }; }
543        
544        /** Name. */
545        public final String name;
546        
547        /** Sum of sample values. */
548        public final int sum;
549        
550        /** Total number of samples. */
551        public final int count;
552        
553        /** Buckets. */
554        public final Browser.Bucket[] buckets;
555        
556        /**
557         * Constructor
558         *
559         * @param name Name.
560         * 
561         * @param sum Sum of sample values.
562         * 
563         * @param count Total number of samples.
564         * 
565         * @param buckets Buckets.
566         */
567        public Histogram(String name, int sum, int count, Browser.Bucket[] buckets)
568        {
569            // Exception-Check(s) to ensure that if any parameters which are not declared as
570            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
571            
572            if (name == null)    BRDPC.throwNPE("name");
573            if (buckets == null) BRDPC.throwNPE("buckets");
574            
575            this.name     = name;
576            this.sum      = sum;
577            this.count    = count;
578            this.buckets  = buckets;
579        }
580        
581        /**
582         * JSON Object Constructor
583         * @param jo A Json-Object having data about an instance of {@code 'Histogram'}.
584         */
585        public Histogram (JsonObject jo)
586        {
587            this.name     = ReadJSON.getString(jo, "name", false, true);
588            this.sum      = ReadPrimJSON.getInt(jo, "sum");
589            this.count    = ReadPrimJSON.getInt(jo, "count");
590            this.buckets = (jo.getJsonArray("buckets") == null)
591                ? null
592                : ReadArrJSON.DimN.objArr(jo.getJsonArray("buckets"), null, 0, Browser.Bucket[].class);
593        
594        }
595        
596        
597        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
598        public boolean equals(Object other)
599        {
600            if (other == null)                       return false;
601            if (other.getClass() != this.getClass()) return false;
602        
603            Histogram o = (Histogram) other;
604        
605            return
606                    Objects.equals(this.name, o.name)
607                &&  (this.sum == o.sum)
608                &&  (this.count == o.count)
609                &&  Arrays.deepEquals(this.buckets, o.buckets);
610        }
611        
612        /** Generates a Hash-Code for {@code 'this'} instance */
613        public int hashCode()
614        {
615            return
616                    Objects.hashCode(this.name)
617                +   this.sum
618                +   this.count
619                +   Arrays.deepHashCode(this.buckets);
620        }
621    }
622    
623    /**
624     * Fired when page is about to start a download.
625     * <BR />
626     * <BR /><B>EXPERIMENTAL</B>
627     */
628    public static class downloadWillBegin
629        extends BrowserEvent
630        implements java.io.Serializable
631    {
632        /** For Object Serialization.  java.io.Serializable */
633        protected static final long serialVersionUID = 1;
634        
635        public boolean[] optionals()
636        { return new boolean[] { false, false, false, false, }; }
637        
638        /** Id of the frame that caused the download to begin. */
639        public final String frameId;
640        
641        /** Global unique identifier of the download. */
642        public final String guid;
643        
644        /** URL of the resource being downloaded. */
645        public final String url;
646        
647        /** Suggested file name of the resource (the actual name of the file saved on disk may differ). */
648        public final String suggestedFilename;
649        
650        /**
651         * Constructor
652         *
653         * @param frameId Id of the frame that caused the download to begin.
654         * 
655         * @param guid Global unique identifier of the download.
656         * 
657         * @param url URL of the resource being downloaded.
658         * 
659         * @param suggestedFilename Suggested file name of the resource (the actual name of the file saved on disk may differ).
660         */
661        public downloadWillBegin
662            (String frameId, String guid, String url, String suggestedFilename)
663        {
664            super("Browser", "downloadWillBegin", 4);
665            
666            // Exception-Check(s) to ensure that if any parameters which are not declared as
667            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
668            
669            if (frameId == null)           BRDPC.throwNPE("frameId");
670            if (guid == null)              BRDPC.throwNPE("guid");
671            if (url == null)               BRDPC.throwNPE("url");
672            if (suggestedFilename == null) BRDPC.throwNPE("suggestedFilename");
673            
674            this.frameId            = frameId;
675            this.guid               = guid;
676            this.url                = url;
677            this.suggestedFilename  = suggestedFilename;
678        }
679        
680        /**
681         * JSON Object Constructor
682         * @param jo A Json-Object having data about an instance of {@code 'downloadWillBegin'}.
683         */
684        public downloadWillBegin (JsonObject jo)
685        {
686            super("Browser", "downloadWillBegin", 4);
687        
688            this.frameId            = ReadJSON.getString(jo, "frameId", false, true);
689            this.guid               = ReadJSON.getString(jo, "guid", false, true);
690            this.url                = ReadJSON.getString(jo, "url", false, true);
691            this.suggestedFilename  = ReadJSON.getString(jo, "suggestedFilename", false, true);
692        }
693        
694        
695        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
696        public boolean equals(Object other)
697        {
698            if (other == null)                       return false;
699            if (other.getClass() != this.getClass()) return false;
700        
701            downloadWillBegin o = (downloadWillBegin) other;
702        
703            return
704                    Objects.equals(this.frameId, o.frameId)
705                &&  Objects.equals(this.guid, o.guid)
706                &&  Objects.equals(this.url, o.url)
707                &&  Objects.equals(this.suggestedFilename, o.suggestedFilename);
708        }
709        
710        /** Generates a Hash-Code for {@code 'this'} instance */
711        public int hashCode()
712        {
713            return
714                    Objects.hashCode(this.frameId)
715                +   Objects.hashCode(this.guid)
716                +   Objects.hashCode(this.url)
717                +   Objects.hashCode(this.suggestedFilename);
718        }
719    }
720    
721    /**
722     * Fired when download makes progress. Last call has |done| == true.
723     * <BR />
724     * <BR /><B>EXPERIMENTAL</B>
725     */
726    public static class downloadProgress
727        extends BrowserEvent
728        implements java.io.Serializable
729    {
730        /** For Object Serialization.  java.io.Serializable */
731        protected static final long serialVersionUID = 1;
732        
733        public boolean[] optionals()
734        { return new boolean[] { false, false, false, false, }; }
735        
736        /** Global unique identifier of the download. */
737        public final String guid;
738        
739        /** Total expected bytes to download. */
740        public final Number totalBytes;
741        
742        /** Total bytes received. */
743        public final Number receivedBytes;
744        
745        /** Download status. */
746        public final String state;
747        
748        /**
749         * Constructor
750         *
751         * @param guid Global unique identifier of the download.
752         * 
753         * @param totalBytes Total expected bytes to download.
754         * 
755         * @param receivedBytes Total bytes received.
756         * 
757         * @param state Download status.
758         * <BR />Acceptable Values: ["inProgress", "completed", "canceled"]
759         */
760        public downloadProgress
761            (String guid, Number totalBytes, Number receivedBytes, String state)
762        {
763            super("Browser", "downloadProgress", 4);
764            
765            // Exception-Check(s) to ensure that if any parameters which are not declared as
766            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
767            
768            if (guid == null)          BRDPC.throwNPE("guid");
769            if (totalBytes == null)    BRDPC.throwNPE("totalBytes");
770            if (receivedBytes == null) BRDPC.throwNPE("receivedBytes");
771            if (state == null)         BRDPC.throwNPE("state");
772            
773            // Exception-Check(s) to ensure that if any parameters which must adhere to a
774            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
775            
776            BRDPC.checkIAE(
777                "state", state,
778                "inProgress", "completed", "canceled"
779            );
780            
781            this.guid           = guid;
782            this.totalBytes     = totalBytes;
783            this.receivedBytes  = receivedBytes;
784            this.state          = state;
785        }
786        
787        /**
788         * JSON Object Constructor
789         * @param jo A Json-Object having data about an instance of {@code 'downloadProgress'}.
790         */
791        public downloadProgress (JsonObject jo)
792        {
793            super("Browser", "downloadProgress", 4);
794        
795            this.guid           = ReadJSON.getString(jo, "guid", false, true);
796            this.totalBytes     = ReadNumberJSON.get(jo, "totalBytes", false, true);
797            this.receivedBytes  = ReadNumberJSON.get(jo, "receivedBytes", false, true);
798            this.state          = ReadJSON.getString(jo, "state", false, true);
799        }
800        
801        
802        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
803        public boolean equals(Object other)
804        {
805            if (other == null)                       return false;
806            if (other.getClass() != this.getClass()) return false;
807        
808            downloadProgress o = (downloadProgress) other;
809        
810            return
811                    Objects.equals(this.guid, o.guid)
812                &&  Objects.equals(this.totalBytes, o.totalBytes)
813                &&  Objects.equals(this.receivedBytes, o.receivedBytes)
814                &&  Objects.equals(this.state, o.state);
815        }
816        
817        /** Generates a Hash-Code for {@code 'this'} instance */
818        public int hashCode()
819        {
820            return
821                    Objects.hashCode(this.guid)
822                +   Objects.hashCode(this.totalBytes)
823                +   Objects.hashCode(this.receivedBytes)
824                +   Objects.hashCode(this.state);
825        }
826    }
827    
828    
829    // Counter for keeping the WebSocket Request ID's distinct.
830    private static int counter = 1;
831    
832    /**
833     * Set permission settings for given origin.
834     * <BR /><B>EXPERIMENTAL</B>
835     * 
836     * @param permission Descriptor of permission to override.
837     * 
838     * @param setting Setting of the permission.
839     * 
840     * @param origin Origin the permission applies to, all origins if not specified.
841     * <BR /><B>OPTIONAL</B>
842     * 
843     * @param browserContextId Context to override. When omitted, default browser context is used.
844     * <BR /><B>OPTIONAL</B>
845     * 
846     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
847     * {@link Ret0}&gt;</CODE>
848     *
849     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
850     * browser receives the invocation-request.
851     *
852     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
853     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
854     * {@code >} to ensure the Browser Function has run to completion.
855     */
856    public static Script<String, JsonObject, Ret0> setPermission(
857            Browser.PermissionDescriptor permission, String setting, String origin, 
858            String browserContextId
859        )
860    {
861        // Exception-Check(s) to ensure that if any parameters which are not declared as
862        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
863        
864        if (permission == null) BRDPC.throwNPE("permission");
865        if (setting == null)    BRDPC.throwNPE("setting");
866        
867        // Exception-Check(s) to ensure that if any parameters which must adhere to a
868        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
869        
870        BRDPC.checkIAE("setting", setting, "Browser.PermissionSetting", Browser.PermissionSetting);
871        
872        final int       webSocketID = 11000000 + counter++;
873        final boolean[] optionals   = { false, false, true, true, };
874        
875        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
876        String requestJSON = WriteJSON.get(
877            parameterTypes.get("setPermission"),
878            parameterNames.get("setPermission"),
879            optionals, webSocketID,
880            "Browser.setPermission",
881            permission, setting, origin, browserContextId
882        );
883        
884        // This Remote Command does not have a Return-Value.
885        return new Script<>
886            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
887    }
888    
889    /**
890     * Grant specific permissions to the given origin and reject all others.
891     * <BR /><B>EXPERIMENTAL</B>
892     * 
893     * @param permissions -
894     * 
895     * @param origin Origin the permission applies to, all origins if not specified.
896     * <BR /><B>OPTIONAL</B>
897     * 
898     * @param browserContextId BrowserContext to override permissions. When omitted, default browser context is used.
899     * <BR /><B>OPTIONAL</B>
900     * 
901     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
902     * {@link Ret0}&gt;</CODE>
903     *
904     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
905     * browser receives the invocation-request.
906     *
907     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
908     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
909     * {@code >} to ensure the Browser Function has run to completion.
910     */
911    public static Script<String, JsonObject, Ret0> grantPermissions
912        (String[] permissions, String origin, String browserContextId)
913    {
914        // Exception-Check(s) to ensure that if any parameters which are not declared as
915        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
916        
917        if (permissions == null) BRDPC.throwNPE("permissions");
918        
919        final int       webSocketID = 11001000 + counter++;
920        final boolean[] optionals   = { false, true, true, };
921        
922        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
923        String requestJSON = WriteJSON.get(
924            parameterTypes.get("grantPermissions"),
925            parameterNames.get("grantPermissions"),
926            optionals, webSocketID,
927            "Browser.grantPermissions",
928            permissions, origin, browserContextId
929        );
930        
931        // This Remote Command does not have a Return-Value.
932        return new Script<>
933            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
934    }
935    
936    /**
937     * Reset all permission management for all origins.
938     * <BR /><B>EXPERIMENTAL</B>
939     * 
940     * @param browserContextId BrowserContext to reset permissions. When omitted, default browser context is used.
941     * <BR /><B>OPTIONAL</B>
942     * 
943     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
944     * {@link Ret0}&gt;</CODE>
945     *
946     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
947     * browser receives the invocation-request.
948     *
949     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
950     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
951     * {@code >} to ensure the Browser Function has run to completion.
952     */
953    public static Script<String, JsonObject, Ret0> resetPermissions(String browserContextId)
954    {
955        final int       webSocketID = 11002000 + counter++;
956        final boolean[] optionals   = { true, };
957        
958        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
959        String requestJSON = WriteJSON.get(
960            parameterTypes.get("resetPermissions"),
961            parameterNames.get("resetPermissions"),
962            optionals, webSocketID,
963            "Browser.resetPermissions",
964            browserContextId
965        );
966        
967        // This Remote Command does not have a Return-Value.
968        return new Script<>
969            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
970    }
971    
972    /**
973     * Set the behavior when downloading a file.
974     * <BR /><B>EXPERIMENTAL</B>
975     * 
976     * @param behavior 
977     * Whether to allow all or deny all download requests, or use default Chrome behavior if
978     * available (otherwise deny). |allowAndName| allows download and names files according to
979     * their dowmload guids.
980     * <BR />Acceptable Values: ["deny", "allow", "allowAndName", "default"]
981     * 
982     * @param browserContextId BrowserContext to set download behavior. When omitted, default browser context is used.
983     * <BR /><B>OPTIONAL</B>
984     * 
985     * @param downloadPath 
986     * The default path to save downloaded files to. This is required if behavior is set to 'allow'
987     * or 'allowAndName'.
988     * <BR /><B>OPTIONAL</B>
989     * 
990     * @param eventsEnabled Whether to emit download events (defaults to false).
991     * <BR /><B>OPTIONAL</B>
992     * 
993     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
994     * {@link Ret0}&gt;</CODE>
995     *
996     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
997     * browser receives the invocation-request.
998     *
999     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1000     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1001     * {@code >} to ensure the Browser Function has run to completion.
1002     */
1003    public static Script<String, JsonObject, Ret0> setDownloadBehavior
1004        (String behavior, String browserContextId, String downloadPath, Boolean eventsEnabled)
1005    {
1006        // Exception-Check(s) to ensure that if any parameters which are not declared as
1007        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1008        
1009        if (behavior == null) BRDPC.throwNPE("behavior");
1010        
1011        // Exception-Check(s) to ensure that if any parameters which must adhere to a
1012        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
1013        
1014        BRDPC.checkIAE(
1015            "behavior", behavior,
1016            "deny", "allow", "allowAndName", "default"
1017        );
1018        
1019        final int       webSocketID = 11003000 + counter++;
1020        final boolean[] optionals   = { false, true, true, true, };
1021        
1022        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1023        String requestJSON = WriteJSON.get(
1024            parameterTypes.get("setDownloadBehavior"),
1025            parameterNames.get("setDownloadBehavior"),
1026            optionals, webSocketID,
1027            "Browser.setDownloadBehavior",
1028            behavior, browserContextId, downloadPath, eventsEnabled
1029        );
1030        
1031        // This Remote Command does not have a Return-Value.
1032        return new Script<>
1033            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1034    }
1035    
1036    /**
1037     * Cancel a download if in progress
1038     * <BR /><B>EXPERIMENTAL</B>
1039     * 
1040     * @param guid Global unique identifier of the download.
1041     * 
1042     * @param browserContextId BrowserContext to perform the action in. When omitted, default browser context is used.
1043     * <BR /><B>OPTIONAL</B>
1044     * 
1045     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1046     * {@link Ret0}&gt;</CODE>
1047     *
1048     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1049     * browser receives the invocation-request.
1050     *
1051     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1052     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1053     * {@code >} to ensure the Browser Function has run to completion.
1054     */
1055    public static Script<String, JsonObject, Ret0> cancelDownload
1056        (String guid, String browserContextId)
1057    {
1058        // Exception-Check(s) to ensure that if any parameters which are not declared as
1059        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1060        
1061        if (guid == null) BRDPC.throwNPE("guid");
1062        
1063        final int       webSocketID = 11004000 + counter++;
1064        final boolean[] optionals   = { false, true, };
1065        
1066        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1067        String requestJSON = WriteJSON.get(
1068            parameterTypes.get("cancelDownload"),
1069            parameterNames.get("cancelDownload"),
1070            optionals, webSocketID,
1071            "Browser.cancelDownload",
1072            guid, browserContextId
1073        );
1074        
1075        // This Remote Command does not have a Return-Value.
1076        return new Script<>
1077            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1078    }
1079    
1080    /**
1081     * Close browser gracefully.
1082     * 
1083     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1084     * {@link Ret0}&gt;</CODE>
1085     *
1086     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1087     * browser receives the invocation-request.
1088     *
1089     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1090     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1091     * {@code >} to ensure the Browser Function has run to completion.
1092     */
1093    public static Script<String, JsonObject, Ret0> close()
1094    {
1095        final int          webSocketID = 11005000 + counter++;
1096        final boolean[]    optionals   = new boolean[0];
1097        
1098        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1099        String requestJSON = WriteJSON.get(
1100            parameterTypes.get("close"),
1101            parameterNames.get("close"),
1102            optionals, webSocketID,
1103            "Browser.close"
1104        );
1105        
1106        // This Remote Command does not have a Return-Value.
1107        return new Script<>
1108            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1109    }
1110    
1111    /**
1112     * Crashes browser on the main thread.
1113     * <BR /><B>EXPERIMENTAL</B>
1114     * 
1115     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1116     * {@link Ret0}&gt;</CODE>
1117     *
1118     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1119     * browser receives the invocation-request.
1120     *
1121     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1122     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1123     * {@code >} to ensure the Browser Function has run to completion.
1124     */
1125    public static Script<String, JsonObject, Ret0> crash()
1126    {
1127        final int          webSocketID = 11006000 + counter++;
1128        final boolean[]    optionals   = new boolean[0];
1129        
1130        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1131        String requestJSON = WriteJSON.get(
1132            parameterTypes.get("crash"),
1133            parameterNames.get("crash"),
1134            optionals, webSocketID,
1135            "Browser.crash"
1136        );
1137        
1138        // This Remote Command does not have a Return-Value.
1139        return new Script<>
1140            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1141    }
1142    
1143    /**
1144     * Crashes GPU process.
1145     * <BR /><B>EXPERIMENTAL</B>
1146     * 
1147     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1148     * {@link Ret0}&gt;</CODE>
1149     *
1150     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1151     * browser receives the invocation-request.
1152     *
1153     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1154     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1155     * {@code >} to ensure the Browser Function has run to completion.
1156     */
1157    public static Script<String, JsonObject, Ret0> crashGpuProcess()
1158    {
1159        final int          webSocketID = 11007000 + counter++;
1160        final boolean[]    optionals   = new boolean[0];
1161        
1162        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1163        String requestJSON = WriteJSON.get(
1164            parameterTypes.get("crashGpuProcess"),
1165            parameterNames.get("crashGpuProcess"),
1166            optionals, webSocketID,
1167            "Browser.crashGpuProcess"
1168        );
1169        
1170        // This Remote Command does not have a Return-Value.
1171        return new Script<>
1172            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1173    }
1174    
1175    /**
1176     * Returns version information.
1177     * 
1178     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1179     * {@link Ret5}&gt;</CODE>
1180     *
1181     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
1182     * {@link Script#exec()}), and a {@link Promise} returned.
1183     *
1184     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
1185     * (using {@link Promise#await()}), the {@code Ret5} will subsequently
1186     * be returned from that call.
1187     * 
1188     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
1189     * in an instance of <B>{@link Ret5}</B>
1190     *
1191     * <BR /><BR /><UL CLASS=JDUL>
1192     * <LI><CODE><B>Ret5.a:</B> String (<B>protocolVersion</B>)</CODE>
1193     *     <BR />Protocol version.
1194     *     <BR /><BR /></LI>
1195     * <LI><CODE><B>Ret5.b:</B> String (<B>product</B>)</CODE>
1196     *     <BR />Product name.
1197     *     <BR /><BR /></LI>
1198     * <LI><CODE><B>Ret5.c:</B> String (<B>revision</B>)</CODE>
1199     *     <BR />Product revision.
1200     *     <BR /><BR /></LI>
1201     * <LI><CODE><B>Ret5.d:</B> String (<B>userAgent</B>)</CODE>
1202     *     <BR />User-Agent.
1203     *     <BR /><BR /></LI>
1204     * <LI><CODE><B>Ret5.e:</B> String (<B>jsVersion</B>)</CODE>
1205     *     <BR />V8 version.
1206     *     </LI>
1207     * </UL>
1208     */
1209    public static Script<String, JsonObject, Ret5<String, String, String, String, String>> getVersion()
1210    {
1211        final int          webSocketID = 11008000 + counter++;
1212        final boolean[]    optionals   = new boolean[0];
1213        
1214        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1215        String requestJSON = WriteJSON.get(
1216            parameterTypes.get("getVersion"),
1217            parameterNames.get("getVersion"),
1218            optionals, webSocketID,
1219            "Browser.getVersion"
1220        );
1221        
1222        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret5'
1223        Function<JsonObject, Ret5<String, String, String, String, String>> 
1224            responseProcessor = (JsonObject jo) -> new Ret5<>(
1225                ReadJSON.getString(jo, "protocolVersion", false, true),
1226                ReadJSON.getString(jo, "product", false, true),
1227                ReadJSON.getString(jo, "revision", false, true),
1228                ReadJSON.getString(jo, "userAgent", false, true),
1229                ReadJSON.getString(jo, "jsVersion", false, true)
1230            );
1231        
1232        // Pass the 'defaultSender' to Script-Constructor
1233        // The sender that is used can be changed before executing script.
1234        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1235    }
1236    
1237    /**
1238     * Returns the command line switches for the browser process if, and only if
1239     * --enable-automation is on the commandline.
1240     * <BR /><B>EXPERIMENTAL</B>
1241     * 
1242     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1243     * String[]&gt;</CODE>
1244     * 
1245     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1246     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1247     * String[]&gt;</CODE> will be returned.
1248     *
1249     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1250     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1251      * may be retrieved.</I>
1252     *
1253     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1254     * <BR /><BR /><UL CLASS=JDUL>
1255     * <LI><CODE>String[] (<B>arguments</B></CODE>)
1256     *     <BR />Commandline parameters
1257     * </LI>
1258     * </UL> */
1259    public static Script<String, JsonObject, String[]> getBrowserCommandLine()
1260    {
1261        final int          webSocketID = 11009000 + counter++;
1262        final boolean[]    optionals   = new boolean[0];
1263        
1264        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1265        String requestJSON = WriteJSON.get(
1266            parameterTypes.get("getBrowserCommandLine"),
1267            parameterNames.get("getBrowserCommandLine"),
1268            optionals, webSocketID,
1269            "Browser.getBrowserCommandLine"
1270        );
1271        
1272        // 'JSON Binding' ... Converts Browser Response-JSON to 'String[]'
1273        Function<JsonObject, String[]> responseProcessor = (JsonObject jo) ->
1274            (jo.getJsonArray("arguments") == null)
1275                ? null
1276                : ReadArrJSON.DimN.strArr(jo.getJsonArray("arguments"), null, 0, String[].class);
1277        
1278        // Pass the 'defaultSender' to Script-Constructor
1279        // The sender that is used can be changed before executing script.
1280        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1281    }
1282    
1283    /**
1284     * Get Chrome histograms.
1285     * <BR /><B>EXPERIMENTAL</B>
1286     * 
1287     * @param query 
1288     * Requested substring in name. Only histograms which have query as a
1289     * substring in their name are extracted. An empty or absent query returns
1290     * all histograms.
1291     * <BR /><B>OPTIONAL</B>
1292     * 
1293     * @param delta If true, retrieve delta since last call.
1294     * <BR /><B>OPTIONAL</B>
1295     * 
1296     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1297     * {@link Browser.Histogram}[]&gt;</CODE>
1298     * 
1299     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1300     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1301     * {@link Browser.Histogram}[]&gt;</CODE> will be returned.
1302     *
1303     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1304     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1305      * may be retrieved.</I>
1306     *
1307     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1308     * <BR /><BR /><UL CLASS=JDUL>
1309     * <LI><CODE>{@link Browser.Histogram}[] (<B>histograms</B></CODE>)
1310     *     <BR />Histograms.
1311     * </LI>
1312     * </UL> */
1313    public static Script<String, JsonObject, Browser.Histogram[]> getHistograms
1314        (String query, Boolean delta)
1315    {
1316        final int       webSocketID = 11010000 + counter++;
1317        final boolean[] optionals   = { true, true, };
1318        
1319        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1320        String requestJSON = WriteJSON.get(
1321            parameterTypes.get("getHistograms"),
1322            parameterNames.get("getHistograms"),
1323            optionals, webSocketID,
1324            "Browser.getHistograms",
1325            query, delta
1326        );
1327        
1328        // 'JSON Binding' ... Converts Browser Response-JSON to 'Browser.Histogram[]'
1329        Function<JsonObject, Browser.Histogram[]> responseProcessor = (JsonObject jo) ->
1330            (jo.getJsonArray("histograms") == null)
1331                ? null
1332                : ReadArrJSON.DimN.objArr(jo.getJsonArray("histograms"), null, 0, Browser.Histogram[].class);
1333        
1334        // Pass the 'defaultSender' to Script-Constructor
1335        // The sender that is used can be changed before executing script.
1336        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1337    }
1338    
1339    /**
1340     * Get a Chrome histogram by name.
1341     * <BR /><B>EXPERIMENTAL</B>
1342     * 
1343     * @param name Requested histogram name.
1344     * 
1345     * @param delta If true, retrieve delta since last call.
1346     * <BR /><B>OPTIONAL</B>
1347     * 
1348     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1349     * {@link Browser.Histogram}&gt;</CODE>
1350     * 
1351     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1352     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1353     * {@link Browser.Histogram}&gt;</CODE> will be returned.
1354     *
1355     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1356     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1357      * may be retrieved.</I>
1358     *
1359     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1360     * <BR /><BR /><UL CLASS=JDUL>
1361     * <LI><CODE>{@link Browser.Histogram} (<B>histogram</B></CODE>)
1362     *     <BR />Histogram.
1363     * </LI>
1364     * </UL> */
1365    public static Script<String, JsonObject, Browser.Histogram> getHistogram
1366        (String name, Boolean delta)
1367    {
1368        // Exception-Check(s) to ensure that if any parameters which are not declared as
1369        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1370        
1371        if (name == null) BRDPC.throwNPE("name");
1372        
1373        final int       webSocketID = 11011000 + counter++;
1374        final boolean[] optionals   = { false, true, };
1375        
1376        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1377        String requestJSON = WriteJSON.get(
1378            parameterTypes.get("getHistogram"),
1379            parameterNames.get("getHistogram"),
1380            optionals, webSocketID,
1381            "Browser.getHistogram",
1382            name, delta
1383        );
1384        
1385        // 'JSON Binding' ... Converts Browser Response-JSON to 'Browser.Histogram'
1386        Function<JsonObject, Browser.Histogram> responseProcessor = (JsonObject jo) ->
1387            ReadJSON.getObject(jo, "histogram", Browser.Histogram.class, false, true);
1388        
1389        // Pass the 'defaultSender' to Script-Constructor
1390        // The sender that is used can be changed before executing script.
1391        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1392    }
1393    
1394    /**
1395     * Get position and size of the browser window.
1396     * <BR /><B>EXPERIMENTAL</B>
1397     * 
1398     * @param windowId Browser window id.
1399     * 
1400     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1401     * {@link Browser.Bounds}&gt;</CODE>
1402     * 
1403     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1404     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1405     * {@link Browser.Bounds}&gt;</CODE> will be returned.
1406     *
1407     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1408     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1409      * may be retrieved.</I>
1410     *
1411     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1412     * <BR /><BR /><UL CLASS=JDUL>
1413     * <LI><CODE>{@link Browser.Bounds} (<B>bounds</B></CODE>)
1414     *     <BR />Bounds information of the window. When window state is 'minimized', the restored window
1415     *     position and size are returned.
1416     * </LI>
1417     * </UL> */
1418    public static Script<String, JsonObject, Browser.Bounds> getWindowBounds(int windowId)
1419    {
1420        final int       webSocketID = 11012000 + counter++;
1421        final boolean[] optionals   = { false, };
1422        
1423        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1424        String requestJSON = WriteJSON.get(
1425            parameterTypes.get("getWindowBounds"),
1426            parameterNames.get("getWindowBounds"),
1427            optionals, webSocketID,
1428            "Browser.getWindowBounds",
1429            windowId
1430        );
1431        
1432        // 'JSON Binding' ... Converts Browser Response-JSON to 'Browser.Bounds'
1433        Function<JsonObject, Browser.Bounds> responseProcessor = (JsonObject jo) ->
1434            ReadJSON.getObject(jo, "bounds", Browser.Bounds.class, false, true);
1435        
1436        // Pass the 'defaultSender' to Script-Constructor
1437        // The sender that is used can be changed before executing script.
1438        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1439    }
1440    
1441    /**
1442     * Get the browser window that contains the devtools target.
1443     * <BR /><B>EXPERIMENTAL</B>
1444     * 
1445     * @param targetId Devtools agent host id. If called as a part of the session, associated targetId is used.
1446     * <BR /><B>OPTIONAL</B>
1447     * 
1448     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1449     * {@link Ret2}&gt;</CODE>
1450     *
1451     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
1452     * {@link Script#exec()}), and a {@link Promise} returned.
1453     *
1454     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
1455     * (using {@link Promise#await()}), the {@code Ret2} will subsequently
1456     * be returned from that call.
1457     * 
1458     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
1459     * in an instance of <B>{@link Ret2}</B>
1460     *
1461     * <BR /><BR /><UL CLASS=JDUL>
1462     * <LI><CODE><B>Ret2.a:</B> Integer (<B>windowId</B>)</CODE>
1463     *     <BR />Browser window id.
1464     *     <BR /><BR /></LI>
1465     * <LI><CODE><B>Ret2.b:</B> {@link Browser.Bounds} (<B>bounds</B>)</CODE>
1466     *     <BR />Bounds information of the window. When window state is 'minimized', the restored window
1467     *     position and size are returned.
1468     *     </LI>
1469     * </UL>
1470     */
1471    public static Script<String, JsonObject, Ret2<Integer, Browser.Bounds>> getWindowForTarget
1472        (String targetId)
1473    {
1474        final int       webSocketID = 11013000 + counter++;
1475        final boolean[] optionals   = { true, };
1476        
1477        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1478        String requestJSON = WriteJSON.get(
1479            parameterTypes.get("getWindowForTarget"),
1480            parameterNames.get("getWindowForTarget"),
1481            optionals, webSocketID,
1482            "Browser.getWindowForTarget",
1483            targetId
1484        );
1485        
1486        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret2'
1487        Function<JsonObject, Ret2<Integer, Browser.Bounds>> 
1488            responseProcessor = (JsonObject jo) -> new Ret2<>(
1489                ReadBoxedJSON.getInteger(jo, "windowId", true),
1490                ReadJSON.getObject(jo, "bounds", Browser.Bounds.class, false, true)
1491            );
1492        
1493        // Pass the 'defaultSender' to Script-Constructor
1494        // The sender that is used can be changed before executing script.
1495        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1496    }
1497    
1498    /**
1499     * Set position and/or size of the browser window.
1500     * <BR /><B>EXPERIMENTAL</B>
1501     * 
1502     * @param windowId Browser window id.
1503     * 
1504     * @param bounds 
1505     * New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined
1506     * with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
1507     * 
1508     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1509     * {@link Ret0}&gt;</CODE>
1510     *
1511     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1512     * browser receives the invocation-request.
1513     *
1514     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1515     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1516     * {@code >} to ensure the Browser Function has run to completion.
1517     */
1518    public static Script<String, JsonObject, Ret0> setWindowBounds
1519        (int windowId, Browser.Bounds bounds)
1520    {
1521        // Exception-Check(s) to ensure that if any parameters which are not declared as
1522        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1523        
1524        if (bounds == null) BRDPC.throwNPE("bounds");
1525        
1526        final int       webSocketID = 11014000 + counter++;
1527        final boolean[] optionals   = { false, false, };
1528        
1529        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1530        String requestJSON = WriteJSON.get(
1531            parameterTypes.get("setWindowBounds"),
1532            parameterNames.get("setWindowBounds"),
1533            optionals, webSocketID,
1534            "Browser.setWindowBounds",
1535            windowId, bounds
1536        );
1537        
1538        // This Remote Command does not have a Return-Value.
1539        return new Script<>
1540            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1541    }
1542    
1543    /**
1544     * Set dock tile details, platform-specific.
1545     * <BR /><B>EXPERIMENTAL</B>
1546     * 
1547     * @param badgeLabel -
1548     * <BR /><B>OPTIONAL</B>
1549     * 
1550     * @param image Png encoded image. (Encoded as a base64 string when passed over JSON)
1551     * <BR /><B>OPTIONAL</B>
1552     * 
1553     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1554     * {@link Ret0}&gt;</CODE>
1555     *
1556     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1557     * browser receives the invocation-request.
1558     *
1559     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1560     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1561     * {@code >} to ensure the Browser Function has run to completion.
1562     */
1563    public static Script<String, JsonObject, Ret0> setDockTile(String badgeLabel, String image)
1564    {
1565        final int       webSocketID = 11015000 + counter++;
1566        final boolean[] optionals   = { true, true, };
1567        
1568        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1569        String requestJSON = WriteJSON.get(
1570            parameterTypes.get("setDockTile"),
1571            parameterNames.get("setDockTile"),
1572            optionals, webSocketID,
1573            "Browser.setDockTile",
1574            badgeLabel, image
1575        );
1576        
1577        // This Remote Command does not have a Return-Value.
1578        return new Script<>
1579            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1580    }
1581    
1582    /**
1583     * Invoke custom browser commands used by telemetry.
1584     * <BR /><B>EXPERIMENTAL</B>
1585     * 
1586     * @param commandId -
1587     * 
1588     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1589     * {@link Ret0}&gt;</CODE>
1590     *
1591     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1592     * browser receives the invocation-request.
1593     *
1594     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1595     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1596     * {@code >} to ensure the Browser Function has run to completion.
1597     */
1598    public static Script<String, JsonObject, Ret0> executeBrowserCommand(String commandId)
1599    {
1600        // Exception-Check(s) to ensure that if any parameters which are not declared as
1601        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1602        
1603        if (commandId == null) BRDPC.throwNPE("commandId");
1604        
1605        // Exception-Check(s) to ensure that if any parameters which must adhere to a
1606        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
1607        
1608        BRDPC.checkIAE("commandId", commandId, "Browser.BrowserCommandId", Browser.BrowserCommandId);
1609        
1610        final int       webSocketID = 11016000 + counter++;
1611        final boolean[] optionals   = { false, };
1612        
1613        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1614        String requestJSON = WriteJSON.get(
1615            parameterTypes.get("executeBrowserCommand"),
1616            parameterNames.get("executeBrowserCommand"),
1617            optionals, webSocketID,
1618            "Browser.executeBrowserCommand",
1619            commandId
1620        );
1621        
1622        // This Remote Command does not have a Return-Value.
1623        return new Script<>
1624            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1625    }
1626    
1627}