internal unsafe override int set(cef_v8accessor_t* self, cef_string_t* name, cef_v8value_t* @object, cef_v8value_t* value, cef_string_t* exception)
        {
            var prop = this.dispatchTable.GetOrDefault(name);
            if (prop == null) return 0;

            var method = prop.SetMethod;
            if (method == null) return 0;

            var instance = this.instance;
            if (instance == null)
            {
                // TODO: self must be got from obj's userdata
                throw new NotImplementedException();
            }

            try
            {
                method.Invoke(instance, 1, &value, null);
            }
            catch (Exception ex)
            {
                // TODO: how exceptions must be formatted ?
                cef_string_t.Copy(ex.ToString(), exception);
            }

            // TODO: this pointer must be typed
            cef_v8value_t.invoke_release((cef_base_t*)@object);
            cef_v8value_t.invoke_release((cef_base_t*)value);

            return 1;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called to get an accessor value. |name| is the name of the property
        /// being accessed. |object| is the This() object from V8's AccessorInfo
        /// structure. |retval| is the value to return for this property. Return
        /// true if handled.
        /// </summary>
        internal virtual int get(cef_v8accessor_t* self, /*const*/ cef_string_t* name, cef_v8value_t* @object, cef_v8value_t** retval, cef_string_t* exception)
        {
            ThrowIfObjectDisposed();

            var m_name = cef_string_t.ToString(name);
            var m_obj = CefV8Value.From(@object);
            CefV8Value m_returnValue;
            string mException;

            var handled = this.Get(m_name, m_obj, out m_returnValue, out mException);

            if (handled)
            {
                if (mException != null)
                {
                    cef_string_t.Copy(mException, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.GetNativePointerAndAddRef();
                }
            }

            return handled ? 1 : 0;
        }
 /// <summary>
 /// Called to retrieve proxy information for the specified |url|.
 /// </summary>
 private void get_proxy_for_url(cef_proxy_handler_t* self, /*const*/ cef_string_t* url, cef_proxy_info_t* proxy_info)
 {
     ThrowIfObjectDisposed();
     string m_url = cef_string_t.ToString(url);
     CefProxyInfo m_info = CefProxyInfo.From(proxy_info);
     GetProxyForUrl(m_url, m_info);
 }
 /// <summary>
 /// Sets the directory path that will be used for storing cookie data. If
 /// |path| is empty data will be stored in memory only. Returns false if
 /// cookies cannot be accessed.
 /// </summary>
 public bool SetStoragePath(string path)
 {
     fixed (char* path_str = path)
     {
         var m_path = new cef_string_t(path_str, path != null ? path.Length : 0);
         return cef_cookie_manager_t.invoke_set_storage_path(this.ptr, &m_path) != 0;
     }
 }
 /// <summary>
 /// Sets a cookie given a valid URL and explicit user-provided cookie
 /// attributes. This function expects each attribute to be well-formed. It will
 /// check for disallowed characters (e.g. the ';' character is disallowed
 /// within the cookie value attribute) and will return false without setting
 /// the cookie if such characters are found. This method must be called on the
 /// IO thread.
 /// </summary>
 public bool SetCookie(string url, CefCookie cookie)
 {
     fixed (char* url_str = url)
     {
         var m_url = new cef_string_t(url_str, url != null ? url.Length : 0);
         return cef_cookie_manager_t.invoke_set_cookie(this.ptr, &m_url, cookie.GetNativeHandle()) != 0;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Moves the cursor to the specified file in the archive.
        /// If |caseSensitive| is true then the search will be case sensitive.
        /// Returns true if the cursor position was set successfully.
        /// </summary>
        public bool MoveToFile(string fileName, bool caseSensitive)
        {
            fixed (char* fileName_str = fileName)
            {
                var n_fileName = new cef_string_t(fileName_str, fileName != null ? fileName.Length : 0);

                return cef_zip_reader_t.invoke_move_to_file(this.ptr, &n_fileName, caseSensitive ? 1 : 0) != 0;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Set the response mime type.
        /// </summary>
        public void SetMimeType(string mimeType)
        {
            fixed (char* mimeType_str = mimeType)
            {
                var n_mimeType = new cef_string_t(mimeType_str, mimeType != null ? mimeType.Length : 0);

                cef_response_t.invoke_set_mime_type(this.ptr, &n_mimeType);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Called when the browser's zoom level has been set to |zoomLevel| for
        /// the given |url|. Return true (1) to indicate that the new setting has
        /// been handled. Return false (0) to use the browser's default zoom
        /// handling behavior.
        /// </summary>
        private int on_set_zoom_level(cef_zoom_handler_t* self, cef_browser_t* browser, /*const*/ cef_string_t* url, double zoomLevel)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_url = cef_string_t.ToString(url);

            return OnSetZoomLevel(m_browser, m_url, zoomLevel) ? 1 : 0;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Returns a complete URL based on the document base URL and the specified partial URL.
 /// </summary>
 public string GetCompleteURL(string partialUrl)
 {
     fixed (char* partialUrl_str = partialUrl)
     {
         var n_partialUrl = new cef_string_t(partialUrl_str, partialUrl != null ? partialUrl.Length : 0);
         var nResult = cef_domdocument_t.invoke_get_complete_url(this.ptr, &n_partialUrl);
         return cef_string_userfree.GetStringAndFree(nResult);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new cookie manager. If |path| is empty data will be stored in
 /// memory only. Returns NULL if creation fails.
 /// </summary>
 public static CefCookieManager CreateManager(string path)
 {
     fixed (char* path_str = path)
     {
         var m_path = new cef_string_t(path_str, path != null ? path.Length : 0);
         var m_cookie_manager = NativeMethods.cef_cookie_manager_create_manager(&m_path);
         return CefCookieManager.FromOrDefault(m_cookie_manager);
     }
 }
        /// <summary>
        /// Called when a geolocation access request is canceled.
        /// |requesting_url| is the URL that originally requested permission and
        /// |request_id| is the unique ID for the permission request.
        /// </summary>
        private void on_cancel_geolocation_permission(cef_geolocation_handler_t* self, cef_browser_t* browser, /*const*/ cef_string_t* requesting_url, int request_id)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_requestingUrl = cef_string_t.ToString(requesting_url);

            OnCancelGeolocationPermission(m_browser, m_requestingUrl, request_id);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns the value of the attribute with the specified qualified name.
        /// </summary>
        public string GetAttribute(string qualifiedName)
        {
            fixed (char* qualifiedName_str = qualifiedName)
            {
                var n_qualifiedName = new cef_string_t(qualifiedName_str, qualifiedName != null ? qualifiedName.Length : 0);

                var nResult = cef_xml_reader_t.invoke_get_attribute_byqname(this.ptr, &n_qualifiedName);
                return cef_string_userfree.GetStringAndFree(nResult);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get the value for the specified response header field.
        /// </summary>
        public string GetHeader(string name)
        {
            fixed (char* name_str = name)
            {
                var n_name = new cef_string_t(name_str, name != null ? name.Length : 0);

                var nResult = cef_response_t.invoke_get_header(this.ptr, &n_name);
                return cef_string_userfree.GetStringAndFree(nResult);
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Create a new CefStreamWriter object for a file.
 /// </summary>
 public static CefStreamWriter Create(string fileName)
 {
     fixed (char* fileName_str = fileName)
     {
         var n_fileName = new cef_string_t(fileName_str, fileName != null ? fileName.Length : 0);
         return CefStreamWriter.From(
             NativeMethods.cef_stream_writer_create_for_file(&n_fileName)
             );
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Returns the document element with the specified ID value.
 /// </summary>
 public CefDomNode GetElementById(string id)
 {
     fixed (char* id_str = id)
     {
         var n_id = new cef_string_t(id_str, id != null ? id.Length : 0);
         return CefDomNode.From(
             cef_domdocument_t.invoke_get_element_by_id(this.ptr, &n_id)
             );
     }
 }
        /// <summary>
        /// Called when a frame's address has changed.
        /// </summary>
        private void on_address_change(cef_display_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, /*const*/ cef_string_t* url)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_frame = CefFrame.From(frame);
            var m_url = cef_string_t.ToString(url);

            this.OnAddressChange(m_browser, m_frame, m_url);
        }
        /// <summary>
        /// Called when a page requests permission to access geolocation information.
        /// |requesting_url| is the URL requesting permission and |request_id| is the
        /// unique ID for the permission request. Call
        /// cef_geolocation_callback_t::Continue to allow or deny the permission
        /// request.
        /// </summary>
        private void on_request_geolocation_permission(cef_geolocation_handler_t* self, cef_browser_t* browser, /*const*/ cef_string_t* requesting_url, int request_id, cef_geolocation_callback_t* callback)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_requestingUrl = cef_string_t.ToString(requesting_url);
            var m_callback = CefGeolocationCallback.From(callback);

            OnRequestGeolocationPermission(m_browser, m_requestingUrl, request_id, m_callback);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Execute a string of JavaScript code in this frame.
        /// The |script_url| parameter is the URL where the script in question can be found, if any.
        /// The renderer may request this URL to show the developer the source of the error.
        /// The |start_line| parameter is the base line number to use for error reporting.
        /// </summary>
        public void ExecuteJavaScript(string jsCode, string scriptUrl, int startLine)
        {
            fixed (char* jsCode_str = jsCode)
            fixed (char* scriptUrl_str = scriptUrl)
            {
                var n_jsCode = new cef_string_t(jsCode_str, jsCode != null ? jsCode.Length : 0);
                var n_scriptUrl = new cef_string_t(scriptUrl_str, scriptUrl != null ? scriptUrl.Length : 0);

                cef_frame_t.invoke_execute_java_script(this.ptr, &n_jsCode, &n_scriptUrl, startLine);
            }
        }
Exemplo n.º 19
0
        public bool Append(string key, string value)
        {
            fixed (char* key_str = key)
            fixed (char* value_str = value)
            {
                var nKey = new cef_string_t(key_str, key != null ? key.Length : 0);
                var nValue = new cef_string_t(value_str, value != null ? value.Length : 0);

                return NativeMethods.cef_string_map_append(this.handle, &nKey, &nValue) != 0;
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Delete all cookies that match the specified parameters. If both |url| and
 /// values |cookieName| are specified all host and domain cookies matching
 /// both will be deleted. If only |url| is specified all host cookies (but not
 /// domain cookies) irrespective of path will be deleted. If |url| is empty all
 /// cookies for all hosts and domains will be deleted. Returns false if a non-
 /// empty invalid URL is specified or if cookies cannot be accessed. This
 /// method must be called on the IO thread.
 /// </summary>
 public bool DeleteCookies(string url, string cookieName)
 {
     fixed (char* url_str = url)
     {
         var m_url = new cef_string_t(url_str, url != null ? url.Length : 0);
         fixed (char* cookieName_str = cookieName)
         {
             var m_cookieName = new cef_string_t(cookieName_str, cookieName != null ? cookieName.Length : 0);
             return cef_cookie_manager_t.invoke_delete_cookies(this.ptr, &m_url, &m_cookieName) != 0;
         }
     }
 }
        /// <summary>
        /// Return a new scheme handler instance to handle the request. |browser| will
        /// be the browser window that initiated the request. If the request was
        /// initiated using the CefWebURLRequest API |browser| will be NULL.
        /// </summary>
        private cef_scheme_handler_t* create(cef_scheme_handler_factory_t* self, cef_browser_t* browser, /*const*/ cef_string_t* scheme_name, cef_request_t* request)
        {
            ThrowIfObjectDisposed();

            var mBrowser = CefBrowser.FromOrDefault(browser);
            var m_schemeName = cef_string_t.ToString(scheme_name);
            var m_request = CefRequest.From(request);

            var handler = this.Create(mBrowser, m_schemeName, m_request);

            return handler.GetNativePointerAndAddRef();
        }
        /// <summary>
        /// Called  to run a JavaScript alert message. Return false to display
        /// the default alert or true if you displayed a custom alert.
        /// </summary>
        private int on_jsalert(cef_jsdialog_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, /*const*/ cef_string_t* message)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_frame = CefFrame.From(frame);
            var m_message = cef_string_t.ToString(message);

            var handled = this.OnJSAlert(m_browser, m_frame, m_message);

            return handled ? 1 : 0;
        }
        /// <summary>
        /// Called on the UI thread before a script extension is loaded.
        /// Return false to let the extension load normally.
        /// </summary>
        private int on_before_script_extension_load(cef_permission_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, /*const*/ cef_string_t* extensionName)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_frame = CefFrame.From(frame);
            var m_extensionName = cef_string_t.ToString(extensionName);

            var handled = this.OnBeforeScriptExtensionLoad(m_browser, m_frame, m_extensionName);

            return handled ? 1 : 0;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Append a new key/value pair at the end of the string multimap.
        /// </summary>
        public void Append(string key, string value)
        {
            fixed (char* key_str = key)
            fixed (char* value_str = value)
            {
                var n_key = new cef_string_t(key_str, key != null ? key.Length : 0);
                var n_value = new cef_string_t(value_str, value != null ? value.Length : 0);

                var result = NativeMethods.cef_string_multimap_append(this.handle, &n_key, &n_value);

                if (result == 0) throw new InvalidOperationException("CefStringMultiMap.Append failed.");
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Create a new CefXmlReader object.
        /// The returned object's methods can only be called from the thread that created the object.
        /// </summary>
        public static CefXmlReader Create(CefStreamReader stream, CefXmlEncodingType encodingType, string uri)
        {
            fixed (char* uri_str = uri)
            {
                var n_uri = new cef_string_t(uri_str, uri != null ? uri.Length : 0);

                return CefXmlReader.From(
                    NativeMethods.cef_xml_reader_create(
                        stream.GetNativePointerAndAddRef(),
                        (cef_xml_encoding_type_t)encodingType,
                        &n_uri)
                        );
            }
        }
        /// <summary>
        /// Register a custom scheme. This method should not be called for the built-in
        /// HTTP, HTTPS, FILE, FTP, ABOUT and DATA schemes.
        ///
        /// If |is_standard| is true the scheme will be treated as a standard scheme.
        /// Standard schemes are subject to URL canonicalization and parsing rules as
        /// defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 available
        /// at http://www.ietf.org/rfc/rfc1738.txt
        ///
        /// In particular, the syntax for standard scheme URLs must be of the form:
        /// <pre>
        ///  [scheme]://[username]:[password]@[host]:[port]/[url-path]
        /// </pre>
        /// Standard scheme URLs must have a host component that is a fully qualified
        /// domain name as defined in Section 3.5 of RFC 1034 [13] and Section 2.1 of
        /// RFC 1123. These URLs will be canonicalized to "scheme://host/path" in the
        /// simplest case and "scheme://*****:*****@host:port/path" in the most
        /// explicit case. For example, "scheme:host/path" and "scheme:///host/path"
        /// will both be canonicalized to "scheme://host/path". The origin of a
        /// standard scheme URL is the combination of scheme, host and port (i.e.,
        /// "scheme://host:port" in the most explicit case).
        ///
        /// For non-standard scheme URLs only the "scheme:" component is parsed and
        /// canonicalized. The remainder of the URL will be passed to the handler
        /// as-is. For example, "scheme:///some%20text" will remain the same.
        /// Non-standard scheme URLs cannot be used as a target for form submission.
        ///
        /// If |is_local| is true the scheme will be treated as local (i.e., with the
        /// same security rules as those applied to "file" URLs). Normal pages cannot
        /// link to or access local URLs. Also, by default, local URLs can only perform
        /// XMLHttpRequest calls to the same URL (origin + path) that originated the
        /// request. To allow XMLHttpRequest calls from a local URL to other URLs with
        /// the same origin set the CefSettings.file_access_from_file_urls_allowed
        /// value to true. To allow XMLHttpRequest calls from a local URL to all
        /// origins set the CefSettings.universal_access_from_file_urls_allowed value
        /// to true.
        ///
        /// If |is_display_isolated| is true the scheme will be treated as display-
        /// isolated. This means that pages cannot display these URLs unless they are
        /// from the same scheme. For example, pages in another origin cannot create
        /// iframes or hyperlinks to URLs with this scheme.
        ///
        /// This function may be called on any thread. It should only be called once
        /// per unique |scheme_name| value. If |scheme_name| is already registered or
        /// if an error occurs this method will return false.
        /// </summary>
        public bool AddCustomScheme(string schemeName, bool isStandard, bool isLocal, bool isDisplayIsolated)
        {
            fixed (char* schemeName_str = schemeName)
            {
                var n_schemeName = new cef_string_t(schemeName_str, schemeName.Length);

                return cef_scheme_registrar_t.invoke_add_custom_scheme(
                    this.ptr,
                    &n_schemeName,
                    isStandard ? 1 : 0,
                    isLocal ? 1 : 0,
                    isDisplayIsolated ? 1 : 0
                    ) != 0;
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Retrieve response header information. If the response length is not
        /// known set |response_length| to -1 and ReadResponse() will be called
        /// until it returns false. If the response length is known set
        /// |response_length| to a positive value and ReadResponse() will be
        /// called until it returns false or the specified number of bytes have
        /// been read. Use the |response| object to set the mime type, http
        /// status code and other optional header values.
        /// To redirect the request to a new URL set |redirectUrl| to the new URL.
        /// </summary>
        private void get_response_headers(cef_scheme_handler_t* self, cef_response_t* response, long* response_length, cef_string_t* redirectUrl)
        {
            ThrowIfObjectDisposed();

            var mResponse = CefResponse.From(response);
            long mResponseLength;
            string mRedirectUrl = null;

            this.GetResponseHeaders(mResponse, out mResponseLength, ref mRedirectUrl);

            *response_length = mResponseLength;
            if (mRedirectUrl != null) {
                cef_string_t.Copy(mRedirectUrl, redirectUrl);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Called when the browser wants to retrieve the zoom level for the
        /// given |url|. Return true (1) if |zoomLevel| has been set to the
        /// custom zoom level. Return false (0) for the browser's default zoom
        /// handling behavior.
        /// </summary>
        private int on_get_zoom_level(cef_zoom_handler_t* self, cef_browser_t* browser, /*const*/ cef_string_t* url, double* zoomLevel)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_url = cef_string_t.ToString(url);

            double m_zoomLevel = 0;
            if (OnGetZoomLevel(m_browser, m_url, ref m_zoomLevel))
            {
                *zoomLevel = m_zoomLevel;
                return 1;
            }
            else
                return 0;
        }
Exemplo n.º 29
0
        /// <summary>
        /// Called to optionally override the default text for a context menu
        /// item. |label| contains the default text and may be modified to
        /// substitute alternate text.
        /// </summary>
        private void get_menu_label(cef_menu_handler_t* self, cef_browser_t* browser, cef_menu_id_t menuId, cef_string_t* label)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_menuId = (CefHandlerMenuId)menuId;
            var m_label = cef_string_t.ToString(label);

            var o_label = m_label;
            this.GetMenuLabel(m_browser, m_menuId, ref m_label);

            if ((object)m_label != (object)o_label)
            {
                cef_string_t.Copy(m_label, label);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Called when the browser fails to load a resource. |errorCode| is the
        /// error code number and |failedUrl| is the URL that failed to load. To
        /// provide custom error text assign the text to |errorText| and return
        /// true. Otherwise, return false for the default error text. See
        /// net\base\net_error_list.h for complete descriptions of the error
        /// codes.
        /// </summary>
        private int on_load_error(cef_load_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_handler_errorcode_t errorCode, /*const*/ cef_string_t* failedUrl, cef_string_t* errorText)
        {
            ThrowIfObjectDisposed();

            var m_browser = CefBrowser.From(browser);
            var m_frame = CefFrame.From(frame);
            var m_failedUrl = cef_string_t.ToString(failedUrl);
            var m_errorText = cef_string_t.ToString(errorText);
            var c_errorText = m_errorText;
            var result = this.OnLoadError(m_browser, m_frame, (CefHandlerErrorCode)errorCode, m_failedUrl, ref m_errorText) ? 1 : 0;
            if ((object)c_errorText != (object)m_errorText)
            {
                cef_string_t.Copy(m_errorText, errorText);
            }
            return result;
        }
 public static extern int cef_string_list_value(cef_string_list *list, int index, ref cef_string_t value);