github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/declarativecontent/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package declarativecontent 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/ffi/js" 9 "github.com/primecitizens/pcz/std/plat/js/webext/declarativecontent/bindings" 10 "github.com/primecitizens/pcz/std/plat/js/webext/events" 11 ) 12 13 type ImageDataType = js.TypedArray[uint8] 14 15 type PageStateMatcherInstanceType uint32 16 17 const ( 18 _ PageStateMatcherInstanceType = iota 19 20 PageStateMatcherInstanceType_DECLARATIVE_CONTENT_PAGE_STATE_MATCHER 21 ) 22 23 func (PageStateMatcherInstanceType) FromRef(str js.Ref) PageStateMatcherInstanceType { 24 return PageStateMatcherInstanceType(bindings.ConstOfPageStateMatcherInstanceType(str)) 25 } 26 27 func (x PageStateMatcherInstanceType) String() (string, bool) { 28 switch x { 29 case PageStateMatcherInstanceType_DECLARATIVE_CONTENT_PAGE_STATE_MATCHER: 30 return "declarativeContent.PageStateMatcher", true 31 default: 32 return "", false 33 } 34 } 35 36 type PageStateMatcher struct { 37 // Css is "PageStateMatcher.css" 38 // 39 // Optional 40 Css js.Array[js.String] 41 // InstanceType is "PageStateMatcher.instanceType" 42 // 43 // Required 44 InstanceType PageStateMatcherInstanceType 45 // IsBookmarked is "PageStateMatcher.isBookmarked" 46 // 47 // Optional 48 // 49 // NOTE: FFI_USE_IsBookmarked MUST be set to true to make this field effective. 50 IsBookmarked bool 51 // PageUrl is "PageStateMatcher.pageUrl" 52 // 53 // Optional 54 // 55 // NOTE: PageUrl.FFI_USE MUST be set to true to get PageUrl used. 56 PageUrl events.UrlFilter 57 58 FFI_USE_IsBookmarked bool // for IsBookmarked. 59 60 FFI_USE bool 61 } 62 63 // FromRef calls UpdateFrom and returns a PageStateMatcher with all fields set. 64 func (p PageStateMatcher) FromRef(ref js.Ref) PageStateMatcher { 65 p.UpdateFrom(ref) 66 return p 67 } 68 69 // New creates a new PageStateMatcher in the application heap. 70 func (p PageStateMatcher) New() js.Ref { 71 return bindings.PageStateMatcherJSLoad( 72 js.Pointer(&p), js.True, 0, 73 ) 74 } 75 76 // UpdateFrom copies value of all fields of the heap object to p. 77 func (p *PageStateMatcher) UpdateFrom(ref js.Ref) { 78 bindings.PageStateMatcherJSStore( 79 js.Pointer(p), ref, 80 ) 81 } 82 83 // Update writes all fields of the p to the heap object referenced by ref. 84 func (p *PageStateMatcher) Update(ref js.Ref) { 85 bindings.PageStateMatcherJSLoad( 86 js.Pointer(p), js.False, ref, 87 ) 88 } 89 90 // FreeMembers frees fields with heap reference, if recursive is true 91 // free all heap references reachable from p. 92 func (p *PageStateMatcher) FreeMembers(recursive bool) { 93 js.Free( 94 p.Css.Ref(), 95 ) 96 p.Css = p.Css.FromRef(js.Undefined) 97 if recursive { 98 p.PageUrl.FreeMembers(true) 99 } 100 } 101 102 type RequestContentScriptInstanceType uint32 103 104 const ( 105 _ RequestContentScriptInstanceType = iota 106 107 RequestContentScriptInstanceType_DECLARATIVE_CONTENT_REQUEST_CONTENT_SCRIPT 108 ) 109 110 func (RequestContentScriptInstanceType) FromRef(str js.Ref) RequestContentScriptInstanceType { 111 return RequestContentScriptInstanceType(bindings.ConstOfRequestContentScriptInstanceType(str)) 112 } 113 114 func (x RequestContentScriptInstanceType) String() (string, bool) { 115 switch x { 116 case RequestContentScriptInstanceType_DECLARATIVE_CONTENT_REQUEST_CONTENT_SCRIPT: 117 return "declarativeContent.RequestContentScript", true 118 default: 119 return "", false 120 } 121 } 122 123 type RequestContentScript struct { 124 // AllFrames is "RequestContentScript.allFrames" 125 // 126 // Optional 127 // 128 // NOTE: FFI_USE_AllFrames MUST be set to true to make this field effective. 129 AllFrames bool 130 // Css is "RequestContentScript.css" 131 // 132 // Optional 133 Css js.Array[js.String] 134 // InstanceType is "RequestContentScript.instanceType" 135 // 136 // Required 137 InstanceType RequestContentScriptInstanceType 138 // Js is "RequestContentScript.js" 139 // 140 // Optional 141 Js js.Array[js.String] 142 // MatchAboutBlank is "RequestContentScript.matchAboutBlank" 143 // 144 // Optional 145 // 146 // NOTE: FFI_USE_MatchAboutBlank MUST be set to true to make this field effective. 147 MatchAboutBlank bool 148 149 FFI_USE_AllFrames bool // for AllFrames. 150 FFI_USE_MatchAboutBlank bool // for MatchAboutBlank. 151 152 FFI_USE bool 153 } 154 155 // FromRef calls UpdateFrom and returns a RequestContentScript with all fields set. 156 func (p RequestContentScript) FromRef(ref js.Ref) RequestContentScript { 157 p.UpdateFrom(ref) 158 return p 159 } 160 161 // New creates a new RequestContentScript in the application heap. 162 func (p RequestContentScript) New() js.Ref { 163 return bindings.RequestContentScriptJSLoad( 164 js.Pointer(&p), js.True, 0, 165 ) 166 } 167 168 // UpdateFrom copies value of all fields of the heap object to p. 169 func (p *RequestContentScript) UpdateFrom(ref js.Ref) { 170 bindings.RequestContentScriptJSStore( 171 js.Pointer(p), ref, 172 ) 173 } 174 175 // Update writes all fields of the p to the heap object referenced by ref. 176 func (p *RequestContentScript) Update(ref js.Ref) { 177 bindings.RequestContentScriptJSLoad( 178 js.Pointer(p), js.False, ref, 179 ) 180 } 181 182 // FreeMembers frees fields with heap reference, if recursive is true 183 // free all heap references reachable from p. 184 func (p *RequestContentScript) FreeMembers(recursive bool) { 185 js.Free( 186 p.Css.Ref(), 187 p.Js.Ref(), 188 ) 189 p.Css = p.Css.FromRef(js.Undefined) 190 p.Js = p.Js.FromRef(js.Undefined) 191 } 192 193 type OneOf_TypedArrayUint8_Any struct { 194 ref js.Ref 195 } 196 197 func (x OneOf_TypedArrayUint8_Any) Ref() js.Ref { 198 return x.ref 199 } 200 201 func (x OneOf_TypedArrayUint8_Any) Free() { 202 x.ref.Free() 203 } 204 205 func (x OneOf_TypedArrayUint8_Any) FromRef(ref js.Ref) OneOf_TypedArrayUint8_Any { 206 return OneOf_TypedArrayUint8_Any{ 207 ref: ref, 208 } 209 } 210 211 func (x OneOf_TypedArrayUint8_Any) TypedArrayUint8() js.TypedArray[uint8] { 212 return js.TypedArray[uint8]{}.FromRef(x.ref) 213 } 214 215 func (x OneOf_TypedArrayUint8_Any) Any() js.Any { 216 return js.Any{}.FromRef(x.ref) 217 } 218 219 type SetIconInstanceType uint32 220 221 const ( 222 _ SetIconInstanceType = iota 223 224 SetIconInstanceType_DECLARATIVE_CONTENT_SET_ICON 225 ) 226 227 func (SetIconInstanceType) FromRef(str js.Ref) SetIconInstanceType { 228 return SetIconInstanceType(bindings.ConstOfSetIconInstanceType(str)) 229 } 230 231 func (x SetIconInstanceType) String() (string, bool) { 232 switch x { 233 case SetIconInstanceType_DECLARATIVE_CONTENT_SET_ICON: 234 return "declarativeContent.SetIcon", true 235 default: 236 return "", false 237 } 238 } 239 240 type SetIcon struct { 241 // ImageData is "SetIcon.imageData" 242 // 243 // Optional 244 ImageData OneOf_TypedArrayUint8_Any 245 // InstanceType is "SetIcon.instanceType" 246 // 247 // Required 248 InstanceType SetIconInstanceType 249 250 FFI_USE bool 251 } 252 253 // FromRef calls UpdateFrom and returns a SetIcon with all fields set. 254 func (p SetIcon) FromRef(ref js.Ref) SetIcon { 255 p.UpdateFrom(ref) 256 return p 257 } 258 259 // New creates a new SetIcon in the application heap. 260 func (p SetIcon) New() js.Ref { 261 return bindings.SetIconJSLoad( 262 js.Pointer(&p), js.True, 0, 263 ) 264 } 265 266 // UpdateFrom copies value of all fields of the heap object to p. 267 func (p *SetIcon) UpdateFrom(ref js.Ref) { 268 bindings.SetIconJSStore( 269 js.Pointer(p), ref, 270 ) 271 } 272 273 // Update writes all fields of the p to the heap object referenced by ref. 274 func (p *SetIcon) Update(ref js.Ref) { 275 bindings.SetIconJSLoad( 276 js.Pointer(p), js.False, ref, 277 ) 278 } 279 280 // FreeMembers frees fields with heap reference, if recursive is true 281 // free all heap references reachable from p. 282 func (p *SetIcon) FreeMembers(recursive bool) { 283 js.Free( 284 p.ImageData.Ref(), 285 ) 286 p.ImageData = p.ImageData.FromRef(js.Undefined) 287 } 288 289 type ShowActionInstanceType uint32 290 291 const ( 292 _ ShowActionInstanceType = iota 293 294 ShowActionInstanceType_DECLARATIVE_CONTENT_SHOW_ACTION 295 ) 296 297 func (ShowActionInstanceType) FromRef(str js.Ref) ShowActionInstanceType { 298 return ShowActionInstanceType(bindings.ConstOfShowActionInstanceType(str)) 299 } 300 301 func (x ShowActionInstanceType) String() (string, bool) { 302 switch x { 303 case ShowActionInstanceType_DECLARATIVE_CONTENT_SHOW_ACTION: 304 return "declarativeContent.ShowAction", true 305 default: 306 return "", false 307 } 308 } 309 310 type ShowAction struct { 311 // InstanceType is "ShowAction.instanceType" 312 // 313 // Required 314 InstanceType ShowActionInstanceType 315 316 FFI_USE bool 317 } 318 319 // FromRef calls UpdateFrom and returns a ShowAction with all fields set. 320 func (p ShowAction) FromRef(ref js.Ref) ShowAction { 321 p.UpdateFrom(ref) 322 return p 323 } 324 325 // New creates a new ShowAction in the application heap. 326 func (p ShowAction) New() js.Ref { 327 return bindings.ShowActionJSLoad( 328 js.Pointer(&p), js.True, 0, 329 ) 330 } 331 332 // UpdateFrom copies value of all fields of the heap object to p. 333 func (p *ShowAction) UpdateFrom(ref js.Ref) { 334 bindings.ShowActionJSStore( 335 js.Pointer(p), ref, 336 ) 337 } 338 339 // Update writes all fields of the p to the heap object referenced by ref. 340 func (p *ShowAction) Update(ref js.Ref) { 341 bindings.ShowActionJSLoad( 342 js.Pointer(p), js.False, ref, 343 ) 344 } 345 346 // FreeMembers frees fields with heap reference, if recursive is true 347 // free all heap references reachable from p. 348 func (p *ShowAction) FreeMembers(recursive bool) { 349 } 350 351 type ShowPageActionInstanceType uint32 352 353 const ( 354 _ ShowPageActionInstanceType = iota 355 356 ShowPageActionInstanceType_DECLARATIVE_CONTENT_SHOW_PAGE_ACTION 357 ) 358 359 func (ShowPageActionInstanceType) FromRef(str js.Ref) ShowPageActionInstanceType { 360 return ShowPageActionInstanceType(bindings.ConstOfShowPageActionInstanceType(str)) 361 } 362 363 func (x ShowPageActionInstanceType) String() (string, bool) { 364 switch x { 365 case ShowPageActionInstanceType_DECLARATIVE_CONTENT_SHOW_PAGE_ACTION: 366 return "declarativeContent.ShowPageAction", true 367 default: 368 return "", false 369 } 370 } 371 372 type ShowPageAction struct { 373 // InstanceType is "ShowPageAction.instanceType" 374 // 375 // Required 376 InstanceType ShowPageActionInstanceType 377 378 FFI_USE bool 379 } 380 381 // FromRef calls UpdateFrom and returns a ShowPageAction with all fields set. 382 func (p ShowPageAction) FromRef(ref js.Ref) ShowPageAction { 383 p.UpdateFrom(ref) 384 return p 385 } 386 387 // New creates a new ShowPageAction in the application heap. 388 func (p ShowPageAction) New() js.Ref { 389 return bindings.ShowPageActionJSLoad( 390 js.Pointer(&p), js.True, 0, 391 ) 392 } 393 394 // UpdateFrom copies value of all fields of the heap object to p. 395 func (p *ShowPageAction) UpdateFrom(ref js.Ref) { 396 bindings.ShowPageActionJSStore( 397 js.Pointer(p), ref, 398 ) 399 } 400 401 // Update writes all fields of the p to the heap object referenced by ref. 402 func (p *ShowPageAction) Update(ref js.Ref) { 403 bindings.ShowPageActionJSLoad( 404 js.Pointer(p), js.False, ref, 405 ) 406 } 407 408 // FreeMembers frees fields with heap reference, if recursive is true 409 // free all heap references reachable from p. 410 func (p *ShowPageAction) FreeMembers(recursive bool) { 411 } 412 413 type OnPageChangedEventCallbackFunc func(this js.Ref) js.Ref 414 415 func (fn OnPageChangedEventCallbackFunc) Register() js.Func[func()] { 416 return js.RegisterCallback[func()]( 417 fn, abi.FuncPCABIInternal(fn), 418 ) 419 } 420 421 func (fn OnPageChangedEventCallbackFunc) DispatchCallback( 422 targetPC uintptr, ctx *js.CallbackContext, 423 ) { 424 args := ctx.Args() 425 if len(args) != 0+1 /* js this */ || 426 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 427 js.ThrowInvalidCallbackInvocation() 428 } 429 430 if ctx.Return(fn( 431 args[0], 432 )) { 433 return 434 } 435 436 js.ThrowCallbackValueNotReturned() 437 } 438 439 type OnPageChangedEventCallback[T any] struct { 440 Fn func(arg T, this js.Ref) js.Ref 441 Arg T 442 } 443 444 func (cb *OnPageChangedEventCallback[T]) Register() js.Func[func()] { 445 return js.RegisterCallback[func()]( 446 cb, abi.FuncPCABIInternal(cb.Fn), 447 ) 448 } 449 450 func (cb *OnPageChangedEventCallback[T]) DispatchCallback( 451 targetPC uintptr, ctx *js.CallbackContext, 452 ) { 453 args := ctx.Args() 454 if len(args) != 0+1 /* js this */ || 455 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 456 js.ThrowInvalidCallbackInvocation() 457 } 458 459 if ctx.Return(cb.Fn( 460 cb.Arg, 461 args[0], 462 )) { 463 return 464 } 465 466 js.ThrowCallbackValueNotReturned() 467 } 468 469 // HasFuncOnPageChanged returns true if the function "WEBEXT.declarativeContent.onPageChanged.addListener" exists. 470 func HasFuncOnPageChanged() bool { 471 return js.True == bindings.HasFuncOnPageChanged() 472 } 473 474 // FuncOnPageChanged returns the function "WEBEXT.declarativeContent.onPageChanged.addListener". 475 func FuncOnPageChanged() (fn js.Func[func(callback js.Func[func()])]) { 476 bindings.FuncOnPageChanged( 477 js.Pointer(&fn), 478 ) 479 return 480 } 481 482 // OnPageChanged calls the function "WEBEXT.declarativeContent.onPageChanged.addListener" directly. 483 func OnPageChanged(callback js.Func[func()]) (ret js.Void) { 484 bindings.CallOnPageChanged( 485 js.Pointer(&ret), 486 callback.Ref(), 487 ) 488 489 return 490 } 491 492 // TryOnPageChanged calls the function "WEBEXT.declarativeContent.onPageChanged.addListener" 493 // in a try/catch block and returns (_, err, ok = false) when it went through 494 // the catch clause. 495 func TryOnPageChanged(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) { 496 ok = js.True == bindings.TryOnPageChanged( 497 js.Pointer(&ret), js.Pointer(&exception), 498 callback.Ref(), 499 ) 500 501 return 502 } 503 504 // HasFuncOffPageChanged returns true if the function "WEBEXT.declarativeContent.onPageChanged.removeListener" exists. 505 func HasFuncOffPageChanged() bool { 506 return js.True == bindings.HasFuncOffPageChanged() 507 } 508 509 // FuncOffPageChanged returns the function "WEBEXT.declarativeContent.onPageChanged.removeListener". 510 func FuncOffPageChanged() (fn js.Func[func(callback js.Func[func()])]) { 511 bindings.FuncOffPageChanged( 512 js.Pointer(&fn), 513 ) 514 return 515 } 516 517 // OffPageChanged calls the function "WEBEXT.declarativeContent.onPageChanged.removeListener" directly. 518 func OffPageChanged(callback js.Func[func()]) (ret js.Void) { 519 bindings.CallOffPageChanged( 520 js.Pointer(&ret), 521 callback.Ref(), 522 ) 523 524 return 525 } 526 527 // TryOffPageChanged calls the function "WEBEXT.declarativeContent.onPageChanged.removeListener" 528 // in a try/catch block and returns (_, err, ok = false) when it went through 529 // the catch clause. 530 func TryOffPageChanged(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) { 531 ok = js.True == bindings.TryOffPageChanged( 532 js.Pointer(&ret), js.Pointer(&exception), 533 callback.Ref(), 534 ) 535 536 return 537 } 538 539 // HasFuncHasOnPageChanged returns true if the function "WEBEXT.declarativeContent.onPageChanged.hasListener" exists. 540 func HasFuncHasOnPageChanged() bool { 541 return js.True == bindings.HasFuncHasOnPageChanged() 542 } 543 544 // FuncHasOnPageChanged returns the function "WEBEXT.declarativeContent.onPageChanged.hasListener". 545 func FuncHasOnPageChanged() (fn js.Func[func(callback js.Func[func()]) bool]) { 546 bindings.FuncHasOnPageChanged( 547 js.Pointer(&fn), 548 ) 549 return 550 } 551 552 // HasOnPageChanged calls the function "WEBEXT.declarativeContent.onPageChanged.hasListener" directly. 553 func HasOnPageChanged(callback js.Func[func()]) (ret bool) { 554 bindings.CallHasOnPageChanged( 555 js.Pointer(&ret), 556 callback.Ref(), 557 ) 558 559 return 560 } 561 562 // TryHasOnPageChanged calls the function "WEBEXT.declarativeContent.onPageChanged.hasListener" 563 // in a try/catch block and returns (_, err, ok = false) when it went through 564 // the catch clause. 565 func TryHasOnPageChanged(callback js.Func[func()]) (ret bool, exception js.Any, ok bool) { 566 ok = js.True == bindings.TryHasOnPageChanged( 567 js.Pointer(&ret), js.Pointer(&exception), 568 callback.Ref(), 569 ) 570 571 return 572 }