Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
serious mode engaged: start of embedding crate using FFI
current status ============= [ ] Successfully crashing CEF [X] Successfully not crashing CEF
- Loading branch information
Mike Blumenkrantz
committed
May 26, 2014
1 parent
4d188e2
commit faa7f18
Showing
12 changed files
with
504 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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 libc::{calloc, size_t,c_int}; | ||
use std::mem; | ||
use types::{cef_browser_settings_t, cef_browser_t, cef_client_t, cef_request_context_t, cef_string_t, cef_window_info_t}; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_browser_host_create_browser(windowInfo: *cef_window_info_t, | ||
client: *mut cef_client_t, | ||
url: *cef_string_t, | ||
settings: *cef_browser_settings_t, | ||
request_context: *mut cef_request_context_t) -> c_int { | ||
0 | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_browser_host_create_browser_sync(windowInfo: *cef_window_info_t, | ||
client: *mut cef_client_t, | ||
url: *cef_string_t, | ||
settings: *cef_browser_settings_t, | ||
request_context: *mut cef_request_context_t) -> *mut cef_browser_t { | ||
unsafe { | ||
let browser = calloc(1, mem::size_of::<cef_browser_t>() as size_t) as *mut cef_browser_t; | ||
browser | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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 libc::{calloc, c_int, size_t}; | ||
use std::mem; | ||
use std::str; | ||
use std::c_vec::CVec; | ||
use std::cast::transmute; | ||
use string::{cef_string_userfree_utf16_alloc, cef_string_utf16_set}; | ||
use types::{cef_command_line_t, cef_string_t, cef_string_userfree_t, cef_string_utf16_t}; | ||
|
||
type command_line_t = command_line; | ||
struct command_line { | ||
pub cl: cef_command_line_t, | ||
pub argc: c_int, | ||
pub argv: Vec<~str>, | ||
} | ||
|
||
static mut GLOBAL_CMDLINE: Option<*mut command_line_t> = None; | ||
|
||
fn command_line_new() -> *mut command_line_t { | ||
unsafe { | ||
let cl = calloc(1, mem::size_of::<command_line>() as size_t) as *mut command_line_t; | ||
(*cl).cl.base.size = mem::size_of::<cef_command_line_t>() as u64; | ||
cl | ||
} | ||
} | ||
|
||
pub fn command_line_init(argc: c_int, argv: **u8) { | ||
unsafe { | ||
let mut a: Vec<~str> = vec!(); | ||
for i in range(0u, argc as uint) { | ||
a.push(str::raw::from_c_str(*argv.offset(i as int) as *i8)); | ||
} | ||
let cl = command_line_new(); | ||
(*cl).argc = argc; | ||
(*cl).argv = a; | ||
(*cl).cl.get_switch_value = command_line_get_switch_value; | ||
GLOBAL_CMDLINE = Some(cl); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, name: *cef_string_t) -> *mut cef_string_userfree_t { | ||
if cmd.is_null() || name.is_null() { | ||
return 0 as *mut cef_string_userfree_t; | ||
} | ||
unsafe { | ||
//technically cef_string_t can be any type of character size | ||
//but the default cef callback uses utf16, so I'm jumping on board the SS Copy | ||
let cl: *mut command_line_t = transmute(cmd); | ||
let cs: *cef_string_utf16_t = transmute(name); | ||
let opt = str::from_utf16(CVec::new((*cs).str, (*cs).length as uint).as_slice()).unwrap(); | ||
//debug!("opt: {}", opt); | ||
for s in (*cl).argv.iter() { | ||
let o = s.trim_left_chars('-'); | ||
//debug!("arg: {}", o); | ||
if o.starts_with(opt) { | ||
let string = cef_string_userfree_utf16_alloc() as *mut cef_string_utf16_t; | ||
let arg = o.slice_from(opt.len() + 1).as_bytes(); | ||
arg.with_c_str(|c_str| { | ||
cef_string_utf16_set(transmute(c_str), arg.len() as u64, string, 1); | ||
}); | ||
return string as *mut cef_string_userfree_t | ||
} | ||
} | ||
} | ||
return 0 as *mut cef_string_userfree_t; | ||
} | ||
|
||
#[no_mangle] | ||
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; | ||
transmute(cl) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_command_line_get_global() -> *mut cef_command_line_t { | ||
unsafe { | ||
match GLOBAL_CMDLINE { | ||
Some(scl) => { | ||
transmute(scl) | ||
}, | ||
None => { | ||
0 as *mut cef_command_line_t | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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 azure; | ||
use command_line::command_line_init; | ||
use eutil::fptr_is_null; | ||
use libc::{c_int, c_void}; | ||
use native; | ||
use servo; | ||
use servo_util::opts; | ||
use std::cast::transmute; | ||
use types::{cef_app_t, cef_main_args_t, cef_settings_t}; | ||
|
||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_initialize(args: *cef_main_args_t, settings: *mut cef_settings_t, | ||
application: *mut cef_app_t, windows_sandbox_info: *c_void) -> c_int { | ||
if args.is_null() { | ||
return 0; | ||
} | ||
unsafe { | ||
command_line_init((*args).argc, (*args).argv); | ||
let cb = (*application).get_browser_process_handler; | ||
if !fptr_is_null(transmute(cb)) { | ||
let handler = cb(application); | ||
if handler.is_not_null() { | ||
let hcb = (*handler).on_context_initialized; | ||
if !fptr_is_null(transmute(hcb)) { | ||
hcb(handler); | ||
} | ||
} | ||
} | ||
} | ||
return 1 | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_shutdown() { | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_run_message_loop() { | ||
let mut urls = Vec::new(); | ||
urls.push("http://www.w3c-test.org".to_owned()); | ||
let opts = opts::Opts { | ||
urls: urls, | ||
render_backend: azure::azure_hl::SkiaBackend, | ||
n_render_threads: 1, | ||
cpu_painting: false, | ||
tile_size: 512, | ||
profiler_period: None, | ||
layout_threads: 1, | ||
//layout_threads: cmp::max(rt::default_sched_threads() * 3 / 4, 1), | ||
exit_after_load: false, | ||
output_file: None, | ||
headless: false, | ||
hard_fail: false, | ||
bubble_widths_separately: false, | ||
}; | ||
native::start(0, 0 as **u8, proc() { | ||
servo::run(opts); | ||
}); | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_quit_message_loop() { | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_execute_process(args: *cef_main_args_t, app: *mut cef_app_t, windows_sandbox_info: *mut c_void) -> c_int { | ||
-1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
pub fn fptr_is_null(fptr: *u8) -> bool { | ||
fptr.is_null() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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 libc::{c_void, size_t}; | ||
use std::mem; | ||
use std::ptr::set_memory; | ||
|
||
extern "C" { | ||
fn tc_new(size: size_t) -> *mut c_void; | ||
fn tc_delete(mem: *mut c_void); | ||
fn tc_newarray(size: size_t) -> *mut c_void; | ||
fn tc_deletearray(mem: *mut c_void); | ||
} | ||
|
||
pub fn newarray0<T>(nmem: size_t) -> *mut T { | ||
let mem = newarray::<T>(nmem) as *mut T; | ||
unsafe { | ||
set_memory(mem, 0 as u8, nmem as uint); | ||
} | ||
mem | ||
} | ||
|
||
pub fn newarray<T>(nmem: size_t) -> *mut T { | ||
unsafe { | ||
tc_newarray(nmem * mem::size_of::<T>() as u64) as *mut T | ||
} | ||
} | ||
|
||
pub fn new0<T>(nmem: size_t) -> *mut T { | ||
let mem = new(nmem * mem::size_of::<T>() as u64) as *mut T; | ||
unsafe { | ||
set_memory(mem, 0 as u8, nmem as uint); | ||
} | ||
mem | ||
} | ||
|
||
pub fn new(size: size_t) -> *mut c_void { | ||
unsafe { | ||
tc_new(size) | ||
} | ||
} | ||
|
||
pub fn delete(mem: *mut c_void) { | ||
unsafe { | ||
tc_delete(mem) | ||
} | ||
} | ||
|
||
pub fn deletearray(mem: *mut c_void) { | ||
unsafe { | ||
tc_deletearray(mem) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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 types::{cef_post_data_element_t, cef_post_data_t, cef_request_t}; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_request_create() -> *mut cef_request_t { | ||
0 as *mut cef_request_t | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_post_data_create() -> *mut cef_post_data_t { | ||
0 as *mut cef_post_data_t | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn cef_post_data_element_create() -> *mut cef_post_data_element_t { | ||
0 as *mut cef_post_data_element_t | ||
} |
Oops, something went wrong.