mirror of
https://github.com/servo/servo.git
synced 2025-06-28 11:03:39 +01:00
Auto merge of #13911 - upsuper:bug1312338, r=Manishearth
Use nsACString to pass string params for bindings This is the Servo side change of [bug 1312338](https://bugzilla.mozilla.org/show_bug.cgi?id=1312338) which has been reviewed by @Manishearth. r? @Manishearth (This should not be merged before the Gecko side code lands in m-c) <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13911) <!-- Reviewable:end -->
This commit is contained in:
commit
a9715c1f02
4 changed files with 44 additions and 46 deletions
|
@ -233,7 +233,13 @@ COMPILATION_TARGETS = {
|
||||||
# Generation of the ffi bindings.
|
# Generation of the ffi bindings.
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"target_dir": "../gecko_bindings",
|
"target_dir": "../gecko_bindings",
|
||||||
"raw_lines": [],
|
"blacklist_types": [
|
||||||
|
"nsACString_internal",
|
||||||
|
],
|
||||||
|
"raw_lines": [
|
||||||
|
"pub use nsstring::nsACString;",
|
||||||
|
"type nsACString_internal = nsACString;",
|
||||||
|
],
|
||||||
"flags": [
|
"flags": [
|
||||||
"--ignore-methods",
|
"--ignore-methods",
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/* automatically generated by rust-bindgen */
|
/* automatically generated by rust-bindgen */
|
||||||
|
|
||||||
|
pub use nsstring::nsACString;
|
||||||
|
type nsACString_internal = nsACString;
|
||||||
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
|
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
|
||||||
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
|
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
|
||||||
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
|
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
|
||||||
|
@ -837,10 +839,10 @@ extern "C" {
|
||||||
pub fn Servo_Node_ClearNodeData(node: RawGeckoNodeBorrowed);
|
pub fn Servo_Node_ClearNodeData(node: RawGeckoNodeBorrowed);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSheet_FromUTF8Bytes(bytes: *const u8, length: u32,
|
pub fn Servo_StyleSheet_FromUTF8Bytes(data: *const nsACString_internal,
|
||||||
parsing_mode: SheetParsingMode,
|
parsing_mode: SheetParsingMode,
|
||||||
base_bytes: *const u8,
|
base_url:
|
||||||
base_length: u32,
|
*const nsACString_internal,
|
||||||
base: *mut ThreadSafeURIHolder,
|
base: *mut ThreadSafeURIHolder,
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
referrer: *mut ThreadSafeURIHolder,
|
||||||
principal:
|
principal:
|
||||||
|
@ -876,10 +878,9 @@ extern "C" {
|
||||||
RawServoStyleSheetBorrowed);
|
RawServoStyleSheetBorrowed);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseProperty(property_bytes: *const u8,
|
pub fn Servo_ParseProperty(property: *const nsACString_internal,
|
||||||
property_length: u32, value_bytes: *const u8,
|
value: *const nsACString_internal,
|
||||||
value_length: u32, base_bytes: *const u8,
|
base_url: *const nsACString_internal,
|
||||||
base_length: u32,
|
|
||||||
base: *mut ThreadSafeURIHolder,
|
base: *mut ThreadSafeURIHolder,
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
referrer: *mut ThreadSafeURIHolder,
|
||||||
principal: *mut ThreadSafePrincipalHolder)
|
principal: *mut ThreadSafePrincipalHolder)
|
||||||
|
@ -893,7 +894,7 @@ extern "C" {
|
||||||
-> ServoComputedValuesStrong;
|
-> ServoComputedValuesStrong;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32)
|
pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
|
||||||
-> RawServoDeclarationBlockStrong;
|
-> RawServoDeclarationBlockStrong;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -907,8 +908,8 @@ extern "C" {
|
||||||
buffer: *mut nsString);
|
buffer: *mut nsString);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_CSSSupports(name: *const u8, name_length: u32,
|
pub fn Servo_CSSSupports(name: *const nsACString_internal,
|
||||||
value: *const u8, value_length: u32) -> bool;
|
value: *const nsACString_internal) -> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
pub fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
||||||
|
|
|
@ -144,6 +144,7 @@ use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::str;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
@ -569,6 +570,10 @@ impl nsACString {
|
||||||
Gecko_AppendUTF16toCString(self as *mut _, other as *const _);
|
Gecko_AppendUTF16toCString(self as *mut _, other as *const _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub unsafe fn as_str_unchecked(&self) -> &str {
|
||||||
|
str::from_utf8_unchecked(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a str> for nsCString<'a> {
|
impl<'a> From<&'a str> for nsCString<'a> {
|
||||||
|
|
|
@ -8,8 +8,6 @@ use env_logger;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
use std::slice;
|
|
||||||
use std::str::from_utf8_unchecked;
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use style::arc_ptr_eq;
|
use style::arc_ptr_eq;
|
||||||
use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
|
use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
|
||||||
|
@ -29,6 +27,7 @@ use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedVal
|
||||||
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
||||||
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
||||||
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
||||||
|
use style::gecko_bindings::bindings::nsACString;
|
||||||
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
||||||
use style::gecko_bindings::structs::ServoElementSnapshot;
|
use style::gecko_bindings::structs::ServoElementSnapshot;
|
||||||
use style::gecko_bindings::structs::nsRestyleHint;
|
use style::gecko_bindings::structs::nsRestyleHint;
|
||||||
|
@ -161,16 +160,14 @@ pub extern "C" fn Servo_Node_ClearNodeData(node: RawGeckoNodeBorrowed) -> () {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(bytes: *const u8,
|
pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(data: *const nsACString,
|
||||||
length: u32,
|
mode: SheetParsingMode,
|
||||||
mode: SheetParsingMode,
|
base_url: *const nsACString,
|
||||||
base_bytes: *const u8,
|
base: *mut ThreadSafeURIHolder,
|
||||||
base_length: u32,
|
referrer: *mut ThreadSafeURIHolder,
|
||||||
base: *mut ThreadSafeURIHolder,
|
principal: *mut ThreadSafePrincipalHolder)
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
-> RawServoStyleSheetStrong {
|
||||||
principal: *mut ThreadSafePrincipalHolder)
|
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
||||||
-> RawServoStyleSheetStrong {
|
|
||||||
let input = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) };
|
|
||||||
|
|
||||||
let origin = match mode {
|
let origin = match mode {
|
||||||
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
||||||
|
@ -178,7 +175,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(bytes: *const u8,
|
||||||
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_str = unsafe { from_utf8_unchecked(slice::from_raw_parts(base_bytes, base_length as usize)) };
|
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
||||||
let url = Url::parse(base_str).unwrap();
|
let url = Url::parse(base_str).unwrap();
|
||||||
let extra_data = unsafe { ParserContextExtraData {
|
let extra_data = unsafe { ParserContextExtraData {
|
||||||
base: Some(GeckoArcURI::new(base)),
|
base: Some(GeckoArcURI::new(base)),
|
||||||
|
@ -367,23 +364,14 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () {
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseProperty(property_bytes: *const u8,
|
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
||||||
property_length: u32,
|
base_url: *const nsACString, base: *mut ThreadSafeURIHolder,
|
||||||
value_bytes: *const u8,
|
|
||||||
value_length: u32,
|
|
||||||
base_bytes: *const u8,
|
|
||||||
base_length: u32,
|
|
||||||
base: *mut ThreadSafeURIHolder,
|
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
referrer: *mut ThreadSafeURIHolder,
|
||||||
principal: *mut ThreadSafePrincipalHolder)
|
principal: *mut ThreadSafePrincipalHolder)
|
||||||
-> RawServoDeclarationBlockStrong {
|
-> RawServoDeclarationBlockStrong {
|
||||||
// All this string wrangling is temporary until the Gecko string bindings land (bug 1294742).
|
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||||
let name = unsafe { from_utf8_unchecked(slice::from_raw_parts(property_bytes,
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
property_length as usize)) };
|
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
||||||
let value_str = unsafe { from_utf8_unchecked(slice::from_raw_parts(value_bytes,
|
|
||||||
value_length as usize)) };
|
|
||||||
let base_str = unsafe { from_utf8_unchecked(slice::from_raw_parts(base_bytes,
|
|
||||||
base_length as usize)) };
|
|
||||||
let base_url = Url::parse(base_str).unwrap();
|
let base_url = Url::parse(base_str).unwrap();
|
||||||
let extra_data = unsafe { ParserContextExtraData {
|
let extra_data = unsafe { ParserContextExtraData {
|
||||||
base: Some(GeckoArcURI::new(base)),
|
base: Some(GeckoArcURI::new(base)),
|
||||||
|
@ -396,7 +384,7 @@ pub extern "C" fn Servo_ParseProperty(property_bytes: *const u8,
|
||||||
extra_data);
|
extra_data);
|
||||||
|
|
||||||
let mut results = vec![];
|
let mut results = vec![];
|
||||||
match PropertyDeclaration::parse(name, &context, &mut Parser::new(value_str),
|
match PropertyDeclaration::parse(name, &context, &mut Parser::new(value),
|
||||||
&mut results, false) {
|
&mut results, false) {
|
||||||
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => {},
|
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => {},
|
||||||
_ => return RawServoDeclarationBlockStrong::null(),
|
_ => return RawServoDeclarationBlockStrong::null(),
|
||||||
|
@ -411,9 +399,8 @@ pub extern "C" fn Servo_ParseProperty(property_bytes: *const u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32)
|
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString) -> RawServoDeclarationBlockStrong {
|
||||||
-> RawServoDeclarationBlockStrong {
|
let value = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
||||||
let value = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) };
|
|
||||||
Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
|
Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,10 +454,9 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_CSSSupports(property: *const u8, property_length: u32,
|
pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const nsACString) -> bool {
|
||||||
value: *const u8, value_length: u32) -> bool {
|
let property = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||||
let property = unsafe { from_utf8_unchecked(slice::from_raw_parts(property, property_length as usize)) };
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
let value = unsafe { from_utf8_unchecked(slice::from_raw_parts(value, value_length as usize)) };
|
|
||||||
|
|
||||||
let base_url = &*DUMMY_BASE_URL;
|
let base_url = &*DUMMY_BASE_URL;
|
||||||
let extra_data = ParserContextExtraData::default();
|
let extra_data = ParserContextExtraData::default();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue