From 9fe95fc77e996ce185ef163c3b22a595d11cd858 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 13 Oct 2014 06:32:50 -0400 Subject: [PATCH 1/8] embedding: implement cef_string_utf16_cmp() --- ports/cef/string.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ports/cef/string.rs b/ports/cef/string.rs index 855fa1226ec..d8cf7d97531 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -167,6 +167,21 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou return 1; } +#[no_mangle] +pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const cef_string_utf16_t) -> c_int { + unsafe { + slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u16]| { + slice::raw::buf_as_slice(mem::transmute((*b).str), (*b).length as uint, |bstr:&[u16]| { + match astr.cmp(&bstr) { + Less => -1, + Equal => 0, + Greater => 1 + } + }) + }) + } +} + #[no_mangle] pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { unsafe { From 4d8ed45e7b4697a789b2d3d7708c5f89cfa2e99f Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:20:04 -0400 Subject: [PATCH 2/8] embedding: begin cef string_list api cef_string_list_alloc() --- ports/cef/lib.rs | 1 + ports/cef/string_list.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 ports/cef/string_list.rs diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index bf7aeec80e6..a4e12301137 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -50,6 +50,7 @@ pub mod eutil; pub mod mem; pub mod request; pub mod string; +pub mod string_list; pub mod task; pub mod types; pub mod urlrequest; diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs new file mode 100644 index 00000000000..9516c5b1848 --- /dev/null +++ b/ports/cef/string_list.rs @@ -0,0 +1,19 @@ +/* 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 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}; +use types::{cef_string_list_t,cef_string_t}; + +//cef_string_list + +#[no_mangle] +extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { + unsafe { + let lt: Box> = box vec!(); + mem::transmute(lt) + } +} From ee8ef615a6198f2c0760823bef734d9c71121477 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:20:44 -0400 Subject: [PATCH 3/8] embedding: cef_string_list_size() --- ports/cef/string_list.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index 9516c5b1848..74716e017d0 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -17,3 +17,12 @@ extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { mem::transmute(lt) } } + +#[no_mangle] +extern "C" fn cef_string_list_size(lt: *const cef_string_list_t) -> c_int { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return 0; } + let v: Box> = mem::transmute(lt); + v.len() as c_int + } +} From f957f989cf7f90e1183601aefa32dcc08fd131b2 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:21:10 -0400 Subject: [PATCH 4/8] embedding: cef_string_list_append() --- ports/cef/string_list.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index 74716e017d0..54310f0b75e 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -26,3 +26,14 @@ extern "C" fn cef_string_list_size(lt: *const cef_string_list_t) -> c_int { v.len() as c_int } } + +#[no_mangle] +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; } + let mut v: Box> = mem::transmute(lt); + let cs = cef_string_userfree_utf8_alloc(); + cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); + v.push(cs); + } +} From 9e5b240899768a23d9ae18943eda41889763860c Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:21:26 -0400 Subject: [PATCH 5/8] embedding: cef_string_list_value() --- ports/cef/string_list.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index 54310f0b75e..d103f5b8da7 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -37,3 +37,14 @@ extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *const c v.push(cs); } } + +#[no_mangle] +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; } + let v: Box> = mem::transmute(lt); + if index as uint > v.len() - 1 { return 0; } + let cs = v.get(index as uint); + cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) + } +} From 866483f05ea0d1f0e659ac1e3be440123baf75e2 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:21:44 -0400 Subject: [PATCH 6/8] embedding: cef_string_list_clear() --- ports/cef/string_list.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index d103f5b8da7..3f5424ace50 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -48,3 +48,17 @@ extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int, va cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) } } + +#[no_mangle] +extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return; } + let mut v: Box> = mem::transmute(lt); + if v.len() == 0 { return; } + let mut cs; + while v.len() != 0 { + cs = v.pop(); + cef_string_userfree_utf8_free(cs.unwrap()); + } + } +} From 04020d2a19e0e35e1829d64cacef79b7e53d69b8 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:23:08 -0400 Subject: [PATCH 7/8] embedding: cef_string_list_free() --- ports/cef/string_list.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index 3f5424ace50..f04862773a7 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -62,3 +62,13 @@ extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { } } } + +#[no_mangle] +extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return; } + let mut v: Box> = mem::transmute(lt); + cef_string_list_clear(lt); + drop(v); + } +} From 31db6389617ad8416565cacce4a6d169f172fdc0 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 14 Oct 2014 15:23:20 -0400 Subject: [PATCH 8/8] embedding: cef_string_list_copy() --- ports/cef/string_list.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index f04862773a7..fdf7e6ddbd2 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -72,3 +72,16 @@ extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { drop(v); } } + +#[no_mangle] +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; } + let v: Box> = mem::transmute(lt); + let lt2 = cef_string_list_alloc(); + for cs in v.iter() { + cef_string_list_append(lt2, mem::transmute((*cs))); + } + lt2 + } +}