示例#1
0
        private IntPtr CreateCallbackClass()
        {
            IntPtr callbackClass = ObjC.AllocateClassPair(ObjC.GetClass("NSObject"), "CallbackClass" + count, IntPtr.Zero);

            ObjC.AddProtocol(callbackClass, ObjC.GetProtocol("WKNavigationDelegate"));
            ObjC.AddProtocol(callbackClass, ObjC.GetProtocol("WKScriptMessageHandler"));

            ObjC.AddMethod(
                callbackClass,
                ObjC.RegisterName("webView:didFinishNavigation:"),
                loadDelegate,
                "v@:@@");

            ObjC.AddMethod(
                callbackClass,
                ObjC.RegisterName("webView:didFailNavigation:withError:"),
                loadFailedDelegate,
                "v@:@@@");

            ObjC.AddMethod(
                callbackClass,
                ObjC.RegisterName("observeValueForKeyPath:ofObject:change:context:"),
                observedValueChangedDelegate,
                "v@:@@@@");

            ObjC.AddMethod(
                callbackClass,
                ObjC.RegisterName("userContentController:didReceiveScriptMessage:"),
                scriptDelegate,
                "v@:@@");

            ObjC.RegisterClassPair(callbackClass);

            return(ObjC.Call(callbackClass, "new"));
        }
示例#2
0
        private string CreateSchemeHandler(IntPtr configuration)
        {
            string host = null;

            if (string.IsNullOrWhiteSpace(config.ExternalHost))
            {
                const string scheme = "spidereye";
                host = UriTools.GetRandomResourceUrl(scheme);

                IntPtr handlerClass = ObjC.AllocateClassPair(ObjC.GetClass("NSObject"), "SchemeHandler" + count, IntPtr.Zero);
                ObjC.AddProtocol(handlerClass, ObjC.GetProtocol("WKURLSchemeHandler"));

                ObjC.AddMethod(
                    handlerClass,
                    ObjC.RegisterName("webView:startURLSchemeTask:"),
                    uriSchemeStartDelegate,
                    "v@:@@");

                ObjC.AddMethod(
                    handlerClass,
                    ObjC.RegisterName("webView:stopURLSchemeTask:"),
                    uriSchemeStopDelegate,
                    "v@:@@");

                ObjC.RegisterClassPair(handlerClass);

                IntPtr handler = ObjC.Call(handlerClass, "new");
                ObjC.Call(configuration, "setURLSchemeHandler:forURLScheme:", handler, NSString.Create(scheme));
            }

            return(host);
        }
示例#3
0
        private static IMenu appMenu; // needed to prevent garbage collection

        static Application()
        {
            OS = GetOS();
            CheckOs(OperatingSystem.MacOS);

            Factory = new CocoaUiFactory();

            // need to keep the delegates around or they will get garbage collected
            ShouldTerminateDelegateRef      = ShouldTerminateCallback;
            AppFinishedLaunchingDelegateRef = AppFinishedLaunching;

            AppHandle = GetApp();
            ObjC.Call(AppHandle, "setActivationPolicy:", IntPtr.Zero);

            IntPtr appDelegateClass = ObjC.AllocateClassPair(ObjC.GetClass("NSObject"), "AppDelegate", IntPtr.Zero);

            ObjC.AddProtocol(appDelegateClass, ObjC.GetProtocol("NSApplicationDelegate"));

            ObjC.AddMethod(
                appDelegateClass,
                ObjC.RegisterName("applicationShouldTerminateAfterLastWindowClosed:"),
                ShouldTerminateDelegateRef,
                "c@:@");

            ObjC.AddMethod(
                appDelegateClass,
                ObjC.RegisterName("applicationDidFinishLaunching:"),
                AppFinishedLaunchingDelegateRef,
                "v@:@");

            ObjC.RegisterClassPair(appDelegateClass);

            IntPtr appDelegate = ObjC.Call(appDelegateClass, "new");

            ObjC.Call(AppHandle, "setDelegate:", appDelegate);

            CreateDefaultAppMenu();
        }
示例#4
0
        private void SetWindowDelegate(IntPtr window)
        {
            IntPtr windowDelegateClass = ObjC.AllocateClassPair(ObjC.GetClass("NSObject"), "WindowDelegate" + count, IntPtr.Zero);

            ObjC.AddProtocol(windowDelegateClass, ObjC.GetProtocol("NSWindowDelegate"));

            ObjC.AddMethod(
                windowDelegateClass,
                ObjC.RegisterName("windowShouldClose:"),
                windowShouldCloseDelegate,
                "c@:@");

            ObjC.AddMethod(
                windowDelegateClass,
                ObjC.RegisterName("windowWillClose:"),
                windowWillCloseDelegate,
                "v@:@");

            ObjC.RegisterClassPair(windowDelegateClass);

            IntPtr windowDelegate = ObjC.Call(windowDelegateClass, "new");

            ObjC.Call(window, "setDelegate:", windowDelegate);
        }