Example #1
0
        private void Initialize(string initialAddress)
        {
            InitializeCef();

            if (!subscribedApplicationExit)
            {
                // subscribe exit again, first time might have failed if Application.Current was null
                Application.Current.Exit += OnApplicationExit;
                subscribedApplicationExit = true;
            }

            lifeSpanHandler = new CefLifeSpanHandler(this);

            chromium = new InternalChromiumBrowser(initialAddress);
            chromium.IsBrowserInitializedChanged += OnWebViewIsBrowserInitializedChanged;
            chromium.FrameLoadEnd               += OnWebViewFrameLoadEnd;
            chromium.LoadError                  += OnWebViewLoadError;
            chromium.TitleChanged               += OnWebViewTitleChanged;
            chromium.PreviewKeyDown             += OnPreviewKeyDown;
            chromium.RequestHandler              = new CefRequestHandler(this);
            chromium.LifeSpanHandler             = lifeSpanHandler;
            chromium.RenderProcessMessageHandler = new CefRenderProcessMessageHandler(this);
            chromium.MenuHandler                 = new CefMenuHandler(this);
            chromium.DialogHandler               = new CefDialogHandler(this);
            chromium.DownloadHandler             = new CefDownloadHandler(this);
            chromium.CleanupElement              = new FrameworkElement(); // prevent chromium to listen to default cleanup element unload events, this will be controlled manually
            chromium.DragHandler                 = new CefDragHandler(this);

            disposables = new[] {
                (IDisposable)AsyncCancellationTokenSource,
                chromium
            };

            RegisterJavascriptObject(Listener.EventListenerObjName, EventsListener);

            Content = chromium;

            GlobalWebViewInitialized?.Invoke(this);

            JavascriptContextCreated  += OnJavascriptContextCreated;
            JavascriptContextReleased += OnJavascriptContextReleased;
            RenderProcessCrashed      += OnRenderProcessCrashed;

            FocusManager.SetIsFocusScope(this, true);
            FocusManager.SetFocusedElement(this, FocusableElement);
        }
Example #2
0
        private void Initialize()
        {
            InitializeCef();

            if (!subscribedApplicationExit)
            {
                // subscribe exit again, first time might have failed if Application.Current was null
                Application.Current.Exit += OnApplicationExit;
                subscribedApplicationExit = true;
            }

            settings        = new BrowserSettings();
            lifeSpanHandler = new CefLifeSpanHandler(this);

            chromium = new InternalChromiumBrowser();
            chromium.BrowserSettings              = settings;
            chromium.IsBrowserInitializedChanged += OnWebViewIsBrowserInitializedChanged;
            chromium.FrameLoadEnd               += OnWebViewFrameLoadEnd;
            chromium.LoadError                  += OnWebViewLoadError;
            chromium.TitleChanged               += OnWebViewTitleChanged;
            chromium.PreviewKeyDown             += OnPreviewKeyDown;
            chromium.RequestHandler              = new CefRequestHandler(this);
            chromium.ResourceHandlerFactory      = new CefResourceHandlerFactory(this);
            chromium.LifeSpanHandler             = lifeSpanHandler;
            chromium.RenderProcessMessageHandler = new CefRenderProcessMessageHandler(this);
            chromium.MenuHandler                 = new CefMenuHandler(this);
            chromium.DialogHandler               = new CefDialogHandler(this);
            chromium.DownloadHandler             = new CefDownloadHandler(this);
            chromium.CleanupElement              = new FrameworkElement(); // prevent chromium to listen to default cleanup element unload events, this will be controlled manually

            jsExecutor = new JavascriptExecutor(this);

            RegisterJavascriptObject(Listener.EventListenerObjName, eventsListener);

            Content = chromium;

            GlobalWebViewInitialized?.Invoke(this);

            DisposableWebViews.Add(this);

            FocusManager.SetIsFocusScope(this, true);
            FocusManager.SetFocusedElement(this, FocusableElement);
        }