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