atmos/os_lib/web_engine/
site_hooks.rs1extern crate alloc;
12use alloc::string::String;
13use alloc::vec::Vec;
14
15pub type FetchResult = Result<(u16, String, Vec<u8>, alloc::collections::BTreeMap<String, String>), &'static str>;
17
18pub trait SiteHooks: Sync {
20 fn fetch_is_special(&self, _method: &str, _full_url: &str) -> bool {
24 false
25 }
26 fn fetch_rewrite_request(&self, url: &str, _body: &[u8]) -> (String, Option<Vec<u8>>) {
28 (String::from(url), None)
29 }
30 fn fetch_on_response(&self, _raw: &mut Vec<u8>) {}
32 fn is_streaming_url(&self, _host: &str, _path: &str) -> bool {
34 false
35 }
36
37 fn user_agent(&self, _host: &str) -> Option<&'static str> {
41 None
42 }
43
44 fn offline_page(
48 &self,
49 _host: &str,
50 _path: &str,
51 _is_https: bool,
52 _is_post: bool,
53 _post_body: &str,
54 ) -> Option<String> {
55 None
56 }
57 fn rewrite_response(&self, _host: &str, _path: &str, _is_https: bool, body: String) -> String {
59 body
60 }
61 fn load_failed_page(&self, _host: &str, _path: &str, _is_https: bool, _err: &str) -> Option<String> {
63 None
64 }
65 fn patch_script(&self, _url: &str, _text: &mut String) {}
67
68 fn load_settle_ms(&self, _host: &str) -> Option<u64> {
74 None
75 }
76 fn is_dark_host(&self, _host: &str) -> bool {
77 false
78 }
79 fn page_tick(&self, _url_with_hash: &str, _frame_depth: u32, _js: &mut dyn core::any::Any) {}
82
83 fn initial_page(&self) -> (&'static str, &'static str) {
85 ("localhost", "AtmOS Browser")
86 }
87 fn resolve_redirect_link(&self, _href: &str) -> Option<String> {
89 None
90 }
91
92 fn default_bookmarks(&self) -> Vec<(&'static str, &'static str)> {
96 Vec::new()
97 }
98 fn omnibox_prefix_suggestion(&self, _q: &str) -> Option<(String, String)> {
100 None
101 }
102 fn search_suggestion_url(&self, s: &str) -> String {
104 String::from(s)
105 }
106 fn navigate_shortcut(&self, _input: &str) -> Option<(String, String)> {
108 None
109 }
110 fn default_search(&self, _input: &str) -> Option<(String, String)> {
112 None
113 }
114 fn search_suggestions(&self, _text: &str) -> Vec<String> {
116 Vec::new()
117 }
118
119 fn media_stream_begin(&self) {}
123 fn media_stream_end(&self) {}
125 fn media_stream_playback_head(&self, _ms: u64) {}
127 fn media_stream_refill(&self, _ms_id: usize) -> bool {
129 false
130 }
131
132 fn map_embed(&self, _url: &str) -> Option<super::embed_map::Embed> {
136 None
137 }
138 fn map_tile_url(&self, _z: u32, _x: i64, _y: i64) -> String {
140 String::new()
141 }
142}
143
144struct NoSite;
146impl SiteHooks for NoSite {}
147
148static NO_SITE: NoSite = NoSite;
149static HOOKS: spin::Mutex<&'static dyn SiteHooks> = spin::Mutex::new(&NO_SITE);
150
151pub fn register(h: &'static dyn SiteHooks) {
153 *HOOKS.lock() = h;
154}
155
156pub fn hooks() -> &'static dyn SiteHooks {
158 *HOOKS.lock()
159}