public WinUIWebViewManager(WebView2Control webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath, string contentRootDir)
     : base(webview, services, dispatcher, fileProvider, jsComponents, hostPageRelativePath)
 {
     _webview = webview;
     _hostPageRelativePath = hostPageRelativePath;
     _contentRootDir       = contentRootDir;
 }
Exemple #2
0
 public void OnReleaseReference_LiveElement_ButtonClicked(object sender, RoutedEventArgs args)
 {
     if (_wv2_Programmatic_Live != null)
     {
         _wv2_Programmatic_Live = null;
     }
 }
Exemple #3
0
        private void OnNavigationCompleted(WebView2 sender, CoreWebView2NavigationCompletedEventArgs args)
        {
            SetNavigationCompletedCount(_navigationCompletedCount + 1);

            string s = string.Format("[{0}]: Got NavigationcOompleted, ", sender.Name);

            _helpers.AppendMessage(s);
            Status2.Text = Status2.Text + " " + s;
        }
Exemple #4
0
        private void OnCoreWebView2Initialized(WebView2 sender, object args)
        {
            SetCoreWebView2InitializedCount(_coreWebView2InitializedCount + 1);

            string s = string.Format("[{0}]: Got CoreWebView2Initialized, ", sender.Name);

            _helpers.AppendMessage(s);
            Status2.Text = Status2.Text + " " + s;
        }
Exemple #5
0
        public WinUIWebView2Wrapper(WebView2Control webView2)
        {
            if (webView2 is null)
            {
                throw new ArgumentNullException(nameof(webView2));
            }

            WebView2             = webView2;
            _coreWebView2Wrapper = new WinUICoreWebView2Wrapper(this);
        }
        public static void NavigateToUri(WebView2 webview, string UriString)
        {
            Uri newUri;

            if (!string.IsNullOrEmpty(UriString) &&
                Uri.TryCreate(UriString, UriKind.RelativeOrAbsolute, out newUri) == true)
            {
                webview.Source = newUri;
            }
        }
Exemple #7
0
        private void OnNavigationStarting(WebView2 sender, CoreWebView2NavigationStartingEventArgs args)
        {
            SetNavigationStartingCount(_navigationStartingCount + 1);

            string s = string.Format("[{0}]: Got NavigationStarting ({1}), ", sender.Name, args.Uri);

            _helpers.AppendMessage(s);
            Status1.Text = s;
            Status3.Text = args.Uri;
        }
Exemple #8
0
        void RemoveWebViewEventHandlers(WebView2 webview)
        {
            ResetCounts();

            webview.NavigationStarting      -= OnNavigationStarting;
            webview.NavigationCompleted     -= OnNavigationCompleted;
            webview.CoreWebView2Initialized -= OnCoreWebView2Initialized;
            webview.Loaded            -= OnLoaded;
            webview.Unloaded          -= OnUnloaded;
            webview.CoreProcessFailed -= OnCoreProcessFailed;
        }
Exemple #9
0
        private async void OnCoreWebView2Initialized_Ensure(WebView2 sender, object args)
        {
            sender.CoreWebView2Initialized -= OnCoreWebView2Initialized_Ensure; // Don't spin creation on next CWV2Initialized!
            await sender.EnsureCoreWebView2Async();

            {
                SetEnsureCoreWebView2CompletionCount(_ensureCoreWebView2CompletionCount + 1);

                string s = string.Format("[{0}]: Got EnsureCWV2 Completion, ", sender.Name);
                _helpers.AppendMessage(s);
                Status2.Text = Status2.Text + " " + s;
            }
        }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of <see cref="WinUIWebViewManager"/>
 /// </summary>
 /// <param name="webview">A <see cref="WebView2Control"/> to access platform-specific WebView2 APIs.</param>
 /// <param name="services">A service provider containing services to be used by this class and also by application code.</param>
 /// <param name="dispatcher">A <see cref="Dispatcher"/> instance that can marshal calls to the required thread or sync context.</param>
 /// <param name="fileProvider">Provides static content to the webview.</param>
 /// <param name="jsComponents">The <see cref="JSComponentConfigurationStore"/>.</param>
 /// <param name="contentRootRelativeToAppRoot">Path to the directory containing application content files.</param>
 /// <param name="hostPagePathWithinFileProvider">Path to the host page within the <paramref name="fileProvider"/>.</param>
 /// <param name="webViewHandler">The <see cref="BlazorWebViewHandler" />.</param>
 public WinUIWebViewManager(
     WebView2Control webview,
     IServiceProvider services,
     Dispatcher dispatcher,
     IFileProvider fileProvider,
     JSComponentConfigurationStore jsComponents,
     string contentRootRelativeToAppRoot,
     string hostPagePathWithinFileProvider,
     BlazorWebViewHandler webViewHandler)
     : base(webview, services, dispatcher, fileProvider, jsComponents, contentRootRelativeToAppRoot, hostPagePathWithinFileProvider, webViewHandler)
 {
     _webview = webview;
     _hostPageRelativePath         = hostPagePathWithinFileProvider;
     _contentRootRelativeToAppRoot = contentRootRelativeToAppRoot;
 }
Exemple #11
0
        public void OnCreate_OfflineElement_ButtonClicked(object sender, RoutedEventArgs args)
        {
            if (_wv2_Programmatic_Offline != null)
            {
                RemoveWebViewEventHandlers(_wv2_Programmatic_Offline);
                _wv2_Programmatic_Offline.Close();
            }

            var myWebView = new WebView2 {
                Name = "WV2_Programmatic_Offline"
            };

            AddWebViewEventHandlers(myWebView);
            _wv2_Programmatic_Offline = myWebView;
        }
Exemple #12
0
        public void OnCreate_CoreProcessFailed_ButtonClicked(object sender, RoutedEventArgs args)
        {
            if (_wv2_CoreProcessFailed != null)
            {
                RemoveWebViewEventHandlers(_wv2_CoreProcessFailed);
                _wv2_CoreProcessFailed.Close();
            }

            var myWebView = new WebView2 {
                Name = "WV2_CoreProcessFailed"
            };

            AddWebViewEventHandlers(myWebView);
            _wv2_CoreProcessFailed    = myWebView;
            WebView2_Container5.Child = _wv2_CoreProcessFailed;
        }
Exemple #13
0
        public void OnCreate_ConcurrentCreationElement_ButtonClicked(object sender, RoutedEventArgs args)
        {
            if (_wv2_ConcurrentCreation != null)
            {
                RemoveWebViewEventHandlers(_wv2_ConcurrentCreation);
                _wv2_ConcurrentCreation.Close();
            }

            var myWebView = new WebView2 {
                Name = "WV2_ConcurrentCreation"
            };

            AddWebViewEventHandlers(myWebView);
            _wv2_ConcurrentCreation   = myWebView;
            WebView2_Container4.Child = _wv2_ConcurrentCreation;
        }
Exemple #14
0
        public void OnCreate_LiveElement_ButtonClicked(object sender, RoutedEventArgs args)
        {
            if (_wv2_Programmatic_Live != null)
            {
                RemoveWebViewEventHandlers(_wv2_Programmatic_Live);
                _wv2_Programmatic_Live.Close();
            }

            var myWebView = new WebView2 {
                Name = "WV2_Programmatic_Live"
            };

            AddWebViewEventHandlers(myWebView);
            _wv2_Programmatic_Live    = myWebView;
            WebView2_Container2.Child = _wv2_Programmatic_Live;
        }
Exemple #15
0
        public void OnCreate_MarkupElement_Blank_ButtonClicked(object sender, RoutedEventArgs args)
        {
            if (_wv2_Markup != null)
            {
                RemoveWebViewEventHandlers(_wv2_Markup);
                _wv2_Markup.Close();
            }

            var myWebView = (WebView2)XamlReader.Load(@"
                <controls:WebView2 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                          xmlns:controls='using:Microsoft.UI.Xaml.Controls'
                          xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                          x:Name='WV2_Markup'/>");

            AddWebViewEventHandlers(myWebView);
            _wv2_Markup = myWebView;
            WebView2_Container3.Child = _wv2_Markup;
        }
Exemple #16
0
        public void OnCreate_MarkupElement_Source_ButtonClicked(object sender, RoutedEventArgs args)
        {
            if (_wv2_Markup != null)
            {
                _wv2_Markup.Close();
                RemoveWebViewEventHandlers(_wv2_Markup);
            }

            string uriString = WebView2Common.GetTestPageUri("SimplePage.html").ToString();

            var myWebView = (WebView2)XamlReader.Load(@"
                <controls:WebView2 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                          xmlns:controls='using:Microsoft.UI.Xaml.Controls'
                          xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                          x:Name='_wv2_Markup'
                          Source='" + uriString + @"'/>");

            AddWebViewEventHandlers(myWebView);
            _wv2_Markup = myWebView;
            WebView2_Container3.Child = _wv2_Markup;
        }
Exemple #17
0
 public WinUIWebView2Wrapper(WebView2Control webView2)
 {
     _webView2 = webView2 ?? throw new ArgumentNullException(nameof(webView2));
 }
        public static void NavigateToUri(WebView2 webview, Uri uri)
        {
            string uriString = uri.ToString();

            NavigateToUri(webview, uriString);
        }
 public static void NavigateToStringMessage(WebView2 webview)
 {
     webview.NavigateToString("You've navigated to a string message.");
 }
        public static void LoadWebPage(WebView2 webview, string testPageName)
        {
            Uri testPageUri = GetTestPageUri(testPageName);

            NavigateToUri(webview, testPageUri);
        }
 public WinUIWebViewManager(WebView2Control nativeWebView2, IWebView2Wrapper webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, string hostPageRelativePath) : base(webview, services, dispatcher, fileProvider, hostPageRelativePath)
 {
     _nativeWebView2 = nativeWebView2;
 }
Exemple #22
0
 // Set Source from OnCoreWebView2Initialized handler (for ConcurrentCreationRequestsTest)
 private void OnCoreWebView2Initialized_Source(WebView2 sender, object args)
 {
     sender.CoreWebView2Initialized -= OnCoreWebView2Initialized_Source; // Don't spin creation on next CWV2Initialized!
     WebView2Common.NavigateToUri(sender, WebView2Common.GetTestPageUri("SimplePageWithButton.html"));
 }