mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Support passing in arguments from embedding. Read arguments for Magic Leap from SERVO_ARGS env var.
This commit is contained in:
parent
d0e9acf1eb
commit
a207574b4c
10 changed files with 46 additions and 18 deletions
|
@ -69,7 +69,7 @@ pub enum MLKeyType {
|
|||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct MLLogger(extern "C" fn(MLLogLevel, *const c_char));
|
||||
|
||||
#[repr(transparent)]
|
||||
|
@ -108,6 +108,7 @@ pub unsafe extern "C" fn init_servo(
|
|||
url_update: MLURLUpdate,
|
||||
keyboard: MLKeyboard,
|
||||
url: *const c_char,
|
||||
args: *const c_char,
|
||||
width: u32,
|
||||
height: u32,
|
||||
hidpi: f32,
|
||||
|
@ -127,8 +128,20 @@ pub unsafe extern "C" fn init_servo(
|
|||
width as i32,
|
||||
height as i32,
|
||||
);
|
||||
let args = if args.is_null() {
|
||||
vec![]
|
||||
} else {
|
||||
CStr::from_ptr(args)
|
||||
.to_str()
|
||||
.unwrap_or("")
|
||||
.split(' ')
|
||||
.map(|s| s.to_owned())
|
||||
.collect()
|
||||
};
|
||||
info!("got args: {:?}", args);
|
||||
|
||||
let opts = InitOptions {
|
||||
args: None,
|
||||
args,
|
||||
url: Some(url.to_string()),
|
||||
density: hidpi,
|
||||
enable_subpixel_text_antialiasing: false,
|
||||
|
|
|
@ -9,7 +9,6 @@ publish = false
|
|||
[dependencies]
|
||||
libservo = { path = "../../../components/servo" }
|
||||
log = "0.4"
|
||||
serde_json = "1.0"
|
||||
|
||||
[target.'cfg(not(target_os = "macos"))'.dependencies]
|
||||
libc = "0.2"
|
||||
|
|
|
@ -41,7 +41,7 @@ thread_local! {
|
|||
pub use servo::embedder_traits::EventLoopWaker;
|
||||
|
||||
pub struct InitOptions {
|
||||
pub args: Option<String>,
|
||||
pub args: Vec<String>,
|
||||
pub url: Option<String>,
|
||||
pub coordinates: Coordinates,
|
||||
pub density: f32,
|
||||
|
@ -135,16 +135,15 @@ pub fn servo_version() -> String {
|
|||
/// Initialize Servo. At that point, we need a valid GL context.
|
||||
/// In the future, this will be done in multiple steps.
|
||||
pub fn init(
|
||||
init_opts: InitOptions,
|
||||
mut init_opts: InitOptions,
|
||||
gl: Rc<dyn gl::Gl>,
|
||||
waker: Box<dyn EventLoopWaker>,
|
||||
callbacks: Box<dyn HostTrait>,
|
||||
) -> Result<(), &'static str> {
|
||||
resources::set(Box::new(ResourceReaderInstance::new()));
|
||||
|
||||
if let Some(args) = init_opts.args {
|
||||
let mut args: Vec<String> = serde_json::from_str(&args)
|
||||
.map_err(|_| "Invalid arguments. Servo arguments must be formatted as a JSON array")?;
|
||||
let mut args = mem::replace(&mut init_opts.args, vec![]);
|
||||
if !args.is_empty() {
|
||||
// opts::from_cmdline_args expects the first argument to be the binary name.
|
||||
args.insert(0, "servo".to_string());
|
||||
|
||||
|
|
|
@ -76,7 +76,12 @@ fn init(
|
|||
crate::env_logger::init();
|
||||
|
||||
let args = unsafe { CStr::from_ptr(opts.args) };
|
||||
let args = args.to_str().map(|s| s.to_string()).ok();
|
||||
let args = args
|
||||
.to_str()
|
||||
.unwrap_or("")
|
||||
.split(' ')
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
|
||||
let url = unsafe { CStr::from_ptr(opts.url) };
|
||||
let url = url.to_str().map(|s| s.to_string()).ok();
|
||||
|
|
|
@ -17,9 +17,10 @@ bench = false
|
|||
android_injected_glue = "0.2"
|
||||
android_logger = "0.7"
|
||||
jni = "0.10.2"
|
||||
log = "0.4"
|
||||
simpleservo = { path = "../api" }
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
serde_json = "1.0"
|
||||
simpleservo = { path = "../api" }
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
|
|
|
@ -683,8 +683,15 @@ fn get_options(env: &JNIEnv, opts: JObject) -> Result<(InitOptions, bool, Option
|
|||
.l()
|
||||
.map_err(|_| "coordinates is not an object")?;
|
||||
let coordinates = jni_coords_to_rust_coords(&env, coordinates)?;
|
||||
|
||||
let args = match args {
|
||||
Some(args) => serde_json::from_str(&args)
|
||||
.map_err(|_| "Invalid arguments. Servo arguments must be formatted as a JSON array")?,
|
||||
None => None,
|
||||
};
|
||||
|
||||
let opts = InitOptions {
|
||||
args,
|
||||
args: args.unwrap_or(vec![]),
|
||||
url,
|
||||
coordinates,
|
||||
density,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue