aboutsummaryrefslogtreecommitdiffstats
path: root/ports/servoshell/egl/ohos/simpleservo.rs
diff options
context:
space:
mode:
authorJonathan Schwender <55576758+jschwe@users.noreply.github.com>2024-10-02 06:27:18 +0200
committerGitHub <noreply@github.com>2024-10-02 04:27:18 +0000
commite534c7d4610807fb1a93f17085ec6ada61a4a342 (patch)
tree07db61ec74a2535586cc2f9033edb1bb3b2ae787 /ports/servoshell/egl/ohos/simpleservo.rs
parentd7da0563d36d8a6dafecb348ce94ff883242f7cb (diff)
downloadservo-e534c7d4610807fb1a93f17085ec6ada61a4a342.tar.gz
servo-e534c7d4610807fb1a93f17085ec6ada61a4a342.zip
ohos: Allow passing arguments to servoshell (#33588)
* ohos: Bump minimum CMake version By bumping the minimum CMake version, we avoid a deprecation warning. The OH 4.0 SDK ships with CMake 3.16, so we can be sure that we have CMake 3.16 or newer available. Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> * ohos: Allow passing arguments to servoshell Allows passing options passed via `wants` to the Ability through to servoshell. This allows easier debugging, either by calling servoshell from a test app, or from the commandline, e.g. ``` hdc shell aa start -a EntryAbility -b org.servo.servoshell -U "https://www.wikipedia.org" \ --pb dom.webgpu.enabled true \ --ps dom.webgpu.wgpu_backend "gl" \ --pi layout.threads 4 ``` Note: While the OH `wants` API differentiates between boolean, string and integer values, we convert everything back to strings, so we can reuse the same parsing code as the desktop servoshell. Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Diffstat (limited to 'ports/servoshell/egl/ohos/simpleservo.rs')
-rw-r--r--ports/servoshell/egl/ohos/simpleservo.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/ports/servoshell/egl/ohos/simpleservo.rs b/ports/servoshell/egl/ohos/simpleservo.rs
index 4dad52c0c75..35ab6028d8b 100644
--- a/ports/servoshell/egl/ohos/simpleservo.rs
+++ b/ports/servoshell/egl/ohos/simpleservo.rs
@@ -17,6 +17,8 @@ use servo::embedder_traits::resources;
/// and that perform_updates need to be called
pub use servo::embedder_traits::EventLoopWaker;
use servo::euclid::Size2D;
+use servo::servo_config::opts;
+use servo::servo_config::opts::ArgumentParsingResult;
use servo::servo_url::ServoUrl;
use servo::webrender_traits::RenderingContext;
use servo::{self, gl, Servo};
@@ -43,6 +45,58 @@ pub fn init(
crate::init_tracing();
let resource_dir = PathBuf::from(&options.resource_dir).join("servo");
resources::set(Box::new(ResourceReaderInstance::new(resource_dir)));
+ let mut args = vec!["servoshell".to_string()];
+ // It would be nice if `from_cmdline_args()` could accept str slices, to avoid allocations here.
+ // Then again, this code could and maybe even should be disabled in production builds.
+ let split_args: Vec<String> = options
+ .commandline_args
+ .split("\u{1f}")
+ .map(|arg| arg.to_string())
+ .collect();
+ args.extend(split_args);
+ debug!("Servo commandline args: {:?}", args);
+
+ let mut opts = getopts::Options::new();
+ opts.optopt(
+ "u",
+ "user-agent",
+ "Set custom user agent string (or ios / android / desktop for platform default)",
+ "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)",
+ );
+ opts.optmulti(
+ "",
+ "pref",
+ "A preference to set to enable",
+ "dom.bluetooth.enabled",
+ );
+ opts.optmulti(
+ "",
+ "pref",
+ "A preference to set to disable",
+ "dom.webgpu.enabled=false",
+ );
+ opts.optmulti(
+ "",
+ "prefs-file",
+ "Load in additional prefs from a file.",
+ "--prefs-file /path/to/prefs.json",
+ );
+
+ let opts_matches;
+ let content_process_token;
+ match opts::from_cmdline_args(opts, &args) {
+ ArgumentParsingResult::ContentProcess(matches, token) => {
+ error!("Content Process mode not supported / tested yet on OpenHarmony!");
+ opts_matches = matches;
+ content_process_token = Some(token);
+ },
+ ArgumentParsingResult::ChromeProcess(matches) => {
+ opts_matches = matches;
+ content_process_token = None;
+ },
+ };
+
+ crate::prefs::register_user_prefs(&opts_matches);
gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(gl::COLOR_BUFFER_BIT);