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