private static NativeClassDefinition CreateSchemeHandler() { // note: WKURLSchemeHandler is not available at runtime and returns null, it's kept for completeness var definition = NativeClassDefinition.FromObject( "SpiderEyeSchemeHandler", WebKit.GetProtocol("WKURLSchemeHandler")); definition.AddMethod <SchemeHandlerDelegate>( "webView:startURLSchemeTask:", "v@:@@", (self, op, view, schemeTask) => { var instance = definition.GetParent <CocoaWebview>(self); UriSchemeStartCallback(instance, schemeTask); }); definition.AddMethod <SchemeHandlerDelegate>( "webView:stopURLSchemeTask:", "v@:@@", (self, op, view, schemeTask) => { /* don't think anything needs to be done here */ }); definition.FinishDeclaration(); return(definition); }
private static NativeClassDefinition CreateCallbackClass() { var definition = NativeClassDefinition.FromObject( "SpiderEyeWebviewCallbacks", WebKit.GetProtocol("WKNavigationDelegate"), // note: WKScriptMessageHandler is not available at runtime and returns null WebKit.GetProtocol("WKScriptMessageHandler")); definition.AddMethod <NavigationDecideDelegate>( "webView:decidePolicyForNavigationAction:decisionHandler:", "v@:@@@", (self, op, view, navigationAction, decisionHandler) => { var instance = definition.GetParent <CocoaWebview>(self); if (instance == null) { return; } var args = new NavigatingEventArgs(instance.Uri); instance.Navigating?.Invoke(instance, args); var block = Marshal.PtrToStructure <NSBlock.BlockLiteral>(decisionHandler); var callback = Marshal.GetDelegateForFunctionPointer <NavigationDecisionDelegate>(block.Invoke); callback(decisionHandler, args.Cancel ? IntPtr.Zero : new IntPtr(1)); }); definition.AddMethod <ObserveValueDelegate>( "observeValueForKeyPath:ofObject:change:context:", "v@:@@@@", (self, op, keyPath, obj, change, context) => { var instance = definition.GetParent <CocoaWebview>(self); if (instance != null) { ObservedValueChanged(instance, keyPath); } }); definition.AddMethod <ScriptCallbackDelegate>( "userContentController:didReceiveScriptMessage:", "v@:@@", (self, op, notification, message) => { var instance = definition.GetParent <CocoaWebview>(self); if (instance != null) { ScriptCallback(instance, message); } }); definition.FinishDeclaration(); return(definition); }