Ejemplo n.º 1
0
        /// <summary>
        /// Create a new OffScreen Chromium Browser. If you use <see cref="CefSharp.JavascriptBinding.JavascriptBindingSettings.LegacyBindingEnabled"/> = true then you must
        /// set <paramref name="automaticallyCreateBrowser"/> to false and call <see cref="CreateBrowser"/> after the objects are registered.
        /// The underlying Chromium Embedded Framework(CEF) Browser is created asynchronouly, to subscribe to the <see cref="BrowserInitialized"/> event it is recommended
        /// that you set <paramref name="automaticallyCreateBrowser"/> to false, subscribe to the event and then call <see cref="CreateBrowser(IWindowInfo, IBrowserSettings)"/>
        /// to ensure you are subscribe to the event before it's fired (Issue https://github.com/cefsharp/CefSharp/issues/3552).
        /// </summary>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        /// <param name="requestContext">See <see cref="RequestContext" /> for more details. Defaults to null</param>
        /// <param name="automaticallyCreateBrowser">automatically create the underlying Browser</param>
        /// <param name="onAfterBrowserCreated">
        /// Use as an alternative to the <see cref="BrowserInitialized"/> event. If the underlying Chromium Embedded Framework (CEF) browser is created successfully,
        /// this action is guranteed to be called after the browser created where as the <see cref="BrowserInitialized"/> event may be called before
        /// you have a chance to subscribe to the event as the CEF Browser is created async. (Issue https://github.com/cefsharp/CefSharp/issues/3552).
        /// </param>
        /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception>
        public ChromiumWebBrowser(string address = "", IBrowserSettings browserSettings = null,
                                  IRequestContext requestContext          = null, bool automaticallyCreateBrowser = true,
                                  Action <IBrowser> onAfterBrowserCreated = null)
        {
            if (!Cef.IsInitialized)
            {
                var settings = new CefSettings();

                if (!Cef.Initialize(settings))
                {
                    throw new InvalidOperationException(CefInitializeFailedErrorMessage);
                }
            }

            RequestContext = requestContext;

            Cef.AddDisposable(this);
            Address = address;
            onAfterBrowserCreatedDelegate = onAfterBrowserCreated;

            managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, true);

            if (automaticallyCreateBrowser)
            {
                CreateBrowser(null, browserSettings);
            }

            RenderHandler = new DefaultRenderHandler(this);
        }
Ejemplo n.º 2
0
        private void InitializeFieldsAndCefIfRequired()
        {
            if (!initialized)
            {
                if (!Cef.IsInitialized && !Cef.Initialize(new CefSettings()))
                {
                    throw new InvalidOperationException("Cef::Initialize() failed");
                }

                Cef.AddDisposable(this);

                if (FocusHandler == null)
                {
                    //If the WinForms UI thread and the CEF UI thread are one in the same
                    //then we don't need the FocusHandler, it's only required when using
                    //MultiThreadedMessageLoop (the default)
                    if (!Cef.CurrentlyOnThread(CefThreadIds.TID_UI))
                    {
                        FocusHandler = new DefaultFocusHandler();
                    }
                }

                if (browserSettings == null)
                {
                    browserSettings = Core.ObjectFactory.CreateBrowserSettings(autoDispose: true);
                }

                managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, false);

                initialized = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new OffScreen Chromium Browser. If you use <see cref="CefSharp.JavascriptBinding.JavascriptBindingSettings.LegacyBindingEnabled"/> = true then you must
        /// set <paramref name="automaticallyCreateBrowser"/> to false and call <see cref="CreateBrowser"/> after the objects are registered.
        /// </summary>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        /// <param name="requestContext">See <see cref="RequestContext" /> for more details. Defaults to null</param>
        /// <param name="automaticallyCreateBrowser">automatically create the underlying Browser</param>
        /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception>
        public ChromiumWebBrowser(string address = "", IBrowserSettings browserSettings = null,
                                  IRequestContext requestContext = null, bool automaticallyCreateBrowser = true)
        {
            if (!Cef.IsInitialized)
            {
                var settings = new CefSettings();

                if (!Cef.Initialize(settings))
                {
                    throw new InvalidOperationException("Cef::Initialize() failed");
                }
            }

            RequestContext = requestContext;

            Cef.AddDisposable(this);
            Address = address;

            managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, true);

            if (automaticallyCreateBrowser)
            {
                CreateBrowser(null, browserSettings);
            }

            RenderHandler = new DefaultRenderHandler(this);
        }
Ejemplo n.º 4
0
 public BaseBrowser(
     IBrowserAdapter browserAdapter
     )
 {
     BrowserAdapter = browserAdapter;
     pageFactory    = new PageFactory();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Required for designer support - this method cannot be inlined as the designer
        /// will attempt to load libcef.dll and will subsiquently throw an exception.
        /// TODO: Still not happy with this method name, need something better
        /// </summary>
        private void InitializeFieldsAndCefIfRequired()
        {
            if (!_initialized)
            {
                if (!Cef.IsInitialized && !Cef.Initialize(_settings))
                {
                    throw new InvalidOperationException("Cef::Initialize() failed");
                }

                Cef.AddDisposable(this);


                if (ResourceRequestHandlerFactory == null)
                {
                    ResourceRequestHandlerFactory = new ResourceRequestHandlerFactory();
                }

                if (_browserSettings == null)
                {
                    _browserSettings = CefSharpBrowserSettings.Create(true);
                }

                _managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, false);

                _initialized = true;
            }
        }
Ejemplo n.º 6
0
 public WebForm(IWebElement webElement, IBrowserAdapter browserAdapter, List <IFormInputAdapter> supportedInputs, int numberOfSetRetries, AfterFieldValueSet afterFieldValueSet = AfterFieldValueSet.Nothing)
     : base(browserAdapter, webElement)
 {
     this.numberOfSetRetries = numberOfSetRetries;
     this.afterFieldValueSet = afterFieldValueSet;
     SupportedInputs         = supportedInputs;
 }
Ejemplo n.º 7
0
        private void InternalDispose(bool disposing)
        {
            if (disposing)
            {
                Interlocked.Exchange(ref browserInitialized, 0);
                CanExecuteJavascriptInMainFrame = false;

                // Don't maintain a reference to event listeners anylonger:
                AddressChanged = null;
                ConsoleMessage = null;
                FrameLoadEnd   = null;
                FrameLoadStart = null;
                IsBrowserInitializedChanged = null;
                LoadError                 = null;
                LoadingStateChanged       = null;
                StatusMessage             = null;
                TitleChanged              = null;
                JavascriptMessageReceived = null;

                // Release reference to handlers, except LifeSpanHandler which is done after Disposing
                // ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
                // We also leave FocusHandler and override with a NoFocusHandler implementation as
                // it so we can block taking Focus (we're dispoing afterall). Issue #3715
                FreeHandlersExceptLifeSpanAndFocus();

                FocusHandler = new NoFocusHandler();

                browser = null;

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

                //Dispose of BrowserSettings if we created it, if user created then they're responsible
                if (browserSettings != null && browserSettings.AutoDispose)
                {
                    browserSettings.Dispose();
                }

                browserSettings = null;

                parkingControl?.Dispose();
                parkingControl = null;

                // LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
                // is called.
                LifeSpanHandler = null;
            }

            Cef.RemoveDisposable(this);
        }
Ejemplo n.º 8
0
        public WebTree(IBrowserAdapter browserAdapter, IWebElement webElement, WebTreeOptions customOptions = null)
            : base(browserAdapter, webElement)
        {
            var options = customOptions ?? new WebTreeOptions();

            this.expanderLocator       = options.GetEffectiveExpanderLocator();
            this.collapserLocator      = options.GetEffectiveCollapseLocator();
            this.isSelfItemsContainer  = options.IsSelfItemsContainer;
            this.itemsContainerLocator = options.ItemsContainerLocator ?? By.TagName(webElement.TagName);;
        }
Ejemplo n.º 9
0
 /// <summary>
 ///     Creates an AboutViewModel Object
 /// </summary>
 public AboutViewModel(IAppInformation appInformation,
                       IEmailAdapter emailAdapter,
                       IBrowserAdapter browserAdapter,
                       IStoreOperations storeOperations)
 {
     this.appInformation = appInformation;
     this.emailAdapter   = emailAdapter;
     this.browserAdapter = browserAdapter;
     storeFeatures       = storeOperations;
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Creates an AboutViewModel Object
 /// </summary>
 public AboutViewModel(IAppInformation appInformation,
                       IEmailAdapter emailAdapter,
                       IBrowserAdapter browserAdapter,
                       IStoreOperations storeOperations,
                       IMvxLogProvider logProvider,
                       IMvxNavigationService navigationService) : base(logProvider, navigationService)
 {
     this.appInformation = appInformation;
     this.emailAdapter   = emailAdapter;
     this.browserAdapter = browserAdapter;
     storeFeatures       = storeOperations;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources for the <see cref="ChromiumWebBrowser"/>
        /// </summary>
        /// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            // Attempt to move the disposeSignaled state from 0 to 1. If successful, we can be assured that
            // this thread is the first thread to do so, and can safely dispose of the object.
            if (Interlocked.CompareExchange(ref disposeSignaled, 1, 0) != 0)
            {
                return;
            }

            if (disposing)
            {
                CanExecuteJavascriptInMainFrame = false;
                Interlocked.Exchange(ref browserInitialized, 0);

                // Don't reference event listeners any longer:
                AddressChanged      = null;
                BrowserInitialized  = null;
                ConsoleMessage      = null;
                FrameLoadEnd        = null;
                FrameLoadStart      = null;
                LoadError           = null;
                LoadingStateChanged = null;
                Paint                     = null;
                AfterPaint                = null;
                StatusMessage             = null;
                TitleChanged              = null;
                JavascriptMessageReceived = null;

                // Release reference to handlers, except LifeSpanHandler which is done after Disposing
                // ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
                // We also leave FocusHandler and override with a NoFocusHandler implementation as
                // it so we can block taking Focus (we're dispoing afterall). Issue #3715
                FreeHandlersExceptLifeSpanAndFocus();

                FocusHandler = new NoFocusHandler();

                browser     = null;
                BrowserCore = null;

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

                // LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
                // is called.
                LifeSpanHandler = null;
            }

            Cef.RemoveDisposable(this);
        }
Ejemplo n.º 12
0
        public async Task GoToRepository_NoParams_CommandCalled()
        {
            IBrowserAdapter webbrowserTaskSetup = Substitute.For <IBrowserAdapter>();

            webbrowserTaskSetup.OpenWebsiteAsync(Arg.Is <Uri>(s => s == new Uri(AppConstants.GitHubRepositoryUrl)))
            .Returns(Task.CompletedTask);

            new AboutViewModel(Substitute.For <IAppInformation>(),
                               Substitute.For <IEmailAdapter>(),
                               webbrowserTaskSetup,
                               Substitute.For <IStoreOperations>())
            .GoToRepositoryCommand
            .Execute(null);

            await webbrowserTaskSetup.Received(1).OpenWebsiteAsync(Arg.Is <Uri>(s => s == new Uri(AppConstants.GitHubRepositoryUrl)));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create a new OffScreen Chromium Browser. If you use <see cref="CefSharp.JavascriptBinding.JavascriptBindingSettings.LegacyBindingEnabled"/> = true then you must
        /// set <paramref name="automaticallyCreateBrowser"/> to false and call <see cref="CreateBrowser"/> after the objects are registered.
        /// </summary>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        /// <param name="requestContext">See <see cref="RequestContext" /> for more details. Defaults to null</param>
        /// <param name="automaticallyCreateBrowser">automatically create the underlying Browser</param>
        /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception>
        public ChromiumWebBrowser(string address, IBrowserSettings browserSettings, IRequestContext requestContext, bool automaticallyCreateBrowser, IRenderTarget renderer)
        {
            if (!Cef.IsInitialized)
            {
                throw new InvalidOperationException("Cef IS NOT INITIALIZED");
            }

            RequestContext = requestContext;
            _renderTarget  = renderer;
            Cef.AddDisposable(this);
            Address = address;

            managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, true);

            if (automaticallyCreateBrowser)
            {
                CreateBrowser(null, browserSettings);
            }
        }
        public BrowserProcessServiceHost(JavascriptObjectRepository javascriptObjectRepository, int parentProcessId, IBrowserAdapter browserAdapter)
            : base(typeof(BrowserProcessService), new Uri[0])
        {
            JavascriptObjectRepository = javascriptObjectRepository;

            var browser = browserAdapter.GetBrowser();
            var serviceName = RenderprocessClientFactory.GetServiceName(parentProcessId, browser.Identifier);

            Description.ApplyServiceBehavior(() => new ServiceDebugBehavior(), p => p.IncludeExceptionDetailInFaults = true);

            var binding = CreateBinding();

            var endPoint = AddServiceEndpoint(
                typeof (IBrowserProcess),
                binding,
                new Uri(serviceName)
            );

            endPoint.Contract.ProtectionLevel = ProtectionLevel.None;
            endPoint.Behaviors.Add(new JavascriptCallbackEndpointBehavior(browserAdapter.JavascriptCallbackFactory));
        }
Ejemplo n.º 15
0
 public WebTable(IBrowserAdapter browserAdapter, IWebElement webElement) : base(browserAdapter, webElement)
 {
     this.columnsMap = GetColumnsMap();
 }
Ejemplo n.º 16
0
 public WebList(IBrowserAdapter browserAdapter, IWebElement webElement) : base(browserAdapter, webElement)
 {
 }
Ejemplo n.º 17
0
 public MvcWebForm(IWebElement webElement, IBrowserAdapter driver, List <IFormInputAdapter> supportedInputs, int numberOfSetRetries, AfterFieldValueSet afterFieldValueSet = AfterFieldValueSet.Nothing)
     : base(webElement, driver, supportedInputs, numberOfSetRetries, afterFieldValueSet)
 {
 }
Ejemplo n.º 18
0
 public CookieBrowser(IBrowserAdapter browserAdapter) : base(browserAdapter)
 {
 }
Ejemplo n.º 19
0
 protected WebElementCollection(IBrowserAdapter browserAdapter, IWebElement webElement)
     : base(browserAdapter, webElement)
 {
 }
        public BrowserProcessServiceHost(JavascriptObjectRepository javascriptObjectRepository, int parentProcessId, IBrowserAdapter browserAdapter)
            : base(typeof(BrowserProcessService), new Uri[0])
        {
            JavascriptObjectRepository = javascriptObjectRepository;

            var browser     = browserAdapter.GetBrowser();
            var serviceName = RenderprocessClientFactory.GetServiceName(parentProcessId, browser.Identifier);

            Description.ApplyServiceBehavior(() => new ServiceDebugBehavior(), p => p.IncludeExceptionDetailInFaults = true);

            var binding = CreateBinding();

            var endPoint = AddServiceEndpoint(
                typeof(IBrowserProcess),
                binding,
                new Uri(serviceName)
                );

            endPoint.Contract.ProtectionLevel = ProtectionLevel.None;
            endPoint.Behaviors.Add(new JavascriptCallbackEndpointBehavior(browserAdapter.JavascriptCallbackFactory));
        }
Ejemplo n.º 21
0
 public WebTableRow(IBrowserAdapter browserAdapter, IWebElement webElement, Dictionary <string, int> columnsMap) : base(browserAdapter, webElement)
 {
     this.webElement = webElement;
     this.columnsMap = columnsMap;
 }