ports/cef: Use the CEF translator tool to generate the full set of CEF

bindings.

This replaces hand-implemented CEF bindings with proper Rust wrappers
automatically generated from the C++ headers. This means that, whenever
CEF's C++ headers change, we can easily generate both the appropriate C
API and the appropriate Rust API. It eliminates much of the hand-written
unsafe code within the CEF port, because the CEF translator tool now
knows how to generate Rust smart pointer wrappers for each class that
corrently perform reference counting.

Additionally, this commit adds utility macros (located in `macros.rs`)
that make it easier to correctly expose Rust objects as CEF objects.
They handle the marshaling of objects between Rust and CEF properly.
The net result of this is that you can write mostly-natural-looking Rust
in the CEF port and interact with it with a natural-looking C++ API on
the embedding side.

This setup relies on the branch of CEF located here:

    https://github.com/pcwalton/chromium-embedded-framework

To regenerate, follow the instructions in `ports/cef/README.md`. For
convenience, and because I don't anticipate the API to change much, I
have vendored in all of the appropriate interfaces.
This commit is contained in:
Patrick Walton 2014-11-24 17:23:30 -08:00
parent 431644bfc8
commit 3bf779cd21
82 changed files with 30917 additions and 1664 deletions

View file

@ -8,7 +8,7 @@ use std::collections::TreeMap;
use std::iter::AdditiveIterator;
use std::mem;
use std::string::String;
use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set};
use string::{cef_string_userfree_utf16_alloc,cef_string_userfree_utf16_free,cef_string_utf16_set};
use types::{cef_string_multimap_t,cef_string_t};
fn string_multimap_to_treemap(smm: *mut cef_string_multimap_t) -> *mut TreeMap<String, Vec<*mut cef_string_t>> {
@ -55,8 +55,8 @@ pub extern "C" fn cef_string_multimap_append(smm: *mut cef_string_multimap_t, ke
let v = string_multimap_to_treemap(smm);
slice_to_str((*key).str as *const u8, (*key).length as uint, |result| {
let s = String::from_str(result);
let csv = cef_string_userfree_utf8_alloc();
cef_string_utf8_set((*value).str as *const u8, (*value).length, csv, 1);
let csv = cef_string_userfree_utf16_alloc();
cef_string_utf16_set((*value).str as *const u16, (*value).length, csv, 1);
match (*v).get_mut(&s) {
Some(vc) => (*vc).push(csv),
None => { (*v).insert(s, vec!(csv)); }
@ -78,7 +78,7 @@ pub extern "C" fn cef_string_multimap_enumerate(smm: *mut cef_string_multimap_t,
return 0;
}
let cs = (*s)[index as uint];
cef_string_utf8_set((*cs).str as *const u8, (*cs).length, value, 1)
cef_string_utf16_set((*cs).str as *const u16, (*cs).length, value, 1)
}
None => 0
}
@ -95,7 +95,10 @@ pub extern "C" fn cef_string_multimap_key(smm: *mut cef_string_multimap_t, index
for (key, val) in (*v).iter() {
if rem < (*val).len() {
return cef_string_utf8_set((*key).as_bytes().as_ptr(), (*key).len() as u64, value, 1);
return cef_string_utf16_set((*key).as_bytes().as_ptr() as *const u16,
(*key).len() as u64,
value,
1);
} else {
rem -= (*val).len();
}
@ -114,7 +117,7 @@ pub extern "C" fn cef_string_multimap_value(smm: *mut cef_string_multimap_t, ind
for val in (*v).values() {
if rem < (*val).len() {
let cs = (*val)[rem as uint];
return cef_string_utf8_set((*cs).str as *const u8, (*cs).length, value, 1);
return cef_string_utf16_set((*cs).str as *const u16, (*cs).length, value, 1);
} else {
rem -= (*val).len();
}
@ -132,7 +135,7 @@ pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) {
for (_, val) in (*v).iter_mut() {
while (*val).len() != 0 {
let cs = (*val).pop();
cef_string_userfree_utf8_free(cs.unwrap());
cef_string_userfree_utf16_free(cs.unwrap());
}
}
(*v).clear();