ohos_web_binding/callback/
mod.rs1use std::ffi::c_char;
2use std::ffi::c_void;
3use std::mem::ManuallyDrop;
4
5pub(crate) struct WebComponentLifeCycleContext {
6 pub(crate) callback: Box<dyn FnMut()>,
7}
8
9pub(crate) type OnControllerAttachContext = WebComponentLifeCycleContext;
10pub(crate) type OnPageBeginContext = WebComponentLifeCycleContext;
11pub(crate) type OnPageEndContext = WebComponentLifeCycleContext;
12pub(crate) type OnDestroyContext = WebComponentLifeCycleContext;
13
14pub unsafe extern "C" fn on_controller_attach(_web_tag: *const c_char, user_data: *mut c_void) {
16 let mut ctx =
17 unsafe { ManuallyDrop::new(Box::from_raw(user_data as *mut OnControllerAttachContext)) };
18 let cb = &mut ctx.callback;
19 cb();
20}
21
22pub unsafe extern "C" fn on_page_begin(_web_tag: *const c_char, user_data: *mut c_void) {
24 let mut ctx = unsafe { ManuallyDrop::new(Box::from_raw(user_data as *mut OnPageBeginContext)) };
25 let cb = &mut ctx.callback;
26 cb();
27}
28
29pub unsafe extern "C" fn on_page_end(_web_tag: *const c_char, user_data: *mut c_void) {
31 let mut ctx = unsafe { ManuallyDrop::new(Box::from_raw(user_data as *mut OnPageEndContext)) };
32 let cb = &mut ctx.callback;
33 cb();
34}
35
36pub unsafe extern "C" fn on_destroy(_web_tag: *const c_char, user_data: *mut c_void) {
38 let mut ctx = unsafe { ManuallyDrop::new(Box::from_raw(user_data as *mut OnDestroyContext)) };
39 let cb = &mut ctx.callback;
40 cb();
41}