001package Torello.Browser.BrowserAPI;
002
003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
004// Java-HTML Imports
005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
006
007import Torello.Browser.*;
008import Torello.Browser.helper.*;
009import Torello.Browser.JavaScriptAPI.*;
010import Torello.JSON.*;
011
012import Torello.Java.ReadOnly.ReadOnlyList;
013import Torello.Java.ReadOnly.ReadOnlyArrayList;
014
015import Torello.JavaDoc.Annotations.StaticFunctional;
016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg;
017
018import Torello.Browser.BrowserAPI.NestedHelpers.Commands.Autofill$$Commands;
019
020
021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
022// JDK Imports
023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
024
025import javax.json.JsonObject;
026import javax.json.JsonValue;
027
028/**
029 * <SPAN CLASS=COPIEDJDK><B>Defines commands and events for Autofill.</B></SPAN>
030 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE>
031 */
032@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE")
033public class Autofill
034{
035    // No Pubic Constructors
036    private Autofill() { }
037
038
039    // ********************************************************************************************
040    // ********************************************************************************************
041    // Enumerated String Constants Lists
042    // ********************************************************************************************
043    // ********************************************************************************************
044
045
046    /**
047     * Specified whether a filled field was done so by using the html autocomplete attribute or autofill heuristics.
048     * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B>
049     */
050    public static final ReadOnlyList<String> FillingStrategy = new ReadOnlyArrayList<>
051        (String.class, "autocompleteAttribute", "autofillInferred");
052
053
054
055    // ********************************************************************************************
056    // ********************************************************************************************
057    // Basic Types
058    // ********************************************************************************************
059    // ********************************************************************************************
060
061
062    /**
063     * <CODE>[No Description Provided by Google]</CODE>
064     * 
065     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
066     */
067    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
068    public static class Address
069        extends BaseType<Address>
070        implements java.io.Serializable
071    {
072        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
073        protected static final long serialVersionUID = 1;
074
075        private static final NestedHelper<Autofill.Address> singleton =
076            Torello.Browser.BrowserAPI.NestedHelpers.Types.
077                Autofill$$Address$$.singleton;
078
079        /** fields and values defining an address. */
080        public final Autofill.AddressField[] fields;
081
082        /** Constructor.  Please review this class' fields for documentation. */
083        public Address(ReadOnlyList<Boolean> isPresent, AddressField[] fields)
084        {
085            super(singleton, Domains.Autofill, "Address", 1);
086
087            this.fields = fields;
088
089            this.isPresent = (isPresent == null)
090                ? singleton.generateIsPresentList(this)
091                : THROWS.check(isPresent, 1, "Autofill.Address");
092        }
093
094        /** Creates an instance of this class from a {@link JsonObject}.*/
095        public static Address fromJSON(JsonObject jo)
096        { return singleton.fromJSON(jo); }
097
098        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
099        public static NestedDescriptor<Address> descriptor()
100        { return singleton.descriptor(); }
101    }
102
103    /**
104     * <CODE>[No Description Provided by Google]</CODE>
105     * 
106     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
107     */
108    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
109    public static class AddressField
110        extends BaseType<AddressField>
111        implements java.io.Serializable
112    {
113        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
114        protected static final long serialVersionUID = 1;
115
116        private static final NestedHelper<Autofill.AddressField> singleton =
117            Torello.Browser.BrowserAPI.NestedHelpers.Types.
118                Autofill$$AddressField$$.singleton;
119
120        /** address field name, for example GIVEN_NAME. */
121        public final String name;
122
123        /** address field value, for example Jon Doe. */
124        public final String value;
125
126        /** Constructor.  Please review this class' fields for documentation. */
127        public AddressField(ReadOnlyList<Boolean> isPresent, String name, String value)
128        {
129            super(singleton, Domains.Autofill, "AddressField", 2);
130
131            this.name   = name;
132            this.value  = value;
133
134            this.isPresent = (isPresent == null)
135                ? singleton.generateIsPresentList(this)
136                : THROWS.check(isPresent, 2, "Autofill.AddressField");
137        }
138
139        /** Creates an instance of this class from a {@link JsonObject}.*/
140        public static AddressField fromJSON(JsonObject jo)
141        { return singleton.fromJSON(jo); }
142
143        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
144        public static NestedDescriptor<AddressField> descriptor()
145        { return singleton.descriptor(); }
146    }
147
148    /**
149     * A list of address fields.
150     * 
151     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
152     */
153    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
154    public static class AddressFields
155        extends BaseType<AddressFields>
156        implements java.io.Serializable
157    {
158        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
159        protected static final long serialVersionUID = 1;
160
161        private static final NestedHelper<Autofill.AddressFields> singleton =
162            Torello.Browser.BrowserAPI.NestedHelpers.Types.
163                Autofill$$AddressFields$$.singleton;
164
165        /** <CODE>[No Description Provided by Google]</CODE> */
166        public final Autofill.AddressField[] fields;
167
168        /** Constructor.  Please review this class' fields for documentation. */
169        public AddressFields(ReadOnlyList<Boolean> isPresent, AddressField[] fields)
170        {
171            super(singleton, Domains.Autofill, "AddressFields", 1);
172
173            this.fields = fields;
174
175            this.isPresent = (isPresent == null)
176                ? singleton.generateIsPresentList(this)
177                : THROWS.check(isPresent, 1, "Autofill.AddressFields");
178        }
179
180        /** Creates an instance of this class from a {@link JsonObject}.*/
181        public static AddressFields fromJSON(JsonObject jo)
182        { return singleton.fromJSON(jo); }
183
184        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
185        public static NestedDescriptor<AddressFields> descriptor()
186        { return singleton.descriptor(); }
187    }
188
189    /**
190     * Defines how an address can be displayed like in chrome://settings/addresses.
191     * Address UI is a two dimensional array, each inner array is an "address information line", and when rendered in a UI surface should be displayed as such.
192     * The following address UI for instance:
193     * [[{name: "GIVE_NAME", value: "Jon"}, {name: "FAMILY_NAME", value: "Doe"}], [{name: "CITY", value: "Munich"}, {name: "ZIP", value: "81456"}]]
194     * should allow the receiver to render:
195     * Jon Doe
196     * Munich 81456
197     * 
198     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
199     */
200    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
201    public static class AddressUI
202        extends BaseType<AddressUI>
203        implements java.io.Serializable
204    {
205        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
206        protected static final long serialVersionUID = 1;
207
208        private static final NestedHelper<Autofill.AddressUI> singleton =
209            Torello.Browser.BrowserAPI.NestedHelpers.Types.
210                Autofill$$AddressUI$$.singleton;
211
212        /** A two dimension array containing the representation of values from an address profile. */
213        public final Autofill.AddressFields[] addressFields;
214
215        /** Constructor.  Please review this class' fields for documentation. */
216        public AddressUI(ReadOnlyList<Boolean> isPresent, AddressFields[] addressFields)
217        {
218            super(singleton, Domains.Autofill, "AddressUI", 1);
219
220            this.addressFields = addressFields;
221
222            this.isPresent = (isPresent == null)
223                ? singleton.generateIsPresentList(this)
224                : THROWS.check(isPresent, 1, "Autofill.AddressUI");
225        }
226
227        /** Creates an instance of this class from a {@link JsonObject}.*/
228        public static AddressUI fromJSON(JsonObject jo)
229        { return singleton.fromJSON(jo); }
230
231        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
232        public static NestedDescriptor<AddressUI> descriptor()
233        { return singleton.descriptor(); }
234    }
235
236    /**
237     * <CODE>[No Description Provided by Google]</CODE>
238     * 
239     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
240     */
241    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
242    public static class CreditCard
243        extends BaseType<CreditCard>
244        implements java.io.Serializable
245    {
246        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
247        protected static final long serialVersionUID = 1;
248
249        private static final NestedHelper<Autofill.CreditCard> singleton =
250            Torello.Browser.BrowserAPI.NestedHelpers.Types.
251                Autofill$$CreditCard$$.singleton;
252
253        /** 16-digit credit card number. */
254        public final String number;
255
256        /** Name of the credit card owner. */
257        public final String name;
258
259        /** 2-digit expiry month. */
260        public final String expiryMonth;
261
262        /** 4-digit expiry year. */
263        public final String expiryYear;
264
265        /** 3-digit card verification code. */
266        public final String cvc;
267
268        /** Constructor.  Please review this class' fields for documentation. */
269        public CreditCard(
270                ReadOnlyList<Boolean> isPresent, String number, String name, String expiryMonth,
271                String expiryYear, String cvc
272            )
273        {
274            super(singleton, Domains.Autofill, "CreditCard", 5);
275
276            this.number         = number;
277            this.name           = name;
278            this.expiryMonth    = expiryMonth;
279            this.expiryYear     = expiryYear;
280            this.cvc            = cvc;
281
282            this.isPresent = (isPresent == null)
283                ? singleton.generateIsPresentList(this)
284                : THROWS.check(isPresent, 5, "Autofill.CreditCard");
285        }
286
287        /** Creates an instance of this class from a {@link JsonObject}.*/
288        public static CreditCard fromJSON(JsonObject jo)
289        { return singleton.fromJSON(jo); }
290
291        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
292        public static NestedDescriptor<CreditCard> descriptor()
293        { return singleton.descriptor(); }
294    }
295
296    /**
297     * <CODE>[No Description Provided by Google]</CODE>
298     * 
299     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
300     */
301    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
302    public static class FilledField
303        extends BaseType<FilledField>
304        implements java.io.Serializable
305    {
306        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
307        protected static final long serialVersionUID = 1;
308
309        private static final NestedHelper<Autofill.FilledField> singleton =
310            Torello.Browser.BrowserAPI.NestedHelpers.Types.
311                Autofill$$FilledField$$.singleton;
312
313        /** The type of the field, e.g text, password etc. */
314        public final String htmlType;
315
316        /** the html id */
317        public final String id;
318
319        /** the html name */
320        public final String name;
321
322        /** the field value */
323        public final String value;
324
325        /** The actual field type, e.g FAMILY_NAME */
326        public final String autofillType;
327
328        /**
329         * The filling strategy
330         * <EMBED CLASS='external-html' DATA-D=Autofill DATA-C=FillingStrategy DATA-F=fillingStrategy DATA-FILE-ID=CDP.EL2>
331         * @see BaseType#enumStrList(String)
332         */
333        public final String fillingStrategy;
334
335        /** The frame the field belongs to */
336        public final String frameId;
337
338        /** The form field's DOM node */
339        public final int fieldId;
340
341        /** Constructor.  Please review this class' fields for documentation. */
342        public FilledField(
343                ReadOnlyList<Boolean> isPresent, String htmlType, String id, String name,
344                String value, String autofillType, String fillingStrategy, String frameId,
345                int fieldId
346            )
347        {
348            super(singleton, Domains.Autofill, "FilledField", 8);
349
350            this.htmlType           = htmlType;
351            this.id                 = id;
352            this.name               = name;
353            this.value              = value;
354            this.autofillType       = autofillType;
355            this.fillingStrategy    = fillingStrategy;
356            this.frameId            = frameId;
357            this.fieldId            = fieldId;
358
359            this.isPresent = (isPresent == null)
360                ? singleton.generateIsPresentList(this)
361                : THROWS.check(isPresent, 8, "Autofill.FilledField");
362        }
363
364        /** Creates an instance of this class from a {@link JsonObject}.*/
365        public static FilledField fromJSON(JsonObject jo)
366        { return singleton.fromJSON(jo); }
367
368        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
369        public static NestedDescriptor<FilledField> descriptor()
370        { return singleton.descriptor(); }
371    }
372
373
374    // ********************************************************************************************
375    // ********************************************************************************************
376    // Event Types
377    // ********************************************************************************************
378    // ********************************************************************************************
379
380
381    /**
382     * Emitted when an address form is filled.
383     * 
384     * <EMBED CLASS=globalDefs DATA-DOMAIN=Autofill DATA-API=BrowserAPI>
385     */
386    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI")
387    public static class addressFormFilled
388        extends BrowserEvent<addressFormFilled>
389        implements java.io.Serializable
390    {
391        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
392        protected static final long serialVersionUID = 1;
393
394        private static final NestedHelper<Autofill.addressFormFilled> singleton =
395            Torello.Browser.BrowserAPI.NestedHelpers.Events.
396                Autofill$$addressFormFilled$$.singleton;
397
398        /** Information about the fields that were filled */
399        public final Autofill.FilledField[] filledFields;
400
401        /**
402         * An UI representation of the address used to fill the form.
403         * Consists of a 2D array where each child represents an address/profile line.
404         */
405        public final Autofill.AddressUI addressUi;
406
407        /** Constructor.  Please review this class' fields for documentation. */
408        public addressFormFilled
409            (ReadOnlyList<Boolean> isPresent, FilledField[] filledFields, AddressUI addressUi)
410        {
411            super(singleton, Domains.Autofill, "addressFormFilled", 2);
412
413            this.filledFields   = filledFields;
414            this.addressUi      = addressUi;
415
416            this.isPresent = (isPresent == null)
417                ? singleton.generateIsPresentList(this)
418                : THROWS.check(isPresent, 2, "Autofill.addressFormFilled");
419        }
420
421        /** Creates an instance of this class from a {@link JsonObject}.*/
422        public static addressFormFilled fromJSON(JsonObject jo)
423        { return singleton.fromJSON(jo); }
424
425        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
426        public static NestedDescriptor<addressFormFilled> descriptor()
427        { return singleton.descriptor(); }
428    }
429
430
431
432
433    // ********************************************************************************************
434    // ********************************************************************************************
435    // Commands
436    // ********************************************************************************************
437    // ********************************************************************************************
438
439
440    /**
441     * Disables autofill domain notifications.
442     * 
443     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
444     *
445     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
446     * browser receives the invocation-request.
447     *
448     * <BR /><BR /><DIV CLASS=JDHint>
449     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
450     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
451     * the Browser Function has run to completion.
452     * </DIV>
453     */
454    public static Script<Void> disable()
455    {
456        // Ultra-Simple Request JSON - Because this method has no parameters
457        final String requestJSON = "{\"method\":\"Autofill.disable\"}";
458
459        return Script.NO_RET(Domains.Autofill, "disable", requestJSON);
460    }
461
462    /**
463     * Enables autofill domain notifications.
464     * 
465     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
466     *
467     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
468     * browser receives the invocation-request.
469     *
470     * <BR /><BR /><DIV CLASS=JDHint>
471     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
472     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
473     * the Browser Function has run to completion.
474     * </DIV>
475     */
476    public static Script<Void> enable()
477    {
478        // Ultra-Simple Request JSON - Because this method has no parameters
479        final String requestJSON = "{\"method\":\"Autofill.enable\"}";
480
481        return Script.NO_RET(Domains.Autofill, "enable", requestJSON);
482    }
483
484    /**
485     * Set addresses so that developers can verify their forms implementation.
486     * 
487     * @param addresses -
488     * 
489     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
490     *
491     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
492     * browser receives the invocation-request.
493     *
494     * <BR /><BR /><DIV CLASS=JDHint>
495     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
496     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
497     * the Browser Function has run to completion.
498     * </DIV>
499     */
500    public static Script<Void> setAddresses(Address[] addresses)
501    {
502        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
503        final String requestJSON = WriteJSON.get(
504            CDPTypes.CDP_TYPE_ARRAY_1D, "addresses", false, "Autofill.setAddresses", (Object)
505            addresses
506        );
507
508        return Script.NO_RET(Domains.Autofill, "setAddresses", requestJSON);
509    }
510
511    /**
512     * Trigger autofill on a form identified by the fieldId.
513     * If the field and related form cannot be autofilled, returns an error.
514     * 
515     * @param fieldId Identifies a field that serves as an anchor for autofill.
516     * 
517     * @param frameId Identifies the frame that field belongs to.
518     * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
519     * 
520     * @param card Credit card information to fill out the form. Credit card data is not saved.
521     * 
522     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
523     *
524     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
525     * browser receives the invocation-request.
526     *
527     * <BR /><BR /><DIV CLASS=JDHint>
528     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
529     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
530     * the Browser Function has run to completion.
531     * </DIV>
532     */
533    public static Script<Void> trigger(int fieldId, String frameId, CreditCard card)
534    {
535        // Convert all Method Parameters into a JSON Request-Object (as a String)
536        final String requestJSON = WriteJSON.get(
537            Autofill$$Commands.trigger$$, "Autofill.trigger",
538            fieldId, frameId, card
539        );
540
541        return Script.NO_RET(Domains.Autofill, "trigger", requestJSON);
542    }
543
544
545}