Пример #1
0
        private void RenderProcessHandler_OnBrowserCreated(object sender, Chromium.Remote.Event.CfrOnBrowserCreatedEventArgs e)
        {
            var browserCore = BrowserCore.GetBrowserCore(e.Browser.Identifier);

            if (browserCore != null)
            {
                var remoteProcess = browserCore.remoteProcess;
                if (remoteProcess != null && remoteProcess != renderProcess)
                {
                    CfxRemoteCallbackManager.SuspendCallbacks(renderProcess.RemoteProcessId);
                }

                browserCore.SetRemoteBrowser(e.Browser, renderProcess);
            }
        }
Пример #2
0
        private void ExecutionThreadEntry(RemoteConnection connection)
        {
            if (returnImmediately)
            {
                // only happens in calls from the browser to the renderer
                CfxDebug.Assert(connection == RemoteClient.connection);
                ExecuteInTargetProcess(connection);
                return;
            }

            if (RemoteClient.connection == null)
            {
                if (!CfxRemoteCallbackManager.IncrementCallbackCount(connection.remoteProcessId))
                {
                    // The application has suspended remote callbacks.
                    // Write the response without ececuting event handlers, returning default values.
                    connection.EnqueueWrite(WriteResponse);
                    return;
                }
            }

            var threadContext = new CfxRemoteCallContext(connection, remoteThreadId);

            threadContext.Enter();
            var threadStackCount = CfxRemoteCallContext.ContextStackCount;

            try {
                ExecuteInTargetProcess(connection);
            } finally {
                if (RemoteClient.connection == null)
                {
                    CfxRemoteCallbackManager.DecrementCallbackCount(connection.remoteProcessId);
                }
                if (threadStackCount != CfxRemoteCallContext.ContextStackCount || CfxRemoteCallContext.CurrentContext != threadContext)
                {
                    CfxRemoteCallContext.resetStack(threadStackCount - 1);
                    throw new CfxException("Unbalanced remote call context stack. Make sure to balance calls to CfxRemoteCallContext.Enter() and CfxRemoteCallContext.Exit() in all render process callback events.");
                }
                threadContext.Exit();
            }

            connection.EnqueueWrite(WriteResponse);
        }
Пример #3
0
        /// <summary>
        /// Prepares and executes the remote procedure in the remote process
        /// </summary>
        internal void Execute(RemoteConnection connection)
        {
            if (returnImmediately)
            {
                RemoteProcedure();
                return;
            }

            if (RemoteClient.connection == null)
            {
                if (!CfxRemoteCallbackManager.IncrementCallbackCount(connection.remoteProcessId))
                {
                    // The application has suspended remote callbacks.
                    // Return without ececuting event handlers, connection will return default values.
                    return;
                }
            }

            var threadContext = new CfxRemoteCallContext(connection, remoteThreadId);

            threadContext.Enter();
            var threadStackCount = CfxRemoteCallContext.ContextStackCount;

            try {
                RemoteProcedure();
            } finally {
                if (RemoteClient.connection == null)
                {
                    CfxRemoteCallbackManager.DecrementCallbackCount(connection.remoteProcessId);
                }
                if (threadStackCount != CfxRemoteCallContext.ContextStackCount || CfxRemoteCallContext.CurrentContext != threadContext)
                {
                    CfxRemoteCallContext.resetStack(threadStackCount - 1);
                    throw new CfxException("Unbalanced remote call context stack. Make sure to balance calls to CfxRemoteCallContext.Enter() and CfxRemoteCallContext.Exit() in all render process callback events.");
                }
                threadContext.Exit();
            }
        }
Пример #4
0
        void RenderProcessHandler_OnBrowserCreated(object sender, CfrOnBrowserCreatedEventArgs e)
        {
            var id = e.Browser.Identifier;
            var wb = HtmlUILauncher.GetBrowser(id);

            if (wb != null)
            {
                var rp = wb.RemoteProcess;
                if (rp != null && rp != this.remoteProcess)
                {
                    // A new process has been created for the browser.
                    // The old process is still alive, but probably it gets
                    // killed soon after this callback returns.
                    // So we suspend all callbacks from the old process.
                    // If there are currently executing callbacks,
                    // this call will block until they are finished.
                    // When this call returns, it should be safe to
                    // continue execution and let the old process die.
                    CfxRemoteCallbackManager.SuspendCallbacks(rp.RemoteProcessId);
                }

                wb.SetRemoteBrowser(e.Browser, remoteProcess);
            }
        }