Exemplo n.º 1
0
 public void RemoteProcessExited(RenderProcess process)
 {
     if (process == this.remoteProcess)
     {
         this.remoteBrowser = null;
         this.remoteProcess = null;
     }
 }
Exemplo n.º 2
0
 void remoteProcess_OnExit(RenderProcess process)
 {
     if (process == this.remoteProcess)
     {
         this.remoteBrowser = null;
         this.remoteProcess = null;
     }
 }
Exemplo n.º 3
0
 public ChromiumFxDispatcher(CfrBrowser browser, CfrV8Context context, IWebSessionLogger logger)
 {
     _Logger           = logger;
     _Browser          = browser;
     _Context          = context;
     TaskRunner        = _Context.TaskRunner;
     _CfrTask          = new CfrTask();
     _CfrTask.Execute += CfrTask_Execute;
 }
 internal EvaluateTask(CfrBrowser browser, string code, Action <CfrV8Value, CfrV8Exception> callback)
 {
     this.browser  = browser;
     this.code     = code;
     this.callback = callback;
     this.Execute += (s, e) =>
     {
         Task_Execute(e);
     };
 }
Exemplo n.º 5
0
 public ChromiumFxWebView(CfrBrowser cfrbrowser, IWebSessionLogger logger)
 {
     _Logger     = logger;
     _Browser    = cfrbrowser;
     _CfrFrame   = _Browser.MainFrame;
     V8Context   = _CfrFrame.V8Context;
     _Dispatcher = new ChromiumFxDispatcher(_Browser, V8Context, _Logger);
     Converter   = new ChromiumFxConverter(V8Context);
     Factory     = new ChromiumFxFactory(V8Context);
 }
Exemplo n.º 6
0
 void VisitDOMCallback(CfrDomDocument doc, CfrBrowser browser)
 {
     LogCallback(doc, browser);
     if (doc.Body.HasChildren)
     {
         LogWriteLine("DOM: document.Body.FirstChild.ElementTagName = " + doc.Body.FirstChild.ElementTagName);
     }
     if (doc.HasSelection)
     {
         LogWriteLine("DOM: document.SelectionAsText = " + doc.SelectionAsText);
     }
 }
Exemplo n.º 7
0
 private void InitializeChromiumWebBrowser()
 {
     this.SuspendLayout();
     this.WebBrowser           = new ChromiumWebBrowser();
     this.WebBrowser.BackColor = System.Drawing.Color.White;
     this.WebBrowser.Dock      = System.Windows.Forms.DockStyle.Fill;
     this.WebBrowser.Location  = new System.Drawing.Point(0, 0);
     this.WebBrowser.Name      = "WebBrowser";
     this.WebBrowser.RemoteCallbackInvokeMode = Chromium.WebBrowser.JSInvokeMode.Inherit;
     this.WebBrowser.Size                  = new System.Drawing.Size(1441, 605);
     this.WebBrowser.TabIndex              = 2;
     this.WebBrowser.RemoteBrowserCreated += (s, e) =>
     {
         remoteBrowser = e.Browser;
     };
     this.Controls.Add(this.WebBrowser);
     this.ResumeLayout(false);
 }
Exemplo n.º 8
0
        public void SetRemoteBrowser(CfrBrowser remoteBrowser, RenderProcess remoteProcess)
        {
            this.remoteBrowser    = remoteBrowser;
            this.remoteProcess    = remoteProcess;
            remoteProcess.OnExit += new Action <RenderProcess>(remoteProcess_OnExit);
            var h = RemoteBrowserCreated;

            if (h != null)
            {
                var e = new RemoteBrowserCreatedEventArgs(remoteBrowser);
                if (RemoteCallbacksWillInvoke && InvokeRequired)
                {
                    RenderThreadInvoke(() => { h(this, e); });
                }
                else
                {
                    h(this, e);
                }
            }
        }
Exemplo n.º 9
0
        internal void SetRemoteBrowser(CfrBrowser remoteBrowser, RenderProcess remoteProcess)
        {
            this.remoteBrowser = remoteBrowser;
            this.remoteProcess = remoteProcess;
            remoteProcess.AddBrowserReference(this);
            var h = RemoteBrowserCreated;

            if (h != null)
            {
                var e = new RemoteBrowserCreatedEventArgs(remoteBrowser);
                if (Owner.InvokeRequired)
                {
                    RenderThreadInvoke(() => { h(this, e); });
                }
                else
                {
                    h(this, e);
                }
            }
        }
Exemplo n.º 10
0
 internal void RaiseOnV8ContextCreated(CfrBrowser browser, CfrFrame frame, CfrV8Context context)
 {
     OnV8ContextCreated?.Invoke(this, new BrowserV8ContextCreatedEventArgs(browser, frame, context));
 }
 public void SetRemoteBrowser(CfrBrowser remoteBrowser)
 {
     this.remoteBrowser = remoteBrowser;
 }
Exemplo n.º 12
0
 private void OnChromiumWebBrowser_RemoteBrowserCreated(object sender, RemoteBrowserCreatedEventArgs e)
 {
     _WebBrowser = e.Browser;
 }
Exemplo n.º 13
0
 internal RemoteBrowserCreatedEventArgs(CfrBrowser browser)
 {
     Browser = browser;
 }
Exemplo n.º 14
0
 public ChromiumFxCRemoteContext(CfrBrowser browser)
 {
     IsInContext           = CfxRemoteCallContext.IsInContext;
     _CfxRemoteCallContext = IsInContext ? null : browser.CreateRemoteCallContext();
     _CfxRemoteCallContext?.Enter();
 }
 private void OnChromiumWebBrowser_RemoteBrowserCreated(object sender, RemoteBrowserCreatedEventArgs e) 
 {
     _WebBrowser = e.Browser;
 }
 public ChromiumFxCRemoteContext(CfrBrowser browser) 
 {
     _CfxRemoteCallContext = (CfxRemoteCallContext.IsInContext) ? null : browser.CreateRemoteCallContext();
     _CfxRemoteCallContext?.Enter();
 }
Exemplo n.º 17
0
 public BrowserV8ContextCreatedEventArgs(CfrBrowser browser, CfrFrame frame, CfrV8Context context)
 {
     Browser = browser;
     Frame   = frame;
     Context = context;
 }
 public ChromiumFxCRemoteContext(CfrBrowser browser)
 {
     _CfxRemoteCallContext = browser.CreateRemoteCallContext();
     _CfxRemoteCallContext.Enter();
 }
Exemplo n.º 19
0
 void remoteProcess_OnExit(RenderProcess process)
 {
     if (process == this.remoteProcess)
     {
         this.remoteBrowser = null;
         this.remoteProcess = null;
     }
 }
Exemplo n.º 20
0
 public void SetRemoteBrowser(CfrBrowser remoteBrowser, RenderProcess remoteProcess)
 {
     this.remoteBrowser = remoteBrowser;
     this.remoteProcess = remoteProcess;
     remoteProcess.OnExit += new Action<RenderProcess>(remoteProcess_OnExit);
     var h = RemoteBrowserCreated;
     if (h != null)
     {
         var e = new RemoteBrowserCreatedEventArgs(remoteBrowser);
         if (RemoteCallbacksWillInvoke && InvokeRequired)
         {
             RenderThreadInvoke(() => { h(this, e); });
         }
         else
         {
             h(this, e);
         }
     }
 }
Exemplo n.º 21
0
 public void SetRemoteBrowser(CfrBrowser remoteBrowser, RenderProcess remoteProcess)
 {
     ((IChromiumWebBrowser)browser).SetRemoteBrowser(remoteBrowser, remoteProcess);
 }
Exemplo n.º 22
0
        public BrowserForm()
        {
            InitializeComponent();

            LogWriteLine("CfxRuntime.ApiHash(0): " + CfxRuntime.ApiHash(0));
            LogWriteLine("CfxRuntime.ApiHash(1): " + CfxRuntime.ApiHash(1));
            LogWriteLine("CfxRuntime.GetCefVersion(): " + CfxRuntime.GetCefVersion());
            LogWriteLine("CfxRuntime.GetChromeVersion(): " + CfxRuntime.GetChromeVersion());
            LogWriteLine("Platform OS: {0}; Arch: {1}", CfxRuntime.PlatformOS, CfxRuntime.PlatformArch);
            LogWriteLine();

            ChromiumWebBrowser.RemoteProcessCreated += (e) => {
                LogWriteLine("Remote render process created with process id {0}", CfxRemoteCallContext.CurrentContext.ProcessId, CfxRemoteCallContext.CurrentContext.ThreadId);
                e.RenderProcessHandler.OnRenderThreadCreated += (s, e1) => {
                    LogWriteLine("RenderProcessHandler.OnRenderThreadCreated, process id = {0}", CfxRemoteCallContext.CurrentContext.ProcessId);
                };
                e.RenderProcessHandler.OnBrowserDestroyed += (s, e1) => {
                    // this is never reached.
                    LogWriteLine("RenderProcessHandler.OnBrowserDestroyed, process id = {0}, browser id = {1}", CfxRemoteCallContext.CurrentContext.ProcessId, e1.Browser.Identifier);
                };
                e.RenderProcessHandler.OnBrowserCreated += (s, e1) => {
                    LogWriteLine("RenderProcessHandler.OnBrowserCreated, process id = {0}, browser id = {1}", CfxRemoteCallContext.CurrentContext.ProcessId, e1.Browser.Identifier);
                };
                e.RenderProcessHandler.OnFocusedNodeChanged += (s, e1) => {
                    LogWriteLine("RenderProcessHandler.OnFocusedNodeChanged, process id = {0}, browser id = {1}, node = {2}", CfxRemoteCallContext.CurrentContext.ProcessId, e1.Browser.Identifier, e1.Node?.Name);
                };
            };

            LoadUrlButton.Click += new EventHandler(LoadUrlButton_Click);
            UrlTextBox.KeyDown  += new KeyEventHandler(UrlTextBox_KeyDown);

            JSHelloWorldButton.Click += new EventHandler(JSHelloWorldButton_Click);
            JSTestPageButton.Click   += new EventHandler(TestButton_Click);
            VisitDomButton.Click     += new EventHandler(VisitDomButton_Click);

            WebBrowser.GlobalObject.AddFunction("CfxHelloWorld").Execute      += CfxHelloWorld_Execute;
            WebBrowser.GlobalObject.AddFunction("testDoubleCallback").Execute += TestDoubleCallback_Execute;

            // related to issue #65
            WebBrowser.GlobalObject.AddFunction("ArrayTestCallback").Execute += (s, e1) => {
                var array = e1.Arguments[0];
                var v0    = array.GetValue(0);
                var v1    = array.GetValue(1);
                if (v0 != null)
                {
                    LogWriteLine("Array test function works: v0 = {0}, v1 = {1}", v0.IntValue, v1.IntValue);
                }
                else
                {
                    LogWriteLine("Array test function: array is broken.");
                }
            };

            // related to pull request #1
            WebBrowser.GlobalObject.AddFunction("ListKeysInDocumentObject").Execute += (s, e1) => {
                var           doc  = e1.Arguments[0];
                List <string> keys = new List <string>();
                if (doc.GetKeys(keys))
                {
                    LogWriteLine("document has {0} keys:", keys.Count);
                    keys.ForEach(k => LogWriteLine(k));
                }
                else
                {
                    LogWriteLine("GetKeys returned false.");
                }
            };

            WebBrowser.GlobalObject.Add("TestObject", new JsTestObject(this));


            var sleepFunction = new JSFunction(JSInvokeMode.DontInvoke);

            sleepFunction.Execute += (s, e) => {
                LogWriteLine("Sleep function: sleep 5 seconds...");
                Thread.Sleep(5000);
                try {
                    var x = e.Arguments[0].IntValue;
                    LogWriteLine("Sleep function: Event args accessed sucessfully.");
                } catch (Exception ex) {
                    LogWriteLine("Sleep function: Error accessing event args:");
                    LogWriteLine(ex.ToString());
                }
            };

            WebBrowser.GlobalObject.Add("SleepFunction", sleepFunction);

            var html = @"

                <html>
                <head><script>
                    function testlog(text) {
                        document.getElementById('testfunc_result').innerHTML += '<br>' + text;
                    }
                </script>
                <script>
                    function doubleCallback(arg1, arg2) {
                        testlog('Function doubleCallback() called. Arguments:');
                        testlog(arg1);
                        testlog(arg2);
                        return 'This text is returned from doubleCallback()';
                    }
                    function clearTestLog() {
                        document.getElementById('testfunc_result').innerHTML = '';
                    }
                </script>
                </head>
                <body>
                    <br><br><b>Local resource/javascript integration test page.</b>
                    <hr><br><br>
                    Local resource image:<br>
                    <img src='http://localresource/image'><br><br>
                    <a href='http://www.google.com/' onclick=""window.open('http://www.google.com/', 'Popup test', 'width=800,height=600,scrollbars=yes'); return false;"">open popup window.open</a>
                    <a href='http://www.google.com/' target=blank>open popup target=blank</a>
                    <br><br>
                    <button id='testbutton1' onclick=""document.getElementById('testfunc_result').innerHTML += '<br>' + CfxHelloWorld('this is the hello world function');"">Execute CfxHelloWorld()</button>
                    <button id='testbutton2' onclick=""
                        testlog('TestObject = ' + TestObject);
                        testlog('TestObject.testFunction = ' + TestObject.testFunction);
                        TestObject.testFunction('this is the test function');
                    "">Execute TestObject.testFunction()</button>
                    <button id='testbutton3' onclick=""
                        testlog('TestObject = ' + TestObject);
                        testlog('TestObject.anotherObject = ' + TestObject.anotherObject);
                        testlog('TestObject.anotherObject.anotherTestFunction = ' + TestObject.anotherObject.anotherTestFunction);
                        testlog(TestObject.anotherObject.anotherTestFunction('this is the other test function'));
                    "">Execute TestObject.anotherObject.anotherTestFunction()</button>
                    <button id='testbutton4' onclick=""
                        testlog('TestObject.dynamicProperty = ' + TestObject.dynamicProperty);
                        testlog('(define TestObject.dynamicProperty += 100)');
                        TestObject.dynamicProperty += 100;
                        testlog('TestObject.dynamicProperty = ' + TestObject.dynamicProperty);
                    "">Defined TestObject properties</button>
                    <button id='testbutton5' onclick=""
                        testlog('TestObject.foo = ' + TestObject.foo);
                        testlog('(define TestObject.foo = 100)');
                        TestObject.foo = 100;
                        testlog('TestObject.foo = ' + TestObject.foo);
                    "">Undefined TestObject properties</button>
                    <button id='testbutton6' onclick=""
                        testlog('Call native function testDoubleCallback(doubleCallback). Return value:');
                        testlog('Return value: ' + testDoubleCallback(doubleCallback));
                    "">Double Callback</button>
                    <br><br><div id='testfunc_result'></div>
            ";

            WebBrowser.SetWebResource("http://localresource/text.html", new Chromium.WebBrowser.WebResource(html));

            var bm = new System.Drawing.Bitmap(100, 100);

            using (var g = System.Drawing.Graphics.FromImage(bm)) {
                g.FillRectangle(System.Drawing.Brushes.Yellow, 0, 0, 99, 99);
                g.DrawRectangle(System.Drawing.Pens.Black, 0, 0, 99, 99);
                g.DrawLine(System.Drawing.Pens.Black, 0, 0, 99, 99);
            }
            WebBrowser.SetWebResource("http://localresource/image", new Chromium.WebBrowser.WebResource(bm));

            WebBrowser.DisplayHandler.OnConsoleMessage += (s, e) => LogCallback(s, e);
            WebBrowser.DisplayHandler.OnTitleChange    += (s, e) => LogCallback(s, e);
            WebBrowser.DisplayHandler.OnStatusMessage  += (s, e) => LogCallback(s, e);

            WebBrowser.DisplayHandler.OnTitleChange += (s, e) => {
                var wb = ChromiumWebBrowser.FromCfxBrowser(e.Browser);
                LogWriteLine("ChromiumWebBrowser.FromCfxBrowser(e.Browser) == WebBrowser: {0}", wb == WebBrowser);
                var title = e.Title;
                BeginInvoke((MethodInvoker)(() => Text = "ChromiumWebBrowser - " + title));
            };

            WebBrowser.LifeSpanHandler.OnBeforePopup += (s, e) => {
                LogCallback(s, e);
            };

            WebBrowser.LoadHandler.OnLoadingStateChange += (s, e) => {
                if (e.IsLoading)
                {
                    return;
                }
                BeginInvoke((MethodInvoker)(() => {
                    UrlTextBox.Text = WebBrowser.Url.ToString();
                }));
            };

            WebBrowser.LoadUrl("http://localresource/text.html");

            WebBrowser.FindToolbar.Visible = true;

            WebBrowser.OnV8ContextCreated += (s, e) => {
                if (e.Frame.IsMain)
                {
                    CfrV8Value     retval;
                    CfrV8Exception exception;
                    if (e.Context.Eval("CfxHelloWorld()", null, 0, out retval, out exception))
                    {
                        LogWriteLine("OnV8ContextCreated: Eval succeeded, retval is '{0}'", retval.StringValue);
                    }
                    else
                    {
                        LogWriteLine("OnV8ContextCreated: Eval failed, exception is '{0}'", exception.Message);
                    }
                }
            };

            WebBrowser.GlobalObject.AddFunction("SubmitAsyncTestFunction").Execute += JS_SubmitAsyncTestFunction;
            WebBrowser.GlobalObject.AddFunction("bigStringFunction").Execute       += JS_bigStringFunction;

            WebBrowser.RemoteBrowserCreated += (s, e) => {
                remoteBrowser = e.Browser;
            };
        }