Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the BlazorWebView.
        /// </summary>
        /// <param name="configure">A delegate that is executed to configure the webview.</param>
        public void Initialize(Action <WebViewOptions> configure)
        {
            var options = new WebViewOptions();

            configure.Invoke(options);

            WebSettings webSettings = this.innerWebView.Settings;

            webSettings.JavaScriptEnabled = true;
            WebView.SetWebContentsDebuggingEnabled(true);
            this.innerWebView.AddJavascriptInterface(new BlazorJavascriptInterface(this), "blazorwebviewinterop");

            var resultCallBack = new ValueCallback <string>(s =>
            {
                // TODO: Handle javascript errors nicer.
                if (!string.IsNullOrEmpty(s))
                {
                    Console.WriteLine(s);
                }
            });

            var blazorWebViewClient = new BlazorWebViewClient();

            this.innerWebView.SetWebViewClient(blazorWebViewClient);

            foreach (var(schemeName, handler) in options.SchemeHandlers)
            {
                blazorWebViewClient.AddCustomScheme(schemeName, handler);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize the BlazorWebView.
        /// </summary>
        /// <param name="configure">A delegate that is executed to configure the webview.</param>
        public void Initialize(Action <WebViewOptions> configure)
        {
            var options = new WebViewOptions();

            configure.Invoke(options);

            this.webview.Navigate("about:blank");

            foreach (var(schemeName, handler) in options.SchemeHandlers)
            {
                this.uriToStreamResolver.AddSchemeHandler(schemeName, handler);
            }
        }
Ejemplo n.º 3
0
        public void Initialize(Action <WebViewOptions> configure)
        {
            _ownerThreadId = Thread.CurrentThread.ManagedThreadId;

            var options = new WebViewOptions();

            configure.Invoke(options);

            _browser = new ChromiumWebBrowser("");
            _browser.RequestHandler             = new BrowserRequestHandler(options.SchemeHandlers);
            _browser.MenuHandler                = new CustomMenuHandler();
            _browser.JavascriptMessageReceived += Browser_JavascriptMessageReceived;
            _browser.Dock = DockStyle.Fill;
            Controls.Add(_browser);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialize the BlazorWebView.
        /// </summary>
        /// <param name="configure">A delegate that is executed to configure the webview.</param>
        public void Initialize(Action <WebViewOptions> configure)
        {
            var options = new WebViewOptions();

            configure.Invoke(options);

            foreach (var(schemeName, handler) in options.SchemeHandlers)
            {
                this.AddCustomScheme(schemeName, handler);
            }

            if (!BlazorWebViewNative_Initialize(this.blazorWebView))
            {
                throw new InvalidOperationException(this.lastErrorMessage);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialize the BlazorWebView.
        /// </summary>
        /// <param name="configure">A delegate that is executed to configure the webview.</param>
        public void Initialize(Action <WebViewOptions> configure)
        {
            var options = new WebViewOptions();

            configure.Invoke(options);

            var webConfig = new WKWebViewConfiguration();

            webConfig.UserContentController = new WKUserContentController();
            webConfig.UserContentController.AddUserScript(new WKUserScript((NSString)InitScriptSource, WKUserScriptInjectionTime.AtDocumentStart, true));
            webConfig.Preferences.SetValueForKey(NSNumber.FromBoolean(true), (NSString)"developerExtrasEnabled");
            webConfig.UserContentController.AddScriptMessageHandler(this, "blazorwebviewinterop");

            foreach (var(schemeName, handler) in options.SchemeHandlers)
            {
                this.AddCustomScheme(webConfig, schemeName, handler);
            }

            this.webView = new WKWebView(this.Frame, webConfig);
            this.webView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
            this.AddSubview(this.webView);
            this.AutosizesSubviews = true;
        }