github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/mimehandlerprivate/apis_js_wasm.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package mimehandlerprivate
     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/mimehandlerprivate/bindings"
    11  )
    12  
    13  type GetStreamDetailsCallbackFunc func(this js.Ref, streamInfo *StreamInfo) js.Ref
    14  
    15  func (fn GetStreamDetailsCallbackFunc) Register() js.Func[func(streamInfo *StreamInfo)] {
    16  	return js.RegisterCallback[func(streamInfo *StreamInfo)](
    17  		fn, abi.FuncPCABIInternal(fn),
    18  	)
    19  }
    20  
    21  func (fn GetStreamDetailsCallbackFunc) DispatchCallback(
    22  	targetPC uintptr, ctx *js.CallbackContext,
    23  ) {
    24  	args := ctx.Args()
    25  	if len(args) != 1+1 /* js this */ ||
    26  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
    27  		js.ThrowInvalidCallbackInvocation()
    28  	}
    29  	var arg0 StreamInfo
    30  	arg0.UpdateFrom(args[0+1])
    31  	defer arg0.FreeMembers(true)
    32  
    33  	if ctx.Return(fn(
    34  		args[0],
    35  
    36  		mark.NoEscape(&arg0),
    37  	)) {
    38  		return
    39  	}
    40  
    41  	js.ThrowCallbackValueNotReturned()
    42  }
    43  
    44  type GetStreamDetailsCallback[T any] struct {
    45  	Fn  func(arg T, this js.Ref, streamInfo *StreamInfo) js.Ref
    46  	Arg T
    47  }
    48  
    49  func (cb *GetStreamDetailsCallback[T]) Register() js.Func[func(streamInfo *StreamInfo)] {
    50  	return js.RegisterCallback[func(streamInfo *StreamInfo)](
    51  		cb, abi.FuncPCABIInternal(cb.Fn),
    52  	)
    53  }
    54  
    55  func (cb *GetStreamDetailsCallback[T]) DispatchCallback(
    56  	targetPC uintptr, ctx *js.CallbackContext,
    57  ) {
    58  	args := ctx.Args()
    59  	if len(args) != 1+1 /* js this */ ||
    60  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
    61  		js.ThrowInvalidCallbackInvocation()
    62  	}
    63  	var arg0 StreamInfo
    64  	arg0.UpdateFrom(args[0+1])
    65  	defer arg0.FreeMembers(true)
    66  
    67  	if ctx.Return(cb.Fn(
    68  		cb.Arg,
    69  		args[0],
    70  
    71  		mark.NoEscape(&arg0),
    72  	)) {
    73  		return
    74  	}
    75  
    76  	js.ThrowCallbackValueNotReturned()
    77  }
    78  
    79  type StreamInfo struct {
    80  	// MimeType is "StreamInfo.mimeType"
    81  	//
    82  	// Optional
    83  	MimeType js.String
    84  	// OriginalUrl is "StreamInfo.originalUrl"
    85  	//
    86  	// Optional
    87  	OriginalUrl js.String
    88  	// StreamUrl is "StreamInfo.streamUrl"
    89  	//
    90  	// Optional
    91  	StreamUrl js.String
    92  	// TabId is "StreamInfo.tabId"
    93  	//
    94  	// Optional
    95  	//
    96  	// NOTE: FFI_USE_TabId MUST be set to true to make this field effective.
    97  	TabId int32
    98  	// ResponseHeaders is "StreamInfo.responseHeaders"
    99  	//
   100  	// Optional
   101  	ResponseHeaders js.Object
   102  	// Embedded is "StreamInfo.embedded"
   103  	//
   104  	// Optional
   105  	//
   106  	// NOTE: FFI_USE_Embedded MUST be set to true to make this field effective.
   107  	Embedded bool
   108  
   109  	FFI_USE_TabId    bool // for TabId.
   110  	FFI_USE_Embedded bool // for Embedded.
   111  
   112  	FFI_USE bool
   113  }
   114  
   115  // FromRef calls UpdateFrom and returns a StreamInfo with all fields set.
   116  func (p StreamInfo) FromRef(ref js.Ref) StreamInfo {
   117  	p.UpdateFrom(ref)
   118  	return p
   119  }
   120  
   121  // New creates a new StreamInfo in the application heap.
   122  func (p StreamInfo) New() js.Ref {
   123  	return bindings.StreamInfoJSLoad(
   124  		js.Pointer(&p), js.True, 0,
   125  	)
   126  }
   127  
   128  // UpdateFrom copies value of all fields of the heap object to p.
   129  func (p *StreamInfo) UpdateFrom(ref js.Ref) {
   130  	bindings.StreamInfoJSStore(
   131  		js.Pointer(p), ref,
   132  	)
   133  }
   134  
   135  // Update writes all fields of the p to the heap object referenced by ref.
   136  func (p *StreamInfo) Update(ref js.Ref) {
   137  	bindings.StreamInfoJSLoad(
   138  		js.Pointer(p), js.False, ref,
   139  	)
   140  }
   141  
   142  // FreeMembers frees fields with heap reference, if recursive is true
   143  // free all heap references reachable from p.
   144  func (p *StreamInfo) FreeMembers(recursive bool) {
   145  	js.Free(
   146  		p.MimeType.Ref(),
   147  		p.OriginalUrl.Ref(),
   148  		p.StreamUrl.Ref(),
   149  		p.ResponseHeaders.Ref(),
   150  	)
   151  	p.MimeType = p.MimeType.FromRef(js.Undefined)
   152  	p.OriginalUrl = p.OriginalUrl.FromRef(js.Undefined)
   153  	p.StreamUrl = p.StreamUrl.FromRef(js.Undefined)
   154  	p.ResponseHeaders = p.ResponseHeaders.FromRef(js.Undefined)
   155  }
   156  
   157  type PdfPluginAttributes struct {
   158  	// BackgroundColor is "PdfPluginAttributes.backgroundColor"
   159  	//
   160  	// Optional
   161  	//
   162  	// NOTE: FFI_USE_BackgroundColor MUST be set to true to make this field effective.
   163  	BackgroundColor float64
   164  	// AllowJavascript is "PdfPluginAttributes.allowJavascript"
   165  	//
   166  	// Optional
   167  	//
   168  	// NOTE: FFI_USE_AllowJavascript MUST be set to true to make this field effective.
   169  	AllowJavascript bool
   170  
   171  	FFI_USE_BackgroundColor bool // for BackgroundColor.
   172  	FFI_USE_AllowJavascript bool // for AllowJavascript.
   173  
   174  	FFI_USE bool
   175  }
   176  
   177  // FromRef calls UpdateFrom and returns a PdfPluginAttributes with all fields set.
   178  func (p PdfPluginAttributes) FromRef(ref js.Ref) PdfPluginAttributes {
   179  	p.UpdateFrom(ref)
   180  	return p
   181  }
   182  
   183  // New creates a new PdfPluginAttributes in the application heap.
   184  func (p PdfPluginAttributes) New() js.Ref {
   185  	return bindings.PdfPluginAttributesJSLoad(
   186  		js.Pointer(&p), js.True, 0,
   187  	)
   188  }
   189  
   190  // UpdateFrom copies value of all fields of the heap object to p.
   191  func (p *PdfPluginAttributes) UpdateFrom(ref js.Ref) {
   192  	bindings.PdfPluginAttributesJSStore(
   193  		js.Pointer(p), ref,
   194  	)
   195  }
   196  
   197  // Update writes all fields of the p to the heap object referenced by ref.
   198  func (p *PdfPluginAttributes) Update(ref js.Ref) {
   199  	bindings.PdfPluginAttributesJSLoad(
   200  		js.Pointer(p), js.False, ref,
   201  	)
   202  }
   203  
   204  // FreeMembers frees fields with heap reference, if recursive is true
   205  // free all heap references reachable from p.
   206  func (p *PdfPluginAttributes) FreeMembers(recursive bool) {
   207  }
   208  
   209  type SetShowBeforeUnloadDialogCallbackFunc func(this js.Ref) js.Ref
   210  
   211  func (fn SetShowBeforeUnloadDialogCallbackFunc) Register() js.Func[func()] {
   212  	return js.RegisterCallback[func()](
   213  		fn, abi.FuncPCABIInternal(fn),
   214  	)
   215  }
   216  
   217  func (fn SetShowBeforeUnloadDialogCallbackFunc) DispatchCallback(
   218  	targetPC uintptr, ctx *js.CallbackContext,
   219  ) {
   220  	args := ctx.Args()
   221  	if len(args) != 0+1 /* js this */ ||
   222  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
   223  		js.ThrowInvalidCallbackInvocation()
   224  	}
   225  
   226  	if ctx.Return(fn(
   227  		args[0],
   228  	)) {
   229  		return
   230  	}
   231  
   232  	js.ThrowCallbackValueNotReturned()
   233  }
   234  
   235  type SetShowBeforeUnloadDialogCallback[T any] struct {
   236  	Fn  func(arg T, this js.Ref) js.Ref
   237  	Arg T
   238  }
   239  
   240  func (cb *SetShowBeforeUnloadDialogCallback[T]) Register() js.Func[func()] {
   241  	return js.RegisterCallback[func()](
   242  		cb, abi.FuncPCABIInternal(cb.Fn),
   243  	)
   244  }
   245  
   246  func (cb *SetShowBeforeUnloadDialogCallback[T]) DispatchCallback(
   247  	targetPC uintptr, ctx *js.CallbackContext,
   248  ) {
   249  	args := ctx.Args()
   250  	if len(args) != 0+1 /* js this */ ||
   251  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
   252  		js.ThrowInvalidCallbackInvocation()
   253  	}
   254  
   255  	if ctx.Return(cb.Fn(
   256  		cb.Arg,
   257  		args[0],
   258  	)) {
   259  		return
   260  	}
   261  
   262  	js.ThrowCallbackValueNotReturned()
   263  }
   264  
   265  // HasFuncGetStreamInfo returns true if the function "WEBEXT.mimeHandlerPrivate.getStreamInfo" exists.
   266  func HasFuncGetStreamInfo() bool {
   267  	return js.True == bindings.HasFuncGetStreamInfo()
   268  }
   269  
   270  // FuncGetStreamInfo returns the function "WEBEXT.mimeHandlerPrivate.getStreamInfo".
   271  func FuncGetStreamInfo() (fn js.Func[func(callback js.Func[func(streamInfo *StreamInfo)])]) {
   272  	bindings.FuncGetStreamInfo(
   273  		js.Pointer(&fn),
   274  	)
   275  	return
   276  }
   277  
   278  // GetStreamInfo calls the function "WEBEXT.mimeHandlerPrivate.getStreamInfo" directly.
   279  func GetStreamInfo(callback js.Func[func(streamInfo *StreamInfo)]) (ret js.Void) {
   280  	bindings.CallGetStreamInfo(
   281  		js.Pointer(&ret),
   282  		callback.Ref(),
   283  	)
   284  
   285  	return
   286  }
   287  
   288  // TryGetStreamInfo calls the function "WEBEXT.mimeHandlerPrivate.getStreamInfo"
   289  // in a try/catch block and returns (_, err, ok = false) when it went through
   290  // the catch clause.
   291  func TryGetStreamInfo(callback js.Func[func(streamInfo *StreamInfo)]) (ret js.Void, exception js.Any, ok bool) {
   292  	ok = js.True == bindings.TryGetStreamInfo(
   293  		js.Pointer(&ret), js.Pointer(&exception),
   294  		callback.Ref(),
   295  	)
   296  
   297  	return
   298  }
   299  
   300  type OnSaveEventCallbackFunc func(this js.Ref, streamUrl js.String) js.Ref
   301  
   302  func (fn OnSaveEventCallbackFunc) Register() js.Func[func(streamUrl js.String)] {
   303  	return js.RegisterCallback[func(streamUrl js.String)](
   304  		fn, abi.FuncPCABIInternal(fn),
   305  	)
   306  }
   307  
   308  func (fn OnSaveEventCallbackFunc) DispatchCallback(
   309  	targetPC uintptr, ctx *js.CallbackContext,
   310  ) {
   311  	args := ctx.Args()
   312  	if len(args) != 1+1 /* js this */ ||
   313  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
   314  		js.ThrowInvalidCallbackInvocation()
   315  	}
   316  
   317  	if ctx.Return(fn(
   318  		args[0],
   319  
   320  		js.String{}.FromRef(args[0+1]),
   321  	)) {
   322  		return
   323  	}
   324  
   325  	js.ThrowCallbackValueNotReturned()
   326  }
   327  
   328  type OnSaveEventCallback[T any] struct {
   329  	Fn  func(arg T, this js.Ref, streamUrl js.String) js.Ref
   330  	Arg T
   331  }
   332  
   333  func (cb *OnSaveEventCallback[T]) Register() js.Func[func(streamUrl js.String)] {
   334  	return js.RegisterCallback[func(streamUrl js.String)](
   335  		cb, abi.FuncPCABIInternal(cb.Fn),
   336  	)
   337  }
   338  
   339  func (cb *OnSaveEventCallback[T]) DispatchCallback(
   340  	targetPC uintptr, ctx *js.CallbackContext,
   341  ) {
   342  	args := ctx.Args()
   343  	if len(args) != 1+1 /* js this */ ||
   344  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
   345  		js.ThrowInvalidCallbackInvocation()
   346  	}
   347  
   348  	if ctx.Return(cb.Fn(
   349  		cb.Arg,
   350  		args[0],
   351  
   352  		js.String{}.FromRef(args[0+1]),
   353  	)) {
   354  		return
   355  	}
   356  
   357  	js.ThrowCallbackValueNotReturned()
   358  }
   359  
   360  // HasFuncOnSave returns true if the function "WEBEXT.mimeHandlerPrivate.onSave.addListener" exists.
   361  func HasFuncOnSave() bool {
   362  	return js.True == bindings.HasFuncOnSave()
   363  }
   364  
   365  // FuncOnSave returns the function "WEBEXT.mimeHandlerPrivate.onSave.addListener".
   366  func FuncOnSave() (fn js.Func[func(callback js.Func[func(streamUrl js.String)])]) {
   367  	bindings.FuncOnSave(
   368  		js.Pointer(&fn),
   369  	)
   370  	return
   371  }
   372  
   373  // OnSave calls the function "WEBEXT.mimeHandlerPrivate.onSave.addListener" directly.
   374  func OnSave(callback js.Func[func(streamUrl js.String)]) (ret js.Void) {
   375  	bindings.CallOnSave(
   376  		js.Pointer(&ret),
   377  		callback.Ref(),
   378  	)
   379  
   380  	return
   381  }
   382  
   383  // TryOnSave calls the function "WEBEXT.mimeHandlerPrivate.onSave.addListener"
   384  // in a try/catch block and returns (_, err, ok = false) when it went through
   385  // the catch clause.
   386  func TryOnSave(callback js.Func[func(streamUrl js.String)]) (ret js.Void, exception js.Any, ok bool) {
   387  	ok = js.True == bindings.TryOnSave(
   388  		js.Pointer(&ret), js.Pointer(&exception),
   389  		callback.Ref(),
   390  	)
   391  
   392  	return
   393  }
   394  
   395  // HasFuncOffSave returns true if the function "WEBEXT.mimeHandlerPrivate.onSave.removeListener" exists.
   396  func HasFuncOffSave() bool {
   397  	return js.True == bindings.HasFuncOffSave()
   398  }
   399  
   400  // FuncOffSave returns the function "WEBEXT.mimeHandlerPrivate.onSave.removeListener".
   401  func FuncOffSave() (fn js.Func[func(callback js.Func[func(streamUrl js.String)])]) {
   402  	bindings.FuncOffSave(
   403  		js.Pointer(&fn),
   404  	)
   405  	return
   406  }
   407  
   408  // OffSave calls the function "WEBEXT.mimeHandlerPrivate.onSave.removeListener" directly.
   409  func OffSave(callback js.Func[func(streamUrl js.String)]) (ret js.Void) {
   410  	bindings.CallOffSave(
   411  		js.Pointer(&ret),
   412  		callback.Ref(),
   413  	)
   414  
   415  	return
   416  }
   417  
   418  // TryOffSave calls the function "WEBEXT.mimeHandlerPrivate.onSave.removeListener"
   419  // in a try/catch block and returns (_, err, ok = false) when it went through
   420  // the catch clause.
   421  func TryOffSave(callback js.Func[func(streamUrl js.String)]) (ret js.Void, exception js.Any, ok bool) {
   422  	ok = js.True == bindings.TryOffSave(
   423  		js.Pointer(&ret), js.Pointer(&exception),
   424  		callback.Ref(),
   425  	)
   426  
   427  	return
   428  }
   429  
   430  // HasFuncHasOnSave returns true if the function "WEBEXT.mimeHandlerPrivate.onSave.hasListener" exists.
   431  func HasFuncHasOnSave() bool {
   432  	return js.True == bindings.HasFuncHasOnSave()
   433  }
   434  
   435  // FuncHasOnSave returns the function "WEBEXT.mimeHandlerPrivate.onSave.hasListener".
   436  func FuncHasOnSave() (fn js.Func[func(callback js.Func[func(streamUrl js.String)]) bool]) {
   437  	bindings.FuncHasOnSave(
   438  		js.Pointer(&fn),
   439  	)
   440  	return
   441  }
   442  
   443  // HasOnSave calls the function "WEBEXT.mimeHandlerPrivate.onSave.hasListener" directly.
   444  func HasOnSave(callback js.Func[func(streamUrl js.String)]) (ret bool) {
   445  	bindings.CallHasOnSave(
   446  		js.Pointer(&ret),
   447  		callback.Ref(),
   448  	)
   449  
   450  	return
   451  }
   452  
   453  // TryHasOnSave calls the function "WEBEXT.mimeHandlerPrivate.onSave.hasListener"
   454  // in a try/catch block and returns (_, err, ok = false) when it went through
   455  // the catch clause.
   456  func TryHasOnSave(callback js.Func[func(streamUrl js.String)]) (ret bool, exception js.Any, ok bool) {
   457  	ok = js.True == bindings.TryHasOnSave(
   458  		js.Pointer(&ret), js.Pointer(&exception),
   459  		callback.Ref(),
   460  	)
   461  
   462  	return
   463  }
   464  
   465  // HasFuncSetPdfPluginAttributes returns true if the function "WEBEXT.mimeHandlerPrivate.setPdfPluginAttributes" exists.
   466  func HasFuncSetPdfPluginAttributes() bool {
   467  	return js.True == bindings.HasFuncSetPdfPluginAttributes()
   468  }
   469  
   470  // FuncSetPdfPluginAttributes returns the function "WEBEXT.mimeHandlerPrivate.setPdfPluginAttributes".
   471  func FuncSetPdfPluginAttributes() (fn js.Func[func(pdfPluginAttributes PdfPluginAttributes)]) {
   472  	bindings.FuncSetPdfPluginAttributes(
   473  		js.Pointer(&fn),
   474  	)
   475  	return
   476  }
   477  
   478  // SetPdfPluginAttributes calls the function "WEBEXT.mimeHandlerPrivate.setPdfPluginAttributes" directly.
   479  func SetPdfPluginAttributes(pdfPluginAttributes PdfPluginAttributes) (ret js.Void) {
   480  	bindings.CallSetPdfPluginAttributes(
   481  		js.Pointer(&ret),
   482  		js.Pointer(&pdfPluginAttributes),
   483  	)
   484  
   485  	return
   486  }
   487  
   488  // TrySetPdfPluginAttributes calls the function "WEBEXT.mimeHandlerPrivate.setPdfPluginAttributes"
   489  // in a try/catch block and returns (_, err, ok = false) when it went through
   490  // the catch clause.
   491  func TrySetPdfPluginAttributes(pdfPluginAttributes PdfPluginAttributes) (ret js.Void, exception js.Any, ok bool) {
   492  	ok = js.True == bindings.TrySetPdfPluginAttributes(
   493  		js.Pointer(&ret), js.Pointer(&exception),
   494  		js.Pointer(&pdfPluginAttributes),
   495  	)
   496  
   497  	return
   498  }
   499  
   500  // HasFuncSetShowBeforeUnloadDialog returns true if the function "WEBEXT.mimeHandlerPrivate.setShowBeforeUnloadDialog" exists.
   501  func HasFuncSetShowBeforeUnloadDialog() bool {
   502  	return js.True == bindings.HasFuncSetShowBeforeUnloadDialog()
   503  }
   504  
   505  // FuncSetShowBeforeUnloadDialog returns the function "WEBEXT.mimeHandlerPrivate.setShowBeforeUnloadDialog".
   506  func FuncSetShowBeforeUnloadDialog() (fn js.Func[func(showDialog bool, callback js.Func[func()])]) {
   507  	bindings.FuncSetShowBeforeUnloadDialog(
   508  		js.Pointer(&fn),
   509  	)
   510  	return
   511  }
   512  
   513  // SetShowBeforeUnloadDialog calls the function "WEBEXT.mimeHandlerPrivate.setShowBeforeUnloadDialog" directly.
   514  func SetShowBeforeUnloadDialog(showDialog bool, callback js.Func[func()]) (ret js.Void) {
   515  	bindings.CallSetShowBeforeUnloadDialog(
   516  		js.Pointer(&ret),
   517  		js.Bool(bool(showDialog)),
   518  		callback.Ref(),
   519  	)
   520  
   521  	return
   522  }
   523  
   524  // TrySetShowBeforeUnloadDialog calls the function "WEBEXT.mimeHandlerPrivate.setShowBeforeUnloadDialog"
   525  // in a try/catch block and returns (_, err, ok = false) when it went through
   526  // the catch clause.
   527  func TrySetShowBeforeUnloadDialog(showDialog bool, callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) {
   528  	ok = js.True == bindings.TrySetShowBeforeUnloadDialog(
   529  		js.Pointer(&ret), js.Pointer(&exception),
   530  		js.Bool(bool(showDialog)),
   531  		callback.Ref(),
   532  	)
   533  
   534  	return
   535  }