зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #8254 - Read params from a file on Android (from connorimes:android-params-file); r=larsbergstrom
Source-Repo: https://github.com/servo/servo Source-Revision: 2d0d9ca04054eefcc094e2643e6388ed57919e84
This commit is contained in:
Родитель
8b4bb62780
Коммит
0520aa1bd3
|
@ -23,6 +23,8 @@ extern crate android_glue;
|
|||
// The window backed by glutin
|
||||
extern crate glutin_app as app;
|
||||
extern crate env_logger;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
// The Servo engine
|
||||
extern crate servo;
|
||||
extern crate time;
|
||||
|
@ -128,11 +130,39 @@ fn setup_logging() {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
/// Attempt to read parameters from a file since they are not passed to us in Android environments.
|
||||
/// The first line should be the "servo" argument and the last should be the URL to load.
|
||||
/// Blank lines and those beginning with a '#' are ignored.
|
||||
/// Each line should be a separate parameter as would be parsed by the shell.
|
||||
/// For example, "servo -p 10 http://en.wikipedia.org/wiki/Rust" would take 4 lines.
|
||||
fn args() -> Vec<String> {
|
||||
vec![
|
||||
"servo".to_owned(),
|
||||
"http://en.wikipedia.org/wiki/Rust".to_owned()
|
||||
]
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
const PARAMS_FILE: &'static str = "/sdcard/servo/android_params";
|
||||
match File::open(PARAMS_FILE) {
|
||||
Ok(f) => {
|
||||
let mut vec = Vec::new();
|
||||
let file = BufReader::new(&f);
|
||||
for line in file.lines() {
|
||||
let l = line.unwrap().trim().to_owned();
|
||||
// ignore blank lines and those that start with a '#'
|
||||
match l.is_empty() || l.as_bytes()[0] == b'#' {
|
||||
true => (),
|
||||
false => vec.push(l),
|
||||
}
|
||||
}
|
||||
vec
|
||||
},
|
||||
Err(e) => {
|
||||
debug!("Failed to open params file '{}': {}", PARAMS_FILE, Error::description(&e));
|
||||
vec![
|
||||
"servo".to_owned(),
|
||||
"http://en.wikipedia.org/wiki/Rust".to_owned()
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# The first line here should be the "servo" argument (without quotes) and the
|
||||
# last should be the URL to load.
|
||||
# Blank lines and those beginning with a '#' are ignored.
|
||||
# Each line should be a separate parameter as would be parsed by the shell.
|
||||
# For example, "servo -p 10 http://en.wikipedia.org/wiki/Rust" would take 4
|
||||
# lines (the "-p" and "10" are separate even though they are related).
|
||||
|
||||
servo
|
||||
http://en.wikipedia.org/wiki/Rust
|
Загрузка…
Ссылка в новой задаче