Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WKUIDelegate runJavaScriptTextInputPanelWithPrompt has incorrect nullability #15728

Open
mattleibow opened this issue Aug 22, 2022 · 4 comments
Labels
api-bindings bug If an issue is a bug or a pull request a bug fix
Milestone

Comments

@mattleibow
Copy link
Member

The API in objc (and also in the ms docs) indicate that values can be null:

https://developer.apple.com/documentation/webkit/wkuidelegate/1538086-webview?language=objc

 public virtual void RunJavaScriptTextInputPanel (
     WebKit.WKWebView webView,
     string prompt,
-    string defaultText,
+    string defaultText?,
     WebKit.WKFrameInfo frame,
-    Action<string> completionHandler);
+    Action<string?> completionHandler);
@chamons chamons added this to the Future milestone Aug 23, 2022
@chamons
Copy link
Contributor

chamons commented Aug 23, 2022

I assume this would be covered by your nullability work, have you looked at this framework yet @tj-devel709 ?

@OMendozaG
Copy link

this bug come from far with xamarin.. please solve this...

@xperseguers
Copy link

xperseguers commented Feb 14, 2025

Any news on this? It looks like with MAUI and .NET v8 (at least) the problem is still present.

@rolfbjarne
Copy link
Member

Can you try using this as a workaround, it's a custom implementation of the runJavaScriptTextInputPanelWithPrompt selector:

using CoreFoundation;
using ObjCRuntime;
using WebKit;
#nullable enable

class MyWKUIDelegate : WKUIDelegate {
	// Custom implementation due to https://github.com/xamarin/xamarin-macios/issues/15728.
	[Export ("webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:")]
	void RunJavaScriptTextInputPanel (WKWebView webView, string prompt, string? defaultText, WKFrameInfo frame, IntPtr blockCompletionHandler)
	{
		var completionHandler = NIDActionArity1V72.Create (blockCompletionHandler);

		// ...
		if (completionHandler is not null)
			completionHandler (null);
	}

	sealed class NIDActionArity1V72 : TrampolineBlockBase {
		[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
		[UserDelegateType (typeof (global::System.Action<string?>))]
		unsafe delegate void DActionArity1V72 (IntPtr block, NativeHandle obj);

		DActionArity1V72 invoker;
		public unsafe NIDActionArity1V72 (BlockLiteral *block) : base (block)
		{
			invoker = block->GetDelegateForBlock<DActionArity1V72> ();
		}
		[Preserve (Conditional=true)]
		public unsafe static global::System.Action<string?>? Create (IntPtr block)
		{
			if (block == IntPtr.Zero)
				return null;
			var del = (global::System.Action<string?>) GetExistingManagedDelegate (block);
			return del ?? new NIDActionArity1V72 ((BlockLiteral *) block).Invoke;
		}
		unsafe void Invoke (string? obj)
		{
			var nsobj = CFString.CreateNative (obj);
			invoker (BlockPointer, nsobj);
			CFString.ReleaseNative (nsobj);
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-bindings bug If an issue is a bug or a pull request a bug fix
Projects
None yet
Development

No branches or pull requests

6 participants