Example #1
0
        /// <summary>
        /// Creates a <see cref="WebViewControlHost"/> within the context of <paramref name="process"/>.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess"/>.</param>
        /// <param name="hostWindowHandle">The parent window handle hosting the control.</param>
        /// <param name="bounds">A <see cref="Rectangle"/> containing numerical values that represent the location and size of the control.</param>
        /// <returns>A <see cref="WebViewControlHost"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="hostWindowHandle"/> is equal to <see cref="IntPtr.Zero"/></exception>
        /// <seealso cref="CreateWebViewControlHostAsync"/>
        internal static WebViewControlHost CreateWebViewControlHost(
            this WebViewControlProcess process,
            IntPtr hostWindowHandle,
            Rectangle bounds)
        {
            Verify.IsNotNull(process);
            Verify.IsFalse(hostWindowHandle == IntPtr.Zero);
            var f = process.CreateWebViewControlHostAsync(hostWindowHandle, bounds).ConfigureAwait(false);

            return(f.GetAwaiter().GetResult());
        }
Example #2
0
        /// <summary>
        /// Creates a <see cref="IWebView" /> within the context of <paramref name="process" />.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="control">An instance of <see cref="Control"/> to parent the <see cref="WebView"/>.</param>
        /// <returns>An <see cref="IWebView"/> instance.</returns>
        /// <exception cref="ArgumentNullException">Occurs when <paramref name="control"/> is <see langword="null" />.</exception>
        internal static IWebView CreateWebView(
            this WebViewControlProcess process,
            Control control)
        {
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            return(process.CreateWebView(control, control.Bounds));
        }
Example #3
0
        /// <summary>
        /// Asynchronously creates a <see cref="WebViewControlHost"/> within the context of <paramref name="process"/>.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess"/>.</param>
        /// <param name="hostWindowHandle">The parent window handle hosting the control.</param>
        /// <param name="bounds">A <see cref="Rectangle"/> containing numerical values that represent the location and size of the control.</param>
        /// <returns>An asynchronous operation that completes with a <see cref="WebViewControlHost"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="hostWindowHandle"/> is equal to <see cref="IntPtr.Zero"/></exception>
        internal static Task <WebViewControlHost> CreateWebViewControlHostAsync(
            this WebViewControlProcess process,
            IntPtr hostWindowHandle,
            Rectangle bounds)
        {
            Verify.IsNotNull(process);
            Verify.IsFalse(hostWindowHandle == IntPtr.Zero);

            var rect = new Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height);

            return(process.CreateWebViewControlHostAsync(hostWindowHandle, rect));
        }
Example #4
0
        /// <summary>
        /// Creates a <see cref="IWebView" /> within the context of <paramref name="process" />.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="control">An instance of <see cref="Control"/> to parent the <see cref="WebView"/>.</param>
        /// <param name="bounds">A <see cref="Rectangle" /> containing numerical values that represent the location and size of the control.</param>
        /// <returns>An <see cref="IWebView"/> instance.</returns>
        /// <exception cref="ArgumentNullException">Occurs when <paramref name="control"/> is <see langword="null" />.</exception>
        internal static async Task <IWebView> CreateWebViewAsync(
            this WebViewControlProcess process,
            Control control,
            Rectangle bounds)
        {
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            var webViewControl = await process.CreateWebViewAsync(control.Handle, bounds).ConfigureAwait(false);

            control.Controls.Add((Control)webViewControl);
            return(webViewControl);
        }
        public static async Task <bool> CanCreateWebViewControlHost()
        {
            if (_canCreate.HasValue)
            {
                return(_canCreate.Value);
            }

            _canCreate = true;

            var process      = default(WebViewControlProcess);
            var windowHandle = default(IntPtr);
            var host         = default(WebViewControlHost);

            void SafeExec(Action action)
            {
                try
                {
                    action();
                }
                catch (Exception)
                {
                }
            }

            try
            {
                process      = new WebViewControlProcess();
                windowHandle = NativeMethods.CreateWindow("Static", 0, 0, 0, 0, 0, IntPtr.Zero);
                host         = await process.CreateWebViewControlHostAsync(windowHandle, new Rect(0, 0, 10, 10)).ConfigureAwait(false);
            }
            catch
            {
                _canCreate = false;
            }
            finally
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(() =>
                {
                    SafeExec(() => NativeMethods.DestroyWindow(windowHandle));
                    SafeExec(() => host?.Close());
                    SafeExec(() => host?.Dispose());
                });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }

            return(_canCreate.Value);
        }
Example #6
0
        /// <summary>
        /// Creates a <see cref="IWebView" /> within the context of <paramref name="process" />.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="hostWindowHandle">The parent window handle hosting the control.</param>
        /// <param name="bounds">A <see cref="Rectangle" /> containing numerical values that represent the location and size of the control.</param>
        /// <returns>An <see cref="IWebView" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="hostWindowHandle"/> is equal to <see cref="IntPtr.Zero"/>, or
        /// <paramref name="process"/> is <see langword="null" />.
        /// </exception>
        internal static IWebView CreateWebView(
            this WebViewControlProcess process,
            IntPtr hostWindowHandle,
            Rectangle bounds)
        {
            if (process is null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            if (hostWindowHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(hostWindowHandle));
            }

            return(new WebView(process.CreateWebViewControlHost(hostWindowHandle, bounds)));
        }
Example #7
0
        /// <summary>
        /// Creates a <see cref="IWebView" /> within the context of <paramref name="process" />.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="hostWindowHandle">The parent window handle hosting the control.</param>
        /// <param name="bounds">A <see cref="Rectangle" /> containing numerical values that represent the location and size of the control.</param>
        /// <returns>An <see cref="IWebView" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="hostWindowHandle"/> is equal to <see cref="IntPtr.Zero"/>, or
        /// <paramref name="process"/> is <see langword="null" />.
        /// </exception>
        internal static async Task <IWebView> CreateWebViewAsync(
            this WebViewControlProcess process,
            IntPtr hostWindowHandle,
            Rectangle bounds)
        {
            if (process is null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            if (hostWindowHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(hostWindowHandle));
            }

            return(new WebView(await process.CreateWebViewControlHostAsync(hostWindowHandle, bounds).ConfigureAwait(false)));
        }
 public WebView(WebViewControlProcess process)
     : this()
 {
     Process = process;
 }