Пример #1
0
        /// <summary>
        /// Send a message to the specified |targetProcess|. Returns true (1) if the
        /// message was sent successfully.
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_browser_capi.h">cef/include/capi/cef_browser_capi.h</see>.
        /// </remarks>
        public bool SendProcessMessage(CfxProcessId targetProcess, CfrProcessMessage message)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxBrowserSendProcessMessageRemoteCall();

            call.@this         = RemotePtr.ptr;
            call.targetProcess = (int)targetProcess;
            if (!CfrObject.CheckConnection(message, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "message");
            }
            call.message = CfrObject.Unwrap(message).ptr;
            call.RequestExecution(connection);
            return(call.__retval);
        }
Пример #2
0
        /// <summary>
        /// Post a task for delayed execution on the specified thread. Equivalent to
        /// using CfrTaskRunner.GetForThread(threadId).PostDelayedTask(task,
        /// delay_ms).
        /// </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 PostDelayedTask(CfxThreadId threadId, CfrTask task, long delayMs)
        {
            var connection = CfxRemoteCallContext.CurrentContext.connection;
            var call       = new CfxRuntimePostDelayedTaskRemoteCall();

            call.threadId = (int)threadId;
            if (!CfrObject.CheckConnection(task, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "task");
            }
            call.task    = CfrObject.Unwrap(task).ptr;
            call.delayMs = delayMs;
            call.RequestExecution(connection);
            return(call.__retval);
        }
Пример #3
0
        /// <summary>
        /// Create a new server that binds to |address| and |port|. |address| must be a
        /// valid IPv4 or IPv6 address (e.g. 127.0.0.1 or ::1) and |port| must be a port
        /// number outside of the reserved range (e.g. between 1025 and 65535 on most
        /// platforms). |backlog| is the maximum number of pending connections. A new
        /// thread will be created for each CreateServer call (the "dedicated server
        /// thread"). It is therefore recommended to use a different CfrServerHandler
        /// instance for each CreateServer call to avoid thread safety issues in the
        /// CfrServerHandler implementation. The
        /// CfrServerHandler.OnServerCreated function will be called on the
        /// dedicated server thread to report success or failure. See
        /// CfrServerHandler.OnServerCreated documentation for a description of
        /// server lifespan.
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_server_capi.h">cef/include/capi/cef_server_capi.h</see>.
        /// </remarks>
        public static void Create(string address, ushort port, int backlog, CfrServerHandler handler)
        {
            var connection = CfxRemoteCallContext.CurrentContext.connection;
            var call       = new CfxServerCreateRemoteCall();

            call.address = address;
            call.port    = port;
            call.backlog = backlog;
            if (!CfrObject.CheckConnection(handler, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "handler");
            }
            call.handler = CfrObject.Unwrap(handler).ptr;
            call.RequestExecution(connection);
        }
        protected override void RemoteProcedure()
        {
            var self = (CfrRenderProcessHandler)System.Runtime.InteropServices.GCHandle.FromIntPtr(gcHandlePtr).Target;

            if (self == null || self.CallbacksDisabled)
            {
                return;
            }
            var e = new CfrGetLoadHandlerEventArgs(this);

            e.connection = CfxRemoteCallContext.CurrentContext.connection;
            self.m_GetLoadHandler?.Invoke(self, e);
            e.connection = null;
            __retval     = CfrObject.Unwrap(e.m_returnValue).ptr;
        }
Пример #5
0
        /// <summary>
        /// Associates a value with the specified identifier and returns true (1) on
        /// success. Returns false (0) if this function is called incorrectly or an
        /// exception is thrown. For read-only values this function will return true
        /// (1) even though assignment failed.
        /// </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 bool SetValue(int index, CfrV8Value value)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxV8ValueSetValueByIndexRemoteCall();

            call.@this = RemotePtr.ptr;
            call.index = index;
            if (!CfrObject.CheckConnection(value, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "value");
            }
            call.value = CfrObject.Unwrap(value).ptr;
            call.RequestExecution(connection);
            return(call.__retval);
        }
Пример #6
0
        /// <summary>
        /// Sets the value at the specified key as type list. Returns true (1) if the
        /// value was set successfully. If |value| is currently owned by another object
        /// then the value will be copied and the |value| reference will not change.
        /// Otherwise, ownership will be transferred to this object and the |value|
        /// reference will be invalidated.
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_values_capi.h">cef/include/capi/cef_values_capi.h</see>.
        /// </remarks>
        public bool SetList(string key, CfrListValue value)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxDictionaryValueSetListRemoteCall();

            call.@this = RemotePtr.ptr;
            call.key   = key;
            if (!CfrObject.CheckConnection(value, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "value");
            }
            call.value = CfrObject.Unwrap(value).ptr;
            call.RequestExecution(connection);
            return(call.__retval);
        }
Пример #7
0
        /// <summary>
        /// Post a task for delayed execution on the thread associated with this task
        /// runner. Execution will occur asynchronously. Delayed tasks are not
        /// supported on V8 WebWorker threads and will be executed without the
        /// specified delay.
        /// </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 bool PostDelayedTask(CfrTask task, long delayMs)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxTaskRunnerPostDelayedTaskRemoteCall();

            call.@this = RemotePtr.ptr;
            if (!CfrObject.CheckConnection(task, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "task");
            }
            call.task    = CfrObject.Unwrap(task).ptr;
            call.delayMs = delayMs;
            call.RequestExecution(connection);
            return(call.__retval);
        }
Пример #8
0
        /// <summary>
        /// Set all values at one time.
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_request_capi.h">cef/include/capi/cef_request_capi.h</see>.
        /// </remarks>
        public void Set(string url, string method, CfrPostData postData, System.Collections.Generic.List <string[]> headerMap)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxRequestSetRemoteCall();

            call.@this  = RemotePtr.ptr;
            call.url    = url;
            call.method = method;
            if (!CfrObject.CheckConnection(postData, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "postData");
            }
            call.postData  = CfrObject.Unwrap(postData).ptr;
            call.headerMap = headerMap;
            call.RequestExecution(connection);
        }
Пример #9
0
        /// <summary>
        /// Associates a value with the specified identifier and returns true (1) on
        /// success. Returns false (0) if this function is called incorrectly or an
        /// exception is thrown. For read-only values this function will return true
        /// (1) even though assignment failed.
        /// </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 bool SetValue(string key, CfrV8Value value, CfxV8PropertyAttribute attribute)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxV8ValueSetValueByKeyRemoteCall();

            call.@this = RemotePtr.ptr;
            call.key   = key;
            if (!CfrObject.CheckConnection(value, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "value");
            }
            call.value     = CfrObject.Unwrap(value).ptr;
            call.attribute = (int)attribute;
            call.RequestExecution(connection);
            return(call.__retval);
        }
Пример #10
0
        /// <summary>
        /// Execute the function using the current V8 context. This function should
        /// only be called from within the scope of a CfrV8Handler or
        /// CfrV8Accessor callback, or in combination with calling enter() and
        /// exit() on a stored CfrV8Context reference. |object| is the receiver
        /// ('this' object) of the function. If |object| is NULL the current context's
        /// global object will be used. |arguments| is the list of arguments that will
        /// be passed to the function. Returns the function return value on success.
        /// Returns NULL if this function is called incorrectly or an exception is
        /// thrown.
        /// </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 CfrV8Value ExecuteFunction(CfrV8Value @object, CfrV8Value[] arguments)
        {
            var call = new CfxV8ValueExecuteFunctionRemoteCall();

            call.@this   = RemotePtr.ptr;
            call.@object = CfrObject.Unwrap(@object).ptr;
            if (arguments != null)
            {
                call.arguments = new IntPtr[arguments.Length];
                for (int i = 0; i < arguments.Length; ++i)
                {
                    call.arguments[i] = CfrObject.Unwrap(arguments[i]).ptr;
                }
            }
            call.RequestExecution(RemotePtr.connection);
            return(CfrV8Value.Wrap(new RemotePtr(call.__retval)));
        }
Пример #11
0
        /// <summary>
        /// Execute the function using the current V8 context. This function should
        /// only be called from within the scope of a CfrV8Handler or
        /// CfrV8Accessor callback, or in combination with calling enter() and
        /// exit() on a stored CfrV8Context reference. |object| is the receiver
        /// ('this' object) of the function. If |object| is NULL the current context's
        /// global object will be used. |arguments| is the list of arguments that will
        /// be passed to the function. Returns the function return value on success.
        /// Returns NULL if this function is called incorrectly or an exception is
        /// thrown.
        /// </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 CfrV8Value ExecuteFunction(CfrV8Value @object, CfrV8Value[] arguments)
        {
            var call = new CfxV8ValueExecuteFunctionRenderProcessCall();

            call.self    = CfrObject.Unwrap(this);
            call.@object = CfrObject.Unwrap(@object);
            if (arguments != null)
            {
                call.arguments = new IntPtr[arguments.Length];
                for (int i = 0; i < arguments.Length; ++i)
                {
                    call.arguments[i] = CfrObject.Unwrap(arguments[i]);
                }
            }
            call.RequestExecution(this);
            return(CfrV8Value.Wrap(call.__retval));
        }
Пример #12
0
        protected override void RemoteProcedure()
        {
            var self = (CfrV8Interceptor)System.Runtime.InteropServices.GCHandle.FromIntPtr(gcHandlePtr).Target;

            if (self == null || self.CallbacksDisabled)
            {
                return;
            }
            var e = new CfrGetByNameEventArgs(this);

            self.m_GetByName?.Invoke(self, e);
            e.m_isInvalid  = true;
            object_release = e.m_object_wrapped == null? 1 : 0;
            retval         = CfrObject.Unwrap(e.m_retval_wrapped).ptr;
            exception      = e.m_exception_wrapped;
            __retval       = e.m_returnValue ? 1 : 0;
        }
Пример #13
0
        /// <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 CfxRuntimeExecuteProcessRemoteCall();

            call.application = CfrObject.Unwrap(application).ptr;
            // 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();
                return(call.__retval);
            } catch (CfxException) {
                return(-2);
            }
        }
        protected override void RemoteProcedure()
        {
            var self = (CfrV8Accessor)System.Runtime.InteropServices.GCHandle.FromIntPtr(gcHandlePtr).Target;

            if (self == null || self.CallbacksDisabled)
            {
                return;
            }
            var e = new CfrV8AccessorGetEventArgs(this);

            e.connection = CfxRemoteCallContext.CurrentContext.connection;
            self.m_Get?.Invoke(self, e);
            e.connection   = null;
            object_release = e.m_object_wrapped == null? 1 : 0;
            retval         = CfrObject.Unwrap(e.m_retval_wrapped).ptr;
            exception      = e.m_exception_wrapped;
            __retval       = e.m_returnValue ? 1 : 0;
        }
Пример #15
0
        /// <summary>
        /// Create a new CfrV8Value object of type object with optional accessor
        /// and/or interceptor. This function should only be called from within the scope
        /// of a CfrRenderProcessHandler, CfrV8Handler or CfrV8Accessor
        /// callback, or in combination with calling enter() and exit() on a stored
        /// CfrV8Context reference.
        /// </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 CfrV8Value CreateObject(CfrV8Accessor accessor, CfrV8Interceptor interceptor)
        {
            var connection = CfxRemoteCallContext.CurrentContext.connection;
            var call       = new CfxV8ValueCreateObjectRemoteCall();

            if (!CfrObject.CheckConnection(accessor, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "accessor");
            }
            call.accessor = CfrObject.Unwrap(accessor).ptr;
            if (!CfrObject.CheckConnection(interceptor, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "interceptor");
            }
            call.interceptor = CfrObject.Unwrap(interceptor).ptr;
            call.RequestExecution(connection);
            return(CfrV8Value.Wrap(new RemotePtr(connection, call.__retval)));
        }
Пример #16
0
        /// <summary>
        /// Create a new URL request that will be treated as originating from this
        /// frame and the associated browser. This request may be intercepted by the
        /// client via CfrResourceRequestHandler or CfrSchemeHandlerFactory.
        /// Use CfrUrlRequest.Create instead if you do not want the request to have
        /// this association, in which case it may be handled differently (see
        /// documentation on that function). Requests may originate from both the
        /// browser process and the render process.
        ///
        /// For requests originating from the browser process:
        ///   - POST data may only contain a single element of type PDE_TYPE_FILE or
        ///     PDE_TYPE_BYTES.
        /// For requests originating from the render process:
        ///   - POST data may only contain a single element of type PDE_TYPE_BYTES.
        ///   - If the response contains Content-Disposition or Mime-Type header values
        ///     that would not normally be rendered then the response may receive
        ///     special handling inside the browser (for example, via the file download
        ///     code path instead of the URL request code path).
        ///
        /// The |request| object will be marked as read-only after calling this
        /// function.
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_frame_capi.h">cef/include/capi/cef_frame_capi.h</see>.
        /// </remarks>
        public CfrUrlRequest CreateUrlRequest(CfrRequest request, CfrUrlRequestClient client)
        {
            var connection = RemotePtr.connection;
            var call       = new CfxFrameCreateUrlRequestRemoteCall();

            call.@this = RemotePtr.ptr;
            if (!CfrObject.CheckConnection(request, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "request");
            }
            call.request = CfrObject.Unwrap(request).ptr;
            if (!CfrObject.CheckConnection(client, connection))
            {
                throw new ArgumentException("Render process connection mismatch.", "client");
            }
            call.client = CfrObject.Unwrap(client).ptr;
            call.RequestExecution(connection);
            return(CfrUrlRequest.Wrap(new RemotePtr(connection, call.__retval)));
        }