RegisterJsObject() public method

public RegisterJsObject ( string name, object objectToBind, bool camelCaseJavascriptNames = true ) : void
name string
objectToBind object
camelCaseJavascriptNames bool
return void
Esempio n. 1
1
        public FormMain(bool startRight=false)
        {
            InitializeComponent();
            VerticalScroll.Visible = false;
            ChromiumBrowser = new ChromiumWebBrowser(Program.HostUrl)
            {
                Dock = DockStyle.Fill
            };
            Controls.Add(ChromiumBrowser);

            Load += (sender, args) =>
            {
                Top = 0;
                Left = startRight ? Screen.PrimaryScreen.WorkingArea.Width / 2 : 0;
                Width = Screen.PrimaryScreen.WorkingArea.Width / 2;
                Height = Screen.PrimaryScreen.WorkingArea.Height;
            };

            FormClosing += (sender, args) =>
            {
                //Make closing feel more responsive.
                Visible = false;
            };

            FormClosed += (sender, args) =>
            {
                Cef.Shutdown();
            };

            ChromiumBrowser.RegisterJsObject("nativeHost", new NativeHost(this));
        }
Esempio n. 2
1
        private void initEditor()
        {
            // cef setting
            var setting = new CefSettings();
            setting.RegisterScheme(new CefCustomScheme()
            {
                SchemeName = LocalSchemeHandler.SchemeName,
                SchemeHandlerFactory = new LocalSchemeHanlderFactory()
            });
            Cef.Initialize(setting);

//            var editorInfo = new FileInfo(@".\static\editor.html");
//            _browser = new ChromiumWebBrowser(editorInfo.FullName)
            _browser = new ChromiumWebBrowser("http://cef/editor.html")
            {
                Dock = DockStyle.Fill
            };

            _browser.RegisterJsObject("cef", new CefCallTest());

            mainPanel.Controls.Add(_browser);
        }
Esempio n. 3
0
 public Form1()
 {
     InitializeComponent();
     InitializeChromium();
     CefSharpSettings.LegacyJavascriptBindingEnabled = true;
     chromeBrowser.RegisterJsObject("cefCustomObject", new CefCustomObject(chromeBrowser, this));
     chromeBrowser.RegisterJsObject("tools", new Tools());
     chromeBrowser.RegisterJsObject("getDataTable", new GetDataTable());
 }
Esempio n. 4
0
        public void Start(string url)
        {
            InitChrome(url);
            //regist the object for js, you can use it from html by js
            browser.RegisterJsObject("cef", new CefCustomObject(browser, this));
            browser.RegisterJsObject("jsobj", new JSObj());
            RequestHandler requestHandler = new RequestHandler();

            browser.RequestHandler = requestHandler;
        }
        public BrowserForm()
        {
            InitializeComponent();

            Text = "CefSharp";
            WindowState = FormWindowState.Maximized;
            String exeFullPath = Application.ExecutablePath;
            String uri = "file://" + exeFullPath.Replace("bin\\x64\\Debug\\CefSharp.MinimalExample.WinForms.EXE", "communication.html");
            browser = new ChromiumWebBrowser(uri)
            {
                Dock = DockStyle.Fill,
            };

            // Inject JS object into web page environment
            browser.RegisterJsObject("bound", new BoundObject());
            browser.FrameLoadEnd += this.OnFrameLoadEnd;

            toolStripContainer.ContentPanel.Controls.Add(browser);

            browser.LoadingStateChanged += OnLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;

            var bitness = Environment.Is64BitProcess ? "x64" : "x86";
            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness);
            DisplayOutput(version);
        }
Esempio n. 6
0
        public FormMain()
        {
            InitializeComponent();

            this.VerticalScroll.Visible = false;

            chromiumBrowser = new ChromiumWebBrowser(Program.HostUrl)
            {
                Dock = DockStyle.Fill
            };
            this.Controls.Add(chromiumBrowser);

            this.FormClosing += (sender, args) =>
            {
                //Make closing feel more responsive.
                this.Visible = false;
            };

            this.FormClosed += (sender, args) =>
            {
                Cef.Shutdown();
            };

            chromiumBrowser.RegisterJsObject("aboutDialog", new AboutDialogJsObject(), camelCaseJavascriptNames: true);
        }
Esempio n. 7
0
        public FormMain()
        {
            InitializeComponent();
            VerticalScroll.Visible = false;

            ChromiumBrowser = new ChromiumWebBrowser(Program.HostUrl)
            {
                Dock = DockStyle.Fill
            };

            Controls.Add(ChromiumBrowser);

            FormClosed += (sender, args) =>
            {
                Cef.Shutdown();
            };

            Load += (sender, args) =>
            {
                FormBorderStyle = FormBorderStyle.None;
                Left = Top = 0;
                Width = Screen.PrimaryScreen.WorkingArea.Width;
                Height = Screen.PrimaryScreen.WorkingArea.Height;
            };

            ChromiumBrowser.RegisterJsObject("nativeHost", new NativeHost(this));
        }
 public ChromiumWebBrowserWrapper(ChromiumWebBrowser webView)
 {
     _webView = webView;
     _nativeExecution = new NativeExecution(this);
     _guiInvoke = invoke => _webView.Invoke(invoke);
     _commandList = new List<string>();
     //Register this object as window.external to mirror the IE8 mobile browser naming
     _webView.RegisterJsObject("external", this);
     //Obsolete in CEF 3: Cef.RegisterJsObject("external", this);
 }
        private void BootStrapForm2_Load(object sender, EventArgs e)
        {
            string page = string.Format("{0}HTMLResources/html/BootstrapFormExample.html", GetAppLocation());
            m_chromeBrowser = new ChromiumWebBrowser(page);
            m_javascriptSvc = new SomeClass(m_chromeBrowser);


            // Register the JavaScriptInteractionObj class with JS
            m_chromeBrowser.RegisterJsObject("winformObj", m_javascriptSvc);

            Controls.Add(m_chromeBrowser);

            ChromeDevToolsSystemMenu.CreateSysMenu(this);
        }
        public void InitBrowser(Panel panel)
        {
            CefSettings cSettings = new CefSettings();
            cSettings.RemoteDebuggingPort = 8088;
            Cef.Initialize(cSettings);

            // Open main page
            mChromeBrowser = new ChromiumWebBrowser(GetPagePath("main.html"));
            mEffectsJsObject = new EffectsJsObject();
            mChromeBrowser.RegisterJsObject("EffectsJsObject", mEffectsJsObject);
            mChromeBrowser.LoadError += MChromeBrowser_LoadError;
            panel.Controls.Add(mChromeBrowser);
            mChromeBrowser.Dock = DockStyle.Fill;
        }
Esempio n. 11
0
 public uChrome(string argUrl)
 {
     if (myChrome == null)
     {
         cefS.CefSharpSettings.LegacyJavascriptBindingEnabled = true;
         myChrome = new cefW.ChromiumWebBrowser(argUrl);
         myChrome.RegisterJsObject("formCall", new JsFormCall());
         myChrome.Dock = DockStyle.Fill;
     }
     else
     {
         this.uBrowser.Load(argUrl);
     }
 }
Esempio n. 12
0
        private void CreateBrowser()
        {
            browser = new ChromiumWebBrowser(defaulturl) {
                Dock = DockStyle.Fill,
            };
            toolStripContainer.ContentPanel.Controls.Add(browser);

            browser.LoadingStateChanged += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;
            browser.RegisterJsObject("bound", new BoundObject());
        }
        public Form1()
        {
            InitializeComponent();

            // Start OWIN host
            WebApi.Start();
            Uri startPath = new Uri(AppDomain.CurrentDomain.BaseDirectory + "www\\loading.html");
            browser = new ChromiumWebBrowser(startPath.AbsoluteUri);
            browser.Dock = DockStyle.Fill;
            browser.TitleChanged += browser_TitleChanged;
            browser.KeyDown += browser_KeyDown;
            browser.RegisterJsObject("clientUtils", new JsClientUtils(this));
            browser.JsDialogHandler = new JsDialog();
            Controls.Add(this.browser);
        }
Esempio n. 14
0
        public TimelineControl()
        {
            InitializeComponent();

            if (DesignMode)
            {
                this.BackColor = Color.Black;
            }
            else
            {

                InitializeCef();

                webBrowser = new ChromiumWebBrowser(path)
                {
                    Dock = DockStyle.Fill
                };
                this.Controls.Add(webBrowser);
                webBrowser.SendToBack();

                webBrowser.MenuHandler = new ChromiumBrowserHandlers.MenuHandler();
                var keyboardHandler = new ChromiumBrowserHandlers.KeyboardHandler();
                keyboardHandler.KeyCommand += webBrowser_KeyCommand;
                webBrowser.KeyboardHandler = keyboardHandler;

                webBrowser.ConsoleMessage += webBrowser_ConsoleMessage;
                webBrowser.LoadError += webBrowser_LoadError;

                webBrowser.BrowserSettings.JavaScriptAccessClipboardDisabled = false;
                webBrowser.BrowserSettings.JavaScriptCloseWindowsDisabled = true;
                webBrowser.BrowserSettings.JavaScriptOpenWindowsDisabled = true;

                scriptObj = new TimelineScriptingObject(null);
                scriptObj.DOMReady += scriptObj_DOMReady;
                scriptObj.ModelUpdated += new EventHandler(scriptObj_ModelUpdated);
                scriptObj.BeginPlayback += new EventHandler(scriptObj_BeginPlayback);
                scriptObj.PausePlayback += new EventHandler(scriptObj_PausePlayback);
                scriptObj.StopPlayback += new EventHandler(scriptObj_StopPlayback);

                webBrowser.RegisterJsObject("external", scriptObj);
            }
        }
Esempio n. 15
0
        public Form1()
        {
            InitializeComponent();

            CefSettings cefsettings = new CefSettings();
            cefsettings.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";
            cefsettings.LogSeverity = LogSeverity.Disable;
            cefsettings.CefCommandLineArgs.Add("enable-npapi", "1");
            cefsettings.CefCommandLineArgs.Add("disable-bundled-ppapi-flash", "1");

            Cef.Initialize(cefsettings);

            chromeBrowser = new ChromiumWebBrowser("https://www.google.com/");
            chromeBrowser.RegisterJsObject("jsObject", this, false);

            chromeBrowser.Size = new Size(800, 600);
            chromeBrowser.Dock = DockStyle.Fill;

            this.panelChrome.Controls.Add(chromeBrowser);
        }
Esempio n. 16
0
        public BrowserWrapper(string url)
        {
            var factory = new LocalSchemeHandlerFactory();
            var settings = new CefSettings();

            settings.RegisterScheme(new CefCustomScheme { SchemeName = "local", SchemeHandlerFactory = factory });
            CefSharp.Cef.Initialize(settings);

            _browser = new ChromiumWebBrowser(url);

            _browser.BrowserSettings = new BrowserSettings()
            {
                FileAccessFromFileUrlsAllowed = true,
                UniversalAccessFromFileUrlsAllowed = true,
                TabToLinksDisabled = true
            };

            _handler = new QCmdHandler(new CommandStore(), new EngineWrapper());

            _browser.RegisterJsObject("qcmd", new QCmdCallback(_handler), false);
        }
        public BrowserForm()
        {
            InitializeComponent();

            Text = "CefSharp";
            WindowState = FormWindowState.Maximized;

            browser = new ChromiumWebBrowser("www.google.com")
            {
                Dock = DockStyle.Fill,
            };


            var assembly = Assembly.GetExecutingAssembly();
            var resourceName = "CefSharp.MinimalExample.WinForms.Resources.CallbackTest.html";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            using (StreamReader reader = new StreamReader(stream))
            {
                string result = reader.ReadToEnd();
                browser.LoadHtml(result, "http://rendering/");
            }


            

            toolStripContainer.ContentPanel.Controls.Add(browser);

            browser.LoadingStateChanged += OnLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;

            var bitness = Environment.Is64BitProcess ? "x64" : "x86";
            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness);
            DisplayOutput(version);

            browser.RegisterJsObject("BoundObject", new BoundObject());
        }
        public BrowserForm()
        {
            InitializeComponent();

            Text = "CefSharp";
            WindowState = FormWindowState.Maximized;

            browser = new ChromiumWebBrowser("www.google.com")
            {
                Dock = DockStyle.Fill,
            };
            browser.RegisterJsObject("jsBind", new JSBinding());
            toolStripContainer.ContentPanel.Controls.Add(browser);

            browser.LoadingStateChanged += OnLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;

            var bitness = Environment.Is64BitProcess ? "x64" : "x86";
            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness);
            DisplayOutput(version);
        }
Esempio n. 19
0
        private void CreateBrowser()
        {
            browser = new ChromiumWebBrowser("file:///C:/Users/automacao.KEYEU/Documents/GitHub/KPP_NetHtml5/KPP_NetHtml5/pages/index.html")
            //browser = new ChromiumWebBrowser("file:///C:/Users/ruise/Documents/GitHub/KPP_NetHtml5/KPP_NetHtml5/pages/index.html")
            {
                Dock = DockStyle.Fill,
            };
            __htmlContainer.Controls.Add(browser);

            browser.LoadingStateChanged += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage += OnBrowserConsoleMessage;
            browser.StatusMessage += OnBrowserStatusMessage;
            browser.TitleChanged += OnBrowserTitleChanged;
            browser.AddressChanged += OnBrowserAddressChanged;
            var bdobject = new BoundObject();
            bdobject.MyProperty = 1;
            browser.RegisterJsObject("bound", bdobject);
        }
Esempio n. 20
0
        private void buttonRegisterCSharpObject_Click(object sender, EventArgs e)
        {
            //To register a JS object, it must occur immediate after the browser has been created
            //So in this instance we'll create a new browser;
            panel1.Controls.Remove(m_chromeBrowser);

            var page = new Uri(string.Format("file:///{0}HTMLResources/html/WinformInteractionExample.html", GetAppLocation()));

            m_chromeBrowser = new ChromiumWebBrowser(page.ToString());

            panel1.Controls.Add(m_chromeBrowser);

            m_jsInteractionObj = new JavaScriptInteractionObj();
            m_jsInteractionObj.SetChromeBrowser(m_chromeBrowser);

            // Register the JavaScriptInteractionObj class with JS
            m_chromeBrowser.RegisterJsObject("winformObj", m_jsInteractionObj);
        }
Esempio n. 21
0
        private void InitializeBrowserControl()
        {
            _formEntryHandler = new FormEntryHandler();
              _formEntryHandler.FormSave += _formEntryHandler_FormSave;
              _formEntryHandler.FormPost += _formEntryHandler_FormPost;

              _browser = new ChromiumWebBrowser(GetPagePath("start.html"))
              {
            Dock = DockStyle.Fill
              };

              PnlHtml.Controls.Add(_browser);

              _browser.AddressChanged += BrowserAddressChanged;
              _browser.ConsoleMessage += BrowserConsoleMessage;
              _browser.LoadError += BrowserLoadError;
              _browser.StatusMessage += BrowserStatusMessage;
              _browser.NavStateChanged += BrowserNavStateChanged;
              _browser.TitleChanged += BrowserTitleChanged;

              _browser.RegisterJsObject("formEntryHandler", _formEntryHandler);
        }