Skip to content

Commit

Permalink
update all cef interfaces to use borrows for string_list params
Browse files Browse the repository at this point in the history
it was somewhat impossible to make this work with allocated string_lists
due to constant leakage from box allocations going out of scope, so this should
simplify it ane be more manageable in the future
  • Loading branch information
Mike Blumenkrantz committed Jun 3, 2015
1 parent e8e300a commit 612cefa
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 39 deletions.
12 changes: 6 additions & 6 deletions ports/cef/interfaces/cef_browser.rs
Expand Up @@ -174,7 +174,7 @@ pub struct _cef_browser_t {
// Returns the names of all existing frames.
//
pub get_frame_names: Option<extern "C" fn(this: *mut cef_browser_t,
names: types::cef_string_list_t) -> ()>,
names: &types::cef_string_list_t) -> ()>,

//
// Send a message to the specified |target_process|. Returns true (1) if the
Expand Down Expand Up @@ -567,7 +567,7 @@ impl CefBrowser {
//
// Returns the names of all existing frames.
//
pub fn get_frame_names(&self, names: Vec<String>) -> () {
pub fn get_frame_names(&self, names: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down Expand Up @@ -647,7 +647,7 @@ pub struct _cef_run_file_dialog_callback_t {
pub on_file_dialog_dismissed: Option<extern "C" fn(
this: *mut cef_run_file_dialog_callback_t,
selected_accept_filter: libc::c_int,
file_paths: types::cef_string_list_t) -> ()>,
file_paths: &types::cef_string_list_t) -> ()>,

//
// The reference count. This will only be present for Rust instances!
Expand Down Expand Up @@ -742,7 +742,7 @@ impl CefRunFileDialogCallback {
// dialog mode. If the selection was cancelled |file_paths| will be NULL.
//
pub fn on_file_dialog_dismissed(&self, selected_accept_filter: libc::c_int,
file_paths: Vec<String>) -> () {
file_paths: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down Expand Up @@ -1047,7 +1047,7 @@ pub struct _cef_browser_host_t {
pub run_file_dialog: Option<extern "C" fn(this: *mut cef_browser_host_t,
mode: types::cef_file_dialog_mode_t, title: *const types::cef_string_t,
default_file_path: *const types::cef_string_t,
accept_filters: types::cef_string_list_t,
accept_filters: &types::cef_string_list_t,
selected_accept_filter: libc::c_int,
callback: *mut interfaces::cef_run_file_dialog_callback_t) -> ()>,

Expand Down Expand Up @@ -1606,7 +1606,7 @@ impl CefBrowserHost {
// will be initiated asynchronously on the UI thread.
//
pub fn run_file_dialog(&self, mode: types::cef_file_dialog_mode_t,
title: &[u16], default_file_path: &[u16], accept_filters: Vec<String>,
title: &[u16], default_file_path: &[u16], accept_filters: &Vec<String>,
selected_accept_filter: libc::c_int,
callback: interfaces::CefRunFileDialogCallback) -> () {
if self.c_object.is_null() ||
Expand Down
6 changes: 4 additions & 2 deletions ports/cef/interfaces/cef_browser_process_handler.rs
Expand Up @@ -95,7 +95,8 @@ pub struct _cef_browser_process_handler_t {
this: *mut cef_browser_process_handler_t) -> *mut interfaces::cef_print_handler_t>,

//
// Called when the application should call cef_do_message_loop_work()
// Called when the application should call cef_do_message_loop_work(). May be
// called from a thread.
//
pub on_work_available: Option<extern "C" fn(
this: *mut cef_browser_process_handler_t) -> ()>,
Expand Down Expand Up @@ -261,7 +262,8 @@ impl CefBrowserProcessHandler {
}

//
// Called when the application should call cef_do_message_loop_work()
// Called when the application should call cef_do_message_loop_work(). May be
// called from a thread.
//
pub fn on_work_available(&self) -> () {
if self.c_object.is_null() ||
Expand Down
8 changes: 4 additions & 4 deletions ports/cef/interfaces/cef_command_line.rs
Expand Up @@ -109,7 +109,7 @@ pub struct _cef_command_line_t {
// array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* }
//
pub get_argv: Option<extern "C" fn(this: *mut cef_command_line_t,
argv: types::cef_string_list_t) -> ()>,
argv: &types::cef_string_list_t) -> ()>,

//
// Constructs and returns the represented command line string. Use this
Expand Down Expand Up @@ -183,7 +183,7 @@ pub struct _cef_command_line_t {
// Get the remaining command line arguments.
//
pub get_arguments: Option<extern "C" fn(this: *mut cef_command_line_t,
arguments: types::cef_string_list_t) -> ()>,
arguments: &types::cef_string_list_t) -> ()>,

//
// Add an argument to the end of the command line.
Expand Down Expand Up @@ -392,7 +392,7 @@ impl CefCommandLine {
// Retrieve the original command line string as a vector of strings. The argv
// array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* }
//
pub fn get_argv(&self, argv: Vec<String>) -> () {
pub fn get_argv(&self, argv: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down Expand Up @@ -572,7 +572,7 @@ impl CefCommandLine {
//
// Get the remaining command line arguments.
//
pub fn get_arguments(&self, arguments: Vec<String>) -> () {
pub fn get_arguments(&self, arguments: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
4 changes: 2 additions & 2 deletions ports/cef/interfaces/cef_context_menu_handler.rs
Expand Up @@ -403,7 +403,7 @@ pub struct _cef_context_menu_params_t {
//
pub get_dictionary_suggestions: Option<extern "C" fn(
this: *mut cef_context_menu_params_t,
suggestions: types::cef_string_list_t) -> libc::c_int>,
suggestions: &types::cef_string_list_t) -> libc::c_int>,

//
// Returns true (1) if the context menu was invoked on an editable node.
Expand Down Expand Up @@ -746,7 +746,7 @@ impl CefContextMenuParams {
// is one.
//
pub fn get_dictionary_suggestions(&self,
suggestions: Vec<String>) -> libc::c_int {
suggestions: &Vec<String>) -> libc::c_int {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
4 changes: 2 additions & 2 deletions ports/cef/interfaces/cef_cookie.rs
Expand Up @@ -64,7 +64,7 @@ pub struct _cef_cookie_manager_t {
// Must be called before any cookies are accessed.
//
pub set_supported_schemes: Option<extern "C" fn(
this: *mut cef_cookie_manager_t, schemes: types::cef_string_list_t,
this: *mut cef_cookie_manager_t, schemes: &types::cef_string_list_t,
callback: *mut interfaces::cef_completion_callback_t) -> ()>,

//
Expand Down Expand Up @@ -227,7 +227,7 @@ impl CefCookieManager {
// executed asnychronously on the IO thread after the change has been applied.
// Must be called before any cookies are accessed.
//
pub fn set_supported_schemes(&self, schemes: Vec<String>,
pub fn set_supported_schemes(&self, schemes: &Vec<String>,
callback: interfaces::CefCompletionCallback) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
Expand Down
8 changes: 4 additions & 4 deletions ports/cef/interfaces/cef_dialog_handler.rs
Expand Up @@ -65,7 +65,7 @@ pub struct _cef_file_dialog_callback_t {
//
pub cont: Option<extern "C" fn(this: *mut cef_file_dialog_callback_t,
selected_accept_filter: libc::c_int,
file_paths: types::cef_string_list_t) -> ()>,
file_paths: &types::cef_string_list_t) -> ()>,

//
// Cancel the file selection.
Expand Down Expand Up @@ -165,7 +165,7 @@ impl CefFileDialogCallback {
// value is treated the same as calling cancel().
//
pub fn cont(&self, selected_accept_filter: libc::c_int,
file_paths: Vec<String>) -> () {
file_paths: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down Expand Up @@ -251,7 +251,7 @@ pub struct _cef_dialog_handler_t {
browser: *mut interfaces::cef_browser_t,
mode: types::cef_file_dialog_mode_t, title: *const types::cef_string_t,
default_file_path: *const types::cef_string_t,
accept_filters: types::cef_string_list_t,
accept_filters: &types::cef_string_list_t,
selected_accept_filter: libc::c_int,
callback: *mut interfaces::cef_file_dialog_callback_t) -> libc::c_int>,

Expand Down Expand Up @@ -357,7 +357,7 @@ impl CefDialogHandler {
//
pub fn on_file_dialog(&self, browser: interfaces::CefBrowser,
mode: types::cef_file_dialog_mode_t, title: &[u16],
default_file_path: &[u16], accept_filters: Vec<String>,
default_file_path: &[u16], accept_filters: &Vec<String>,
selected_accept_filter: libc::c_int,
callback: interfaces::CefFileDialogCallback) -> libc::c_int {
if self.c_object.is_null() ||
Expand Down
4 changes: 2 additions & 2 deletions ports/cef/interfaces/cef_display_handler.rs
Expand Up @@ -77,7 +77,7 @@ pub struct _cef_display_handler_t {
//
pub on_favicon_urlchange: Option<extern "C" fn(
this: *mut cef_display_handler_t, browser: *mut interfaces::cef_browser_t,
icon_urls: types::cef_string_list_t) -> ()>,
icon_urls: &types::cef_string_list_t) -> ()>,

//
// Called when the browser is about to display a tooltip. |text| contains the
Expand Down Expand Up @@ -234,7 +234,7 @@ impl CefDisplayHandler {
// Called when the page icon changes.
//
pub fn on_favicon_urlchange(&self, browser: interfaces::CefBrowser,
icon_urls: Vec<String>) -> () {
icon_urls: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
4 changes: 2 additions & 2 deletions ports/cef/interfaces/cef_drag_data.rs
Expand Up @@ -149,7 +149,7 @@ pub struct _cef_drag_data_t {
// window.
//
pub get_file_names: Option<extern "C" fn(this: *mut cef_drag_data_t,
names: types::cef_string_list_t) -> libc::c_int>,
names: &types::cef_string_list_t) -> libc::c_int>,

//
// Set the link URL that is being dragged.
Expand Down Expand Up @@ -499,7 +499,7 @@ impl CefDragData {
// Retrieve the list of file names that are being dragged into the browser
// window.
//
pub fn get_file_names(&self, names: Vec<String>) -> libc::c_int {
pub fn get_file_names(&self, names: &Vec<String>) -> libc::c_int {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
16 changes: 8 additions & 8 deletions ports/cef/interfaces/cef_ssl_info.rs
Expand Up @@ -97,28 +97,28 @@ pub struct _cef_sslcert_principal_t {
//
pub get_street_addresses: Option<extern "C" fn(
this: *mut cef_sslcert_principal_t,
addresses: types::cef_string_list_t) -> ()>,
addresses: &types::cef_string_list_t) -> ()>,

//
// Retrieve the list of organization names.
//
pub get_organization_names: Option<extern "C" fn(
this: *mut cef_sslcert_principal_t, names: types::cef_string_list_t) -> (
this: *mut cef_sslcert_principal_t, names: &types::cef_string_list_t) -> (
)>,

//
// Retrieve the list of organization unit names.
//
pub get_organization_unit_names: Option<extern "C" fn(
this: *mut cef_sslcert_principal_t, names: types::cef_string_list_t) -> (
this: *mut cef_sslcert_principal_t, names: &types::cef_string_list_t) -> (
)>,

//
// Retrieve the list of domain components.
//
pub get_domain_components: Option<extern "C" fn(
this: *mut cef_sslcert_principal_t,
components: types::cef_string_list_t) -> ()>,
components: &types::cef_string_list_t) -> ()>,

//
// The reference count. This will only be present for Rust instances!
Expand Down Expand Up @@ -288,7 +288,7 @@ impl CefSSLCertPrincipal {
//
// Retrieve the list of street addresses.
//
pub fn get_street_addresses(&self, addresses: Vec<String>) -> () {
pub fn get_street_addresses(&self, addresses: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand All @@ -304,7 +304,7 @@ impl CefSSLCertPrincipal {
//
// Retrieve the list of organization names.
//
pub fn get_organization_names(&self, names: Vec<String>) -> () {
pub fn get_organization_names(&self, names: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand All @@ -320,7 +320,7 @@ impl CefSSLCertPrincipal {
//
// Retrieve the list of organization unit names.
//
pub fn get_organization_unit_names(&self, names: Vec<String>) -> () {
pub fn get_organization_unit_names(&self, names: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand All @@ -336,7 +336,7 @@ impl CefSSLCertPrincipal {
//
// Retrieve the list of domain components.
//
pub fn get_domain_components(&self, components: Vec<String>) -> () {
pub fn get_domain_components(&self, components: &Vec<String>) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
4 changes: 2 additions & 2 deletions ports/cef/interfaces/cef_v8.rs
Expand Up @@ -1364,7 +1364,7 @@ pub struct _cef_v8value_t {
// based keys will also be returned as strings.
//
pub get_keys: Option<extern "C" fn(this: *mut cef_v8value_t,
keys: types::cef_string_list_t) -> libc::c_int>,
keys: &types::cef_string_list_t) -> libc::c_int>,

//
// Sets the user data for this object and returns true (1) on success. Returns
Expand Down Expand Up @@ -2117,7 +2117,7 @@ impl CefV8Value {
// Read the keys for the object's values into the specified vector. Integer-
// based keys will also be returned as strings.
//
pub fn get_keys(&self, keys: Vec<String>) -> libc::c_int {
pub fn get_keys(&self, keys: &Vec<String>) -> libc::c_int {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
4 changes: 2 additions & 2 deletions ports/cef/interfaces/cef_values.rs
Expand Up @@ -1099,7 +1099,7 @@ pub struct _cef_dictionary_value_t {
// Reads all keys for this dictionary into the specified vector.
//
pub get_keys: Option<extern "C" fn(this: *mut cef_dictionary_value_t,
keys: types::cef_string_list_t) -> libc::c_int>,
keys: &types::cef_string_list_t) -> libc::c_int>,

//
// Removes the value at the specified key. Returns true (1) is the value was
Expand Down Expand Up @@ -1489,7 +1489,7 @@ impl CefDictionaryValue {
//
// Reads all keys for this dictionary into the specified vector.
//
pub fn get_keys(&self, keys: Vec<String>) -> libc::c_int {
pub fn get_keys(&self, keys: &Vec<String>) -> libc::c_int {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
Expand Down
2 changes: 1 addition & 1 deletion ports/cef/window.rs
Expand Up @@ -356,7 +356,7 @@ impl WindowMethods for Window {
browser.downcast().forward.set(forward);
if check_ptr_exist!(browser.get_host().get_client(), get_display_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_display_handler(), on_favicon_urlchange) {
browser.get_host().get_client().get_display_handler().on_favicon_urlchange((*browser).clone(), browser.downcast().favicons.borrow().clone());
browser.get_host().get_client().get_display_handler().on_favicon_urlchange((*browser).clone(), &browser.downcast().favicons.borrow());
}
if check_ptr_exist!(browser.get_host().get_client(), get_load_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_load_handler(), on_loading_state_change) {
Expand Down
11 changes: 9 additions & 2 deletions ports/cef/wrappers.rs
Expand Up @@ -135,7 +135,6 @@ cef_noop_wrapper!(*mut cef_jsdialog_handler_t);
cef_noop_wrapper!(*mut cef_keyboard_handler_t);
cef_noop_wrapper!(*mut cef_load_handler_t);
cef_noop_wrapper!(*mut cef_request_handler_t);
cef_noop_wrapper!(*mut cef_string_list_t);
cef_noop_wrapper!(*mut cef_string_utf16);
cef_noop_wrapper!(c_int);
cef_noop_wrapper!(CefApp);
Expand Down Expand Up @@ -185,10 +184,10 @@ cef_noop_wrapper!(f64);
cef_noop_wrapper!(i64);
cef_noop_wrapper!(u32);
cef_noop_wrapper!(u64);
cef_noop_wrapper!(cef_string_list_t);

cef_unimplemented_wrapper!(*const *mut cef_v8value_t, *const CefV8Value);
cef_unimplemented_wrapper!(*mut *mut cef_post_data_element_t, *mut CefPostDataElement);
cef_unimplemented_wrapper!(cef_string_list_t, Vec<String>);
cef_unimplemented_wrapper!(cef_string_map_t, HashMap<String,String>);
cef_unimplemented_wrapper!(cef_string_multimap_t, HashMap<String,Vec<String>>);
cef_unimplemented_wrapper!(cef_string_t, String);
Expand Down Expand Up @@ -293,3 +292,11 @@ impl<'a> CefWrap<cef_string_t> for &'a mut String {
}
}

impl<'a> CefWrap<&'a cef_string_list_t> for &'a cef_string_list_t {
fn to_c(stringlist: &'a cef_string_list_t) -> &'a cef_string_list_t {
stringlist
}
unsafe fn to_rust(_: &'a cef_string_list_t) -> &'a cef_string_list_t {
panic!("unimplemented CEF type conversion: cef_string_t");
}
}

0 comments on commit 612cefa

Please sign in to comment.