예제 #1
0
        internal void Initialize(IServiceProvider services, RootComponentList rootComponents)
        {
            Services = services;

            MainWindow = new PhotinoWindow()
                         .SetTitle("Photino.Blazor App")
                         .SetUseOsDefaultLocation(false)
                         .SetWidth(1000)
                         .SetHeight(900)
                         .SetLeft(450)
                         .SetTop(100);

            MainWindow.RegisterCustomSchemeHandler(PhotinoWebViewManager.BlazorAppScheme, HandleWebRequest);

            // We assume the host page is always in the root of the content directory, because it's
            // unclear there's any other use case. We can add more options later if so.
            string hostPage       = "index.html";
            var    contentRootDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
            var    fileProvider   = new PhysicalFileProvider(contentRootDir);

            var dispatcher   = new PhotinoDispatcher(MainWindow);
            var jsComponents = new JSComponentConfigurationStore();

            WindowManager  = new PhotinoWebViewManager(MainWindow, services, dispatcher, new Uri(PhotinoWebViewManager.AppBaseUri), fileProvider, jsComponents, hostPage);
            RootComponents = new BlazorWindowRootComponents(WindowManager, jsComponents);
            foreach (var component in rootComponents)
            {
                RootComponents.Add(component.Item1, component.Item2);
            }
        }
예제 #2
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="hostPageRelativePath">Path to the host page within the <paramref name="fileProvider"/>.</param>
 /// <param name="contentRootDir">Path to the directory containing application content files.</param>
 /// <param name="webViewHandler">The <see cref="BlazorWebViewHandler" />.</param>
 public WinUIWebViewManager(
     WebView2Control webview,
     IServiceProvider services,
     Dispatcher dispatcher,
     IFileProvider fileProvider,
     JSComponentConfigurationStore jsComponents,
     string hostPageRelativePath,
     string contentRootDir,
     BlazorWebViewHandler webViewHandler)
     : base(webview, services, dispatcher, fileProvider, jsComponents, hostPageRelativePath, webViewHandler)
 {
     _webview = webview;
     _hostPageRelativePath = hostPageRelativePath;
     _contentRootDir       = contentRootDir;
 }
예제 #3
0
    public PageContext(
        Dispatcher dispatcher,
        AsyncServiceScope serviceScope,
        IpcSender ipcSender,
        JSComponentConfigurationStore jsComponentsConfiguration,
        string baseUrl,
        string startUrl)
    {
        _serviceScope = serviceScope;
        var services = serviceScope.ServiceProvider;

        NavigationManager = (WebViewNavigationManager)services.GetRequiredService <NavigationManager>();
        NavigationManager.AttachToWebView(ipcSender, baseUrl, startUrl);

        JSRuntime = (WebViewJSRuntime)services.GetRequiredService <IJSRuntime>();
        JSRuntime.AttachToWebView(ipcSender);

        var loggerFactory = services.GetRequiredService <ILoggerFactory>();
        var jsComponents  = new JSComponentInterop(jsComponentsConfiguration);

        Renderer = new WebViewRenderer(services, dispatcher, ipcSender, loggerFactory, JSRuntime, jsComponents);
    }
예제 #4
0
        /// <summary>
        /// Constructs an instance of <see cref="BlazorWindow"/>.
        /// </summary>
        /// <param name="title">The window title.</param>
        /// <param name="hostPage">The path to the host page.</param>
        /// <param name="services">The service provider.</param>
        /// <param name="configureWindow">A callback that configures the window.</param>
        public BlazorWindow(
            string title,
            string hostPage,
            IServiceProvider services,
            Action <PhotinoWindowOptions>?configureWindow = null)
        {
            _window = new PhotinoWindow(title, options =>
            {
                options.CustomSchemeHandlers.Add(PhotinoWebViewManager.BlazorAppScheme, HandleWebRequest);
                configureWindow?.Invoke(options);
            }, width: 1600, height: 1200, left: 300, top: 300);

            // We assume the host page is always in the root of the content directory, because it's
            // unclear there's any other use case. We can add more options later if so.
            var contentRootDir       = Path.GetDirectoryName(Path.GetFullPath(hostPage)) !;
            var hostPageRelativePath = Path.GetRelativePath(contentRootDir, hostPage);
            var fileProvider         = new PhysicalFileProvider(contentRootDir);

            var dispatcher   = new PhotinoDispatcher(_window);
            var jsComponents = new JSComponentConfigurationStore();

            _manager       = new PhotinoWebViewManager(_window, services, dispatcher, new Uri(PhotinoWebViewManager.AppBaseUri), fileProvider, jsComponents, hostPageRelativePath);
            RootComponents = new BlazorWindowRootComponents(_manager, jsComponents);
        }
예제 #5
0
 internal BlazorWindowRootComponents(PhotinoWebViewManager manager, JSComponentConfigurationStore jsComponents)
 {
     _manager     = manager;
     JSComponents = jsComponents;
 }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of <see cref="IOSWebViewManager"/>
        /// </summary>
        /// <param name="blazorMauiWebViewHandler">The <see cref="BlazorWebViewHandler"/>.</param>
        /// <param name="webview">The <see cref="WKWebView"/> to render web content in.</param>
        /// <param name="provider">The <see cref="IServiceProvider"/> for the application.</param>
        /// <param name="dispatcher">A <see cref="Dispatcher"/> instance 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">Describes configuration for adding, removing, and updating root components from JavaScript code.</param>
        /// <param name="contentRootRelativeToAppRoot">Path to the directory containing application content files.</param>
        /// <param name="hostPageRelativePath">Path to the host page within the fileProvider.</param>

        public IOSWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler, WKWebView webview, IServiceProvider provider, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string contentRootRelativeToAppRoot, string hostPageRelativePath)
            : base(provider, dispatcher, BlazorWebViewHandler.AppOriginUri, fileProvider, jsComponents, hostPageRelativePath)
        {
            ArgumentNullException.ThrowIfNull(nameof(blazorMauiWebViewHandler));
            ArgumentNullException.ThrowIfNull(nameof(webview));

            if (provider.GetService <MauiBlazorMarkerService>() is null)
            {
                throw new InvalidOperationException(
                          "Unable to find the required services. " +
                          $"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView)}' in the application startup code.");
            }

            _blazorMauiWebViewHandler = blazorMauiWebViewHandler;
            _webview = webview;
            _contentRootRelativeToAppRoot = contentRootRelativeToAppRoot;

            InitializeWebView();
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of <see cref="TizenWebViewManager"/>
 /// </summary>
 /// <param name="blazorMauiWebViewHandler">The <see cref="BlazorWebViewHandler"/>.</param>
 /// <param name="webview">A wrapper to access platform-specific WebView APIs.</param>
 /// <param name="provider">The <see cref="IServiceProvider"/> for the application.</param>
 /// <param name="dispatcher">A <see cref="Dispatcher"/> instance 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">Describes configuration for adding, removing, and updating root components from JavaScript code.</param>
 /// <param name="contentRootRelativeToAppRoot">Path to the directory containing application content files.</param>
 /// <param name="hostPageRelativePath">Path to the host page within the fileProvider.</param>
 public TizenWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler, TWebView webview, IServiceProvider provider, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string contentRootRelativeToAppRoot, string hostPageRelativePath)
     : base(provider, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath)
 {
     _blazorMauiWebViewHandler = blazorMauiWebViewHandler ?? throw new ArgumentNullException(nameof(blazorMauiWebViewHandler));
     _webview = webview ?? throw new ArgumentNullException(nameof(webview));
     _contentRootRelativeToAppRoot = contentRootRelativeToAppRoot;
 }
예제 #8
0
        /// <summary>
        /// Constructs an instance of <see cref="WebView2WebViewManager"/>.
        /// </summary>
        /// <param name="webview">A wrapper 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="hostPageRelativePath">Path to the host page within the <paramref name="fileProvider"/>.</param>
        public WebView2WebViewManager(IWebView2Wrapper webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath)
            : base(services, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath)
        {
            _webview = webview ?? throw new ArgumentNullException(nameof(webview));

            // Unfortunately the CoreWebView2 can only be instantiated asynchronously.
            // We want the external API to behave as if initalization is synchronous,
            // so keep track of a task we can await during LoadUri.
            _webviewReadyTask = InitializeWebView2();
        }
예제 #9
0
 public WinUIWebViewManager(WebView2Control nativeWebView2, IWebView2Wrapper webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath, string contentRootDir)
     : base(webview, services, dispatcher, fileProvider, jsComponents, hostPageRelativePath)
 {
     _nativeWebView2       = nativeWebView2;
     _hostPageRelativePath = hostPageRelativePath;
     _contentRootDir       = contentRootDir;
 }
예제 #10
0
 public RootComponentsCollection(JSComponentConfigurationStore jSComponents)
 {
     _jSComponents = jSComponents;
 }
예제 #11
0
    public PhotinoWebViewManager(PhotinoWindow window, IServiceProvider provider, Dispatcher dispatcher, Uri appBaseUri, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath)
        : base(provider, dispatcher, appBaseUri, fileProvider, jsComponents, hostPageRelativePath)
    {
        _window = window ?? throw new ArgumentNullException(nameof(window));
        _window.WebMessageReceived += (sender, message) =>
        {
            // On some platforms, we need to move off the browser UI thread
            Task.Factory.StartNew(message =>
            {
                // TODO: Fix this. Photino should ideally tell us the URL that the message comes from so we
                // know whether to trust it. Currently it's hardcoded to trust messages from any source, including
                // if the webview is somehow navigated to an external URL.
                var messageOriginUrl = new Uri(AppBaseUri);

                MessageReceived(messageOriginUrl, (string)message !);
            }, message, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
        };
    }
예제 #12
0
        public IOSWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler, WKWebView webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath)
            : base(services, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath)
        {
            _blazorMauiWebViewHandler = blazorMauiWebViewHandler ?? throw new ArgumentNullException(nameof(blazorMauiWebViewHandler));
            _webview = webview ?? throw new ArgumentNullException(nameof(webview));

            InitializeWebView();
        }
예제 #13
0
        public ValueTask InitializeJSComponentSupportAsync(JSComponentConfigurationStore configuration, JsonSerializerOptions jsonOptions)
        {
            var interop = new JSComponentInterop(configuration, jsonOptions);

            return(InitializeJSComponentSupportAsync(interop));
        }