コード例 #1
0
ファイル: CfrRuntime.cs プロジェクト: xmcy0011/NanUI
        /// <summary>
        /// Post a task for execution on the specified thread. Equivalent to using
        /// CfrTaskRunner.GetForThread(threadId).PostTask(task).
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_task_capi.h">cef/include/capi/cef_task_capi.h</see>.
        /// </remarks>
        public static bool PostTask(CfxThreadId threadId, CfrTask task)
        {
            var call = new CfxRuntimePostTaskRenderProcessCall();

            call.threadId = (int)threadId;
            call.task     = CfrObject.Unwrap(task);
            call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);
            return(call.__retval);
        }
コード例 #2
0
ファイル: CfrRuntime.cs プロジェクト: xmcy0011/NanUI
        /// <summary>
        /// Register a new V8 extension with the specified JavaScript extension code and
        /// handler. Functions implemented by the handler are prototyped using the
        /// keyword 'native'. The calling of a native function is restricted to the scope
        /// in which the prototype of the native function is defined. This function may
        /// only be called on the render process main thread.
        /// Example JavaScript extension code: &lt;pre>
        /// // create the 'example' global object if it doesn't already exist.
        /// if (!example)
        /// example = {};
        /// // create the 'example.test' global object if it doesn't already exist.
        /// if (!example.test)
        /// example.test = {};
        /// (function() {
        /// // Define the function 'example.test.myfunction'.
        /// example.test.myfunction = function() {
        /// // Call CfrV8Handler.Execute() with the function name 'MyFunction'
        /// // and no arguments.
        /// native function MyFunction();
        /// return MyFunction();
        /// };
        /// // Define the getter function for parameter 'example.test.myparam'.
        /// example.test.__defineGetter__('myparam', function() {
        /// // Call CfrV8Handler.Execute() with the function name 'GetMyParam'
        /// // and no arguments.
        /// native function GetMyParam();
        /// return GetMyParam();
        /// });
        /// // Define the setter function for parameter 'example.test.myparam'.
        /// example.test.__defineSetter__('myparam', function(b) {
        /// // Call CfrV8Handler.Execute() with the function name 'SetMyParam'
        /// // and a single argument.
        /// native function SetMyParam();
        /// if(b) SetMyParam(b);
        /// });
        /// // Extension definitions can also contain normal JavaScript variables
        /// // and functions.
        /// var myint = 0;
        /// example.test.increment = function() {
        /// myint += 1;
        /// return myint;
        /// };
        /// })();
        /// &lt;/pre> Example usage in the page: &lt;pre>
        /// // Call the function.
        /// example.test.myfunction();
        /// // Set the parameter.
        /// example.test.myparam = value;
        /// // Get the parameter.
        /// value = example.test.myparam;
        /// // Call another function.
        /// example.test.increment();
        /// &lt;/pre>
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_v8_capi.h">cef/include/capi/cef_v8_capi.h</see>.
        /// </remarks>
        public static bool RegisterExtension(string extensionName, string javascriptCode, CfrV8Handler handler)
        {
            var call = new CfxRuntimeRegisterExtensionRenderProcessCall();

            call.extensionName  = extensionName;
            call.javascriptCode = javascriptCode;
            call.handler        = CfrObject.Unwrap(handler);
            call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);
            return(call.__retval);
        }
コード例 #3
0
ファイル: CfrApp.cs プロジェクト: xmcy0011/NanUI
            /// <summary>
            /// Set the return value for the <see cref="CfrApp.GetRenderProcessHandler"/> render process callback.
            /// Calling SetReturnValue() more then once per callback or from different event handlers will cause an exception to be thrown.
            /// </summary>
            public void SetReturnValue(CfrRenderProcessHandler returnValue)
            {
                if (returnValueSet)
                {
                    throw new CfxException("The return value has already been set");
                }
                var call = new CfxGetRenderProcessHandlerSetReturnValueRenderProcessCall();

                call.eventArgsId = eventArgsId;
                call.value       = CfrObject.Unwrap(returnValue);
                call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);
                returnValueSet = true;
            }
コード例 #4
0
ファイル: CfrRuntime.cs プロジェクト: xmcy0011/NanUI
        /// <summary>
        /// This function should be called from the render process startup callback
        /// provided to CfxRuntime.Initialize() in the browser process. It will
        /// call into the render process passing in the provided |application|
        /// object and block until the render process exits.
        /// The |application| object will receive CEF framework callbacks
        /// from within the render process.
        /// </summary>
        public static int ExecuteProcess(CfrApp application)
        {
            var call = new CfxRuntimeExecuteProcessRenderProcessCall();

            call.application = CfrObject.Unwrap(application);
            // Looks like this almost never returns with a value
            // from the call into the render process. Probably the
            // IPC connection doesn't get a chance to send over the
            // return value from CfxRuntime.ExecuteProcess() when the
            // render process exits. So we don't throw an exception but
            // use a return value of -2 to indicate connection lost.
            try {
                call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);
                return(call.__retval);
            } catch (CfxException) {
                return(-2);
            }
        }
コード例 #5
0
ファイル: RemoteCall.cs プロジェクト: xmcy0011/NanUI
 internal void RequestExecution(CfrObject owner)
 {
     RequestExecution(owner.connection);
 }