github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/extension/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package extension 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/core/mark" 9 "github.com/primecitizens/pcz/std/ffi/js" 10 "github.com/primecitizens/pcz/std/plat/js/webext/extension/bindings" 11 "github.com/primecitizens/pcz/std/plat/js/webext/runtime" 12 ) 13 14 type ViewType uint32 15 16 const ( 17 _ ViewType = iota 18 19 ViewType_TAB 20 ViewType_POPUP 21 ) 22 23 func (ViewType) FromRef(str js.Ref) ViewType { 24 return ViewType(bindings.ConstOfViewType(str)) 25 } 26 27 func (x ViewType) String() (string, bool) { 28 switch x { 29 case ViewType_TAB: 30 return "tab", true 31 case ViewType_POPUP: 32 return "popup", true 33 default: 34 return "", false 35 } 36 } 37 38 type GetViewsArgFetchProperties struct { 39 // TabId is "GetViewsArgFetchProperties.tabId" 40 // 41 // Optional 42 // 43 // NOTE: FFI_USE_TabId MUST be set to true to make this field effective. 44 TabId int64 45 // Type is "GetViewsArgFetchProperties.type" 46 // 47 // Optional 48 Type ViewType 49 // WindowId is "GetViewsArgFetchProperties.windowId" 50 // 51 // Optional 52 // 53 // NOTE: FFI_USE_WindowId MUST be set to true to make this field effective. 54 WindowId int64 55 56 FFI_USE_TabId bool // for TabId. 57 FFI_USE_WindowId bool // for WindowId. 58 59 FFI_USE bool 60 } 61 62 // FromRef calls UpdateFrom and returns a GetViewsArgFetchProperties with all fields set. 63 func (p GetViewsArgFetchProperties) FromRef(ref js.Ref) GetViewsArgFetchProperties { 64 p.UpdateFrom(ref) 65 return p 66 } 67 68 // New creates a new GetViewsArgFetchProperties in the application heap. 69 func (p GetViewsArgFetchProperties) New() js.Ref { 70 return bindings.GetViewsArgFetchPropertiesJSLoad( 71 js.Pointer(&p), js.True, 0, 72 ) 73 } 74 75 // UpdateFrom copies value of all fields of the heap object to p. 76 func (p *GetViewsArgFetchProperties) UpdateFrom(ref js.Ref) { 77 bindings.GetViewsArgFetchPropertiesJSStore( 78 js.Pointer(p), ref, 79 ) 80 } 81 82 // Update writes all fields of the p to the heap object referenced by ref. 83 func (p *GetViewsArgFetchProperties) Update(ref js.Ref) { 84 bindings.GetViewsArgFetchPropertiesJSLoad( 85 js.Pointer(p), js.False, ref, 86 ) 87 } 88 89 // FreeMembers frees fields with heap reference, if recursive is true 90 // free all heap references reachable from p. 91 func (p *GetViewsArgFetchProperties) FreeMembers(recursive bool) { 92 } 93 94 type LastErrorProperty struct { 95 // Message is "LastErrorProperty.message" 96 // 97 // Required 98 Message js.String 99 100 FFI_USE bool 101 } 102 103 // FromRef calls UpdateFrom and returns a LastErrorProperty with all fields set. 104 func (p LastErrorProperty) FromRef(ref js.Ref) LastErrorProperty { 105 p.UpdateFrom(ref) 106 return p 107 } 108 109 // New creates a new LastErrorProperty in the application heap. 110 func (p LastErrorProperty) New() js.Ref { 111 return bindings.LastErrorPropertyJSLoad( 112 js.Pointer(&p), js.True, 0, 113 ) 114 } 115 116 // UpdateFrom copies value of all fields of the heap object to p. 117 func (p *LastErrorProperty) UpdateFrom(ref js.Ref) { 118 bindings.LastErrorPropertyJSStore( 119 js.Pointer(p), ref, 120 ) 121 } 122 123 // Update writes all fields of the p to the heap object referenced by ref. 124 func (p *LastErrorProperty) Update(ref js.Ref) { 125 bindings.LastErrorPropertyJSLoad( 126 js.Pointer(p), js.False, ref, 127 ) 128 } 129 130 // FreeMembers frees fields with heap reference, if recursive is true 131 // free all heap references reachable from p. 132 func (p *LastErrorProperty) FreeMembers(recursive bool) { 133 js.Free( 134 p.Message.Ref(), 135 ) 136 p.Message = p.Message.FromRef(js.Undefined) 137 } 138 139 type OnRequestArgSendResponseFunc func(this js.Ref) js.Ref 140 141 func (fn OnRequestArgSendResponseFunc) Register() js.Func[func()] { 142 return js.RegisterCallback[func()]( 143 fn, abi.FuncPCABIInternal(fn), 144 ) 145 } 146 147 func (fn OnRequestArgSendResponseFunc) DispatchCallback( 148 targetPC uintptr, ctx *js.CallbackContext, 149 ) { 150 args := ctx.Args() 151 if len(args) != 0+1 /* js this */ || 152 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 153 js.ThrowInvalidCallbackInvocation() 154 } 155 156 if ctx.Return(fn( 157 args[0], 158 )) { 159 return 160 } 161 162 js.ThrowCallbackValueNotReturned() 163 } 164 165 type OnRequestArgSendResponse[T any] struct { 166 Fn func(arg T, this js.Ref) js.Ref 167 Arg T 168 } 169 170 func (cb *OnRequestArgSendResponse[T]) Register() js.Func[func()] { 171 return js.RegisterCallback[func()]( 172 cb, abi.FuncPCABIInternal(cb.Fn), 173 ) 174 } 175 176 func (cb *OnRequestArgSendResponse[T]) DispatchCallback( 177 targetPC uintptr, ctx *js.CallbackContext, 178 ) { 179 args := ctx.Args() 180 if len(args) != 0+1 /* js this */ || 181 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 182 js.ThrowInvalidCallbackInvocation() 183 } 184 185 if ctx.Return(cb.Fn( 186 cb.Arg, 187 args[0], 188 )) { 189 return 190 } 191 192 js.ThrowCallbackValueNotReturned() 193 } 194 195 type OnRequestExternalArgSendResponseFunc func(this js.Ref) js.Ref 196 197 func (fn OnRequestExternalArgSendResponseFunc) Register() js.Func[func()] { 198 return js.RegisterCallback[func()]( 199 fn, abi.FuncPCABIInternal(fn), 200 ) 201 } 202 203 func (fn OnRequestExternalArgSendResponseFunc) DispatchCallback( 204 targetPC uintptr, ctx *js.CallbackContext, 205 ) { 206 args := ctx.Args() 207 if len(args) != 0+1 /* js this */ || 208 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 209 js.ThrowInvalidCallbackInvocation() 210 } 211 212 if ctx.Return(fn( 213 args[0], 214 )) { 215 return 216 } 217 218 js.ThrowCallbackValueNotReturned() 219 } 220 221 type OnRequestExternalArgSendResponse[T any] struct { 222 Fn func(arg T, this js.Ref) js.Ref 223 Arg T 224 } 225 226 func (cb *OnRequestExternalArgSendResponse[T]) Register() js.Func[func()] { 227 return js.RegisterCallback[func()]( 228 cb, abi.FuncPCABIInternal(cb.Fn), 229 ) 230 } 231 232 func (cb *OnRequestExternalArgSendResponse[T]) DispatchCallback( 233 targetPC uintptr, ctx *js.CallbackContext, 234 ) { 235 args := ctx.Args() 236 if len(args) != 0+1 /* js this */ || 237 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 238 js.ThrowInvalidCallbackInvocation() 239 } 240 241 if ctx.Return(cb.Fn( 242 cb.Arg, 243 args[0], 244 )) { 245 return 246 } 247 248 js.ThrowCallbackValueNotReturned() 249 } 250 251 // HasFuncGetBackgroundPage returns true if the function "WEBEXT.extension.getBackgroundPage" exists. 252 func HasFuncGetBackgroundPage() bool { 253 return js.True == bindings.HasFuncGetBackgroundPage() 254 } 255 256 // FuncGetBackgroundPage returns the function "WEBEXT.extension.getBackgroundPage". 257 func FuncGetBackgroundPage() (fn js.Func[func() js.Any]) { 258 bindings.FuncGetBackgroundPage( 259 js.Pointer(&fn), 260 ) 261 return 262 } 263 264 // GetBackgroundPage calls the function "WEBEXT.extension.getBackgroundPage" directly. 265 func GetBackgroundPage() (ret js.Any) { 266 bindings.CallGetBackgroundPage( 267 js.Pointer(&ret), 268 ) 269 270 return 271 } 272 273 // TryGetBackgroundPage calls the function "WEBEXT.extension.getBackgroundPage" 274 // in a try/catch block and returns (_, err, ok = false) when it went through 275 // the catch clause. 276 func TryGetBackgroundPage() (ret js.Any, exception js.Any, ok bool) { 277 ok = js.True == bindings.TryGetBackgroundPage( 278 js.Pointer(&ret), js.Pointer(&exception), 279 ) 280 281 return 282 } 283 284 // HasFuncGetExtensionTabs returns true if the function "WEBEXT.extension.getExtensionTabs" exists. 285 func HasFuncGetExtensionTabs() bool { 286 return js.True == bindings.HasFuncGetExtensionTabs() 287 } 288 289 // FuncGetExtensionTabs returns the function "WEBEXT.extension.getExtensionTabs". 290 func FuncGetExtensionTabs() (fn js.Func[func(windowId int64) js.Array[js.Any]]) { 291 bindings.FuncGetExtensionTabs( 292 js.Pointer(&fn), 293 ) 294 return 295 } 296 297 // GetExtensionTabs calls the function "WEBEXT.extension.getExtensionTabs" directly. 298 func GetExtensionTabs(windowId int64) (ret js.Array[js.Any]) { 299 bindings.CallGetExtensionTabs( 300 js.Pointer(&ret), 301 float64(windowId), 302 ) 303 304 return 305 } 306 307 // TryGetExtensionTabs calls the function "WEBEXT.extension.getExtensionTabs" 308 // in a try/catch block and returns (_, err, ok = false) when it went through 309 // the catch clause. 310 func TryGetExtensionTabs(windowId int64) (ret js.Array[js.Any], exception js.Any, ok bool) { 311 ok = js.True == bindings.TryGetExtensionTabs( 312 js.Pointer(&ret), js.Pointer(&exception), 313 float64(windowId), 314 ) 315 316 return 317 } 318 319 // HasFuncGetURL returns true if the function "WEBEXT.extension.getURL" exists. 320 func HasFuncGetURL() bool { 321 return js.True == bindings.HasFuncGetURL() 322 } 323 324 // FuncGetURL returns the function "WEBEXT.extension.getURL". 325 func FuncGetURL() (fn js.Func[func(path js.String) js.String]) { 326 bindings.FuncGetURL( 327 js.Pointer(&fn), 328 ) 329 return 330 } 331 332 // GetURL calls the function "WEBEXT.extension.getURL" directly. 333 func GetURL(path js.String) (ret js.String) { 334 bindings.CallGetURL( 335 js.Pointer(&ret), 336 path.Ref(), 337 ) 338 339 return 340 } 341 342 // TryGetURL calls the function "WEBEXT.extension.getURL" 343 // in a try/catch block and returns (_, err, ok = false) when it went through 344 // the catch clause. 345 func TryGetURL(path js.String) (ret js.String, exception js.Any, ok bool) { 346 ok = js.True == bindings.TryGetURL( 347 js.Pointer(&ret), js.Pointer(&exception), 348 path.Ref(), 349 ) 350 351 return 352 } 353 354 // HasFuncGetViews returns true if the function "WEBEXT.extension.getViews" exists. 355 func HasFuncGetViews() bool { 356 return js.True == bindings.HasFuncGetViews() 357 } 358 359 // FuncGetViews returns the function "WEBEXT.extension.getViews". 360 func FuncGetViews() (fn js.Func[func(fetchProperties GetViewsArgFetchProperties) js.Array[js.Any]]) { 361 bindings.FuncGetViews( 362 js.Pointer(&fn), 363 ) 364 return 365 } 366 367 // GetViews calls the function "WEBEXT.extension.getViews" directly. 368 func GetViews(fetchProperties GetViewsArgFetchProperties) (ret js.Array[js.Any]) { 369 bindings.CallGetViews( 370 js.Pointer(&ret), 371 js.Pointer(&fetchProperties), 372 ) 373 374 return 375 } 376 377 // TryGetViews calls the function "WEBEXT.extension.getViews" 378 // in a try/catch block and returns (_, err, ok = false) when it went through 379 // the catch clause. 380 func TryGetViews(fetchProperties GetViewsArgFetchProperties) (ret js.Array[js.Any], exception js.Any, ok bool) { 381 ok = js.True == bindings.TryGetViews( 382 js.Pointer(&ret), js.Pointer(&exception), 383 js.Pointer(&fetchProperties), 384 ) 385 386 return 387 } 388 389 // InIncognitoContext returns the value of property "WEBEXT.extension.inIncognitoContext". 390 // 391 // The returned bool will be false if there is no such property. 392 func InIncognitoContext() (ret bool, ok bool) { 393 ok = js.True == bindings.GetInIncognitoContext( 394 js.Pointer(&ret), 395 ) 396 397 return 398 } 399 400 // SetInIncognitoContext sets the value of property "WEBEXT.extension.inIncognitoContext" to val. 401 // 402 // It returns false if the property cannot be set. 403 func SetInIncognitoContext(val bool) bool { 404 return js.True == bindings.SetInIncognitoContext( 405 js.Bool(bool(val))) 406 } 407 408 // HasFuncIsAllowedFileSchemeAccess returns true if the function "WEBEXT.extension.isAllowedFileSchemeAccess" exists. 409 func HasFuncIsAllowedFileSchemeAccess() bool { 410 return js.True == bindings.HasFuncIsAllowedFileSchemeAccess() 411 } 412 413 // FuncIsAllowedFileSchemeAccess returns the function "WEBEXT.extension.isAllowedFileSchemeAccess". 414 func FuncIsAllowedFileSchemeAccess() (fn js.Func[func() js.Promise[js.Boolean]]) { 415 bindings.FuncIsAllowedFileSchemeAccess( 416 js.Pointer(&fn), 417 ) 418 return 419 } 420 421 // IsAllowedFileSchemeAccess calls the function "WEBEXT.extension.isAllowedFileSchemeAccess" directly. 422 func IsAllowedFileSchemeAccess() (ret js.Promise[js.Boolean]) { 423 bindings.CallIsAllowedFileSchemeAccess( 424 js.Pointer(&ret), 425 ) 426 427 return 428 } 429 430 // TryIsAllowedFileSchemeAccess calls the function "WEBEXT.extension.isAllowedFileSchemeAccess" 431 // in a try/catch block and returns (_, err, ok = false) when it went through 432 // the catch clause. 433 func TryIsAllowedFileSchemeAccess() (ret js.Promise[js.Boolean], exception js.Any, ok bool) { 434 ok = js.True == bindings.TryIsAllowedFileSchemeAccess( 435 js.Pointer(&ret), js.Pointer(&exception), 436 ) 437 438 return 439 } 440 441 // HasFuncIsAllowedIncognitoAccess returns true if the function "WEBEXT.extension.isAllowedIncognitoAccess" exists. 442 func HasFuncIsAllowedIncognitoAccess() bool { 443 return js.True == bindings.HasFuncIsAllowedIncognitoAccess() 444 } 445 446 // FuncIsAllowedIncognitoAccess returns the function "WEBEXT.extension.isAllowedIncognitoAccess". 447 func FuncIsAllowedIncognitoAccess() (fn js.Func[func() js.Promise[js.Boolean]]) { 448 bindings.FuncIsAllowedIncognitoAccess( 449 js.Pointer(&fn), 450 ) 451 return 452 } 453 454 // IsAllowedIncognitoAccess calls the function "WEBEXT.extension.isAllowedIncognitoAccess" directly. 455 func IsAllowedIncognitoAccess() (ret js.Promise[js.Boolean]) { 456 bindings.CallIsAllowedIncognitoAccess( 457 js.Pointer(&ret), 458 ) 459 460 return 461 } 462 463 // TryIsAllowedIncognitoAccess calls the function "WEBEXT.extension.isAllowedIncognitoAccess" 464 // in a try/catch block and returns (_, err, ok = false) when it went through 465 // the catch clause. 466 func TryIsAllowedIncognitoAccess() (ret js.Promise[js.Boolean], exception js.Any, ok bool) { 467 ok = js.True == bindings.TryIsAllowedIncognitoAccess( 468 js.Pointer(&ret), js.Pointer(&exception), 469 ) 470 471 return 472 } 473 474 // LastError returns the value of property "WEBEXT.extension.lastError". 475 // 476 // The returned bool will be false if there is no such property. 477 func LastError() (ret LastErrorProperty, ok bool) { 478 ok = js.True == bindings.GetLastError( 479 js.Pointer(&ret), 480 ) 481 482 return 483 } 484 485 // SetLastError sets the value of property "WEBEXT.extension.lastError" to val. 486 // 487 // It returns false if the property cannot be set. 488 func SetLastError(val LastErrorProperty) bool { 489 return js.True == bindings.SetLastError( 490 js.Pointer(&val)) 491 } 492 493 type OnRequestEventCallbackFunc func(this js.Ref, request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()]) js.Ref 494 495 func (fn OnRequestEventCallbackFunc) Register() js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])] { 496 return js.RegisterCallback[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]( 497 fn, abi.FuncPCABIInternal(fn), 498 ) 499 } 500 501 func (fn OnRequestEventCallbackFunc) DispatchCallback( 502 targetPC uintptr, ctx *js.CallbackContext, 503 ) { 504 args := ctx.Args() 505 if len(args) != 3+1 /* js this */ || 506 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 507 js.ThrowInvalidCallbackInvocation() 508 } 509 var arg1 runtime.MessageSender 510 arg1.UpdateFrom(args[1+1]) 511 defer arg1.FreeMembers(true) 512 513 if ctx.Return(fn( 514 args[0], 515 516 js.Any{}.FromRef(args[0+1]), 517 mark.NoEscape(&arg1), 518 js.Func[func()]{}.FromRef(args[2+1]), 519 )) { 520 return 521 } 522 523 js.ThrowCallbackValueNotReturned() 524 } 525 526 type OnRequestEventCallback[T any] struct { 527 Fn func(arg T, this js.Ref, request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()]) js.Ref 528 Arg T 529 } 530 531 func (cb *OnRequestEventCallback[T]) Register() js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])] { 532 return js.RegisterCallback[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]( 533 cb, abi.FuncPCABIInternal(cb.Fn), 534 ) 535 } 536 537 func (cb *OnRequestEventCallback[T]) DispatchCallback( 538 targetPC uintptr, ctx *js.CallbackContext, 539 ) { 540 args := ctx.Args() 541 if len(args) != 3+1 /* js this */ || 542 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 543 js.ThrowInvalidCallbackInvocation() 544 } 545 var arg1 runtime.MessageSender 546 arg1.UpdateFrom(args[1+1]) 547 defer arg1.FreeMembers(true) 548 549 if ctx.Return(cb.Fn( 550 cb.Arg, 551 args[0], 552 553 js.Any{}.FromRef(args[0+1]), 554 mark.NoEscape(&arg1), 555 js.Func[func()]{}.FromRef(args[2+1]), 556 )) { 557 return 558 } 559 560 js.ThrowCallbackValueNotReturned() 561 } 562 563 // HasFuncOnRequest returns true if the function "WEBEXT.extension.onRequest.addListener" exists. 564 func HasFuncOnRequest() bool { 565 return js.True == bindings.HasFuncOnRequest() 566 } 567 568 // FuncOnRequest returns the function "WEBEXT.extension.onRequest.addListener". 569 func FuncOnRequest() (fn js.Func[func(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])])]) { 570 bindings.FuncOnRequest( 571 js.Pointer(&fn), 572 ) 573 return 574 } 575 576 // OnRequest calls the function "WEBEXT.extension.onRequest.addListener" directly. 577 func OnRequest(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void) { 578 bindings.CallOnRequest( 579 js.Pointer(&ret), 580 callback.Ref(), 581 ) 582 583 return 584 } 585 586 // TryOnRequest calls the function "WEBEXT.extension.onRequest.addListener" 587 // in a try/catch block and returns (_, err, ok = false) when it went through 588 // the catch clause. 589 func TryOnRequest(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void, exception js.Any, ok bool) { 590 ok = js.True == bindings.TryOnRequest( 591 js.Pointer(&ret), js.Pointer(&exception), 592 callback.Ref(), 593 ) 594 595 return 596 } 597 598 // HasFuncOffRequest returns true if the function "WEBEXT.extension.onRequest.removeListener" exists. 599 func HasFuncOffRequest() bool { 600 return js.True == bindings.HasFuncOffRequest() 601 } 602 603 // FuncOffRequest returns the function "WEBEXT.extension.onRequest.removeListener". 604 func FuncOffRequest() (fn js.Func[func(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])])]) { 605 bindings.FuncOffRequest( 606 js.Pointer(&fn), 607 ) 608 return 609 } 610 611 // OffRequest calls the function "WEBEXT.extension.onRequest.removeListener" directly. 612 func OffRequest(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void) { 613 bindings.CallOffRequest( 614 js.Pointer(&ret), 615 callback.Ref(), 616 ) 617 618 return 619 } 620 621 // TryOffRequest calls the function "WEBEXT.extension.onRequest.removeListener" 622 // in a try/catch block and returns (_, err, ok = false) when it went through 623 // the catch clause. 624 func TryOffRequest(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void, exception js.Any, ok bool) { 625 ok = js.True == bindings.TryOffRequest( 626 js.Pointer(&ret), js.Pointer(&exception), 627 callback.Ref(), 628 ) 629 630 return 631 } 632 633 // HasFuncHasOnRequest returns true if the function "WEBEXT.extension.onRequest.hasListener" exists. 634 func HasFuncHasOnRequest() bool { 635 return js.True == bindings.HasFuncHasOnRequest() 636 } 637 638 // FuncHasOnRequest returns the function "WEBEXT.extension.onRequest.hasListener". 639 func FuncHasOnRequest() (fn js.Func[func(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) bool]) { 640 bindings.FuncHasOnRequest( 641 js.Pointer(&fn), 642 ) 643 return 644 } 645 646 // HasOnRequest calls the function "WEBEXT.extension.onRequest.hasListener" directly. 647 func HasOnRequest(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret bool) { 648 bindings.CallHasOnRequest( 649 js.Pointer(&ret), 650 callback.Ref(), 651 ) 652 653 return 654 } 655 656 // TryHasOnRequest calls the function "WEBEXT.extension.onRequest.hasListener" 657 // in a try/catch block and returns (_, err, ok = false) when it went through 658 // the catch clause. 659 func TryHasOnRequest(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret bool, exception js.Any, ok bool) { 660 ok = js.True == bindings.TryHasOnRequest( 661 js.Pointer(&ret), js.Pointer(&exception), 662 callback.Ref(), 663 ) 664 665 return 666 } 667 668 type OnRequestExternalEventCallbackFunc func(this js.Ref, request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()]) js.Ref 669 670 func (fn OnRequestExternalEventCallbackFunc) Register() js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])] { 671 return js.RegisterCallback[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]( 672 fn, abi.FuncPCABIInternal(fn), 673 ) 674 } 675 676 func (fn OnRequestExternalEventCallbackFunc) DispatchCallback( 677 targetPC uintptr, ctx *js.CallbackContext, 678 ) { 679 args := ctx.Args() 680 if len(args) != 3+1 /* js this */ || 681 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 682 js.ThrowInvalidCallbackInvocation() 683 } 684 var arg1 runtime.MessageSender 685 arg1.UpdateFrom(args[1+1]) 686 defer arg1.FreeMembers(true) 687 688 if ctx.Return(fn( 689 args[0], 690 691 js.Any{}.FromRef(args[0+1]), 692 mark.NoEscape(&arg1), 693 js.Func[func()]{}.FromRef(args[2+1]), 694 )) { 695 return 696 } 697 698 js.ThrowCallbackValueNotReturned() 699 } 700 701 type OnRequestExternalEventCallback[T any] struct { 702 Fn func(arg T, this js.Ref, request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()]) js.Ref 703 Arg T 704 } 705 706 func (cb *OnRequestExternalEventCallback[T]) Register() js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])] { 707 return js.RegisterCallback[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]( 708 cb, abi.FuncPCABIInternal(cb.Fn), 709 ) 710 } 711 712 func (cb *OnRequestExternalEventCallback[T]) DispatchCallback( 713 targetPC uintptr, ctx *js.CallbackContext, 714 ) { 715 args := ctx.Args() 716 if len(args) != 3+1 /* js this */ || 717 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 718 js.ThrowInvalidCallbackInvocation() 719 } 720 var arg1 runtime.MessageSender 721 arg1.UpdateFrom(args[1+1]) 722 defer arg1.FreeMembers(true) 723 724 if ctx.Return(cb.Fn( 725 cb.Arg, 726 args[0], 727 728 js.Any{}.FromRef(args[0+1]), 729 mark.NoEscape(&arg1), 730 js.Func[func()]{}.FromRef(args[2+1]), 731 )) { 732 return 733 } 734 735 js.ThrowCallbackValueNotReturned() 736 } 737 738 // HasFuncOnRequestExternal returns true if the function "WEBEXT.extension.onRequestExternal.addListener" exists. 739 func HasFuncOnRequestExternal() bool { 740 return js.True == bindings.HasFuncOnRequestExternal() 741 } 742 743 // FuncOnRequestExternal returns the function "WEBEXT.extension.onRequestExternal.addListener". 744 func FuncOnRequestExternal() (fn js.Func[func(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])])]) { 745 bindings.FuncOnRequestExternal( 746 js.Pointer(&fn), 747 ) 748 return 749 } 750 751 // OnRequestExternal calls the function "WEBEXT.extension.onRequestExternal.addListener" directly. 752 func OnRequestExternal(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void) { 753 bindings.CallOnRequestExternal( 754 js.Pointer(&ret), 755 callback.Ref(), 756 ) 757 758 return 759 } 760 761 // TryOnRequestExternal calls the function "WEBEXT.extension.onRequestExternal.addListener" 762 // in a try/catch block and returns (_, err, ok = false) when it went through 763 // the catch clause. 764 func TryOnRequestExternal(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void, exception js.Any, ok bool) { 765 ok = js.True == bindings.TryOnRequestExternal( 766 js.Pointer(&ret), js.Pointer(&exception), 767 callback.Ref(), 768 ) 769 770 return 771 } 772 773 // HasFuncOffRequestExternal returns true if the function "WEBEXT.extension.onRequestExternal.removeListener" exists. 774 func HasFuncOffRequestExternal() bool { 775 return js.True == bindings.HasFuncOffRequestExternal() 776 } 777 778 // FuncOffRequestExternal returns the function "WEBEXT.extension.onRequestExternal.removeListener". 779 func FuncOffRequestExternal() (fn js.Func[func(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])])]) { 780 bindings.FuncOffRequestExternal( 781 js.Pointer(&fn), 782 ) 783 return 784 } 785 786 // OffRequestExternal calls the function "WEBEXT.extension.onRequestExternal.removeListener" directly. 787 func OffRequestExternal(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void) { 788 bindings.CallOffRequestExternal( 789 js.Pointer(&ret), 790 callback.Ref(), 791 ) 792 793 return 794 } 795 796 // TryOffRequestExternal calls the function "WEBEXT.extension.onRequestExternal.removeListener" 797 // in a try/catch block and returns (_, err, ok = false) when it went through 798 // the catch clause. 799 func TryOffRequestExternal(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret js.Void, exception js.Any, ok bool) { 800 ok = js.True == bindings.TryOffRequestExternal( 801 js.Pointer(&ret), js.Pointer(&exception), 802 callback.Ref(), 803 ) 804 805 return 806 } 807 808 // HasFuncHasOnRequestExternal returns true if the function "WEBEXT.extension.onRequestExternal.hasListener" exists. 809 func HasFuncHasOnRequestExternal() bool { 810 return js.True == bindings.HasFuncHasOnRequestExternal() 811 } 812 813 // FuncHasOnRequestExternal returns the function "WEBEXT.extension.onRequestExternal.hasListener". 814 func FuncHasOnRequestExternal() (fn js.Func[func(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) bool]) { 815 bindings.FuncHasOnRequestExternal( 816 js.Pointer(&fn), 817 ) 818 return 819 } 820 821 // HasOnRequestExternal calls the function "WEBEXT.extension.onRequestExternal.hasListener" directly. 822 func HasOnRequestExternal(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret bool) { 823 bindings.CallHasOnRequestExternal( 824 js.Pointer(&ret), 825 callback.Ref(), 826 ) 827 828 return 829 } 830 831 // TryHasOnRequestExternal calls the function "WEBEXT.extension.onRequestExternal.hasListener" 832 // in a try/catch block and returns (_, err, ok = false) when it went through 833 // the catch clause. 834 func TryHasOnRequestExternal(callback js.Func[func(request js.Any, sender *runtime.MessageSender, sendResponse js.Func[func()])]) (ret bool, exception js.Any, ok bool) { 835 ok = js.True == bindings.TryHasOnRequestExternal( 836 js.Pointer(&ret), js.Pointer(&exception), 837 callback.Ref(), 838 ) 839 840 return 841 } 842 843 // HasFuncSendRequest returns true if the function "WEBEXT.extension.sendRequest" exists. 844 func HasFuncSendRequest() bool { 845 return js.True == bindings.HasFuncSendRequest() 846 } 847 848 // FuncSendRequest returns the function "WEBEXT.extension.sendRequest". 849 func FuncSendRequest() (fn js.Func[func(extensionId js.String, request js.Any) js.Promise[js.Any]]) { 850 bindings.FuncSendRequest( 851 js.Pointer(&fn), 852 ) 853 return 854 } 855 856 // SendRequest calls the function "WEBEXT.extension.sendRequest" directly. 857 func SendRequest(extensionId js.String, request js.Any) (ret js.Promise[js.Any]) { 858 bindings.CallSendRequest( 859 js.Pointer(&ret), 860 extensionId.Ref(), 861 request.Ref(), 862 ) 863 864 return 865 } 866 867 // TrySendRequest calls the function "WEBEXT.extension.sendRequest" 868 // in a try/catch block and returns (_, err, ok = false) when it went through 869 // the catch clause. 870 func TrySendRequest(extensionId js.String, request js.Any) (ret js.Promise[js.Any], exception js.Any, ok bool) { 871 ok = js.True == bindings.TrySendRequest( 872 js.Pointer(&ret), js.Pointer(&exception), 873 extensionId.Ref(), 874 request.Ref(), 875 ) 876 877 return 878 } 879 880 // HasFuncSetUpdateUrlData returns true if the function "WEBEXT.extension.setUpdateUrlData" exists. 881 func HasFuncSetUpdateUrlData() bool { 882 return js.True == bindings.HasFuncSetUpdateUrlData() 883 } 884 885 // FuncSetUpdateUrlData returns the function "WEBEXT.extension.setUpdateUrlData". 886 func FuncSetUpdateUrlData() (fn js.Func[func(data js.String)]) { 887 bindings.FuncSetUpdateUrlData( 888 js.Pointer(&fn), 889 ) 890 return 891 } 892 893 // SetUpdateUrlData calls the function "WEBEXT.extension.setUpdateUrlData" directly. 894 func SetUpdateUrlData(data js.String) (ret js.Void) { 895 bindings.CallSetUpdateUrlData( 896 js.Pointer(&ret), 897 data.Ref(), 898 ) 899 900 return 901 } 902 903 // TrySetUpdateUrlData calls the function "WEBEXT.extension.setUpdateUrlData" 904 // in a try/catch block and returns (_, err, ok = false) when it went through 905 // the catch clause. 906 func TrySetUpdateUrlData(data js.String) (ret js.Void, exception js.Any, ok bool) { 907 ok = js.True == bindings.TrySetUpdateUrlData( 908 js.Pointer(&ret), js.Pointer(&exception), 909 data.Ref(), 910 ) 911 912 return 913 }