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><CODE>[No Description Provided by Google]</CODE></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 Storage
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private Storage () { }
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 : Storage.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>(2);
078        parameterNames.put("clearDataForOrigin", v);
079        Collections.addAll(v, new String[]
080        { "origin", "storageTypes", });
081
082        v = new Vector<String>(1);
083        parameterNames.put("getCookies", v);
084        Collections.addAll(v, new String[]
085        { "browserContextId", });
086
087        v = new Vector<String>(2);
088        parameterNames.put("setCookies", v);
089        Collections.addAll(v, new String[]
090        { "cookies", "browserContextId", });
091
092        v = new Vector<String>(1);
093        parameterNames.put("clearCookies", v);
094        Collections.addAll(v, new String[]
095        { "browserContextId", });
096
097        v = new Vector<String>(1);
098        parameterNames.put("getUsageAndQuota", v);
099        Collections.addAll(v, new String[]
100        { "origin", });
101
102        v = new Vector<String>(2);
103        parameterNames.put("overrideQuotaForOrigin", v);
104        Collections.addAll(v, new String[]
105        { "origin", "quotaSize", });
106
107        v = new Vector<String>(1);
108        parameterNames.put("trackCacheStorageForOrigin", v);
109        Collections.addAll(v, new String[]
110        { "origin", });
111
112        v = new Vector<String>(1);
113        parameterNames.put("trackIndexedDBForOrigin", v);
114        Collections.addAll(v, new String[]
115        { "origin", });
116
117        v = new Vector<String>(1);
118        parameterNames.put("untrackCacheStorageForOrigin", v);
119        Collections.addAll(v, new String[]
120        { "origin", });
121
122        v = new Vector<String>(1);
123        parameterNames.put("untrackIndexedDBForOrigin", v);
124        Collections.addAll(v, new String[]
125        { "origin", });
126
127        parameterNames.put("getTrustTokens", EMPTY_VEC_STR);
128
129        v = new Vector<String>(1);
130        parameterNames.put("clearTrustTokens", v);
131        Collections.addAll(v, new String[]
132        { "issuerOrigin", });
133    }
134
135
136    // ********************************************************************************************
137    // ********************************************************************************************
138    // Types - Static Inner Classes
139    // ********************************************************************************************
140    // ********************************************************************************************
141
142    /** Enum of possible storage types. */
143    public static final String[] StorageType =
144    { 
145        "appcache", "cookies", "file_systems", "indexeddb", "local_storage", "shader_cache", 
146        "websql", "service_workers", "cache_storage", "all", "other", 
147    };
148    
149    /** Usage for a storage type. */
150    public static class UsageForType
151        extends BaseType
152        implements java.io.Serializable
153    {
154        /** For Object Serialization.  java.io.Serializable */
155        protected static final long serialVersionUID = 1;
156        
157        public boolean[] optionals()
158        { return new boolean[] { false, false, }; }
159        
160        /** Name of storage type. */
161        public final String storageType;
162        
163        /** Storage usage (bytes). */
164        public final Number usage;
165        
166        /**
167         * Constructor
168         *
169         * @param storageType Name of storage type.
170         * 
171         * @param usage Storage usage (bytes).
172         */
173        public UsageForType(String storageType, Number usage)
174        {
175            // Exception-Check(s) to ensure that if any parameters which are not declared as
176            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
177            
178            if (storageType == null) THROWS.throwNPE("storageType");
179            if (usage == null)       THROWS.throwNPE("usage");
180            
181            // Exception-Check(s) to ensure that if any parameters which must adhere to a
182            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
183            
184            THROWS.checkIAE("storageType", storageType, "Storage.StorageType", Storage.StorageType);
185            
186            this.storageType  = storageType;
187            this.usage        = usage;
188        }
189        
190        /**
191         * JSON Object Constructor
192         * @param jo A Json-Object having data about an instance of {@code 'UsageForType'}.
193         */
194        public UsageForType (JsonObject jo)
195        {
196            this.storageType  = ReadJSON.getString(jo, "storageType", false, true);
197            this.usage        = ReadNumberJSON.get(jo, "usage", false, true);
198        }
199        
200        
201        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
202        public boolean equals(Object other)
203        {
204            if (this == other)                       return true;
205            if (other == null)                       return false;
206            if (other.getClass() != this.getClass()) return false;
207        
208            UsageForType o = (UsageForType) other;
209        
210            return
211                    Objects.equals(this.storageType, o.storageType)
212                &&  Objects.equals(this.usage, o.usage);
213        }
214        
215        /** Generates a Hash-Code for {@code 'this'} instance */
216        public int hashCode()
217        {
218            return
219                    Objects.hashCode(this.storageType)
220                +   Objects.hashCode(this.usage);
221        }
222    }
223    
224    /**
225     * Pair of issuer origin and number of available (signed, but not used) Trust
226     * Tokens from that issuer.
227     * <BR />
228     * <BR /><B>EXPERIMENTAL</B>
229     */
230    public static class TrustTokens
231        extends BaseType
232        implements java.io.Serializable
233    {
234        /** For Object Serialization.  java.io.Serializable */
235        protected static final long serialVersionUID = 1;
236        
237        public boolean[] optionals()
238        { return new boolean[] { false, false, }; }
239        
240        /** <CODE>[No Description Provided by Google]</CODE> */
241        public final String issuerOrigin;
242        
243        /** <CODE>[No Description Provided by Google]</CODE> */
244        public final Number count;
245        
246        /**
247         * Constructor
248         *
249         * @param issuerOrigin -
250         * 
251         * @param count -
252         */
253        public TrustTokens(String issuerOrigin, Number count)
254        {
255            // Exception-Check(s) to ensure that if any parameters which are not declared as
256            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
257            
258            if (issuerOrigin == null) THROWS.throwNPE("issuerOrigin");
259            if (count == null)        THROWS.throwNPE("count");
260            
261            this.issuerOrigin  = issuerOrigin;
262            this.count         = count;
263        }
264        
265        /**
266         * JSON Object Constructor
267         * @param jo A Json-Object having data about an instance of {@code 'TrustTokens'}.
268         */
269        public TrustTokens (JsonObject jo)
270        {
271            this.issuerOrigin  = ReadJSON.getString(jo, "issuerOrigin", false, true);
272            this.count         = ReadNumberJSON.get(jo, "count", false, true);
273        }
274        
275        
276        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
277        public boolean equals(Object other)
278        {
279            if (this == other)                       return true;
280            if (other == null)                       return false;
281            if (other.getClass() != this.getClass()) return false;
282        
283            TrustTokens o = (TrustTokens) other;
284        
285            return
286                    Objects.equals(this.issuerOrigin, o.issuerOrigin)
287                &&  Objects.equals(this.count, o.count);
288        }
289        
290        /** Generates a Hash-Code for {@code 'this'} instance */
291        public int hashCode()
292        {
293            return
294                    Objects.hashCode(this.issuerOrigin)
295                +   Objects.hashCode(this.count);
296        }
297    }
298    
299    /** A cache's contents have been modified. */
300    public static class cacheStorageContentUpdated
301        extends BrowserEvent
302        implements java.io.Serializable
303    {
304        /** For Object Serialization.  java.io.Serializable */
305        protected static final long serialVersionUID = 1;
306        
307        public boolean[] optionals()
308        { return new boolean[] { false, false, }; }
309        
310        /** Origin to update. */
311        public final String origin;
312        
313        /** Name of cache in origin. */
314        public final String cacheName;
315        
316        /**
317         * Constructor
318         *
319         * @param origin Origin to update.
320         * 
321         * @param cacheName Name of cache in origin.
322         */
323        public cacheStorageContentUpdated(String origin, String cacheName)
324        {
325            super("Storage", "cacheStorageContentUpdated", 2);
326            
327            // Exception-Check(s) to ensure that if any parameters which are not declared as
328            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
329            
330            if (origin == null)    THROWS.throwNPE("origin");
331            if (cacheName == null) THROWS.throwNPE("cacheName");
332            
333            this.origin     = origin;
334            this.cacheName  = cacheName;
335        }
336        
337        /**
338         * JSON Object Constructor
339         * @param jo A Json-Object having data about an instance of {@code 'cacheStorageContentUpdated'}.
340         */
341        public cacheStorageContentUpdated (JsonObject jo)
342        {
343            super("Storage", "cacheStorageContentUpdated", 2);
344        
345            this.origin     = ReadJSON.getString(jo, "origin", false, true);
346            this.cacheName  = ReadJSON.getString(jo, "cacheName", false, true);
347        }
348        
349        
350        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
351        public boolean equals(Object other)
352        {
353            if (this == other)                       return true;
354            if (other == null)                       return false;
355            if (other.getClass() != this.getClass()) return false;
356        
357            cacheStorageContentUpdated o = (cacheStorageContentUpdated) other;
358        
359            return
360                    Objects.equals(this.origin, o.origin)
361                &&  Objects.equals(this.cacheName, o.cacheName);
362        }
363        
364        /** Generates a Hash-Code for {@code 'this'} instance */
365        public int hashCode()
366        {
367            return
368                    Objects.hashCode(this.origin)
369                +   Objects.hashCode(this.cacheName);
370        }
371    }
372    
373    /** A cache has been added/deleted. */
374    public static class cacheStorageListUpdated
375        extends BrowserEvent
376        implements java.io.Serializable
377    {
378        /** For Object Serialization.  java.io.Serializable */
379        protected static final long serialVersionUID = 1;
380        
381        public boolean[] optionals()
382        { return new boolean[] { false, }; }
383        
384        /** Origin to update. */
385        public final String origin;
386        
387        /**
388         * Constructor
389         *
390         * @param origin Origin to update.
391         */
392        public cacheStorageListUpdated(String origin)
393        {
394            super("Storage", "cacheStorageListUpdated", 1);
395            
396            // Exception-Check(s) to ensure that if any parameters which are not declared as
397            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
398            
399            if (origin == null) THROWS.throwNPE("origin");
400            
401            this.origin  = origin;
402        }
403        
404        /**
405         * JSON Object Constructor
406         * @param jo A Json-Object having data about an instance of {@code 'cacheStorageListUpdated'}.
407         */
408        public cacheStorageListUpdated (JsonObject jo)
409        {
410            super("Storage", "cacheStorageListUpdated", 1);
411        
412            this.origin  = ReadJSON.getString(jo, "origin", false, true);
413        }
414        
415        
416        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
417        public boolean equals(Object other)
418        {
419            if (this == other)                       return true;
420            if (other == null)                       return false;
421            if (other.getClass() != this.getClass()) return false;
422        
423            cacheStorageListUpdated o = (cacheStorageListUpdated) other;
424        
425            return
426                    Objects.equals(this.origin, o.origin);
427        }
428        
429        /** Generates a Hash-Code for {@code 'this'} instance */
430        public int hashCode()
431        {
432            return
433                    Objects.hashCode(this.origin);
434        }
435    }
436    
437    /** The origin's IndexedDB object store has been modified. */
438    public static class indexedDBContentUpdated
439        extends BrowserEvent
440        implements java.io.Serializable
441    {
442        /** For Object Serialization.  java.io.Serializable */
443        protected static final long serialVersionUID = 1;
444        
445        public boolean[] optionals()
446        { return new boolean[] { false, false, false, }; }
447        
448        /** Origin to update. */
449        public final String origin;
450        
451        /** Database to update. */
452        public final String databaseName;
453        
454        /** ObjectStore to update. */
455        public final String objectStoreName;
456        
457        /**
458         * Constructor
459         *
460         * @param origin Origin to update.
461         * 
462         * @param databaseName Database to update.
463         * 
464         * @param objectStoreName ObjectStore to update.
465         */
466        public indexedDBContentUpdated
467            (String origin, String databaseName, String objectStoreName)
468        {
469            super("Storage", "indexedDBContentUpdated", 3);
470            
471            // Exception-Check(s) to ensure that if any parameters which are not declared as
472            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
473            
474            if (origin == null)          THROWS.throwNPE("origin");
475            if (databaseName == null)    THROWS.throwNPE("databaseName");
476            if (objectStoreName == null) THROWS.throwNPE("objectStoreName");
477            
478            this.origin           = origin;
479            this.databaseName     = databaseName;
480            this.objectStoreName  = objectStoreName;
481        }
482        
483        /**
484         * JSON Object Constructor
485         * @param jo A Json-Object having data about an instance of {@code 'indexedDBContentUpdated'}.
486         */
487        public indexedDBContentUpdated (JsonObject jo)
488        {
489            super("Storage", "indexedDBContentUpdated", 3);
490        
491            this.origin           = ReadJSON.getString(jo, "origin", false, true);
492            this.databaseName     = ReadJSON.getString(jo, "databaseName", false, true);
493            this.objectStoreName  = ReadJSON.getString(jo, "objectStoreName", false, true);
494        }
495        
496        
497        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
498        public boolean equals(Object other)
499        {
500            if (this == other)                       return true;
501            if (other == null)                       return false;
502            if (other.getClass() != this.getClass()) return false;
503        
504            indexedDBContentUpdated o = (indexedDBContentUpdated) other;
505        
506            return
507                    Objects.equals(this.origin, o.origin)
508                &&  Objects.equals(this.databaseName, o.databaseName)
509                &&  Objects.equals(this.objectStoreName, o.objectStoreName);
510        }
511        
512        /** Generates a Hash-Code for {@code 'this'} instance */
513        public int hashCode()
514        {
515            return
516                    Objects.hashCode(this.origin)
517                +   Objects.hashCode(this.databaseName)
518                +   Objects.hashCode(this.objectStoreName);
519        }
520    }
521    
522    /** The origin's IndexedDB database list has been modified. */
523    public static class indexedDBListUpdated
524        extends BrowserEvent
525        implements java.io.Serializable
526    {
527        /** For Object Serialization.  java.io.Serializable */
528        protected static final long serialVersionUID = 1;
529        
530        public boolean[] optionals()
531        { return new boolean[] { false, }; }
532        
533        /** Origin to update. */
534        public final String origin;
535        
536        /**
537         * Constructor
538         *
539         * @param origin Origin to update.
540         */
541        public indexedDBListUpdated(String origin)
542        {
543            super("Storage", "indexedDBListUpdated", 1);
544            
545            // Exception-Check(s) to ensure that if any parameters which are not declared as
546            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
547            
548            if (origin == null) THROWS.throwNPE("origin");
549            
550            this.origin  = origin;
551        }
552        
553        /**
554         * JSON Object Constructor
555         * @param jo A Json-Object having data about an instance of {@code 'indexedDBListUpdated'}.
556         */
557        public indexedDBListUpdated (JsonObject jo)
558        {
559            super("Storage", "indexedDBListUpdated", 1);
560        
561            this.origin  = ReadJSON.getString(jo, "origin", false, true);
562        }
563        
564        
565        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
566        public boolean equals(Object other)
567        {
568            if (this == other)                       return true;
569            if (other == null)                       return false;
570            if (other.getClass() != this.getClass()) return false;
571        
572            indexedDBListUpdated o = (indexedDBListUpdated) other;
573        
574            return
575                    Objects.equals(this.origin, o.origin);
576        }
577        
578        /** Generates a Hash-Code for {@code 'this'} instance */
579        public int hashCode()
580        {
581            return
582                    Objects.hashCode(this.origin);
583        }
584    }
585    
586    
587    // Counter for keeping the WebSocket Request ID's distinct.
588    private static int counter = 1;
589    
590    /**
591     * Clears storage for origin.
592     * 
593     * @param origin Security origin.
594     * 
595     * @param storageTypes Comma separated list of StorageType to clear.
596     * 
597     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
598     * {@link Ret0}&gt;</CODE>
599     *
600     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
601     * browser receives the invocation-request.
602     *
603     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
604     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
605     * {@code >} to ensure the Browser Function has run to completion.
606     */
607    public static Script<String, JsonObject, Ret0> clearDataForOrigin
608        (String origin, String storageTypes)
609    {
610        // Exception-Check(s) to ensure that if any parameters which are not declared as
611        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
612        
613        if (origin == null)       THROWS.throwNPE("origin");
614        if (storageTypes == null) THROWS.throwNPE("storageTypes");
615        
616        final int       webSocketID = 37000000 + counter++;
617        final boolean[] optionals   = { false, false, };
618        
619        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
620        String requestJSON = WriteJSON.get(
621            parameterTypes.get("clearDataForOrigin"),
622            parameterNames.get("clearDataForOrigin"),
623            optionals, webSocketID,
624            "Storage.clearDataForOrigin",
625            origin, storageTypes
626        );
627        
628        // This Remote Command does not have a Return-Value.
629        return new Script<>
630            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
631    }
632    
633    /**
634     * Returns all browser cookies.
635     * 
636     * @param browserContextId Browser context to use when called on the browser endpoint.
637     * <BR /><B>OPTIONAL</B>
638     * 
639     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
640     * {@link Network.Cookie}[]&gt;</CODE>
641     * 
642     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
643     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
644     * {@link Network.Cookie}[]&gt;</CODE> will be returned.
645     *
646     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
647     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
648      * may be retrieved.</I>
649     *
650     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
651     * <BR /><BR /><UL CLASS=JDUL>
652     * <LI><CODE>{@link Network.Cookie}[] (<B>cookies</B></CODE>)
653     *     <BR />Array of cookie objects.
654     * </LI>
655     * </UL> */
656    public static Script<String, JsonObject, Network.Cookie[]> getCookies
657        (String browserContextId)
658    {
659        final int       webSocketID = 37001000 + counter++;
660        final boolean[] optionals   = { true, };
661        
662        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
663        String requestJSON = WriteJSON.get(
664            parameterTypes.get("getCookies"),
665            parameterNames.get("getCookies"),
666            optionals, webSocketID,
667            "Storage.getCookies",
668            browserContextId
669        );
670        
671        // 'JSON Binding' ... Converts Browser Response-JSON to 'Network.Cookie[]'
672        Function<JsonObject, Network.Cookie[]> responseProcessor = (JsonObject jo) ->
673            (jo.getJsonArray("cookies") == null)
674                ? null
675                : RJArrIntoStream.objArr(jo.getJsonArray("cookies"), null, 0, Network.Cookie.class).toArray(Network.Cookie[]::new);
676        
677        return new Script<>(webSocketID, requestJSON, responseProcessor);
678    }
679    
680    /**
681     * Sets given cookies.
682     * 
683     * @param cookies Cookies to be set.
684     * 
685     * @param browserContextId Browser context to use when called on the browser endpoint.
686     * <BR /><B>OPTIONAL</B>
687     * 
688     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
689     * {@link Ret0}&gt;</CODE>
690     *
691     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
692     * browser receives the invocation-request.
693     *
694     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
695     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
696     * {@code >} to ensure the Browser Function has run to completion.
697     */
698    public static Script<String, JsonObject, Ret0> setCookies
699        (Network.CookieParam[] cookies, String browserContextId)
700    {
701        // Exception-Check(s) to ensure that if any parameters which are not declared as
702        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
703        
704        if (cookies == null) THROWS.throwNPE("cookies");
705        
706        final int       webSocketID = 37002000 + counter++;
707        final boolean[] optionals   = { false, true, };
708        
709        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
710        String requestJSON = WriteJSON.get(
711            parameterTypes.get("setCookies"),
712            parameterNames.get("setCookies"),
713            optionals, webSocketID,
714            "Storage.setCookies",
715            cookies, browserContextId
716        );
717        
718        // This Remote Command does not have a Return-Value.
719        return new Script<>
720            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
721    }
722    
723    /**
724     * Clears cookies.
725     * 
726     * @param browserContextId Browser context to use when called on the browser endpoint.
727     * <BR /><B>OPTIONAL</B>
728     * 
729     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
730     * {@link Ret0}&gt;</CODE>
731     *
732     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
733     * browser receives the invocation-request.
734     *
735     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
736     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
737     * {@code >} to ensure the Browser Function has run to completion.
738     */
739    public static Script<String, JsonObject, Ret0> clearCookies(String browserContextId)
740    {
741        final int       webSocketID = 37003000 + counter++;
742        final boolean[] optionals   = { true, };
743        
744        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
745        String requestJSON = WriteJSON.get(
746            parameterTypes.get("clearCookies"),
747            parameterNames.get("clearCookies"),
748            optionals, webSocketID,
749            "Storage.clearCookies",
750            browserContextId
751        );
752        
753        // This Remote Command does not have a Return-Value.
754        return new Script<>
755            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
756    }
757    
758    /**
759     * Returns usage and quota in bytes.
760     * 
761     * @param origin Security origin.
762     * 
763     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
764     * {@link Ret4}&gt;</CODE>
765     *
766     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
767     * {@link Script#exec()}), and a {@link Promise} returned.
768     *
769     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
770     * (using {@link Promise#await()}), the {@code Ret4} will subsequently
771     * be returned from that call.
772     * 
773     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
774     * in an instance of <B>{@link Ret4}</B>
775     *
776     * <BR /><BR /><UL CLASS=JDUL>
777     * <LI><CODE><B>Ret4.a:</B> Number (<B>usage</B>)</CODE>
778     *     <BR />Storage usage (bytes).
779     *     <BR /><BR /></LI>
780     * <LI><CODE><B>Ret4.b:</B> Number (<B>quota</B>)</CODE>
781     *     <BR />Storage quota (bytes).
782     *     <BR /><BR /></LI>
783     * <LI><CODE><B>Ret4.c:</B> Boolean (<B>overrideActive</B>)</CODE>
784     *     <BR />Whether or not the origin has an active storage quota override
785     *     <BR /><BR /></LI>
786     * <LI><CODE><B>Ret4.d:</B> {@link Storage.UsageForType}[] (<B>usageBreakdown</B>)</CODE>
787     *     <BR />Storage usage per type (bytes).
788     *     </LI>
789     * </UL>
790     */
791    public static Script<String, JsonObject, Ret4<Number, Number, Boolean, Storage.UsageForType[]>> getUsageAndQuota
792        (String origin)
793    {
794        // Exception-Check(s) to ensure that if any parameters which are not declared as
795        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
796        
797        if (origin == null) THROWS.throwNPE("origin");
798        
799        final int       webSocketID = 37004000 + counter++;
800        final boolean[] optionals   = { false, };
801        
802        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
803        String requestJSON = WriteJSON.get(
804            parameterTypes.get("getUsageAndQuota"),
805            parameterNames.get("getUsageAndQuota"),
806            optionals, webSocketID,
807            "Storage.getUsageAndQuota",
808            origin
809        );
810        
811        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret4'
812        Function<JsonObject, Ret4<Number, Number, Boolean, Storage.UsageForType[]>> 
813            responseProcessor = (JsonObject jo) -> new Ret4<>(
814                ReadNumberJSON.get(jo, "usage", false, true),
815                ReadNumberJSON.get(jo, "quota", false, true),
816                ReadBoxedJSON.getBoolean(jo, "overrideActive", true),
817                (jo.getJsonArray("usageBreakdown") == null)
818                    ? null
819                    : RJArrIntoStream.objArr(jo.getJsonArray("usageBreakdown"), null, 0, Storage.UsageForType.class).toArray(Storage.UsageForType[]::new)
820            );
821        
822        return new Script<>(webSocketID, requestJSON, responseProcessor);
823    }
824    
825    /**
826     * Override quota for the specified origin
827     * <BR /><B>EXPERIMENTAL</B>
828     * 
829     * @param origin Security origin.
830     * 
831     * @param quotaSize 
832     * The quota size (in bytes) to override the original quota with.
833     * If this is called multiple times, the overridden quota will be equal to
834     * the quotaSize provided in the final call. If this is called without
835     * specifying a quotaSize, the quota will be reset to the default value for
836     * the specified origin. If this is called multiple times with different
837     * origins, the override will be maintained for each origin until it is
838     * disabled (called without a quotaSize).
839     * <BR /><B>OPTIONAL</B>
840     * 
841     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
842     * {@link Ret0}&gt;</CODE>
843     *
844     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
845     * browser receives the invocation-request.
846     *
847     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
848     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
849     * {@code >} to ensure the Browser Function has run to completion.
850     */
851    public static Script<String, JsonObject, Ret0> overrideQuotaForOrigin
852        (String origin, Number quotaSize)
853    {
854        // Exception-Check(s) to ensure that if any parameters which are not declared as
855        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
856        
857        if (origin == null) THROWS.throwNPE("origin");
858        
859        final int       webSocketID = 37005000 + counter++;
860        final boolean[] optionals   = { false, true, };
861        
862        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
863        String requestJSON = WriteJSON.get(
864            parameterTypes.get("overrideQuotaForOrigin"),
865            parameterNames.get("overrideQuotaForOrigin"),
866            optionals, webSocketID,
867            "Storage.overrideQuotaForOrigin",
868            origin, quotaSize
869        );
870        
871        // This Remote Command does not have a Return-Value.
872        return new Script<>
873            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
874    }
875    
876    /**
877     * Registers origin to be notified when an update occurs to its cache storage list.
878     * 
879     * @param origin Security origin.
880     * 
881     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
882     * {@link Ret0}&gt;</CODE>
883     *
884     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
885     * browser receives the invocation-request.
886     *
887     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
888     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
889     * {@code >} to ensure the Browser Function has run to completion.
890     */
891    public static Script<String, JsonObject, Ret0> trackCacheStorageForOrigin(String origin)
892    {
893        // Exception-Check(s) to ensure that if any parameters which are not declared as
894        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
895        
896        if (origin == null) THROWS.throwNPE("origin");
897        
898        final int       webSocketID = 37006000 + counter++;
899        final boolean[] optionals   = { false, };
900        
901        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
902        String requestJSON = WriteJSON.get(
903            parameterTypes.get("trackCacheStorageForOrigin"),
904            parameterNames.get("trackCacheStorageForOrigin"),
905            optionals, webSocketID,
906            "Storage.trackCacheStorageForOrigin",
907            origin
908        );
909        
910        // This Remote Command does not have a Return-Value.
911        return new Script<>
912            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
913    }
914    
915    /**
916     * Registers origin to be notified when an update occurs to its IndexedDB.
917     * 
918     * @param origin Security origin.
919     * 
920     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
921     * {@link Ret0}&gt;</CODE>
922     *
923     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
924     * browser receives the invocation-request.
925     *
926     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
927     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
928     * {@code >} to ensure the Browser Function has run to completion.
929     */
930    public static Script<String, JsonObject, Ret0> trackIndexedDBForOrigin(String origin)
931    {
932        // Exception-Check(s) to ensure that if any parameters which are not declared as
933        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
934        
935        if (origin == null) THROWS.throwNPE("origin");
936        
937        final int       webSocketID = 37007000 + counter++;
938        final boolean[] optionals   = { false, };
939        
940        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
941        String requestJSON = WriteJSON.get(
942            parameterTypes.get("trackIndexedDBForOrigin"),
943            parameterNames.get("trackIndexedDBForOrigin"),
944            optionals, webSocketID,
945            "Storage.trackIndexedDBForOrigin",
946            origin
947        );
948        
949        // This Remote Command does not have a Return-Value.
950        return new Script<>
951            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
952    }
953    
954    /**
955     * Unregisters origin from receiving notifications for cache storage.
956     * 
957     * @param origin Security origin.
958     * 
959     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
960     * {@link Ret0}&gt;</CODE>
961     *
962     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
963     * browser receives the invocation-request.
964     *
965     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
966     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
967     * {@code >} to ensure the Browser Function has run to completion.
968     */
969    public static Script<String, JsonObject, Ret0> untrackCacheStorageForOrigin(String origin)
970    {
971        // Exception-Check(s) to ensure that if any parameters which are not declared as
972        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
973        
974        if (origin == null) THROWS.throwNPE("origin");
975        
976        final int       webSocketID = 37008000 + counter++;
977        final boolean[] optionals   = { false, };
978        
979        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
980        String requestJSON = WriteJSON.get(
981            parameterTypes.get("untrackCacheStorageForOrigin"),
982            parameterNames.get("untrackCacheStorageForOrigin"),
983            optionals, webSocketID,
984            "Storage.untrackCacheStorageForOrigin",
985            origin
986        );
987        
988        // This Remote Command does not have a Return-Value.
989        return new Script<>
990            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
991    }
992    
993    /**
994     * Unregisters origin from receiving notifications for IndexedDB.
995     * 
996     * @param origin Security origin.
997     * 
998     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
999     * {@link Ret0}&gt;</CODE>
1000     *
1001     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1002     * browser receives the invocation-request.
1003     *
1004     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1005     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1006     * {@code >} to ensure the Browser Function has run to completion.
1007     */
1008    public static Script<String, JsonObject, Ret0> untrackIndexedDBForOrigin(String origin)
1009    {
1010        // Exception-Check(s) to ensure that if any parameters which are not declared as
1011        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1012        
1013        if (origin == null) THROWS.throwNPE("origin");
1014        
1015        final int       webSocketID = 37009000 + counter++;
1016        final boolean[] optionals   = { false, };
1017        
1018        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1019        String requestJSON = WriteJSON.get(
1020            parameterTypes.get("untrackIndexedDBForOrigin"),
1021            parameterNames.get("untrackIndexedDBForOrigin"),
1022            optionals, webSocketID,
1023            "Storage.untrackIndexedDBForOrigin",
1024            origin
1025        );
1026        
1027        // This Remote Command does not have a Return-Value.
1028        return new Script<>
1029            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
1030    }
1031    
1032    /**
1033     * Returns the number of stored Trust Tokens per issuer for the
1034     * current browsing context.
1035     * <BR /><B>EXPERIMENTAL</B>
1036     * 
1037     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1038     * {@link Storage.TrustTokens}[]&gt;</CODE>
1039     * 
1040     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1041     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1042     * {@link Storage.TrustTokens}[]&gt;</CODE> will be returned.
1043     *
1044     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1045     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1046      * may be retrieved.</I>
1047     *
1048     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1049     * <BR /><BR /><UL CLASS=JDUL>
1050     * <LI><CODE>{@link Storage.TrustTokens}[] (<B>tokens</B></CODE>)
1051     *     <BR />-
1052     * </LI>
1053     * </UL> */
1054    public static Script<String, JsonObject, Storage.TrustTokens[]> getTrustTokens()
1055    {
1056        final int          webSocketID = 37010000 + counter++;
1057        final boolean[]    optionals   = new boolean[0];
1058        
1059        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1060        String requestJSON = WriteJSON.get(
1061            parameterTypes.get("getTrustTokens"),
1062            parameterNames.get("getTrustTokens"),
1063            optionals, webSocketID,
1064            "Storage.getTrustTokens"
1065        );
1066        
1067        // 'JSON Binding' ... Converts Browser Response-JSON to 'Storage.TrustTokens[]'
1068        Function<JsonObject, Storage.TrustTokens[]> responseProcessor = (JsonObject jo) ->
1069            (jo.getJsonArray("tokens") == null)
1070                ? null
1071                : RJArrIntoStream.objArr(jo.getJsonArray("tokens"), null, 0, Storage.TrustTokens.class).toArray(Storage.TrustTokens[]::new);
1072        
1073        return new Script<>(webSocketID, requestJSON, responseProcessor);
1074    }
1075    
1076    /**
1077     * Removes all Trust Tokens issued by the provided issuerOrigin.
1078     * Leaves other stored data, including the issuer's Redemption Records, intact.
1079     * <BR /><B>EXPERIMENTAL</B>
1080     * 
1081     * @param issuerOrigin -
1082     * 
1083     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1084     * Boolean&gt;</CODE>
1085     * 
1086     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1087     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1088     * Boolean&gt;</CODE> will be returned.
1089     *
1090     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1091     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1092      * may be retrieved.</I>
1093     *
1094     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1095     * <BR /><BR /><UL CLASS=JDUL>
1096     * <LI><CODE>Boolean (<B>didDeleteTokens</B></CODE>)
1097     *     <BR />True if any tokens were deleted, false otherwise.
1098     * </LI>
1099     * </UL> */
1100    public static Script<String, JsonObject, Boolean> clearTrustTokens(String issuerOrigin)
1101    {
1102        // Exception-Check(s) to ensure that if any parameters which are not declared as
1103        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1104        
1105        if (issuerOrigin == null) THROWS.throwNPE("issuerOrigin");
1106        
1107        final int       webSocketID = 37011000 + counter++;
1108        final boolean[] optionals   = { false, };
1109        
1110        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1111        String requestJSON = WriteJSON.get(
1112            parameterTypes.get("clearTrustTokens"),
1113            parameterNames.get("clearTrustTokens"),
1114            optionals, webSocketID,
1115            "Storage.clearTrustTokens",
1116            issuerOrigin
1117        );
1118        
1119        // 'JSON Binding' ... Converts Browser Response-JSON to 'Boolean'
1120        Function<JsonObject, Boolean> responseProcessor = (JsonObject jo) ->
1121            ReadPrimJSON.getBoolean(jo, "didDeleteTokens");
1122        
1123        return new Script<>(webSocketID, requestJSON, responseProcessor);
1124    }
1125    
1126}