From d33f74f499db050efa3aff49cd3e7349a182fba2 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 14 Nov 2014 14:26:00 -0500 Subject: [PATCH 1/3] embedding: remove eutil::fptr_is_null, fix #3967, add Option<> to fptrs --- ports/cef/command_line.rs | 4 +- ports/cef/core.rs | 18 +- ports/cef/eutil.rs | 4 - ports/cef/string.rs | 20 +-- ports/cef/string_list.rs | 13 +- ports/cef/string_map.rs | 16 +- ports/cef/types.rs | 360 +++++++++++++++++++------------------- 7 files changed, 213 insertions(+), 222 deletions(-) diff --git a/ports/cef/command_line.rs b/ports/cef/command_line.rs index 755e26696246..f8116f762ed2 100644 --- a/ports/cef/command_line.rs +++ b/ports/cef/command_line.rs @@ -35,7 +35,7 @@ pub fn command_line_init(argc: c_int, argv: *const *const u8) { let cl = command_line_new(); (*cl).argc = argc; (*cl).argv = a; - (*cl).cl.get_switch_value = command_line_get_switch_value; + (*cl).cl.get_switch_value = Some(command_line_get_switch_value); GLOBAL_CMDLINE = Some(cl); } } @@ -72,7 +72,7 @@ pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, na pub extern "C" fn cef_command_line_create() -> *mut cef_command_line_t { unsafe { let cl = command_line_new(); - (*cl).cl.get_switch_value = command_line_get_switch_value; + (*cl).cl.get_switch_value = Some(command_line_get_switch_value); mem::transmute(cl) } } diff --git a/ports/cef/core.rs b/ports/cef/core.rs index fc94574cb126..0d8d814634d6 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -4,14 +4,12 @@ use command_line::command_line_init; -use eutil::fptr_is_null; use geom::size::TypedSize2D; use glfw_app; use libc::{c_int, c_void}; use native; use servo::Browser; use servo_util::opts; -use std::mem; use types::{cef_app_t, cef_main_args_t, cef_settings_t}; #[no_mangle] @@ -25,15 +23,13 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t, } unsafe { command_line_init((*args).argc, (*args).argv); - let cb = (*application).get_browser_process_handler; - if !fptr_is_null(mem::transmute(cb)) { - let handler = cb(application); - if handler.is_not_null() { - let hcb = (*handler).on_context_initialized; - if !fptr_is_null(mem::transmute(hcb)) { - hcb(handler); - } - } + if !(*application).get_browser_process_handler.is_some() { return 1; } + let cb = (*application).get_browser_process_handler.unwrap(); + let handler = cb(application); + if handler.is_not_null() { + if !(*handler).on_context_initialized.is_some() { return 1; } + let hcb = (*handler).on_context_initialized.unwrap(); + hcb(handler); } } return 1 diff --git a/ports/cef/eutil.rs b/ports/cef/eutil.rs index d5f9760f6bb4..be0052bdfef7 100644 --- a/ports/cef/eutil.rs +++ b/ports/cef/eutil.rs @@ -6,10 +6,6 @@ use libc::c_int; use std::slice; use std::str; -pub fn fptr_is_null(fptr: *const u8) -> bool { - fptr.is_null() -} - pub fn slice_to_str(s: *const u8, l: uint, f: |&str| -> c_int) -> c_int { unsafe { slice::raw::buf_as_slice(s, l, |result| { diff --git a/ports/cef/string.rs b/ports/cef/string.rs index c9f74af624fd..36872ef19f90 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use eutil::{fptr_is_null, slice_to_str}; +use eutil::slice_to_str; use libc::{size_t, c_int, c_ushort,c_void}; use libc::types::os::arch::c95::wchar_t; use mem::{new0,newarray0,delete,deletearray}; @@ -52,8 +52,8 @@ pub extern "C" fn cef_string_userfree_utf16_free(cs: *mut cef_string_userfree_ut #[no_mangle] pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) { unsafe { - if !fptr_is_null(mem::transmute((*cs).dtor)) { - let dtor = (*cs).dtor; + if (*cs).dtor.is_some() { + let dtor = (*cs).dtor.unwrap(); dtor((*cs).str); } (*cs).length = 0; @@ -81,7 +81,7 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: * ptr::copy_memory((*output).str, src, src_len as uint); (*output).length = src_len; - (*output).dtor = string_utf8_dtor; + (*output).dtor = Some(string_utf8_dtor); } } else { (*output).str = mem::transmute(src); @@ -134,8 +134,8 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out #[no_mangle] pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) { unsafe { - if !fptr_is_null(mem::transmute((*cs).dtor)) { - let dtor = (*cs).dtor; + if (*cs).dtor.is_some() { + let dtor = (*cs).dtor.unwrap(); dtor((*cs).str); } (*cs).length = 0; @@ -163,7 +163,7 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou ptr::copy_memory((*output).str, src, src_len as uint); (*output).length = src_len; - (*output).dtor = string_utf16_dtor; + (*output).dtor = Some(string_utf16_dtor); } } else { (*output).str = mem::transmute(src); @@ -192,8 +192,8 @@ pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const c #[no_mangle] pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { unsafe { - if !fptr_is_null(mem::transmute((*cs).dtor)) { - let dtor = (*cs).dtor; + if (*cs).dtor.is_some() { + let dtor = (*cs).dtor.unwrap(); dtor((*cs).str); } (*cs).length = 0; @@ -221,7 +221,7 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp ptr::copy_memory((*output).str, src, src_len as uint); (*output).length = src_len; - (*output).dtor = string_wide_dtor; + (*output).dtor = Some(string_wide_dtor); } } else { (*output).str = mem::transmute(src); diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index 3a202e82d424..fde447ed94d9 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use eutil::fptr_is_null; use libc::{c_int}; use std::mem; use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set}; @@ -26,7 +25,7 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { #[no_mangle] pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int { unsafe { - if fptr_is_null(mem::transmute(lt)) { return 0; } + if lt.is_null() { return 0; } let v = string_list_to_vec(lt); (*v).len() as c_int } @@ -35,7 +34,7 @@ pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int { #[no_mangle] pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *const cef_string_t) { unsafe { - if fptr_is_null(mem::transmute(lt)) { return; } + if lt.is_null() { return; } let v = string_list_to_vec(lt); let cs = cef_string_userfree_utf8_alloc(); cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); @@ -46,7 +45,7 @@ pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *con #[no_mangle] pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int, value: *mut cef_string_t) -> c_int { unsafe { - if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; } + if index < 0 || lt.is_null() { return 0; } let v = string_list_to_vec(lt); if index as uint > (*v).len() - 1 { return 0; } let cs = (*v)[index as uint]; @@ -57,7 +56,7 @@ pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int #[no_mangle] pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { unsafe { - if fptr_is_null(mem::transmute(lt)) { return; } + if lt.is_null() { return; } let v = string_list_to_vec(lt); if (*v).len() == 0 { return; } let mut cs; @@ -71,7 +70,7 @@ pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { #[no_mangle] pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { unsafe { - if fptr_is_null(mem::transmute(lt)) { return; } + if lt.is_null() { return; } let v: Box> = mem::transmute(lt); cef_string_list_clear(lt); drop(v); @@ -81,7 +80,7 @@ pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { #[no_mangle] pub extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_string_list_t { unsafe { - if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; } + if lt.is_null() { return 0 as *mut cef_string_list_t; } let v = string_list_to_vec(lt); let lt2 = cef_string_list_alloc(); for cs in (*v).iter() { diff --git a/ports/cef/string_map.rs b/ports/cef/string_map.rs index 67753b3c5dc4..2ca2e4e0f9c9 100644 --- a/ports/cef/string_map.rs +++ b/ports/cef/string_map.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use eutil::{fptr_is_null, slice_to_str}; +use eutil::slice_to_str; use libc::{c_int}; use std::collections::TreeMap; use std::mem; @@ -27,7 +27,7 @@ pub extern "C" fn cef_string_map_alloc() -> *mut cef_string_map_t { #[no_mangle] pub extern "C" fn cef_string_map_size(sm: *mut cef_string_map_t) -> c_int { unsafe { - if fptr_is_null(mem::transmute(sm)) { return 0; } + if sm.is_null() { return 0; } let v = string_map_to_treemap(sm); (*v).len() as c_int } @@ -36,7 +36,7 @@ pub extern "C" fn cef_string_map_size(sm: *mut cef_string_map_t) -> c_int { #[no_mangle] pub extern "C" fn cef_string_map_append(sm: *mut cef_string_map_t, key: *const cef_string_t, value: *const cef_string_t) -> c_int { unsafe { - if fptr_is_null(mem::transmute(sm)) { return 0; } + if sm.is_null() { return 0; } let v = string_map_to_treemap(sm); slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { let s = String::from_str(result); @@ -51,7 +51,7 @@ pub extern "C" fn cef_string_map_append(sm: *mut cef_string_map_t, key: *const c #[no_mangle] pub extern "C" fn cef_string_map_find(sm: *mut cef_string_map_t, key: *const cef_string_t, value: *mut cef_string_t) -> c_int { unsafe { - if fptr_is_null(mem::transmute(sm)) { return 0; } + if sm.is_null() { return 0; } let v = string_map_to_treemap(sm); slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { match (*v).find(&String::from_str(result)) { @@ -68,7 +68,7 @@ pub extern "C" fn cef_string_map_find(sm: *mut cef_string_map_t, key: *const cef #[no_mangle] pub extern "C" fn cef_string_map_key(sm: *mut cef_string_map_t, index: c_int, value: *mut cef_string_t) -> c_int { unsafe { - if index < 0 || fptr_is_null(mem::transmute(sm)) { return 0; } + if index < 0 || sm.is_null() { return 0; } let v = string_map_to_treemap(sm); if index as uint > (*v).len() - 1 { return 0; } @@ -85,7 +85,7 @@ pub extern "C" fn cef_string_map_key(sm: *mut cef_string_map_t, index: c_int, va #[no_mangle] pub extern "C" fn cef_string_map_value(sm: *mut cef_string_map_t, index: c_int, value: *mut cef_string_t) -> c_int { unsafe { - if index < 0 || fptr_is_null(mem::transmute(sm)) { return 0; } + if index < 0 || sm.is_null() { return 0; } let v = string_map_to_treemap(sm); if index as uint > (*v).len() - 1 { return 0; } @@ -102,7 +102,7 @@ pub extern "C" fn cef_string_map_value(sm: *mut cef_string_map_t, index: c_int, #[no_mangle] pub extern "C" fn cef_string_map_clear(sm: *mut cef_string_map_t) { unsafe { - if fptr_is_null(mem::transmute(sm)) { return; } + if sm.is_null() { return; } let v = string_map_to_treemap(sm); for val in (*v).values() { cef_string_userfree_utf8_free(*val); @@ -114,7 +114,7 @@ pub extern "C" fn cef_string_map_clear(sm: *mut cef_string_map_t) { #[no_mangle] pub extern "C" fn cef_string_map_free(sm: *mut cef_string_map_t) { unsafe { - if fptr_is_null(mem::transmute(sm)) { return; } + if sm.is_null() { return; } let _v: Box> = mem::transmute(sm); cef_string_map_clear(sm); } diff --git a/ports/cef/types.rs b/ports/cef/types.rs index 46a7fa12af42..667305d58359 100644 --- a/ports/cef/types.rs +++ b/ports/cef/types.rs @@ -38,7 +38,7 @@ pub type cef_string_userfree_utf8_t = cef_string_utf8; pub struct cef_string_utf8 { pub str: *mut u8, pub length: size_t, - pub dtor: extern "C" fn(str: *mut u8), + pub dtor: Option, } pub type cef_string_utf16_t = cef_string_utf16; @@ -46,7 +46,7 @@ pub type cef_string_userfree_utf16_t = cef_string_utf16; pub struct cef_string_utf16 { pub str: *mut c_ushort, pub length: size_t, - pub dtor: extern "C" fn(str: *mut c_ushort), + pub dtor: Option, } pub type cef_string_wide_t = cef_string_wide; @@ -54,7 +54,7 @@ pub type cef_string_userfree_wide_t = cef_string_wide; pub struct cef_string_wide { pub str: *mut wchar_t, pub length: size_t, - pub dtor: extern "C" fn(str: *mut wchar_t), + pub dtor: Option, } pub type cef_main_args_t = cef_main_args; @@ -501,29 +501,29 @@ pub struct cef_process_message { // Returns true (1) if this object is valid. Do not call any other functions // if this function returns false (0). /// - pub is_valid: extern "C" fn(process_message: *mut cef_process_message) -> c_int, + pub is_valid: Option c_int>, /// // Returns true (1) if the values of this object are read-only. Some APIs may // expose read-only objects. /// - pub is_read_only: extern "C" fn(process_message: *mut cef_process_message) -> c_int, + pub is_read_only: Option c_int>, /// // Returns a writable copy of this object. /// - pub copy: extern "C" fn(process_message: *mut cef_process_message) -> *mut cef_process_message, + pub copy: Option *mut cef_process_message>, /// // Returns the message name. /// // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_name: extern "C" fn(process_message: *mut cef_process_message) -> *mut cef_string_userfree_t, + pub get_name: Option *mut cef_string_userfree_t>, /// // Returns the list of arguments. /// - pub get_argument_list: extern "C" fn(process_message: *mut cef_process_message) -> *mut cef_list_value, + pub get_argument_list: Option *mut cef_list_value>, } /// @@ -746,18 +746,18 @@ pub struct cef_base { /// // Increment the reference count. /// - pub add_ref: extern "C" fn(base: *mut cef_base) -> c_int, + pub add_ref: Option c_int>, /// // Decrement the reference count. Delete this object when no references // remain. /// - pub release: extern "C" fn(base: *mut cef_base) -> c_int, + pub release: Option c_int>, /// // Returns the current number of references. /// - pub get_refct: extern "C" fn(base: *mut cef_base) -> c_int, + pub get_refct: Option c_int>, } /// @@ -781,116 +781,116 @@ pub struct cef_command_line { // Returns true (1) if this object is valid. Do not call any other functions // if this function returns false (0). /// - pub is_valid: extern "C" fn(cmd: *mut cef_command_line), + pub is_valid: Option, /// // Returns true (1) if the values of this object are read-only. Some APIs may // expose read-only objects. /// - pub is_read_only: extern "C" fn(cmd: *mut cef_command_line), + pub is_read_only: Option, /// // Returns a writable copy of this object. /// - pub copy: extern "C" fn(cmd: *mut cef_command_line) -> *mut cef_command_line, + pub copy: Option *mut cef_command_line>, /// // Initialize the command line with the specified |argc| and |argv| values. // The first argument must be the name of the program. This function is only // supported on non-Windows platforms. /// - pub init_from_argv: extern "C" fn(cmd: *mut cef_command_line, argc: c_int, argv: *const u8), + pub init_from_argv: Option, /// // Initialize the command line with the string returned by calling // GetCommandLineW(). This function is only supported on Windows. /// - pub init_from_string: extern "C" fn(cmd: *mut cef_command_line, command_line: *const cef_string_t), + pub init_from_string: Option, /// // Reset the command-line switches and arguments but leave the program // component unchanged. /// - pub reset: extern "C" fn(cmd: *mut cef_command_line), + pub reset: Option, /// // Retrieve the original command line string as a vector of strings. The argv // array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* } /// - pub get_argv: extern "C" fn(cmd: *mut cef_command_line, argv: *mut cef_string_list_t), + pub get_argv: Option, /// // Constructs and returns the represented command line string. Use this // function cautiously because quoting behavior is unclear. /// // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_command_line_string: extern "C" fn(cmd: *mut cef_command_line) -> *mut cef_string_userfree_t, + pub get_command_line_string: Option *mut cef_string_userfree_t>, /// // Get the program part of the command line string (the first item). /// // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_program: extern "C" fn(cmd: *mut cef_command_line) -> *mut cef_string_userfree_t, + pub get_program: Option *mut cef_string_userfree_t>, /// // Set the program part of the command line string (the first item). /// - pub set_program: extern "C" fn(cmd: *mut cef_command_line, name: *const cef_string_t), + pub set_program: Option, /// // Returns true (1) if the command line has switches. /// - pub has_switches: extern "C" fn(cmd: *mut cef_command_line) -> c_int, + pub has_switches: Option c_int>, /// // Returns true (1) if the command line contains the given switch. /// - pub has_switch: extern "C" fn(cmd: *mut cef_command_line, name: *const cef_string_t) -> c_int, + pub has_switch: Option c_int>, /// // Returns the value associated with the given switch. If the switch has no // value or isn't present this function returns the NULL string. /// // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_switch_value: extern "C" fn(cmd: *mut cef_command_line, name: *const cef_string_t) -> *mut cef_string_userfree_t, + pub get_switch_value: Option *mut cef_string_userfree_t>, /// // Returns the map of switch names and values. If a switch has no value an // NULL string is returned. /// - pub get_switches: extern "C" fn(cmd: *mut cef_command_line, switches: cef_string_map_t), + pub get_switches: Option, /// // Add a switch to the end of the command line. If the switch has no value // pass an NULL value string. /// - pub append_switch: extern "C" fn(cmd: *mut cef_command_line, name: *const cef_string_t), + pub append_switch: Option, /// // Add a switch with the specified value to the end of the command line. /// - pub append_switch_with_value: extern "C" fn(cmd: *mut cef_command_line, name: *const cef_string_t, value: *const cef_string_t), + pub append_switch_with_value: Option, /// // True if there are remaining command line arguments. /// - pub has_arguments: extern "C" fn(cmd: *mut cef_command_line) -> c_int, + pub has_arguments: Option c_int>, /// // Get the remaining command line arguments. /// - pub get_arguments: extern "C" fn(cmd: *mut cef_command_line, arguments: *mut cef_string_list_t), + pub get_arguments: Option, /// // Add an argument to the end of the command line. /// - pub append_argument: extern "C" fn(cmd: *mut cef_command_line, argument: *const cef_string_t), + pub append_argument: Option, /// // Insert a command before the current command. Common for debuggers, like // "valgrind" or "gdb --args". /// - pub prepend_wrapper: extern "C" fn(cmd: *mut cef_command_line, wrapper: *const cef_string_t), + pub prepend_wrapper: Option, } @@ -950,10 +950,10 @@ pub struct cef_scheme_registrar { // per unique |scheme_name| value. If |scheme_name| is already registered or // if an error occurs this function will return false (0). /// - _add_custom_scheme: extern "C" fn(registrar: *mut cef_scheme_registrar, + pub add_custom_scheme: Option, } /// @@ -973,8 +973,8 @@ pub struct cef_resource_bundle_handler { // string and return true (1). To use the default translation return false // (0). Supported message IDs are listed in cef_pack_strings.h. /// - pub get_localized_string: extern "C" fn(bundle_handler: *mut cef_resource_bundle_handler, - message_id: c_int, string: *mut cef_string_t) -> c_int, + pub get_localized_string: Option c_int>, /// // Called to retrieve data for the resource specified by |resource_id|. To @@ -984,8 +984,8 @@ pub struct cef_resource_bundle_handler { // resident in memory. Supported resource IDs are listed in // cef_pack_resources.h. /// - pub get_data_resource: extern "C" fn(bundle_handler: *mut cef_resource_bundle_handler, - resource_id: c_int, data: *mut *mut c_void, data_size: *mut size_t) -> c_int, + pub get_data_resource: Option c_int>, } @@ -1004,115 +1004,115 @@ pub struct cef_list_value { // Returns true (1) if this object is valid. Do not call any other functions // if this function returns false (0). /// - pub is_valid: extern "C" fn(list_value: *mut cef_list_value) -> c_int, + pub is_valid: Option c_int>, /// // Returns true (1) if this object is currently owned by another object. /// - pub is_owned: extern "C" fn(list_value: *mut cef_list_value) -> c_int, + pub is_owned: Option c_int>, /// // Returns true (1) if the values of this object are read-only. Some APIs may // expose read-only objects. /// - pub is_read_only: extern "C" fn(list_value: *mut cef_list_value) -> c_int, + pub is_read_only: Option c_int>, /// // Returns a writable copy of this object. /// - pub copy: extern "C" fn(list_value: *mut cef_list_value) -> *mut cef_list_value, + pub copy: Option *mut cef_list_value>, /// // Sets the number of values. If the number of values is expanded all new // value slots will default to type null. Returns true (1) on success. /// - pub set_size: extern "C" fn(list_value: *mut cef_list_value, size: size_t) -> c_int, + pub set_size: Option c_int>, /// // Returns the number of values. /// - pub get_size: extern "C" fn(list_value: *mut cef_list_value) -> size_t, + pub get_size: Option size_t>, /// // Removes all values. Returns true (1) on success. /// - pub clear: extern "C" fn(list_value: *mut cef_list_value) -> c_int, + pub clear: Option c_int>, /// // Removes the value at the specified index. /// - pub remove: extern "C" fn(list_value: *mut cef_list_value) -> c_int, + pub remove: Option c_int>, /// // Returns the value type at the specified index. /// - pub get_type: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> cef_value_type_t, + pub get_type: Option cef_value_type_t>, /// // Returns the value at the specified index as type bool. /// - pub get_bool: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> c_int, + pub get_bool: Option c_int>, /// // Returns the value at the specified index as type int. /// - pub get_int: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> c_int, + pub get_int: Option c_int>, /// // Returns the value at the specified index as type double. /// - pub get_double: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> c_double, + pub get_double: Option c_double>, /// // Returns the value at the specified index as type string. /// // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_string: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> *mut cef_string_userfree_t, + pub get_string: Option *mut cef_string_userfree_t>, /// // Returns the value at the specified index as type binary. /// - pub get_binary: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> *mut cef_binary_value, + pub get_binary: Option *mut cef_binary_value>, /// // Returns the value at the specified index as type dictionary. /// - pub get_dictionary: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> *mut cef_dictionary_value, + pub get_dictionary: Option *mut cef_dictionary_value>, /// // Returns the value at the specified index as type list. /// - pub get_list: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> *mut cef_list_value, + pub get_list: Option *mut cef_list_value>, /// // Sets the value at the specified index as type null. Returns true (1) if the // value was set successfully. /// - pub set_null: extern "C" fn(list_value: *mut cef_list_value, index: c_int) -> c_int, + pub set_null: Option c_int>, /// // Sets the value at the specified index as type bool. Returns true (1) if the // value was set successfully. /// - pub set_bool: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: c_int) -> c_int, + pub set_bool: Option c_int>, /// // Sets the value at the specified index as type int. Returns true (1) if the // value was set successfully. /// - pub set_int: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: c_int) -> c_int, + pub set_int: Option c_int>, /// // Sets the value at the specified index as type double. Returns true (1) if // the value was set successfully. /// - pub set_double: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: c_double) -> c_int, + pub set_double: Option c_int>, /// // Sets the value at the specified index as type string. Returns true (1) if // the value was set successfully. /// - pub set_string: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: *const cef_string_t) -> c_int, + pub set_string: Option c_int>, /// // Sets the value at the specified index as type binary. Returns true (1) if @@ -1122,7 +1122,7 @@ pub struct cef_list_value { // change. Otherwise, ownership will be transferred to this object and the // |value| reference will be invalidated. /// - pub set_binary: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: *mut cef_binary_value) -> c_int, + pub set_binary: Option c_int>, /// // Sets the value at the specified index as type dict. Returns true (1) if the @@ -1132,7 +1132,7 @@ pub struct cef_list_value { // Otherwise, ownership will be transferred to this object and the |value| // reference will be invalidated. /// - pub set_dictionary: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: *mut cef_dictionary_value) -> c_int, + pub set_dictionary: Option c_int>, /// // Sets the value at the specified index as type list. Returns true (1) if the @@ -1142,7 +1142,7 @@ pub struct cef_list_value { // Otherwise, ownership will be transferred to this object and the |value| // reference will be invalidated. /// - pub set_list: extern "C" fn(list_value: *mut cef_list_value, index: c_int, value: *mut cef_list_value) -> c_int, + pub set_list: Option c_int>, } /// @@ -1161,7 +1161,7 @@ pub struct cef_browser_process_handler { // Called on the browser process UI thread immediately after the CEF context // has been initialized. /// - pub on_context_initialized: extern "C" fn(browser_handler: *mut cef_browser_process_handler), + pub on_context_initialized: Option, /// // Called before a child process is launched. Will be called on the browser @@ -1170,7 +1170,7 @@ pub struct cef_browser_process_handler { // opportunity to modify the child process command line. Do not keep a // reference to |command_line| outside of this function. /// - pub on_before_child_process_launch: extern "C" fn(browser_handler: *mut cef_browser_process_handler, command_line: *mut cef_command_line), + pub on_before_child_process_launch: Option, /// // Called on the browser process IO thread after the main thread has been @@ -1179,7 +1179,7 @@ pub struct cef_browser_process_handler { // cef_render_process_handler_t::on_render_thread_created() in the render // process. Do not keep a reference to |extra_info| outside of this function. /// - pub on_render_process_thread_created: extern "C" fn(browser_handler: *mut cef_browser_process_handler, extra_info: *mut cef_list_value), + pub on_render_process_thread_created: Option, } @@ -1200,9 +1200,9 @@ pub struct cef_run_file_dialog_callback { // depending on the dialog mode. If the selection was cancelled |file_paths| // will be NULL. /// - pub cont: extern "C" fn(run_file_dialog_callback: *mut cef_run_file_dialog_callback, + pub cont: Option, } /// @@ -1221,7 +1221,7 @@ pub struct cef_browser_host { /// // Returns the hosted browser object. /// - pub get_browser: extern "C" fn(browser_host: *mut cef_browser_host) -> *mut cef_browser, + pub get_browser: Option *mut cef_browser>, /// // Call this function before destroying a contained browser window. This @@ -1229,7 +1229,7 @@ pub struct cef_browser_host { // browser window is destroyed. See cef_life_span_handler_t::do_close() // documentation for additional usage information. /// - pub parent_window_will_close: extern "C" fn(browser_host: *mut cef_browser_host), + pub parent_window_will_close: Option, /// // Request that the browser close. The JavaScript 'onbeforeunload' event will @@ -1241,48 +1241,48 @@ pub struct cef_browser_host { // cef_life_span_handler_t::do_close() documentation for additional usage // information. /// - pub close_browser: extern "C" fn(browser_host: *mut cef_browser_host, force_close: c_int), + pub close_browser: Option, /// // Set focus for the browser window. If |enable| is true (1) focus will be set // to the window. Otherwise, focus will be removed. /// - pub set_focus: extern "C" fn(browser_host: *mut cef_browser_host, force_close: c_int), + pub set_focus: Option, /// // Retrieve the window handle for this browser. /// - pub get_window_handle: extern "C" fn(browser_host: *mut cef_browser_host) -> *mut cef_window_handle_t, + pub get_window_handle: Option *mut cef_window_handle_t>, /// // Retrieve the window handle of the browser that opened this browser. Will // return NULL for non-popup windows. This function can be used in combination // with custom handling of modal windows. /// - pub get_opener_window_handle: extern "C" fn(browser_host: *mut cef_browser_host) -> *mut cef_window_handle_t, + pub get_opener_window_handle: Option *mut cef_window_handle_t>, /// // Returns the client for this browser. /// - pub get_client: extern "C" fn(browser_host: *mut cef_browser_host) -> *mut cef_client_t, + pub get_client: Option *mut cef_client_t>, /// // Returns the request context for this browser. /// - pub get_request_context: extern "C" fn(browser_host: *mut cef_browser_host) -> *mut cef_request_context_t, + pub get_request_context: Option *mut cef_request_context_t>, /// // Get the current zoom level. The default zoom level is 0.0. This function // can only be called on the UI thread. /// - pub get_zoom_level: extern "C" fn(browser_host: *mut cef_browser_host) -> c_double, + pub get_zoom_level: Option c_double>, /// // Change the zoom level to the specified value. Specify 0.0 to reset the zoom // level. If called on the UI thread the change will be applied immediately. // Otherwise, the change will be applied asynchronously on the UI thread. /// - pub set_zoom_level: extern "C" fn(browser_host: *mut cef_browser_host, zoomLevel: c_double), + pub set_zoom_level: Option, /// // Call to run a file chooser dialog. Only a single file chooser dialog may be @@ -1296,20 +1296,20 @@ pub struct cef_browser_host { // dialog is already pending. The dialog will be initiated asynchronously on // the UI thread. /// - pub run_file_dialog: extern "C" fn(browser_host: *mut cef_browser_host, + pub run_file_dialog: Option, /// // Download the file at |url| using cef_download_handler_t. /// - pub start_download: extern "C" fn(browser_host: *mut cef_browser_host, url: *const cef_string_t), + pub start_download: Option, /// // Print the current browser contents. /// - pub print: extern "C" fn(browser_host: *mut cef_browser_host), + pub print: Option, /// // Search for |searchText|. |identifier| can be used to have multiple searches @@ -1318,43 +1318,43 @@ pub struct cef_browser_host { // be case-sensitive. |findNext| indicates whether this is the first request // or a follow-up. /// - pub find: extern "C" fn(browser_host: *mut cef_browser_host, identifier: c_int, searchText: *const cef_string_t, - forward: c_int, matchCase: c_int, findNext: c_int), + pub find: Option, /// // Cancel all searches that are currently going on. /// - pub stop_finding: extern "C" fn(browser_host: *mut cef_browser_host, clearSelection: c_int), + pub stop_finding: Option, /// // Open developer tools in its own window. /// - pub show_dev_tools: extern "C" fn(browser_host: *mut cef_browser_host, + pub show_dev_tools: Option, /// // Explicitly close the developer tools window if one exists for this browser // instance. /// - pub close_dev_tools: extern "C" fn(browser_host: *mut cef_browser_host), + pub close_dev_tools: Option, /// // Set whether mouse cursor change is disabled. /// - pub set_mouse_cursor_change_disabled: extern "C" fn(browser_host: *mut cef_browser_host, - disabled: c_int), + pub set_mouse_cursor_change_disabled: Option, /// // Returns true (1) if mouse cursor change is disabled. /// - pub is_mouse_cursor_change_disabled: extern "C" fn(browser_host: *mut cef_browser_host) -> c_int, + pub is_mouse_cursor_change_disabled: Option c_int>, /// // Returns true (1) if window rendering is disabled. /// - pub is_window_rendering_disabled: extern "C" fn(browser_host: *mut cef_browser_host) -> c_int, + pub is_window_rendering_disabled: Option c_int>, /// // Notify the browser that the widget has been resized. The browser will first @@ -1362,14 +1362,14 @@ pub struct cef_browser_host { // cef_render_handler_t::OnPaint asynchronously with the updated regions. This // function is only used when window rendering is disabled. /// - pub was_resized: extern "C" fn(browser_host: *mut cef_browser_host), + pub was_resized: Option, /// // Notify the browser that it has been hidden or shown. Layouting and // cef_render_handler_t::OnPaint notification will stop when the browser is // hidden. This function is only used when window rendering is disabled. /// - pub was_hidden: extern "C" fn(browser_host: *mut cef_browser_host, hidden: c_int), + pub was_hidden: Option, /// // Send a notification to the browser that the screen info has changed. The @@ -1379,37 +1379,37 @@ pub struct cef_browser_host { // current display. This function is only used when window rendering is // disabled. /// - pub notify_screen_info_changed: extern "C" fn(browser_host: *mut cef_browser_host), + pub notify_screen_info_changed: Option, /// // Invalidate the |dirtyRect| region of the view. The browser will call // cef_render_handler_t::OnPaint asynchronously with the updated regions. This // function is only used when window rendering is disabled. /// - pub invalidate: extern "C" fn(browser_host: *mut cef_browser_host, - dirtyRect: *const cef_rect, t: cef_paint_element_type_t), + pub invalidate: Option, /// // Send a key event to the browser. /// - pub send_key_event: extern "C" fn(browser_host: *mut cef_browser_host, - event: *const cef_key_event), + pub send_key_event: Option, /// // Send a mouse click event to the browser. The |x| and |y| coordinates are // relative to the upper-left corner of the view. /// - pub send_mouse_click_event: extern "C" fn(browser_host: *mut cef_browser_host, + pub send_mouse_click_event: Option, /// // Send a mouse move event to the browser. The |x| and |y| coordinates are // relative to the upper-left corner of the view. /// - pub send_mouse_move_event: extern "C" fn(browser_host: *mut cef_browser_host, - event: *const cef_mouse_event, mouseLeave: c_int), + pub send_mouse_move_event: Option, /// // Send a mouse wheel event to the browser. The |x| and |y| coordinates are @@ -1418,37 +1418,37 @@ pub struct cef_browser_host { // In order to scroll inside select popups with window rendering disabled // cef_render_handler_t::GetScreenPoint should be implemented properly. /// - pub send_mouse_wheel_event: extern "C" fn(browser_host: *mut cef_browser_host, - event: *const cef_mouse_event, deltaX: c_int, deltaY: c_int), + pub send_mouse_wheel_event: Option, /// // Send a focus event to the browser. /// - pub send_focus_event: extern "C" fn(browser_host: *mut cef_browser_host, setFocus: c_int), + pub send_focus_event: Option, /// // Send a capture lost event to the browser. /// - pub send_capture_lost_event: extern "C" fn(browser_host: *mut cef_browser_host), + pub send_capture_lost_event: Option, /// // Get the NSTextInputContext implementation for enabling IME on Mac when // window rendering is disabled. /// - pub get_nstext_input_context: extern "C" fn(browser_host: *mut cef_browser_host) -> cef_text_input_context_t, + pub get_nstext_input_context: Option cef_text_input_context_t>, /// // Handles a keyDown event prior to passing it through the NSTextInputClient // machinery. /// - pub handle_key_event_before_text_input_client: extern "C" fn(browser_host: *mut cef_browser_host, - key_event: *mut cef_event_handle_t), + pub handle_key_event_before_text_input_client: Option, /// // Performs any additional actions after NSTextInputClient handles the event. /// - pub handle_key_event_after_text_input_client: extern "C" fn(browser_host: *mut cef_browser_host, - key_event: *mut cef_event_handle_t), + pub handle_key_event_after_text_input_client: Option, } @@ -1469,112 +1469,112 @@ pub struct cef_browser { // Returns the browser host object. This function can only be called in the // browser process. /// - pub get_host: extern "C" fn(browser: *mut cef_browser) -> *mut cef_browser_host, + pub get_host: Option *mut cef_browser_host>, /// // Returns true (1) if the browser can navigate backwards. /// - pub can_go_back: extern "C" fn(browser: *mut cef_browser) -> c_int, + pub can_go_back: Option c_int>, /// // Navigate backwards. /// - pub go_back: extern "C" fn(browser: *mut cef_browser), + pub go_back: Option, /// // Returns true (1) if the browser can navigate forwards. /// - pub can_go_forward: extern "C" fn(browser: *mut cef_browser) -> c_int, + pub can_go_forward: Option c_int>, /// // Navigate forwards. /// - pub go_forward: extern "C" fn(browser: *mut cef_browser), + pub go_forward: Option, /// // Returns true (1) if the browser is currently loading. /// - pub is_loading: extern "C" fn(browser: *mut cef_browser) -> c_int, + pub is_loading: Option c_int>, /// // Reload the current page. /// - pub reload: extern "C" fn(browser: *mut cef_browser), + pub reload: Option, /// // Reload the current page ignoring any cached data. /// - pub reload_ignore_cache: extern "C" fn(browser: *mut cef_browser), + pub reload_ignore_cache: Option, /// // Stop loading the page. /// - pub stop_load: extern "C" fn(browser: *mut cef_browser), + pub stop_load: Option, /// // Returns the globally unique identifier for this browser. /// - pub get_identifier: extern "C" fn(browser: *mut cef_browser) -> c_int, + pub get_identifier: Option c_int>, /// // Returns true (1) if this object is pointing to the same handle as |that| // object. /// - pub is_same: extern "C" fn(browser: *mut cef_browser, that: *mut cef_browser) -> c_int, + pub is_same: Option c_int>, /// // Returns true (1) if the window is a popup window. /// - pub is_popup: extern "C" fn(browser: *mut cef_browser) -> c_int, + pub is_popup: Option c_int>, /// // Returns true (1) if a document has been loaded in the browser. /// - pub has_document: extern "C" fn(browser: *mut cef_browser) -> c_int, + pub has_document: Option c_int>, /// // Returns the main (top-level) frame for the browser window. /// - pub get_main_frame: extern "C" fn(browser: *mut cef_browser) -> *mut cef_frame, + pub get_main_frame: Option *mut cef_frame>, /// // Returns the focused frame for the browser window. /// - pub get_focused_frame: extern "C" fn(browser: *mut cef_browser) -> *mut cef_frame, + pub get_focused_frame: Option *mut cef_frame>, /// // Returns the frame with the specified identifier, or NULL if not found. /// - pub get_frame_byident: extern "C" fn(browser: *mut cef_browser, identifier: c_longlong) -> *mut cef_frame, + pub get_frame_byident: Option *mut cef_frame>, /// // Returns the frame with the specified name, or NULL if not found. /// - pub get_frame: extern "C" fn(browser: *mut cef_browser, name: *const cef_string_t) -> *mut cef_frame, + pub get_frame: Option *mut cef_frame>, /// // Returns the number of frames that currently exist. /// - pub get_frame_count: extern "C" fn(browser: *mut cef_browser) -> size_t, + pub get_frame_count: Option size_t>, /// // Returns the identifiers of all existing frames. /// - pub get_frame_identifiers: extern "C" fn(browser: *mut cef_browser, + pub get_frame_identifiers: Option, /// // Returns the names of all existing frames. /// - pub get_frame_names: extern "C" fn(browser: *mut cef_browser, names: *mut cef_string_list_t), + pub get_frame_names: Option, // // Send a message to the specified |target_process|. Returns true (1) if the // message was sent successfully. /// - pub send_process_message: extern "C" fn(browser: *mut cef_browser, target_process: cef_process_id_t, - message: *mut cef_process_message) -> c_int, + pub send_process_message: Option c_int>, } /// @@ -1595,41 +1595,41 @@ pub struct cef_render_process_handler { // cef_browser_process_handler_t::on_render_process_thread_created(). Do not // keep a reference to |extra_info| outside of this function. /// - pub on_render_thread_created: extern "C" fn(render_handler: *mut cef_render_process_handler, extra_info: *mut cef_list_value), + pub on_render_thread_created: Option, /// // Called after WebKit has been initialized. /// - pub on_web_kit_initialized: extern "C" fn(render_handler: *mut cef_render_process_handler), + pub on_web_kit_initialized: Option, /// // Called after a browser has been created. When browsing cross-origin a new // browser will be created before the old browser with the same identifier is // destroyed. /// - pub on_browser_created: extern "C" fn(render_handler: *mut cef_render_process_handler, browser: *mut cef_browser), + pub on_browser_created: Option, /// // Called before a browser is destroyed. /// - pub on_browser_destroyed: extern "C" fn(render_handler: *mut cef_render_process_handler, browser: *mut cef_browser), + pub on_browser_destroyed: Option, /// // Return the handler for browser load status events. /// - pub get_load_handler: extern "C" fn(render_handler: *mut cef_render_process_handler) -> *mut cef_load_handler, + pub get_load_handler: Option *mut cef_load_handler>, /// // Called before browser navigation. Return true (1) to cancel the navigation // or false (0) to allow the navigation to proceed. The |request| object // cannot be modified in this callback. /// - pub on_before_navigation: extern "C" fn(render_handler: *mut cef_render_process_handler, + pub on_before_navigation: Option c_int, + is_redirect: c_int) -> c_int>, /// // Called immediately after the V8 context for a frame has been created. To @@ -1639,31 +1639,31 @@ pub struct cef_render_process_handler { // on the associated thread can be retrieved via the // cef_v8context_t::get_task_runner() function. /// - pub on_context_created: extern "C" fn(render_handler: *mut cef_render_process_handler, + pub on_context_created: Option, /// // Called immediately before the V8 context for a frame is released. No // references to the context should be kept after this function is called. /// - pub on_context_released: extern "C" fn(render_handler: *mut cef_render_process_handler, + pub on_context_released: Option, /// // Called for global uncaught exceptions in a frame. Execution of this // callback is disabled by default. To enable set // CefSettings.uncaught_exception_stack_size 0. /// - pub on_uncaught_exception: extern "C" fn(render_handler: *mut cef_render_process_handler, + pub on_uncaught_exception: Option, /// // Called when a new node in the the browser gets focus. The |node| value may @@ -1673,20 +1673,20 @@ pub struct cef_render_process_handler { // keep references to or attempt to access any DOM objects outside the scope // of this function. /// - pub on_focused_node_changed: extern "C" fn(render_handler: *mut cef_render_process_handler, + pub on_focused_node_changed: Option, /// // Called when a new message is received from a different process. Return true // (1) if the message was handled or false (0) otherwise. Do not keep a // reference to or attempt to access the message outside of this callback. /// - pub on_process_message_received: extern "C" fn(render_handler: *mut cef_render_process_handler, + pub on_process_message_received: Optionc_int, + message: *mut cef_process_message) ->c_int>, } /// @@ -1711,7 +1711,7 @@ pub struct cef_app { // modify command-line arguments for non-browser processes as this may result // in undefined behavior including crashes. /// - pub on_before_command_line_processing: extern "C" fn(app: *mut cef_app_t, process_type: *const cef_string_t, command_line: *mut cef_command_line), + pub on_before_command_line_processing: Option, /// // Provides an opportunity to register custom schemes. Do not keep a reference @@ -1719,7 +1719,7 @@ pub struct cef_app { // each process and the registered schemes should be the same across all // processes. /// - pub on_register_custom_schemes: extern "C" fn(app: *mut cef_app_t, registrar: *mut cef_scheme_registrar), + pub on_register_custom_schemes: Option, /// // Return the handler for resource bundle events. If @@ -1727,19 +1727,19 @@ pub struct cef_app { // If no handler is returned resources will be loaded from pack files. This // function is called by the browser and render processes on multiple threads. /// - pub get_resource_bundle_handler: extern "C" fn(app: *mut cef_app_t) -> *mut cef_resource_bundle_handler, + pub get_resource_bundle_handler: Option *mut cef_resource_bundle_handler>, /// // Return the handler for functionality specific to the browser process. This // function is called on multiple threads in the browser process. /// - pub get_browser_process_handler: extern "C" fn(app: *mut cef_app_t) -> *mut cef_browser_process_handler, + pub get_browser_process_handler: Option *mut cef_browser_process_handler>, /// // Return the handler for functionality specific to the render process. This // function is called on the render process main thread. /// - pub get_render_process_handler: extern "C" fn(app: *mut cef_app_t) -> *mut cef_render_process_handler, + pub get_render_process_handler: Option *mut cef_render_process_handler>, } @@ -1761,35 +1761,35 @@ pub struct cef_urlrequest { // Returns the request object used to create this URL request. The returned // object is read-only and should not be modified. /// - pub get_request: extern "C" fn(url_req: *mut cef_urlrequest) -> *mut cef_request_t, + pub get_request: Option *mut cef_request_t>, /// // Returns the client. /// - pub get_client: extern "C" fn(url_req: *mut cef_urlrequest) -> *mut cef_urlrequest_client_t, + pub get_client: Option *mut cef_urlrequest_client_t>, /// // Returns the request status. /// - pub get_request_status: extern "C" fn(url_req: *mut cef_urlrequest) -> cef_urlrequest_status_t, + pub get_request_status: Option cef_urlrequest_status_t>, /// // Returns the request error if status is UR_CANCELED or UR_FAILED, or 0 // otherwise. /// - pub get_request_error: extern "C" fn(url_req: *mut cef_urlrequest) -> cef_errorcode_t, + pub get_request_error: Option cef_errorcode_t>, /// // Returns the response, or NULL if no response information is available. // Response information will only be available after the upload has completed. // The returned object is read-only and should not be modified. /// - pub get_response: extern "C" fn(url_req: *mut cef_urlrequest) -> *mut cef_response_t, + pub get_response: Option *mut cef_response_t>, /// // Cancel the request. /// - pub cancel: extern "C" fn(url_req: *mut cef_urlrequest), + pub cancel: Option, } @@ -1808,47 +1808,47 @@ pub struct cef_post_data_element { /// // Returns true (1) if this object is read-only. /// - pub is_read_only: extern "C" fn(post_data_element: *mut cef_post_data_element) -> c_int, + pub is_read_only: Option c_int>, /// // Remove all contents from the post data element. /// - pub set_to_empty: extern "C" fn(post_data_element: *mut cef_post_data_element), + pub set_to_empty: Option, /// // The post data element will represent a file. /// - pub set_to_file: extern "C" fn(post_data_element: *mut cef_post_data_element, fileName: *const cef_string_t), + pub set_to_file: Option, /// // The post data element will represent bytes. The bytes passed in will be // copied. /// - pub set_to_bytes: extern "C" fn(post_data_element: *mut cef_post_data_element, - size: size_t, bytes: *const c_void), + pub set_to_bytes: Option, /// // Return the type of this post data element. /// - pub get_type: extern "C" fn(post_data_element: *mut cef_post_data_element) -> cef_postdataelement_type_t, + pub get_type: Option cef_postdataelement_type_t>, /// // Return the file name. /// // The resulting string must be freed by calling cef_string_userfree_free(). - pub get_file: extern "C" fn(post_data_element: *mut cef_post_data_element) -> *mut cef_string_userfree_t, + pub get_file: Option *mut cef_string_userfree_t>, /// // Return the number of bytes. /// - pub get_bytes_count: extern "C" fn(post_data_element: *mut cef_post_data_element) -> size_t, + pub get_bytes_count: Option size_t>, /// // Read up to |size| bytes into |bytes| and return the number of bytes // actually read. /// - pub get_bytes: extern "C" fn(post_data_element: *mut cef_post_data_element, - size: size_t, bytes: *mut c_void) -> size_t, + pub get_bytes: Option size_t>, } @@ -1866,34 +1866,34 @@ pub struct cef_post_data { /// // Returns true (1) if this object is read-only. /// - pub is_read_only: extern "C" fn(post_data: *mut cef_post_data) -> c_int, + pub is_read_only: Option c_int>, /// // Returns the number of existing post data elements. /// - pub get_element_count: extern "C" fn(post_data: *mut cef_post_data) -> size_t, + pub get_element_count: Option size_t>, /// // Retrieve the post data elements. /// - pub get_elements: extern "C" fn(post_data: *mut cef_post_data, - elements_count: *mut size_t, elements: *mut *mut cef_post_data_element), + pub get_elements: Option, /// // Remove the specified post data element. Returns true (1) if the removal // succeeds. /// - pub remove_element: extern "C" fn(post_data: *mut cef_post_data, - element: *mut cef_post_data_element) -> c_int, + pub remove_element: Option c_int>, /// // Add the specified post data element. Returns true (1) if the add succeeds. /// - pub add_element: extern "C" fn(post_data: *mut cef_post_data, - element: *mut cef_post_data_element) -> c_int, + pub add_element: Option c_int>, /// // Remove all existing post data elements. /// - pub remove_elements: extern "C" fn(post_data: *mut cef_post_data), + pub remove_elements: Option, } From 11e30731ef141cde6a489f27311279d79aed8975 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 14 Nov 2014 15:34:54 -0500 Subject: [PATCH 2/3] embedding: change Option<> unwrapping for fptrs to use match --- ports/cef/core.rs | 22 +++++++++++++++------- ports/cef/string.rs | 30 ++++++++++++++++++------------ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 0d8d814634d6..44533b896611 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -23,13 +23,21 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t, } unsafe { command_line_init((*args).argc, (*args).argv); - if !(*application).get_browser_process_handler.is_some() { return 1; } - let cb = (*application).get_browser_process_handler.unwrap(); - let handler = cb(application); - if handler.is_not_null() { - if !(*handler).on_context_initialized.is_some() { return 1; } - let hcb = (*handler).on_context_initialized.unwrap(); - hcb(handler); + match (*application).get_browser_process_handler { + Some(cb) => { + let handler = cb(application); + if handler.is_not_null() { + match (*handler).on_context_initialized { + Some(hcb) => { + hcb(handler); + return 1; + }, + None => { return 1; } + } + } + return 1; + }, + None => { return 1; } } } return 1 diff --git a/ports/cef/string.rs b/ports/cef/string.rs index 36872ef19f90..fe94b7bc7507 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -52,10 +52,12 @@ pub extern "C" fn cef_string_userfree_utf16_free(cs: *mut cef_string_userfree_ut #[no_mangle] pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) { unsafe { - if (*cs).dtor.is_some() { - let dtor = (*cs).dtor.unwrap(); - dtor((*cs).str); - } + match (*cs).dtor { + Some(dtor) => { + dtor((*cs).str); + }, + None => () + }; (*cs).length = 0; (*cs).str = 0 as *mut u8; (*cs).dtor = mem::transmute(0 as *const u8); @@ -134,10 +136,12 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out #[no_mangle] pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) { unsafe { - if (*cs).dtor.is_some() { - let dtor = (*cs).dtor.unwrap(); - dtor((*cs).str); - } + match (*cs).dtor { + Some(dtor) => { + dtor((*cs).str); + }, + None => () + }; (*cs).length = 0; (*cs).str = 0 as *mut c_ushort; (*cs).dtor = mem::transmute(0 as *const u8); @@ -192,10 +196,12 @@ pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const c #[no_mangle] pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { unsafe { - if (*cs).dtor.is_some() { - let dtor = (*cs).dtor.unwrap(); - dtor((*cs).str); - } + match (*cs).dtor { + Some(dtor) => { + dtor((*cs).str); + }, + None => () + }; (*cs).length = 0; (*cs).str = 0 as *mut wchar_t; (*cs).dtor = mem::transmute(0 as *const u8); From 5f10092995d8c800fece8463e330d64c9a558768 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 14 Nov 2014 17:17:40 -0500 Subject: [PATCH 3/3] embedding: convert callback Option<> matching to map() --- ports/cef/core.rs | 16 +++------------- ports/cef/string.rs | 21 +++------------------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 44533b896611..16558b43bd87 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -23,22 +23,12 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t, } unsafe { command_line_init((*args).argc, (*args).argv); - match (*application).get_browser_process_handler { - Some(cb) => { + (*application).get_browser_process_handler.map(|cb| { let handler = cb(application); if handler.is_not_null() { - match (*handler).on_context_initialized { - Some(hcb) => { - hcb(handler); - return 1; - }, - None => { return 1; } - } + (*handler).on_context_initialized.map(|hcb| hcb(handler)); } - return 1; - }, - None => { return 1; } - } + }); } return 1 } diff --git a/ports/cef/string.rs b/ports/cef/string.rs index fe94b7bc7507..9f3baac8f10f 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -52,12 +52,7 @@ pub extern "C" fn cef_string_userfree_utf16_free(cs: *mut cef_string_userfree_ut #[no_mangle] pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) { unsafe { - match (*cs).dtor { - Some(dtor) => { - dtor((*cs).str); - }, - None => () - }; + (*cs).dtor.map(|dtor| dtor((*cs).str)); (*cs).length = 0; (*cs).str = 0 as *mut u8; (*cs).dtor = mem::transmute(0 as *const u8); @@ -136,12 +131,7 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out #[no_mangle] pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) { unsafe { - match (*cs).dtor { - Some(dtor) => { - dtor((*cs).str); - }, - None => () - }; + (*cs).dtor.map(|dtor| dtor((*cs).str)); (*cs).length = 0; (*cs).str = 0 as *mut c_ushort; (*cs).dtor = mem::transmute(0 as *const u8); @@ -196,12 +186,7 @@ pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const c #[no_mangle] pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { unsafe { - match (*cs).dtor { - Some(dtor) => { - dtor((*cs).str); - }, - None => () - }; + (*cs).dtor.map(|dtor| dtor((*cs).str)); (*cs).length = 0; (*cs).str = 0 as *mut wchar_t; (*cs).dtor = mem::transmute(0 as *const u8);