From 253723409022546475240b04843ed19ad321d847 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:48:17 +0800 Subject: [PATCH] ohos: Add FFI-APIs to navigate back and forward (#33206) To be useful it requires using the latest version of the OH demo ArkTS app, but it is still compatible with older versions, as the newly added FFI functions will simply be unused in such a case. Signed-off-by: Jonathan Schwender --- ports/servoshell/egl/ohos.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ports/servoshell/egl/ohos.rs b/ports/servoshell/egl/ohos.rs index ba59f1cf5b3..425471cd4ce 100644 --- a/ports/servoshell/egl/ohos.rs +++ b/ports/servoshell/egl/ohos.rs @@ -13,7 +13,6 @@ use std::time::Duration; use log::{debug, error, info, warn, LevelFilter}; use napi_derive_ohos::{module_exports, napi}; -use napi_ohos::bindgen_prelude::Undefined; use napi_ohos::threadsafe_function::{ ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode, }; @@ -85,6 +84,8 @@ enum TouchEventType { enum ServoAction { WakeUp, LoadUrl(String), + GoBack, + GoForward, TouchEvent { kind: TouchEventType, x: f32, @@ -120,6 +121,8 @@ impl ServoAction { let res = match self { WakeUp => servo.perform_updates(), LoadUrl(url) => servo.load_uri(url.as_str()), + GoBack => servo.go_back(), + GoForward => servo.go_forward(), TouchEvent { kind, x, @@ -357,11 +360,21 @@ fn init(exports: JsObject, env: Env) -> napi_ohos::Result<()> { } #[napi(js_name = "loadURL")] -pub fn load_url(url: String) -> Undefined { +pub fn load_url(url: String) { debug!("load url"); call(ServoAction::LoadUrl(url)).expect("Failed to load url"); } +#[napi] +pub fn go_back() { + call(ServoAction::GoBack).expect("Failed to call servo"); +} + +#[napi] +pub fn go_forward() { + call(ServoAction::GoForward).expect("Failed to call servo"); +} + #[napi(js_name = "registerURLcallback")] pub fn register_url_callback(cb: JsFunction) -> napi_ohos::Result<()> { info!("register_url_callback called!");