public BrowserControl(
     IContextMenuHandler contextMenuHandler,
     IDisplayHandler displayHandler,
     IDownloadHandler downloadHandler,
     IKeyboardHandler keyboardHandler,
     ILifeSpanHandler lifeSpanHandler,
     IRequestHandler requestHandler,
     string url) : base(url)
 {
     this.contextMenuHandler = contextMenuHandler;
     this.displayHandler     = displayHandler;
     this.downloadHandler    = downloadHandler;
     this.keyboardHandler    = keyboardHandler;
     this.lifeSpanHandler    = lifeSpanHandler;
     this.requestHandler     = requestHandler;
 }
Esempio n. 2
0
        public BrowserForm(bool multiThreadedMessageLoopEnabled, IContextMenuHandler callback)
        {
            InitializeComponent();

            var bitness = Environment.Is64BitProcess ? "x64" : "x86";

            WindowState = FormWindowState.Maximized;
            Load       += BrowserFormLoad;

            //Only perform layout when control has completly finished resizing
            ResizeBegin += (s, e) => SuspendLayout();
            ResizeEnd   += (s, e) => ResumeLayout(true);

            this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;
            this.callback = callback;
        }
Esempio n. 3
0
 public void SetMenu(IContextMenuHandler menu)
 {
     _chromiumWebBrowser.MenuHandler = menu;
 }
Esempio n. 4
0
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled, IContextMenuHandler callback)
        {
            InitializeComponent();

            var browser = new ChromiumWebBrowser(url)
            {
                Dock = DockStyle.Fill
            };

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler     = callback;
            browser.RequestHandler  = new WinFormsRequestHandler(openNewTab);
            browser.JsDialogHandler = new JsDialogHandler();
            browser.DownloadHandler = new DownloadHandler();
            if (multiThreadedMessageLoopEnabled)
            {
                browser.KeyboardHandler = new KeyboardHandler();
            }
            else
            {
                //When MultiThreadedMessageLoop is disabled we don't need the
                //CefSharp focus handler implementation.
                browser.FocusHandler = null;
            }

            //Handling DevTools docked inside the same window requires
            //an instance of the LifeSpanHandler all the window events,
            //e.g. creation, resize, moving, closing etc.
            browser.LifeSpanHandler = new LifeSpanHandler(openPopupsAsTabs: false);

            browser.LoadingStateChanged         += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage              += OnBrowserConsoleMessage;
            browser.TitleChanged                += OnBrowserTitleChanged;
            browser.AddressChanged              += OnBrowserAddressChanged;
            browser.StatusMessage               += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.LoadError += OnLoadError;

            browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync: false, options: BindingOptions.DefaultBinder);
            browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);

            //If you call CefSharp.BindObjectAsync in javascript and pass in the name of an object which is not yet
            //bound, then ResolveObject will be called, you can then register it
            browser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
            {
                var repo = e.ObjectRepository;
                if (e.ObjectName == "boundAsync2")
                {
                    repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
                }
            };

            browser.RenderProcessMessageHandler = new RenderProcessMessageHandler();
            browser.DisplayHandler = new DisplayHandler();
            //browser.MouseDown += OnBrowserMouseClick;
            browser.HandleCreated += OnBrowserHandleCreated;
            //browser.ResourceHandlerFactory = new FlashResourceHandlerFactory();
            this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;

            var eventObject = new ScriptedMethodsBoundObject();

            eventObject.EventArrived += OnJavascriptEventArrived;
            // Use the default of camelCaseJavascriptNames
            // .Net methods starting with a capitol will be translated to starting with a lower case letter when called from js
            browser.JavascriptObjectRepository.Register("boundEvent", eventObject, isAsync: false, options: BindingOptions.DefaultBinder);

            CefExample.RegisterTestResources(browser);

            var version = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);

            //Set label directly, don't use DisplayOutput as call would be a NOOP (no valid handle yet).
            outputLabel.Text = version;
        }