001package Torello.Browser.BrowserAPI; 002 003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 004// Java-HTML Imports 005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 006 007import Torello.Browser.*; 008import Torello.Browser.helper.*; 009import Torello.Browser.JavaScriptAPI.*; 010import Torello.JSON.*; 011 012import Torello.Java.ReadOnly.ReadOnlyList; 013import Torello.Java.ReadOnly.ReadOnlyArrayList; 014 015import Torello.JavaDoc.Annotations.StaticFunctional; 016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg; 017 018import Torello.Browser.BrowserAPI.NestedHelpers.Commands.BackgroundService$$Commands; 019 020 021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 022// JDK Imports 023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 024 025import javax.json.JsonObject; 026import javax.json.JsonValue; 027 028/** 029 * <SPAN CLASS=COPIEDJDK><B>Defines events for background web platform features.</B></SPAN> 030 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE> 031 */ 032@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE") 033public class BackgroundService 034{ 035 // No Pubic Constructors 036 private BackgroundService() { } 037 038 039 // ******************************************************************************************** 040 // ******************************************************************************************** 041 // Enumerated String Constants Lists 042 // ******************************************************************************************** 043 // ******************************************************************************************** 044 045 046 /** 047 * The Background Service that will be associated with the commands/events. 048 * Every Background Service operates independently, but they share the same 049 * API. 050 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 051 */ 052 public static final ReadOnlyList<String> ServiceName = new ReadOnlyArrayList<>( 053 String.class, 054 "backgroundFetch", "backgroundSync", "notifications", "paymentHandler", 055 "periodicBackgroundSync", "pushMessaging" 056 ); 057 058 059 060 // ******************************************************************************************** 061 // ******************************************************************************************** 062 // Basic Types 063 // ******************************************************************************************** 064 // ******************************************************************************************** 065 066 067 /** 068 * <CODE>[No Description Provided by Google]</CODE> 069 * 070 * <EMBED CLASS=globalDefs DATA-DOMAIN=BackgroundService DATA-API=BrowserAPI> 071 */ 072 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 073 public static class BackgroundServiceEvent 074 extends BaseType<BackgroundServiceEvent> 075 implements java.io.Serializable 076 { 077 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 078 protected static final long serialVersionUID = 1; 079 080 private static final NestedHelper<BackgroundService.BackgroundServiceEvent> singleton = 081 Torello.Browser.BrowserAPI.NestedHelpers.Types. 082 BackgroundService$$BackgroundServiceEvent$$.singleton; 083 084 /** Timestamp of the event (in seconds). */ 085 public final Number timestamp; 086 087 /** The origin this event belongs to. */ 088 public final String origin; 089 090 /** The Service Worker ID that initiated the event. */ 091 public final String serviceWorkerRegistrationId; 092 093 /** 094 * The Background Service this event belongs to. 095 * <EMBED CLASS='external-html' DATA-D=BackgroundService DATA-C=ServiceName DATA-F=service DATA-FILE-ID=CDP.EL2> 096 * @see BaseType#enumStrList(String) 097 */ 098 public final String service; 099 100 /** A description of the event. */ 101 public final String eventName; 102 103 /** An identifier that groups related events together. */ 104 public final String instanceId; 105 106 /** A list of event-specific information. */ 107 public final BackgroundService.EventMetadata[] eventMetadata; 108 109 /** Storage key this event belongs to. */ 110 public final String storageKey; 111 112 /** Constructor. Please review this class' fields for documentation. */ 113 public BackgroundServiceEvent( 114 ReadOnlyList<Boolean> isPresent, Number timestamp, String origin, 115 String serviceWorkerRegistrationId, String service, String eventName, 116 String instanceId, EventMetadata[] eventMetadata, String storageKey 117 ) 118 { 119 super(singleton, Domains.BackgroundService, "BackgroundServiceEvent", 8); 120 121 this.timestamp = timestamp; 122 this.origin = origin; 123 this.serviceWorkerRegistrationId = serviceWorkerRegistrationId; 124 this.service = service; 125 this.eventName = eventName; 126 this.instanceId = instanceId; 127 this.eventMetadata = eventMetadata; 128 this.storageKey = storageKey; 129 130 this.isPresent = (isPresent == null) 131 ? singleton.generateIsPresentList(this) 132 : THROWS.check(isPresent, 8, "BackgroundService.BackgroundServiceEvent"); 133 } 134 135 /** Creates an instance of this class from a {@link JsonObject}.*/ 136 public static BackgroundServiceEvent fromJSON(JsonObject jo) 137 { return singleton.fromJSON(jo); } 138 139 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 140 public static NestedDescriptor<BackgroundServiceEvent> descriptor() 141 { return singleton.descriptor(); } 142 } 143 144 /** 145 * A key-value pair for additional event information to pass along. 146 * 147 * <EMBED CLASS=globalDefs DATA-DOMAIN=BackgroundService DATA-API=BrowserAPI> 148 */ 149 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 150 public static class EventMetadata 151 extends BaseType<EventMetadata> 152 implements java.io.Serializable 153 { 154 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 155 protected static final long serialVersionUID = 1; 156 157 private static final NestedHelper<BackgroundService.EventMetadata> singleton = 158 Torello.Browser.BrowserAPI.NestedHelpers.Types. 159 BackgroundService$$EventMetadata$$.singleton; 160 161 /** <CODE>[No Description Provided by Google]</CODE> */ 162 public final String key; 163 164 /** <CODE>[No Description Provided by Google]</CODE> */ 165 public final String value; 166 167 /** Constructor. Please review this class' fields for documentation. */ 168 public EventMetadata(ReadOnlyList<Boolean> isPresent, String key, String value) 169 { 170 super(singleton, Domains.BackgroundService, "EventMetadata", 2); 171 172 this.key = key; 173 this.value = value; 174 175 this.isPresent = (isPresent == null) 176 ? singleton.generateIsPresentList(this) 177 : THROWS.check(isPresent, 2, "BackgroundService.EventMetadata"); 178 } 179 180 /** Creates an instance of this class from a {@link JsonObject}.*/ 181 public static EventMetadata fromJSON(JsonObject jo) 182 { return singleton.fromJSON(jo); } 183 184 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 185 public static NestedDescriptor<EventMetadata> descriptor() 186 { return singleton.descriptor(); } 187 } 188 189 190 // ******************************************************************************************** 191 // ******************************************************************************************** 192 // Event Types 193 // ******************************************************************************************** 194 // ******************************************************************************************** 195 196 197 /** 198 * Called with all existing backgroundServiceEvents when enabled, and all new 199 * events afterwards if enabled and recording. 200 * 201 * <EMBED CLASS=globalDefs DATA-DOMAIN=BackgroundService DATA-API=BrowserAPI> 202 */ 203 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI") 204 public static class backgroundServiceEventReceived 205 extends BrowserEvent<backgroundServiceEventReceived> 206 implements java.io.Serializable 207 { 208 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 209 protected static final long serialVersionUID = 1; 210 211 private static final NestedHelper<BackgroundService.backgroundServiceEventReceived> singleton = 212 Torello.Browser.BrowserAPI.NestedHelpers.Events. 213 BackgroundService$$backgroundServiceEventReceived$$.singleton; 214 215 /** <CODE>[No Description Provided by Google]</CODE> */ 216 public final BackgroundService.BackgroundServiceEvent backgroundServiceEvent; 217 218 /** Constructor. Please review this class' fields for documentation. */ 219 public backgroundServiceEventReceived 220 (ReadOnlyList<Boolean> isPresent, BackgroundServiceEvent backgroundServiceEvent) 221 { 222 super(singleton, Domains.BackgroundService, "backgroundServiceEventReceived", 1); 223 224 this.backgroundServiceEvent = backgroundServiceEvent; 225 226 this.isPresent = (isPresent == null) 227 ? singleton.generateIsPresentList(this) 228 : THROWS.check(isPresent, 1, "BackgroundService.backgroundServiceEventReceived"); 229 } 230 231 /** Creates an instance of this class from a {@link JsonObject}.*/ 232 public static backgroundServiceEventReceived fromJSON(JsonObject jo) 233 { return singleton.fromJSON(jo); } 234 235 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 236 public static NestedDescriptor<backgroundServiceEventReceived> descriptor() 237 { return singleton.descriptor(); } 238 } 239 240 /** 241 * Called when the recording state for the service has been updated. 242 * 243 * <EMBED CLASS=globalDefs DATA-DOMAIN=BackgroundService DATA-API=BrowserAPI> 244 */ 245 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI") 246 public static class recordingStateChanged 247 extends BrowserEvent<recordingStateChanged> 248 implements java.io.Serializable 249 { 250 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 251 protected static final long serialVersionUID = 1; 252 253 private static final NestedHelper<BackgroundService.recordingStateChanged> singleton = 254 Torello.Browser.BrowserAPI.NestedHelpers.Events. 255 BackgroundService$$recordingStateChanged$$.singleton; 256 257 /** <CODE>[No Description Provided by Google]</CODE> */ 258 public final boolean isRecording; 259 260 /** 261 * <CODE>[No Description Provided by Google]</CODE> 262 * <EMBED CLASS='external-html' DATA-D=BackgroundService DATA-C=ServiceName DATA-F=service DATA-FILE-ID=CDP.EL2> 263 * @see BaseType#enumStrList(String) 264 */ 265 public final String service; 266 267 /** Constructor. Please review this class' fields for documentation. */ 268 public recordingStateChanged 269 (ReadOnlyList<Boolean> isPresent, boolean isRecording, String service) 270 { 271 super(singleton, Domains.BackgroundService, "recordingStateChanged", 2); 272 273 this.isRecording = isRecording; 274 this.service = service; 275 276 this.isPresent = (isPresent == null) 277 ? singleton.generateIsPresentList(this) 278 : THROWS.check(isPresent, 2, "BackgroundService.recordingStateChanged"); 279 } 280 281 /** Creates an instance of this class from a {@link JsonObject}.*/ 282 public static recordingStateChanged fromJSON(JsonObject jo) 283 { return singleton.fromJSON(jo); } 284 285 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 286 public static NestedDescriptor<recordingStateChanged> descriptor() 287 { return singleton.descriptor(); } 288 } 289 290 291 292 293 // ******************************************************************************************** 294 // ******************************************************************************************** 295 // Commands 296 // ******************************************************************************************** 297 // ******************************************************************************************** 298 299 300 /** 301 * Clears all stored data for the service. 302 * 303 * @param service - 304 * 305 * @return An instance of <CODE>{@link Script}<Void></CODE> 306 * 307 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 308 * browser receives the invocation-request. 309 * 310 * <BR /><BR /><DIV CLASS=JDHint> 311 * This Browser-Function <I>does not have</I> a return-value. You may choose to 312 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 313 * the Browser Function has run to completion. 314 * </DIV> 315 */ 316 public static Script<Void> clearEvents(String service) 317 { 318 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 319 final String requestJSON = WriteJSON.get 320 (CDPTypes.STRING, "service", false, "BackgroundService.clearEvents", service); 321 322 return Script.NO_RET(Domains.BackgroundService, "clearEvents", requestJSON); 323 } 324 325 /** 326 * Set the recording state for the service. 327 * 328 * @param shouldRecord - 329 * 330 * @param service - 331 * 332 * @return An instance of <CODE>{@link Script}<Void></CODE> 333 * 334 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 335 * browser receives the invocation-request. 336 * 337 * <BR /><BR /><DIV CLASS=JDHint> 338 * This Browser-Function <I>does not have</I> a return-value. You may choose to 339 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 340 * the Browser Function has run to completion. 341 * </DIV> 342 */ 343 public static Script<Void> setRecording(boolean shouldRecord, String service) 344 { 345 // Convert all Method Parameters into a JSON Request-Object (as a String) 346 final String requestJSON = WriteJSON.get( 347 BackgroundService$$Commands.setRecording$$, "BackgroundService.setRecording", 348 shouldRecord, service 349 ); 350 351 return Script.NO_RET(Domains.BackgroundService, "setRecording", requestJSON); 352 } 353 354 /** 355 * Enables event updates for the service. 356 * 357 * @param service - 358 * 359 * @return An instance of <CODE>{@link Script}<Void></CODE> 360 * 361 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 362 * browser receives the invocation-request. 363 * 364 * <BR /><BR /><DIV CLASS=JDHint> 365 * This Browser-Function <I>does not have</I> a return-value. You may choose to 366 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 367 * the Browser Function has run to completion. 368 * </DIV> 369 */ 370 public static Script<Void> startObserving(String service) 371 { 372 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 373 final String requestJSON = WriteJSON.get 374 (CDPTypes.STRING, "service", false, "BackgroundService.startObserving", service); 375 376 return Script.NO_RET(Domains.BackgroundService, "startObserving", requestJSON); 377 } 378 379 /** 380 * Disables event updates for the service. 381 * 382 * @param service - 383 * 384 * @return An instance of <CODE>{@link Script}<Void></CODE> 385 * 386 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 387 * browser receives the invocation-request. 388 * 389 * <BR /><BR /><DIV CLASS=JDHint> 390 * This Browser-Function <I>does not have</I> a return-value. You may choose to 391 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 392 * the Browser Function has run to completion. 393 * </DIV> 394 */ 395 public static Script<Void> stopObserving(String service) 396 { 397 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 398 final String requestJSON = WriteJSON.get 399 (CDPTypes.STRING, "service", false, "BackgroundService.stopObserving", service); 400 401 return Script.NO_RET(Domains.BackgroundService, "stopObserving", requestJSON); 402 } 403 404 405}