browser_window/core/
browser_window.rs

1#[cfg(not(any(feature = "gtk", feature = "edge2")))]
2pub mod c;
3#[cfg(feature = "edge2")]
4mod edge2;
5#[cfg(feature = "gtk")]
6mod webkit;
7
8use std::borrow::Cow;
9
10use browser_window_c::*;
11#[cfg(not(any(feature = "gtk", feature = "edge2")))]
12pub use c::{BrowserWindowImpl, JsEvaluationError};
13#[cfg(feature = "edge2")]
14pub use edge2::{BrowserWindowImpl, JsEvaluationError};
15#[cfg(feature = "gtk")]
16pub use webkit::{BrowserWindowImpl, JsEvaluationError};
17
18use super::{
19	super::event::*,
20	application::ApplicationImpl,
21	cookie::CookieJarImpl,
22	window::{WindowImpl, WindowOptions},
23};
24use crate::{browser::*, prelude::JsValue, rc::*};
25
26
27//pub type BrowserWindowEventHandler<'a, A> = EventHandler<'a,
28// BrowserWindowHandle, A>;
29
30pub type BrowserWindowOptions = cbw_BrowserWindowOptions;
31
32/// The data that is passed to the C FFI handler function
33pub(crate) struct BrowserUserData {
34	pub(crate) _handle: Rc<BrowserWindowOwner>,
35}
36
37pub type CreationCallbackFn = fn(bw: BrowserWindowImpl, data: *mut ());
38pub type EvalJsCallbackFn =
39	fn(bw: BrowserWindowImpl, data: *mut (), result: Result<JsValue, JsEvaluationError>);
40
41pub trait BrowserWindowEventExt {
42	fn on_address_changed(&self, _handle: Weak<BrowserWindowOwner>) -> AddressChangedEvent {
43		unimplemented!();
44	}
45	fn on_console_message(&self, _handle: Weak<BrowserWindowOwner>) -> ConsoleMessageEvent {
46		unimplemented!();
47	}
48	fn on_favicon_changed(&self, _handle: Weak<BrowserWindowOwner>) -> FaviconChangedEvent {
49		unimplemented!();
50	}
51	fn on_fullscreen_mode_changed(
52		&self, _handle: Weak<BrowserWindowOwner>,
53	) -> FullscreenModeChangedEvent {
54		unimplemented!();
55	}
56	fn on_loading_progress_changed(
57		&self, _handle: Weak<BrowserWindowOwner>,
58	) -> LoadingProgressChangedEvent {
59		unimplemented!();
60	}
61	fn on_message(&self, _handle: Weak<BrowserWindowOwner>) -> MessageEvent;
62	fn on_navigation_end(&self, _handle: Weak<BrowserWindowOwner>) -> NavigationEndEvent {
63		unimplemented!();
64	}
65	fn on_navigation_start(&self, _handle: Weak<BrowserWindowOwner>) -> NavigationStartEvent {
66		unimplemented!();
67	}
68	fn on_page_title_changed(&self, _handle: Weak<BrowserWindowOwner>) -> PageTitleChangedEvent {
69		unimplemented!();
70	}
71	fn on_status_message(&self, _handle: Weak<BrowserWindowOwner>) -> StatusMessageEvent {
72		unimplemented!();
73	}
74	fn on_tooltip(&self, _handle: Weak<BrowserWindowOwner>) -> TooltipEvent {
75		unimplemented!();
76	}
77}
78
79pub trait BrowserWindowExt: BrowserWindowEventExt + Clone {
80	fn cookie_jar(&self) -> Option<CookieJarImpl>;
81
82	/// Executes the given JavaScript string.
83	/// The result will be provided by invoking the callback function.
84	fn eval_js(&self, js: &str, callback: EvalJsCallbackFn, callback_data: *mut ());
85
86	/// Like `eval_js`, except it can be called from any thread.
87	fn eval_js_threadsafe(&self, js: &str, callback: EvalJsCallbackFn, callback_data: *mut ());
88
89	fn free(&self);
90
91	/// Causes the browser to navigate to the given URI.
92	fn navigate(&self, uri: &str);
93
94	fn url<'a>(&'a self) -> Cow<'a, str>;
95
96	/// Gives a handle to the underlying window.
97	fn window(&self) -> WindowImpl;
98
99	fn new(
100		app: ApplicationImpl, parent: WindowImpl, source: Source, title: &str, width: Option<u32>,
101		height: Option<u32>, options: &WindowOptions,
102		browser_window_options: &BrowserWindowOptions, creation_callback: CreationCallbackFn,
103		callback_data: *mut (),
104	);
105}
106
107
108impl BrowserWindowImpl {
109	pub(crate) fn free_user_data(user_data: *mut ()) {
110		let ptr = user_data as *mut BrowserUserData;
111		unsafe {
112			let _ = Box::from_raw(ptr);
113		}
114	}
115}