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><CODE>[No Description Provided by Google]</CODE></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 Storage 029{ 030 // ******************************************************************************************** 031 // ******************************************************************************************** 032 // Class Header Stuff 033 // ******************************************************************************************** 034 // ******************************************************************************************** 035 036 037 // No Pubic Constructors 038 private Storage () { } 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 : Storage.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>(2); 077 parameterNames.put("clearDataForOrigin", v); 078 Collections.addAll(v, new String[] 079 { "origin", "storageTypes", }); 080 081 v = new Vector<String>(1); 082 parameterNames.put("getCookies", v); 083 Collections.addAll(v, new String[] 084 { "browserContextId", }); 085 086 v = new Vector<String>(2); 087 parameterNames.put("setCookies", v); 088 Collections.addAll(v, new String[] 089 { "cookies", "browserContextId", }); 090 091 v = new Vector<String>(1); 092 parameterNames.put("clearCookies", v); 093 Collections.addAll(v, new String[] 094 { "browserContextId", }); 095 096 v = new Vector<String>(1); 097 parameterNames.put("getUsageAndQuota", v); 098 Collections.addAll(v, new String[] 099 { "origin", }); 100 101 v = new Vector<String>(2); 102 parameterNames.put("overrideQuotaForOrigin", v); 103 Collections.addAll(v, new String[] 104 { "origin", "quotaSize", }); 105 106 v = new Vector<String>(1); 107 parameterNames.put("trackCacheStorageForOrigin", v); 108 Collections.addAll(v, new String[] 109 { "origin", }); 110 111 v = new Vector<String>(1); 112 parameterNames.put("trackIndexedDBForOrigin", v); 113 Collections.addAll(v, new String[] 114 { "origin", }); 115 116 v = new Vector<String>(1); 117 parameterNames.put("untrackCacheStorageForOrigin", v); 118 Collections.addAll(v, new String[] 119 { "origin", }); 120 121 v = new Vector<String>(1); 122 parameterNames.put("untrackIndexedDBForOrigin", v); 123 Collections.addAll(v, new String[] 124 { "origin", }); 125 126 parameterNames.put("getTrustTokens", EMPTY_VEC_STR); 127 128 v = new Vector<String>(1); 129 parameterNames.put("clearTrustTokens", v); 130 Collections.addAll(v, new String[] 131 { "issuerOrigin", }); 132 } 133 134 135 // ******************************************************************************************** 136 // ******************************************************************************************** 137 // Types - Static Inner Classes 138 // ******************************************************************************************** 139 // ******************************************************************************************** 140 141 /** Enum of possible storage types. */ 142 public static final String[] StorageType = 143 { 144 "appcache", "cookies", "file_systems", "indexeddb", "local_storage", "shader_cache", 145 "websql", "service_workers", "cache_storage", "all", "other", 146 }; 147 148 /** Usage for a storage type. */ 149 public static class UsageForType extends BaseType 150 { 151 /** For Object Serialization. java.io.Serializable */ 152 protected static final long serialVersionUID = 1; 153 154 public boolean[] optionals() 155 { return new boolean[] { false, false, }; } 156 157 /** Name of storage type. */ 158 public final String storageType; 159 160 /** Storage usage (bytes). */ 161 public final Number usage; 162 163 /** 164 * Constructor 165 * 166 * @param storageType Name of storage type. 167 * 168 * @param usage Storage usage (bytes). 169 */ 170 public UsageForType(String storageType, Number usage) 171 { 172 // Exception-Check(s) to ensure that if any parameters which are not declared as 173 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 174 175 if (storageType == null) BRDPC.throwNPE("storageType"); 176 if (usage == null) BRDPC.throwNPE("usage"); 177 178 // Exception-Check(s) to ensure that if any parameters which must adhere to a 179 // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw. 180 181 BRDPC.checkIAE("storageType", storageType, "Storage.StorageType", Storage.StorageType); 182 183 this.storageType = storageType; 184 this.usage = usage; 185 } 186 187 /** 188 * JSON Object Constructor 189 * @param jo A Json-Object having data about an instance of {@code 'UsageForType'}. 190 */ 191 public UsageForType (JsonObject jo) 192 { 193 this.storageType = ReadJSON.getString(jo, "storageType", false, true); 194 this.usage = ReadJSON.getNUMBER(jo, "usage", false, true); 195 } 196 197 } 198 199 /** 200 * Pair of issuer origin and number of available (signed, but not used) Trust 201 * Tokens from that issuer. 202 * <BR /> 203 * <BR /><B>EXPERIMENTAL</B> 204 */ 205 public static class TrustTokens extends BaseType 206 { 207 /** For Object Serialization. java.io.Serializable */ 208 protected static final long serialVersionUID = 1; 209 210 public boolean[] optionals() 211 { return new boolean[] { false, false, }; } 212 213 /** <CODE>[No Description Provided by Google]</CODE> */ 214 public final String issuerOrigin; 215 216 /** <CODE>[No Description Provided by Google]</CODE> */ 217 public final Number count; 218 219 /** 220 * Constructor 221 * 222 * @param issuerOrigin - 223 * 224 * @param count - 225 */ 226 public TrustTokens(String issuerOrigin, Number count) 227 { 228 // Exception-Check(s) to ensure that if any parameters which are not declared as 229 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 230 231 if (issuerOrigin == null) BRDPC.throwNPE("issuerOrigin"); 232 if (count == null) BRDPC.throwNPE("count"); 233 234 this.issuerOrigin = issuerOrigin; 235 this.count = count; 236 } 237 238 /** 239 * JSON Object Constructor 240 * @param jo A Json-Object having data about an instance of {@code 'TrustTokens'}. 241 */ 242 public TrustTokens (JsonObject jo) 243 { 244 this.issuerOrigin = ReadJSON.getString(jo, "issuerOrigin", false, true); 245 this.count = ReadJSON.getNUMBER(jo, "count", false, true); 246 } 247 248 } 249 250 /** A cache's contents have been modified. */ 251 public static class cacheStorageContentUpdated extends BrowserEvent 252 { 253 /** For Object Serialization. java.io.Serializable */ 254 protected static final long serialVersionUID = 1; 255 256 public boolean[] optionals() 257 { return new boolean[] { false, false, }; } 258 259 /** Origin to update. */ 260 public final String origin; 261 262 /** Name of cache in origin. */ 263 public final String cacheName; 264 265 /** 266 * Constructor 267 * 268 * @param origin Origin to update. 269 * 270 * @param cacheName Name of cache in origin. 271 */ 272 public cacheStorageContentUpdated(String origin, String cacheName) 273 { 274 super("Storage", "cacheStorageContentUpdated", 2); 275 276 // Exception-Check(s) to ensure that if any parameters which are not declared as 277 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 278 279 if (origin == null) BRDPC.throwNPE("origin"); 280 if (cacheName == null) BRDPC.throwNPE("cacheName"); 281 282 this.origin = origin; 283 this.cacheName = cacheName; 284 } 285 286 /** 287 * JSON Object Constructor 288 * @param jo A Json-Object having data about an instance of {@code 'cacheStorageContentUpdated'}. 289 */ 290 public cacheStorageContentUpdated (JsonObject jo) 291 { 292 super("Storage", "cacheStorageContentUpdated", 2); 293 294 this.origin = ReadJSON.getString(jo, "origin", false, true); 295 this.cacheName = ReadJSON.getString(jo, "cacheName", false, true); 296 } 297 298 } 299 300 /** A cache has been added/deleted. */ 301 public static class cacheStorageListUpdated extends BrowserEvent 302 { 303 /** For Object Serialization. java.io.Serializable */ 304 protected static final long serialVersionUID = 1; 305 306 public boolean[] optionals() 307 { return new boolean[] { false, }; } 308 309 /** Origin to update. */ 310 public final String origin; 311 312 /** 313 * Constructor 314 * 315 * @param origin Origin to update. 316 */ 317 public cacheStorageListUpdated(String origin) 318 { 319 super("Storage", "cacheStorageListUpdated", 1); 320 321 // Exception-Check(s) to ensure that if any parameters which are not declared as 322 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 323 324 if (origin == null) BRDPC.throwNPE("origin"); 325 326 this.origin = origin; 327 } 328 329 /** 330 * JSON Object Constructor 331 * @param jo A Json-Object having data about an instance of {@code 'cacheStorageListUpdated'}. 332 */ 333 public cacheStorageListUpdated (JsonObject jo) 334 { 335 super("Storage", "cacheStorageListUpdated", 1); 336 337 this.origin = ReadJSON.getString(jo, "origin", false, true); 338 } 339 340 } 341 342 /** The origin's IndexedDB object store has been modified. */ 343 public static class indexedDBContentUpdated extends BrowserEvent 344 { 345 /** For Object Serialization. java.io.Serializable */ 346 protected static final long serialVersionUID = 1; 347 348 public boolean[] optionals() 349 { return new boolean[] { false, false, false, }; } 350 351 /** Origin to update. */ 352 public final String origin; 353 354 /** Database to update. */ 355 public final String databaseName; 356 357 /** ObjectStore to update. */ 358 public final String objectStoreName; 359 360 /** 361 * Constructor 362 * 363 * @param origin Origin to update. 364 * 365 * @param databaseName Database to update. 366 * 367 * @param objectStoreName ObjectStore to update. 368 */ 369 public indexedDBContentUpdated 370 (String origin, String databaseName, String objectStoreName) 371 { 372 super("Storage", "indexedDBContentUpdated", 3); 373 374 // Exception-Check(s) to ensure that if any parameters which are not declared as 375 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 376 377 if (origin == null) BRDPC.throwNPE("origin"); 378 if (databaseName == null) BRDPC.throwNPE("databaseName"); 379 if (objectStoreName == null) BRDPC.throwNPE("objectStoreName"); 380 381 this.origin = origin; 382 this.databaseName = databaseName; 383 this.objectStoreName = objectStoreName; 384 } 385 386 /** 387 * JSON Object Constructor 388 * @param jo A Json-Object having data about an instance of {@code 'indexedDBContentUpdated'}. 389 */ 390 public indexedDBContentUpdated (JsonObject jo) 391 { 392 super("Storage", "indexedDBContentUpdated", 3); 393 394 this.origin = ReadJSON.getString(jo, "origin", false, true); 395 this.databaseName = ReadJSON.getString(jo, "databaseName", false, true); 396 this.objectStoreName = ReadJSON.getString(jo, "objectStoreName", false, true); 397 } 398 399 } 400 401 /** The origin's IndexedDB database list has been modified. */ 402 public static class indexedDBListUpdated extends BrowserEvent 403 { 404 /** For Object Serialization. java.io.Serializable */ 405 protected static final long serialVersionUID = 1; 406 407 public boolean[] optionals() 408 { return new boolean[] { false, }; } 409 410 /** Origin to update. */ 411 public final String origin; 412 413 /** 414 * Constructor 415 * 416 * @param origin Origin to update. 417 */ 418 public indexedDBListUpdated(String origin) 419 { 420 super("Storage", "indexedDBListUpdated", 1); 421 422 // Exception-Check(s) to ensure that if any parameters which are not declared as 423 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 424 425 if (origin == null) BRDPC.throwNPE("origin"); 426 427 this.origin = origin; 428 } 429 430 /** 431 * JSON Object Constructor 432 * @param jo A Json-Object having data about an instance of {@code 'indexedDBListUpdated'}. 433 */ 434 public indexedDBListUpdated (JsonObject jo) 435 { 436 super("Storage", "indexedDBListUpdated", 1); 437 438 this.origin = ReadJSON.getString(jo, "origin", false, true); 439 } 440 441 } 442 443 444 // Counter for keeping the WebSocket Request ID's distinct. 445 private static int counter = 1; 446 447 /** 448 * Clears storage for origin. 449 * 450 * @param origin Security origin. 451 * 452 * @param storageTypes Comma separated list of StorageType to clear. 453 * 454 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 455 * {@link Ret0}></CODE> 456 * 457 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 458 * browser receives the invocation-request. 459 * 460 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 461 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 462 * {@code >} to ensure the Browser Function has run to completion. 463 */ 464 public static Script<String, JsonObject, Ret0> clearDataForOrigin 465 (String origin, String storageTypes) 466 { 467 // Exception-Check(s) to ensure that if any parameters which are not declared as 468 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 469 470 if (origin == null) BRDPC.throwNPE("origin"); 471 if (storageTypes == null) BRDPC.throwNPE("storageTypes"); 472 473 final int webSocketID = 37000000 + counter++; 474 final boolean[] optionals = { false, false, }; 475 476 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 477 String requestJSON = WriteJSON.get( 478 parameterTypes.get("clearDataForOrigin"), 479 parameterNames.get("clearDataForOrigin"), 480 optionals, webSocketID, 481 "Storage.clearDataForOrigin", 482 origin, storageTypes 483 ); 484 485 // This Remote Command does not have a Return-Value. 486 return new Script<> 487 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 488 } 489 490 /** 491 * Returns all browser cookies. 492 * 493 * @param browserContextId Browser context to use when called on the browser endpoint. 494 * <BR /><B>OPTIONAL</B> 495 * 496 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 497 * {@link Network.Cookie}[]></CODE> 498 * 499 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 500 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 501 * {@link Network.Cookie}[]></CODE> will be returned. 502 * 503 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 504 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 505 * may be retrieved.</I> 506 * 507 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 508 * <BR /><BR /><UL CLASS=JDUL> 509 * <LI><CODE>{@link Network.Cookie}[] (<B>cookies</B></CODE>) 510 * <BR />Array of cookie objects. 511 * </LI> 512 * </UL> */ 513 public static Script<String, JsonObject, Network.Cookie[]> getCookies 514 (String browserContextId) 515 { 516 final int webSocketID = 37001000 + counter++; 517 final boolean[] optionals = { true, }; 518 519 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 520 String requestJSON = WriteJSON.get( 521 parameterTypes.get("getCookies"), 522 parameterNames.get("getCookies"), 523 optionals, webSocketID, 524 "Storage.getCookies", 525 browserContextId 526 ); 527 528 // 'JSON Binding' ... Converts Browser Response-JSON to 'Network.Cookie[]' 529 Function<JsonObject, Network.Cookie[]> responseProcessor = (JsonObject jo) -> 530 (jo.getJsonArray("cookies") == null) 531 ? null 532 : ReadArrJSON.DimN.objArr(jo.getJsonArray("cookies"), null, 0, Network.Cookie[].class); 533 534 // Pass the 'defaultSender' to Script-Constructor 535 // The sender that is used can be changed before executing script. 536 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 537 } 538 539 /** 540 * Sets given cookies. 541 * 542 * @param cookies Cookies to be set. 543 * 544 * @param browserContextId Browser context to use when called on the browser endpoint. 545 * <BR /><B>OPTIONAL</B> 546 * 547 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 548 * {@link Ret0}></CODE> 549 * 550 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 551 * browser receives the invocation-request. 552 * 553 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 554 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 555 * {@code >} to ensure the Browser Function has run to completion. 556 */ 557 public static Script<String, JsonObject, Ret0> setCookies 558 (Network.CookieParam[] cookies, String browserContextId) 559 { 560 // Exception-Check(s) to ensure that if any parameters which are not declared as 561 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 562 563 if (cookies == null) BRDPC.throwNPE("cookies"); 564 565 final int webSocketID = 37002000 + counter++; 566 final boolean[] optionals = { false, true, }; 567 568 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 569 String requestJSON = WriteJSON.get( 570 parameterTypes.get("setCookies"), 571 parameterNames.get("setCookies"), 572 optionals, webSocketID, 573 "Storage.setCookies", 574 cookies, browserContextId 575 ); 576 577 // This Remote Command does not have a Return-Value. 578 return new Script<> 579 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 580 } 581 582 /** 583 * Clears cookies. 584 * 585 * @param browserContextId Browser context to use when called on the browser endpoint. 586 * <BR /><B>OPTIONAL</B> 587 * 588 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 589 * {@link Ret0}></CODE> 590 * 591 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 592 * browser receives the invocation-request. 593 * 594 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 595 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 596 * {@code >} to ensure the Browser Function has run to completion. 597 */ 598 public static Script<String, JsonObject, Ret0> clearCookies(String browserContextId) 599 { 600 final int webSocketID = 37003000 + counter++; 601 final boolean[] optionals = { true, }; 602 603 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 604 String requestJSON = WriteJSON.get( 605 parameterTypes.get("clearCookies"), 606 parameterNames.get("clearCookies"), 607 optionals, webSocketID, 608 "Storage.clearCookies", 609 browserContextId 610 ); 611 612 // This Remote Command does not have a Return-Value. 613 return new Script<> 614 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 615 } 616 617 /** 618 * Returns usage and quota in bytes. 619 * 620 * @param origin Security origin. 621 * 622 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 623 * {@link Ret4}></CODE> 624 * 625 * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 626 * {@link Script#exec()}), and a {@link Promise} returned. 627 * 628 * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B> 629 * (using {@link Promise#await()}), the {@code Ret4} will subsequently 630 * be returned from that call. 631 * 632 * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated 633 * in an instance of <B>{@link Ret4}</B> 634 * 635 * <BR /><BR /><UL CLASS=JDUL> 636 * <LI><CODE><B>Ret4.a:</B> Number (<B>usage</B>)</CODE> 637 * <BR />Storage usage (bytes). 638 * <BR /><BR /></LI> 639 * <LI><CODE><B>Ret4.b:</B> Number (<B>quota</B>)</CODE> 640 * <BR />Storage quota (bytes). 641 * <BR /><BR /></LI> 642 * <LI><CODE><B>Ret4.c:</B> Boolean (<B>overrideActive</B>)</CODE> 643 * <BR />Whether or not the origin has an active storage quota override 644 * <BR /><BR /></LI> 645 * <LI><CODE><B>Ret4.d:</B> {@link Storage.UsageForType}[] (<B>usageBreakdown</B>)</CODE> 646 * <BR />Storage usage per type (bytes). 647 * </LI> 648 * </UL> 649 */ 650 public static Script<String, JsonObject, Ret4<Number, Number, Boolean, Storage.UsageForType[]>> getUsageAndQuota 651 (String origin) 652 { 653 // Exception-Check(s) to ensure that if any parameters which are not declared as 654 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 655 656 if (origin == null) BRDPC.throwNPE("origin"); 657 658 final int webSocketID = 37004000 + counter++; 659 final boolean[] optionals = { false, }; 660 661 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 662 String requestJSON = WriteJSON.get( 663 parameterTypes.get("getUsageAndQuota"), 664 parameterNames.get("getUsageAndQuota"), 665 optionals, webSocketID, 666 "Storage.getUsageAndQuota", 667 origin 668 ); 669 670 // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret4' 671 Function<JsonObject, Ret4<Number, Number, Boolean, Storage.UsageForType[]>> 672 responseProcessor = (JsonObject jo) -> new Ret4<>( 673 ReadJSON.getNUMBER(jo, "usage", false, true), 674 ReadJSON.getNUMBER(jo, "quota", false, true), 675 ReadJSON.getBOOLEAN(jo, "overrideActive", true), 676 (jo.getJsonArray("usageBreakdown") == null) 677 ? null 678 : ReadArrJSON.DimN.objArr(jo.getJsonArray("usageBreakdown"), null, 0, Storage.UsageForType[].class) 679 ); 680 681 // Pass the 'defaultSender' to Script-Constructor 682 // The sender that is used can be changed before executing script. 683 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 684 } 685 686 /** 687 * Override quota for the specified origin 688 * <BR /><B>EXPERIMENTAL</B> 689 * 690 * @param origin Security origin. 691 * 692 * @param quotaSize 693 * The quota size (in bytes) to override the original quota with. 694 * If this is called multiple times, the overridden quota will be equal to 695 * the quotaSize provided in the final call. If this is called without 696 * specifying a quotaSize, the quota will be reset to the default value for 697 * the specified origin. If this is called multiple times with different 698 * origins, the override will be maintained for each origin until it is 699 * disabled (called without a quotaSize). 700 * <BR /><B>OPTIONAL</B> 701 * 702 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 703 * {@link Ret0}></CODE> 704 * 705 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 706 * browser receives the invocation-request. 707 * 708 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 709 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 710 * {@code >} to ensure the Browser Function has run to completion. 711 */ 712 public static Script<String, JsonObject, Ret0> overrideQuotaForOrigin 713 (String origin, Number quotaSize) 714 { 715 // Exception-Check(s) to ensure that if any parameters which are not declared as 716 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 717 718 if (origin == null) BRDPC.throwNPE("origin"); 719 720 final int webSocketID = 37005000 + counter++; 721 final boolean[] optionals = { false, true, }; 722 723 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 724 String requestJSON = WriteJSON.get( 725 parameterTypes.get("overrideQuotaForOrigin"), 726 parameterNames.get("overrideQuotaForOrigin"), 727 optionals, webSocketID, 728 "Storage.overrideQuotaForOrigin", 729 origin, quotaSize 730 ); 731 732 // This Remote Command does not have a Return-Value. 733 return new Script<> 734 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 735 } 736 737 /** 738 * Registers origin to be notified when an update occurs to its cache storage list. 739 * 740 * @param origin Security origin. 741 * 742 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 743 * {@link Ret0}></CODE> 744 * 745 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 746 * browser receives the invocation-request. 747 * 748 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 749 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 750 * {@code >} to ensure the Browser Function has run to completion. 751 */ 752 public static Script<String, JsonObject, Ret0> trackCacheStorageForOrigin(String origin) 753 { 754 // Exception-Check(s) to ensure that if any parameters which are not declared as 755 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 756 757 if (origin == null) BRDPC.throwNPE("origin"); 758 759 final int webSocketID = 37006000 + counter++; 760 final boolean[] optionals = { false, }; 761 762 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 763 String requestJSON = WriteJSON.get( 764 parameterTypes.get("trackCacheStorageForOrigin"), 765 parameterNames.get("trackCacheStorageForOrigin"), 766 optionals, webSocketID, 767 "Storage.trackCacheStorageForOrigin", 768 origin 769 ); 770 771 // This Remote Command does not have a Return-Value. 772 return new Script<> 773 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 774 } 775 776 /** 777 * Registers origin to be notified when an update occurs to its IndexedDB. 778 * 779 * @param origin Security origin. 780 * 781 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 782 * {@link Ret0}></CODE> 783 * 784 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 785 * browser receives the invocation-request. 786 * 787 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 788 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 789 * {@code >} to ensure the Browser Function has run to completion. 790 */ 791 public static Script<String, JsonObject, Ret0> trackIndexedDBForOrigin(String origin) 792 { 793 // Exception-Check(s) to ensure that if any parameters which are not declared as 794 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 795 796 if (origin == null) BRDPC.throwNPE("origin"); 797 798 final int webSocketID = 37007000 + counter++; 799 final boolean[] optionals = { false, }; 800 801 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 802 String requestJSON = WriteJSON.get( 803 parameterTypes.get("trackIndexedDBForOrigin"), 804 parameterNames.get("trackIndexedDBForOrigin"), 805 optionals, webSocketID, 806 "Storage.trackIndexedDBForOrigin", 807 origin 808 ); 809 810 // This Remote Command does not have a Return-Value. 811 return new Script<> 812 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 813 } 814 815 /** 816 * Unregisters origin from receiving notifications for cache storage. 817 * 818 * @param origin Security origin. 819 * 820 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 821 * {@link Ret0}></CODE> 822 * 823 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 824 * browser receives the invocation-request. 825 * 826 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 827 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 828 * {@code >} to ensure the Browser Function has run to completion. 829 */ 830 public static Script<String, JsonObject, Ret0> untrackCacheStorageForOrigin(String origin) 831 { 832 // Exception-Check(s) to ensure that if any parameters which are not declared as 833 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 834 835 if (origin == null) BRDPC.throwNPE("origin"); 836 837 final int webSocketID = 37008000 + counter++; 838 final boolean[] optionals = { false, }; 839 840 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 841 String requestJSON = WriteJSON.get( 842 parameterTypes.get("untrackCacheStorageForOrigin"), 843 parameterNames.get("untrackCacheStorageForOrigin"), 844 optionals, webSocketID, 845 "Storage.untrackCacheStorageForOrigin", 846 origin 847 ); 848 849 // This Remote Command does not have a Return-Value. 850 return new Script<> 851 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 852 } 853 854 /** 855 * Unregisters origin from receiving notifications for IndexedDB. 856 * 857 * @param origin Security origin. 858 * 859 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 860 * {@link Ret0}></CODE> 861 * 862 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 863 * browser receives the invocation-request. 864 * 865 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 866 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 867 * {@code >} to ensure the Browser Function has run to completion. 868 */ 869 public static Script<String, JsonObject, Ret0> untrackIndexedDBForOrigin(String origin) 870 { 871 // Exception-Check(s) to ensure that if any parameters which are not declared as 872 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 873 874 if (origin == null) BRDPC.throwNPE("origin"); 875 876 final int webSocketID = 37009000 + counter++; 877 final boolean[] optionals = { false, }; 878 879 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 880 String requestJSON = WriteJSON.get( 881 parameterTypes.get("untrackIndexedDBForOrigin"), 882 parameterNames.get("untrackIndexedDBForOrigin"), 883 optionals, webSocketID, 884 "Storage.untrackIndexedDBForOrigin", 885 origin 886 ); 887 888 // This Remote Command does not have a Return-Value. 889 return new Script<> 890 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 891 } 892 893 /** 894 * Returns the number of stored Trust Tokens per issuer for the 895 * current browsing context. 896 * <BR /><B>EXPERIMENTAL</B> 897 * 898 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 899 * {@link Storage.TrustTokens}[]></CODE> 900 * 901 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 902 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 903 * {@link Storage.TrustTokens}[]></CODE> will be returned. 904 * 905 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 906 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 907 * may be retrieved.</I> 908 * 909 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 910 * <BR /><BR /><UL CLASS=JDUL> 911 * <LI><CODE>{@link Storage.TrustTokens}[] (<B>tokens</B></CODE>) 912 * <BR />- 913 * </LI> 914 * </UL> */ 915 public static Script<String, JsonObject, Storage.TrustTokens[]> getTrustTokens() 916 { 917 final int webSocketID = 37010000 + counter++; 918 final boolean[] optionals = new boolean[0]; 919 920 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 921 String requestJSON = WriteJSON.get( 922 parameterTypes.get("getTrustTokens"), 923 parameterNames.get("getTrustTokens"), 924 optionals, webSocketID, 925 "Storage.getTrustTokens" 926 ); 927 928 // 'JSON Binding' ... Converts Browser Response-JSON to 'Storage.TrustTokens[]' 929 Function<JsonObject, Storage.TrustTokens[]> responseProcessor = (JsonObject jo) -> 930 (jo.getJsonArray("tokens") == null) 931 ? null 932 : ReadArrJSON.DimN.objArr(jo.getJsonArray("tokens"), null, 0, Storage.TrustTokens[].class); 933 934 // Pass the 'defaultSender' to Script-Constructor 935 // The sender that is used can be changed before executing script. 936 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 937 } 938 939 /** 940 * Removes all Trust Tokens issued by the provided issuerOrigin. 941 * Leaves other stored data, including the issuer's Redemption Records, intact. 942 * <BR /><B>EXPERIMENTAL</B> 943 * 944 * @param issuerOrigin - 945 * 946 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 947 * Boolean></CODE> 948 * 949 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 950 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 951 * Boolean></CODE> will be returned. 952 * 953 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 954 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 955 * may be retrieved.</I> 956 * 957 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 958 * <BR /><BR /><UL CLASS=JDUL> 959 * <LI><CODE>Boolean (<B>didDeleteTokens</B></CODE>) 960 * <BR />True if any tokens were deleted, false otherwise. 961 * </LI> 962 * </UL> */ 963 public static Script<String, JsonObject, Boolean> clearTrustTokens(String issuerOrigin) 964 { 965 // Exception-Check(s) to ensure that if any parameters which are not declared as 966 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 967 968 if (issuerOrigin == null) BRDPC.throwNPE("issuerOrigin"); 969 970 final int webSocketID = 37011000 + counter++; 971 final boolean[] optionals = { false, }; 972 973 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 974 String requestJSON = WriteJSON.get( 975 parameterTypes.get("clearTrustTokens"), 976 parameterNames.get("clearTrustTokens"), 977 optionals, webSocketID, 978 "Storage.clearTrustTokens", 979 issuerOrigin 980 ); 981 982 // 'JSON Binding' ... Converts Browser Response-JSON to 'Boolean' 983 Function<JsonObject, Boolean> responseProcessor = (JsonObject jo) -> 984 ReadJSON.getBoolean(jo, "didDeleteTokens"); 985 986 // Pass the 'defaultSender' to Script-Constructor 987 // The sender that is used can be changed before executing script. 988 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 989 } 990 991}