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.FedCm$$Commands; 019 020 021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 022// JDK Imports 023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 024 025import javax.json.JsonObject; 026import javax.json.JsonValue; 027 028/** 029 * <SPAN CLASS=COPIEDJDK><B>This domain allows interacting with the FedCM dialog.</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 FedCm 034{ 035 // No Pubic Constructors 036 private FedCm() { } 037 038 039 // ******************************************************************************************** 040 // ******************************************************************************************** 041 // Enumerated String Constants Lists 042 // ******************************************************************************************** 043 // ******************************************************************************************** 044 045 046 /** 047 * The URLs that each account has 048 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 049 */ 050 public static final ReadOnlyList<String> AccountUrlType = new ReadOnlyArrayList<> 051 (String.class, "PrivacyPolicy", "TermsOfService"); 052 053 /** 054 * The buttons on the FedCM dialog. 055 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 056 */ 057 public static final ReadOnlyList<String> DialogButton = new ReadOnlyArrayList<> 058 (String.class, "ConfirmIdpLoginContinue", "ErrorGotIt", "ErrorMoreDetails"); 059 060 /** 061 * The types of FedCM dialogs. 062 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 063 */ 064 public static final ReadOnlyList<String> DialogType = new ReadOnlyArrayList<> 065 (String.class, "AccountChooser", "AutoReauthn", "ConfirmIdpLogin", "Error"); 066 067 /** 068 * Whether this is a sign-up or sign-in action for this account, i.e. 069 * whether this account has ever been used to sign in to this RP before. 070 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 071 */ 072 public static final ReadOnlyList<String> LoginState = new ReadOnlyArrayList<> 073 (String.class, "SignIn", "SignUp"); 074 075 076 077 // ******************************************************************************************** 078 // ******************************************************************************************** 079 // Basic Types 080 // ******************************************************************************************** 081 // ******************************************************************************************** 082 083 084 /** 085 * Corresponds to IdentityRequestAccount 086 * 087 * <EMBED CLASS=globalDefs DATA-DOMAIN=FedCm DATA-API=BrowserAPI> 088 */ 089 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 090 public static class Account 091 extends BaseType<Account> 092 implements java.io.Serializable 093 { 094 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 095 protected static final long serialVersionUID = 1; 096 097 private static final NestedHelper<FedCm.Account> singleton = 098 Torello.Browser.BrowserAPI.NestedHelpers.Types. 099 FedCm$$Account$$.singleton; 100 101 /** <CODE>[No Description Provided by Google]</CODE> */ 102 public final String accountId; 103 104 /** <CODE>[No Description Provided by Google]</CODE> */ 105 public final String email; 106 107 /** <CODE>[No Description Provided by Google]</CODE> */ 108 public final String name; 109 110 /** <CODE>[No Description Provided by Google]</CODE> */ 111 public final String givenName; 112 113 /** <CODE>[No Description Provided by Google]</CODE> */ 114 public final String pictureUrl; 115 116 /** <CODE>[No Description Provided by Google]</CODE> */ 117 public final String idpConfigUrl; 118 119 /** <CODE>[No Description Provided by Google]</CODE> */ 120 public final String idpLoginUrl; 121 122 /** 123 * <CODE>[No Description Provided by Google]</CODE> 124 * <EMBED CLASS='external-html' DATA-D=FedCm DATA-C=LoginState DATA-F=loginState DATA-FILE-ID=CDP.EL2> 125 * @see BaseType#enumStrList(String) 126 */ 127 public final String loginState; 128 129 /** 130 * These two are only set if the loginState is signUp 131 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 132 */ 133 public final String termsOfServiceUrl; 134 135 /** 136 * <CODE>[No Description Provided by Google]</CODE> 137 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 138 */ 139 public final String privacyPolicyUrl; 140 141 /** Constructor. Please review this class' fields for documentation. */ 142 public Account( 143 ReadOnlyList<Boolean> isPresent, String accountId, String email, String name, 144 String givenName, String pictureUrl, String idpConfigUrl, String idpLoginUrl, 145 String loginState, String termsOfServiceUrl, String privacyPolicyUrl 146 ) 147 { 148 super(singleton, Domains.FedCm, "Account", 10); 149 150 this.accountId = accountId; 151 this.email = email; 152 this.name = name; 153 this.givenName = givenName; 154 this.pictureUrl = pictureUrl; 155 this.idpConfigUrl = idpConfigUrl; 156 this.idpLoginUrl = idpLoginUrl; 157 this.loginState = loginState; 158 this.termsOfServiceUrl = termsOfServiceUrl; 159 this.privacyPolicyUrl = privacyPolicyUrl; 160 161 this.isPresent = (isPresent == null) 162 ? singleton.generateIsPresentList(this) 163 : THROWS.check(isPresent, 10, "FedCm.Account"); 164 } 165 166 /** Creates an instance of this class from a {@link JsonObject}.*/ 167 public static Account fromJSON(JsonObject jo) 168 { return singleton.fromJSON(jo); } 169 170 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 171 public static NestedDescriptor<Account> descriptor() 172 { return singleton.descriptor(); } 173 } 174 175 176 // ******************************************************************************************** 177 // ******************************************************************************************** 178 // Event Types 179 // ******************************************************************************************** 180 // ******************************************************************************************** 181 182 183 /** 184 * Triggered when a dialog is closed, either by user action, JS abort, 185 * or a command below. 186 * 187 * <EMBED CLASS=globalDefs DATA-DOMAIN=FedCm DATA-API=BrowserAPI> 188 */ 189 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI") 190 public static class dialogClosed 191 extends BrowserEvent<dialogClosed> 192 implements java.io.Serializable 193 { 194 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 195 protected static final long serialVersionUID = 1; 196 197 private static final NestedHelper<FedCm.dialogClosed> singleton = 198 Torello.Browser.BrowserAPI.NestedHelpers.Events. 199 FedCm$$dialogClosed$$.singleton; 200 201 /** <CODE>[No Description Provided by Google]</CODE> */ 202 public final String dialogId; 203 204 /** Constructor. Please review this class' fields for documentation. */ 205 public dialogClosed(ReadOnlyList<Boolean> isPresent, String dialogId) 206 { 207 super(singleton, Domains.FedCm, "dialogClosed", 1); 208 209 this.dialogId = dialogId; 210 211 this.isPresent = (isPresent == null) 212 ? singleton.generateIsPresentList(this) 213 : THROWS.check(isPresent, 1, "FedCm.dialogClosed"); 214 } 215 216 /** Creates an instance of this class from a {@link JsonObject}.*/ 217 public static dialogClosed fromJSON(JsonObject jo) 218 { return singleton.fromJSON(jo); } 219 220 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 221 public static NestedDescriptor<dialogClosed> descriptor() 222 { return singleton.descriptor(); } 223 } 224 225 /** 226 * <CODE>[No Description Provided by Google]</CODE> 227 * 228 * <EMBED CLASS=globalDefs DATA-DOMAIN=FedCm DATA-API=BrowserAPI> 229 */ 230 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI") 231 public static class dialogShown 232 extends BrowserEvent<dialogShown> 233 implements java.io.Serializable 234 { 235 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 236 protected static final long serialVersionUID = 1; 237 238 private static final NestedHelper<FedCm.dialogShown> singleton = 239 Torello.Browser.BrowserAPI.NestedHelpers.Events. 240 FedCm$$dialogShown$$.singleton; 241 242 /** <CODE>[No Description Provided by Google]</CODE> */ 243 public final String dialogId; 244 245 /** 246 * <CODE>[No Description Provided by Google]</CODE> 247 * <EMBED CLASS='external-html' DATA-D=FedCm DATA-C=DialogType DATA-F=dialogType DATA-FILE-ID=CDP.EL2> 248 * @see BaseType#enumStrList(String) 249 */ 250 public final String dialogType; 251 252 /** <CODE>[No Description Provided by Google]</CODE> */ 253 public final FedCm.Account[] accounts; 254 255 /** 256 * These exist primarily so that the caller can verify the 257 * RP context was used appropriately. 258 */ 259 public final String title; 260 261 /** 262 * <CODE>[No Description Provided by Google]</CODE> 263 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 264 */ 265 public final String subtitle; 266 267 /** Constructor. Please review this class' fields for documentation. */ 268 public dialogShown( 269 ReadOnlyList<Boolean> isPresent, String dialogId, String dialogType, 270 Account[] accounts, String title, String subtitle 271 ) 272 { 273 super(singleton, Domains.FedCm, "dialogShown", 5); 274 275 this.dialogId = dialogId; 276 this.dialogType = dialogType; 277 this.accounts = accounts; 278 this.title = title; 279 this.subtitle = subtitle; 280 281 this.isPresent = (isPresent == null) 282 ? singleton.generateIsPresentList(this) 283 : THROWS.check(isPresent, 5, "FedCm.dialogShown"); 284 } 285 286 /** Creates an instance of this class from a {@link JsonObject}.*/ 287 public static dialogShown fromJSON(JsonObject jo) 288 { return singleton.fromJSON(jo); } 289 290 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 291 public static NestedDescriptor<dialogShown> descriptor() 292 { return singleton.descriptor(); } 293 } 294 295 296 297 298 // ******************************************************************************************** 299 // ******************************************************************************************** 300 // Commands 301 // ******************************************************************************************** 302 // ******************************************************************************************** 303 304 305 /** 306 * <CODE>[No Description Provided by Google]</CODE> 307 * 308 * @param dialogId - 309 * 310 * @param dialogButton - 311 * 312 * @return An instance of <CODE>{@link Script}<Void></CODE> 313 * 314 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 315 * browser receives the invocation-request. 316 * 317 * <BR /><BR /><DIV CLASS=JDHint> 318 * This Browser-Function <I>does not have</I> a return-value. You may choose to 319 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 320 * the Browser Function has run to completion. 321 * </DIV> 322 */ 323 public static Script<Void> clickDialogButton(String dialogId, String dialogButton) 324 { 325 // Convert all Method Parameters into a JSON Request-Object (as a String) 326 final String requestJSON = WriteJSON.get( 327 FedCm$$Commands.clickDialogButton$$, "FedCm.clickDialogButton", 328 dialogId, dialogButton 329 ); 330 331 return Script.NO_RET(Domains.FedCm, "clickDialogButton", requestJSON); 332 } 333 334 /** 335 * <CODE>[No Description Provided by Google]</CODE> 336 * 337 * @return An instance of <CODE>{@link Script}<Void></CODE> 338 * 339 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 340 * browser receives the invocation-request. 341 * 342 * <BR /><BR /><DIV CLASS=JDHint> 343 * This Browser-Function <I>does not have</I> a return-value. You may choose to 344 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 345 * the Browser Function has run to completion. 346 * </DIV> 347 */ 348 public static Script<Void> disable() 349 { 350 // Ultra-Simple Request JSON - Because this method has no parameters 351 final String requestJSON = "{\"method\":\"FedCm.disable\"}"; 352 353 return Script.NO_RET(Domains.FedCm, "disable", requestJSON); 354 } 355 356 /** 357 * <CODE>[No Description Provided by Google]</CODE> 358 * 359 * @param dialogId - 360 * 361 * @param triggerCooldown - 362 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 363 * 364 * @return An instance of <CODE>{@link Script}<Void></CODE> 365 * 366 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 367 * browser receives the invocation-request. 368 * 369 * <BR /><BR /><DIV CLASS=JDHint> 370 * This Browser-Function <I>does not have</I> a return-value. You may choose to 371 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 372 * the Browser Function has run to completion. 373 * </DIV> 374 */ 375 public static Script<Void> dismissDialog(String dialogId, Boolean triggerCooldown) 376 { 377 // Convert all Method Parameters into a JSON Request-Object (as a String) 378 final String requestJSON = WriteJSON.get( 379 FedCm$$Commands.dismissDialog$$, "FedCm.dismissDialog", 380 dialogId, triggerCooldown 381 ); 382 383 return Script.NO_RET(Domains.FedCm, "dismissDialog", requestJSON); 384 } 385 386 /** 387 * <CODE>[No Description Provided by Google]</CODE> 388 * 389 * @param disableRejectionDelay 390 * Allows callers to disable the promise rejection delay that would 391 * normally happen, if this is unimportant to what's being tested. 392 * (step 4 of https://fedidcg.github.io/FedCM/#browser-api-rp-sign-in) 393 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 394 * 395 * @return An instance of <CODE>{@link Script}<Void></CODE> 396 * 397 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 398 * browser receives the invocation-request. 399 * 400 * <BR /><BR /><DIV CLASS=JDHint> 401 * This Browser-Function <I>does not have</I> a return-value. You may choose to 402 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 403 * the Browser Function has run to completion. 404 * </DIV> 405 */ 406 public static Script<Void> enable(Boolean disableRejectionDelay) 407 { 408 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 409 final String requestJSON = WriteJSON.get( 410 CDPTypes.BOXED_BOOLEAN, "disableRejectionDelay", true, "FedCm.enable", 411 disableRejectionDelay 412 ); 413 414 return Script.NO_RET(Domains.FedCm, "enable", requestJSON); 415 } 416 417 /** 418 * <CODE>[No Description Provided by Google]</CODE> 419 * 420 * @param dialogId - 421 * 422 * @param accountIndex - 423 * 424 * @param accountUrlType - 425 * 426 * @return An instance of <CODE>{@link Script}<Void></CODE> 427 * 428 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 429 * browser receives the invocation-request. 430 * 431 * <BR /><BR /><DIV CLASS=JDHint> 432 * This Browser-Function <I>does not have</I> a return-value. You may choose to 433 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 434 * the Browser Function has run to completion. 435 * </DIV> 436 */ 437 public static Script<Void> openUrl(String dialogId, int accountIndex, String accountUrlType) 438 { 439 // Convert all Method Parameters into a JSON Request-Object (as a String) 440 final String requestJSON = WriteJSON.get( 441 FedCm$$Commands.openUrl$$, "FedCm.openUrl", 442 dialogId, accountIndex, accountUrlType 443 ); 444 445 return Script.NO_RET(Domains.FedCm, "openUrl", requestJSON); 446 } 447 448 /** 449 * Resets the cooldown time, if any, to allow the next FedCM call to show 450 * a dialog even if one was recently dismissed by the user. 451 * 452 * @return An instance of <CODE>{@link Script}<Void></CODE> 453 * 454 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 455 * browser receives the invocation-request. 456 * 457 * <BR /><BR /><DIV CLASS=JDHint> 458 * This Browser-Function <I>does not have</I> a return-value. You may choose to 459 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 460 * the Browser Function has run to completion. 461 * </DIV> 462 */ 463 public static Script<Void> resetCooldown() 464 { 465 // Ultra-Simple Request JSON - Because this method has no parameters 466 final String requestJSON = "{\"method\":\"FedCm.resetCooldown\"}"; 467 468 return Script.NO_RET(Domains.FedCm, "resetCooldown", requestJSON); 469 } 470 471 /** 472 * <CODE>[No Description Provided by Google]</CODE> 473 * 474 * @param dialogId - 475 * 476 * @param accountIndex - 477 * 478 * @return An instance of <CODE>{@link Script}<Void></CODE> 479 * 480 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 481 * browser receives the invocation-request. 482 * 483 * <BR /><BR /><DIV CLASS=JDHint> 484 * This Browser-Function <I>does not have</I> a return-value. You may choose to 485 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 486 * the Browser Function has run to completion. 487 * </DIV> 488 */ 489 public static Script<Void> selectAccount(String dialogId, int accountIndex) 490 { 491 // Convert all Method Parameters into a JSON Request-Object (as a String) 492 final String requestJSON = WriteJSON.get( 493 FedCm$$Commands.selectAccount$$, "FedCm.selectAccount", 494 dialogId, accountIndex 495 ); 496 497 return Script.NO_RET(Domains.FedCm, "selectAccount", requestJSON); 498 } 499 500 501}