Skip to content

Commit

Permalink
auto merge of #3984 : zmike/servo/embedding-option_callbacks, r=jdm
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Nov 15, 2014
2 parents 0ab70dd + 5f10092 commit 443b1b9
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 228 deletions.
4 changes: 2 additions & 2 deletions ports/cef/command_line.rs
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
16 changes: 5 additions & 11 deletions ports/cef/core.rs
Expand Up @@ -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]
Expand All @@ -25,16 +23,12 @@ 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);
(*application).get_browser_process_handler.map(|cb| {
let handler = cb(application);
if handler.is_not_null() {
(*handler).on_context_initialized.map(|hcb| hcb(handler));
}
}
}
});
}
return 1
}
Expand Down
4 changes: 0 additions & 4 deletions ports/cef/eutil.rs
Expand Up @@ -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| {
Expand Down
23 changes: 7 additions & 16 deletions ports/cef/string.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -52,10 +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 {
if !fptr_is_null(mem::transmute((*cs).dtor)) {
let dtor = (*cs).dtor;
dtor((*cs).str);
}
(*cs).dtor.map(|dtor| dtor((*cs).str));
(*cs).length = 0;
(*cs).str = 0 as *mut u8;
(*cs).dtor = mem::transmute(0 as *const u8);
Expand All @@ -81,7 +78,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);
Expand Down Expand Up @@ -134,10 +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 {
if !fptr_is_null(mem::transmute((*cs).dtor)) {
let dtor = (*cs).dtor;
dtor((*cs).str);
}
(*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);
Expand All @@ -163,7 +157,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);
Expand Down Expand Up @@ -192,10 +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 {
if !fptr_is_null(mem::transmute((*cs).dtor)) {
let dtor = (*cs).dtor;
dtor((*cs).str);
}
(*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);
Expand All @@ -221,7 +212,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);
Expand Down
13 changes: 6 additions & 7 deletions ports/cef/string_list.rs
Expand Up @@ -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};
Expand All @@ -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
}
Expand All @@ -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);
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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<Vec<*mut cef_string_t>> = mem::transmute(lt);
cef_string_list_clear(lt);
drop(v);
Expand All @@ -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() {
Expand Down
16 changes: 8 additions & 8 deletions ports/cef/string_map.rs
Expand Up @@ -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;
Expand All @@ -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
}
Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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; }

Expand All @@ -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; }

Expand All @@ -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);
Expand All @@ -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<TreeMap<String, *mut cef_string_t>> = mem::transmute(sm);
cef_string_map_clear(sm);
}
Expand Down

0 comments on commit 443b1b9

Please sign in to comment.