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