示例#1
0
        public frmBrowser()
        {
            this.Text = "Browser";

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

            this.Shown += (se, ev) =>
            {
                this.Top    = 0;
                this.Left   = 0;
                this.Width  = Screen.PrimaryScreen.WorkingArea.Width / 2;
                this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            };

            var browser = new ChromiumWebBrowser(URL)
            {
                Dock            = DockStyle.Fill,
                BrowserSettings =
                {
                    DefaultEncoding = "UTF-8",
                    WebGl           = CefState.Disabled,
                    WebSecurity     = CefState.Disabled,
                }
            };

            this.Controls.Add(browser);
            this.Browser = browser;
            //browser.MenuHandler = new MenuHandler(this);
        }
示例#2
0
        public KeyRequestForm(Framework.Data.APIKey keyType)
        {
            InitializeComponent();
            string url;

            if (_apiKeyType == Framework.Data.APIKey.GeocachingLive)
            {
                url = "http://application.globalcaching.eu/TokenRequest.aspx";
            }
            else
            {
                url = "http://application.globalcaching.eu/TokenRequest.aspx?target=staging";
            }

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

            panel1.Controls.Add(browser);
            browser.IsLoadingChanged += browser_IsLoadingChanged;
            Browser     = browser;
            _apiKeyType = keyType;

            Disposed += KeyRequestForm_Disposed;
        }
示例#3
0
        void InitBrowser()
        {
            Cef.Initialize(new CefSettings()
            {
            });

            string page = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "View\\index.html");

            var browser = new ChromiumWebBrowser(page)
            {
                Dock        = DockStyle.Fill,
                MenuHandler = new CefSharpContextMenuHandler()
            };

            browser.BrowserSettings = new BrowserSettings()
            {
                FileAccessFromFileUrls      = CefState.Enabled,
                UniversalAccessFromFileUrls = CefState.Enabled,
            };

            this.Browser = browser;
            this.Controls.Add(browser);

            this.Browser.RegisterJsObject("windowsApp", new JavascriptInteractionController());
        }
        public BrowserTabUserControl(string url)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler = new MenuHandler();
            browser.NavStateChanged += OnBrowserNavStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.HandleCreated += OnBrowserHandleCreated;

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

            Disposed += BrowserTabUserControlDisposed;
        }
示例#5
0
        public BrowserTabUserControl(string url)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            Browser.MenuHandler      = new MenuHandler();
            Browser.NavStateChanged += OnBrowserNavStateChanged;
            Browser.ConsoleMessage  += OnBrowserConsoleMessage;
            Browser.TitleChanged    += OnBrowserTitleChanged;
            Browser.AddressChanged  += OnBrowserAddressChanged;
            Browser.StatusMessage   += OnBrowserStatusMessage;

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

            DisplayOutput(version);

            Disposed += BrowserTabUserControlDisposed;
        }
        public BrowserTabUserControl(string url)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler    = new MenuHandler();
            browser.RequestHandler = new RequestHandler();
            //browser.FocusHandler = new FocusHandler(browser, urlTextBox);
            browser.NavStateChanged             += OnBrowserNavStateChanged;
            browser.ConsoleMessage              += OnBrowserConsoleMessage;
            browser.TitleChanged                += OnBrowserTitleChanged;
            browser.AddressChanged              += OnBrowserAddressChanged;
            browser.StatusMessage               += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.IsLoadingChanged            += OnIsLoadingChanged;
            browser.DragHandler = new DragHandler();
            browser.RegisterJsObject("bound", new BoundObject());

            CefExample.RegisterTestResources(browser);

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

            DisplayOutput(version);

            Disposed += BrowserTabUserControlDisposed;
        }
        public BrowserTabUserControl(string url)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler = new MenuHandler();
            browser.RequestHandler = new RequestHandler();
            browser.JsDialogHandler = new JsDialogHandler();
            browser.GeolocationHandler = new GeolocationHandler();
            browser.DownloadHandler = new DownloadHandler();
            //browser.FocusHandler = new FocusHandler(browser, urlTextBox);
            browser.NavStateChanged += OnBrowserNavStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.IsLoadingChanged += OnIsLoadingChanged;
            browser.DragHandler = new DragHandler();
            browser.RegisterJsObject("bound", new BoundObject());

            CefExample.RegisterTestResources(browser);

            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
            DisplayOutput(version);
        }
示例#8
0
        private void OnLoad(object sender, EventArgs e)
        {
            var browser = new ChromiumWebBrowser(FileHost.StartupUrl)
            {
                Dock = DockStyle.Fill
            };

            BrowserPanel.Controls.Add(browser);
            Browser = browser;
        }
示例#9
0
 void KeyRequestForm_Disposed(object sender, EventArgs e)
 {
     Disposed -= KeyRequestForm_Disposed;
     if (Browser != null)
     {
         var browser = (ChromiumWebBrowser)Browser;
         browser.IsLoadingChanged -= browser_IsLoadingChanged;
         Browser.Dispose();
         Browser = null;
     }
 }
示例#10
0
 void KeyRequestForm_Disposed(object sender, EventArgs e)
 {
     Disposed -= KeyRequestForm_Disposed;
     if (Browser != null)
     {
         var browser = (ChromiumWebBrowser)Browser;
         browser.IsLoadingChanged -= browser_IsLoadingChanged;
         Browser.Dispose();
         Browser = null;
     }
 }
示例#11
0
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler        = new MenuHandler();
            browser.RequestHandler     = new WinFormsRequestHandler(openNewTab);
            browser.JsDialogHandler    = new JsDialogHandler();
            browser.GeolocationHandler = new GeolocationHandler();
            browser.DownloadHandler    = new DownloadHandler();
            if (multiThreadedMessageLoopEnabled)
            {
                browser.KeyboardHandler = new KeyboardHandler();
            }
            browser.LifeSpanHandler              = new LifeSpanHandler();
            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);
            browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true);
            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);

            DisplayOutput(version);
        }
        public BrowserTabUserControl(Action<string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler = new MenuHandler();
            browser.RequestHandler = new WinFormsRequestHandler(openNewTab);
            browser.JsDialogHandler = new JsDialogHandler();
            browser.GeolocationHandler = new GeolocationHandler();
            browser.DownloadHandler = new DownloadHandler();
            if (multiThreadedMessageLoopEnabled)
            {
                browser.KeyboardHandler = new KeyboardHandler();
            }
            browser.LifeSpanHandler = new LifeSpanHandler();
            browser.LoadingStateChanged += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.LoadError += OnLoadError;
            browser.RegisterJsObject("bound", new BoundObject());
            browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject());
            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.RegisterJsObject("boundEvent", eventObject, BindingOptions.DefaultBinder);

            CefExample.RegisterTestResources(browser);

            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
            DisplayOutput(version);
        }
示例#13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var browser = new ChromiumWebBrowser(String.Empty)
            {
                Dock            = DockStyle.Fill,
                BrowserSettings = new BrowserSettings
                {
                    FileAccessFromFileUrls      = CefState.Enabled,
                    UniversalAccessFromFileUrls = CefState.Enabled,
                    Javascript   = CefState.Enabled,
                    ImageLoading = CefState.Enabled,
                    JavascriptAccessClipboard = CefState.Enabled,
                    JavascriptCloseWindows    = CefState.Enabled,
                    JavascriptDomPaste        = CefState.Enabled
                }
            };

            browser.RequestContext = new RequestContext(new RequestContextHandler());

            browser.LoadingStateChanged         += OnLoadingStateChanged;
            browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged;
            panel1.Controls.Add(browser);
            Browser = browser;
            browser.LoadHtml("<html><body>Wait Login...\n<script>\n callbackObj.LoginWebFrame(\"aaa\");\n</script>\n</body></html>");
            var bindScriptOption = new CefSharp.BindingOptions();

            //bindScriptOption.CamelCaseJavascriptNames = false;
            browser.Load(home_url);
            //browser.MenuHandler = new MenuHandler();
            //browser.RequestHandler = new WinFormsRequestHandler(openNewTab);
            //browser.JsDialogHandler = new JsDialogHandler();
            //browser.DownloadHandler = new MyDownLoadFile();
            //browser.RequestHandler = new MyRequestHandler();

            Browser.FrameLoadStart += (sender0, e0) =>
            {
                var uri = new Uri(e0.Url);
                this.toolStripStatusLabel1.Text = uri.ToString() + " loading";
            };
            Browser.FrameLoadEnd += (sender0, e0) =>
            {
                var uri = new Uri(e0.Url);
                this.toolStripStatusLabel1.Text = uri.ToString() + " ";
            };
        }
示例#14
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var url = "www.baidu.com";

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

            Browser = browser;

            browser.BrowserSettings.ImageLoading = CefState.Disabled;

            browser.FrameLoadEnd += new EventHandler <FrameLoadEndEventArgs>(End);

            P_Web.Controls.Add(browser);
            browser.Load(url);
        }
示例#15
0
        public static async Task <TaskResult <string> > FilterAllFramesHTML(IWinFormsWebBrowser Browser, TimeSpan frameReadTimout)
        {
            TaskResult <string> result = new TaskResult <string>("");

            if (Browser.IsBrowserInitialized)
            {
                var         mainFrame = Browser.GetMainFrame();
                List <long> allFrames = Browser.GetBrowser().GetFrameIdentifiers();
                for (int i = 0; i < allFrames.Count && !result.Sucess; i++)
                {
                    var currentFrame = Browser.GetBrowser().GetFrame(allFrames[i]);
                    if (currentFrame != null && currentFrame.IsValid && !currentFrame.IsDisposed)
                    {
                        result = await isFrameContentBlocked(currentFrame, frameReadTimout);
                    }
                }
            }

            return(result);
        }
        public BrowserTabUserControl(string url)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler        = new MenuHandler();
            browser.RequestHandler     = new RequestHandler();
            browser.JsDialogHandler    = new JsDialogHandler();
            browser.GeolocationHandler = new GeolocationHandler();
            browser.DownloadHandler    = new DownloadHandler();
            browser.KeyboardHandler    = new KeyboardHandler();
            //browser.LifeSpanHandler = new LifeSpanHandler();
            browser.LoadingStateChanged         += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage              += OnBrowserConsoleMessage;
            browser.TitleChanged                += OnBrowserTitleChanged;
            browser.AddressChanged              += OnBrowserAddressChanged;
            browser.StatusMessage               += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.LoadError  += OnLoadError;
            browser.DragHandler = new DragHandler();
            if (CefSharpSettings.WcfEnabled)
            {
                browser.RegisterJsObject("bound", new BoundObject());
            }
            browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject());

            CefExample.RegisterTestResources(browser);

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

            DisplayOutput(version);
        }
        public BrowserTabUserControl(string url)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler = new MenuHandler();
            browser.RequestHandler = new RequestHandler();
            browser.JsDialogHandler = new JsDialogHandler();
            browser.GeolocationHandler = new GeolocationHandler();
            browser.DownloadHandler = new DownloadHandler();
            browser.KeyboardHandler = new KeyboardHandler();
            //browser.LifeSpanHandler = new LifeSpanHandler();
            browser.LoadingStateChanged += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.LoadError += OnLoadError;
            browser.DragHandler = new DragHandler();
            if (CefSharpSettings.WcfEnabled)
            {
                browser.RegisterJsObject("bound", new BoundObject());
            }
            browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject());

            CefExample.RegisterTestResources(browser);

            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
            DisplayOutput(version);
        }
示例#18
0
        public KeyRequestForm(Framework.Data.APIKey keyType)
        {
            InitializeComponent();
            string url;
            if (_apiKeyType == Framework.Data.APIKey.GeocachingLive)
            {
                url = "http://application.globalcaching.eu/TokenRequest.aspx";
            }
            else
            {
                url = "http://application.globalcaching.eu/TokenRequest.aspx?target=staging";
            }

            var browser = new ChromiumWebBrowser(url)
            {
                Dock = DockStyle.Fill
            };
            panel1.Controls.Add(browser);
            browser.IsLoadingChanged += browser_IsLoadingChanged;
            Browser = browser;
            _apiKeyType = keyType;

            Disposed += KeyRequestForm_Disposed;
        }
示例#19
0
        public BrowserControl(string url)
        {
            InitializeComponent();
            browser = new ChromiumWebBrowser(url)
            {
                Dock = DockStyle.Fill
            };
            browserPanel.Controls.Add(browser);
            BrowserSettings bs = new BrowserSettings();

            bs.WebSecurityDisabled  = true;
            bs.DefaultEncoding      = "UTF8";
            browser.BrowserSettings = bs;


            Browser = browser;

            //browser.HandleCreated += OnBrowserHandleCreated;
            browser.IsLoadingChanged += OnLoadingChanged;
            browser.FrameLoadStart   += FrameLoadStart;
            browser.FrameLoadEnd     += FrameLoadEnd;
            browser.NavStateChanged  += OnBrowserNavStateChanged;
            Disposed += BrowserControlDisposed;
        }
示例#20
0
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled,
                                     ChromiumWebBrowser browser = null, IWindowInfo windoInfo = null)
        {
            InitializeComponent();
            initialURL = url;


            //add an if statement to initialize the settings once. else the app is going to crash
            if (CefSharp.Cef.IsInitialized == false)
            {
                string appdata   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string cachePath = Path.Combine(appdata, "FilteredChromeBrowser", "cache");
                if (!Directory.Exists(cachePath))
                {
                    Directory.CreateDirectory(cachePath);
                }

                CefSettings Settings = new CefSettings();
                Settings.CachePath = cachePath;  //always set the cachePath, else this wont work
                Settings.CefCommandLineArgs.Add("no-proxy-server", "1");


                CefSharp.Cef.Initialize(Settings);
            }

            if (browser == null || windoInfo == null)
            {
                browser = new ChromiumWebBrowser("about:blank")
                {
                    Dock = DockStyle.Fill
                };

                CefSharpSettings.LegacyJavascriptBindingEnabled = true;
                browser.RegisterJsObject("print", new EmptyObject());
                this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;
            }
            else
            {
                var rect = browserPanel.ClientRectangle;
                windoInfo.SetAsChild(browserPanel.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
            }

            browserPanel.Controls.Add(browser);
            Browser = browser;

            browser.MenuHandler = new MenuHandler(new Action(() => {
                this.InvokeOnUiThreadIfRequired(() => { ToggleBottomToolStrip(); });
            }));
            myPageNavigationManager = new WinFormsRequestHandler(openNewTab);
            browser.RequestHandler  = myPageNavigationManager;
            browser.JsDialogHandler = new JsDialogHandler();

            var dm = new DownloadHandler(CefSharp.WinForms.Example.Properties.Settings.Default.saveFolder);

            dm.OnDownloadUpdatedFired += Dm_OnDownloadUpdatedFired;
            browser.DownloadHandler    = dm;


            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.
            myLifeSpanHandler       = new LifeSpanHandler(openPopupsAsTabs: true);
            browser.LifeSpanHandler = myLifeSpanHandler;


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

            browser.FrameLoadEnd += Browser_FrameLoadEnd;

            browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged;



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


            //CefExample.RegisterTestResources(browser);


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

            DisplayOutput(version);
        }
示例#21
0
		protected override void InitializeUI()
		{
			base.InitializeUI();
			browser = (ChromiumWebBrowser)mycroParser.ObjectCollection["browser"];
			browser.Load(internalUrl);
		}
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler     = new MenuHandler();
            browser.RequestHandler  = new WinFormsRequestHandler(openNewTab);
            browser.JsDialogHandler = new JsDialogHandler();
            browser.DownloadHandler = new DownloadHandler();
            browser.AudioHandler    = new CefSharp.Handler.AudioHandler();
            browser.FrameHandler    = new CefSharp.Handler.FrameHandler();

            if (multiThreadedMessageLoopEnabled)
            {
                browser.KeyboardHandler = new KeyboardHandler();
            }

            //The CefSharp.WinForms.Handler.LifeSpanHandler implementation
            //allows for Popups to be hosted in Controls/Tabs
            //This example also demonstrates docking DevTools in a SplitPanel
            browser.LifeSpanHandler = LifeSpanHandler
                                      .Create()
                                      .OnPopupCreated((ctrl, targetUrl) =>
            {
                //Don't try using ctrl.FindForm() here as
                //the control hasn't been attached to a parent yet.
                if (FindForm() is BrowserForm owner)
                {
                    owner.AddTab(ctrl, targetUrl);
                }
            })
                                      .OnPopupDestroyed((ctrl, popupBrowser) =>
            {
                //If we docked  DevTools (hosted it ourselves rather than the default popup)
                //Used when the BrowserTabUserControl.ShowDevToolsDocked method is called
                if (popupBrowser.MainFrame.Url.Equals("devtools://devtools/devtools_app.html"))
                {
                    //Dispose of the parent control we used to host DevTools, this will release the DevTools window handle
                    //and the ILifeSpanHandler.OnBeforeClose() will be call after.
                    ctrl.Dispose();
                }
                else
                {
                    //If browser is disposed or the handle has been released then we don't
                    //need to remove the tab in this example. The user likely used the
                    // File -> Close Tab menu option which also calls BrowserForm.RemoveTab
                    if (!ctrl.IsDisposed && ctrl.IsHandleCreated)
                    {
                        if (ctrl.FindForm() is BrowserForm owner)
                        {
                            var windowHandle = popupBrowser.GetHost().GetWindowHandle();

                            owner.RemoveTab(windowHandle);
                        }

                        ctrl.Dispose();
                    }
                }
            })
                                      .Build();

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

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

            //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")
                {
#if NETCOREAPP
                    repo.Register("boundAsync2", new AsyncBoundObject(), options: BindingOptions.DefaultBinder);
#else
                    repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
#endif
                }
            };

            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
#if !NETCOREAPP
            browser.JavascriptObjectRepository.Register("boundEvent", eventObject, isAsync: false, options: BindingOptions.DefaultBinder);
#endif

            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;
        }
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled)
        {
            InitializeComponent();

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

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler     = new MenuHandler();
            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);

            DisplayOutput(version);
        }
示例#24
0
 protected override void InitializeUI()
 {
     base.InitializeUI();
     browser = (ChromiumWebBrowser)mycroParser.ObjectCollection["browser"];
     browser.Load(internalUrl);
 }