web_extensions_sys/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use js_sys::Function;
4use wasm_bindgen::{prelude::*, JsStatic};
5
6mod action;
7mod bookmarks;
8#[cfg(feature = "firefox")]
9mod browser_action;
10mod cookies;
11mod commands;
12#[cfg(feature = "firefox")]
13mod contextual_identities;
14mod context_menus;
15mod downloads;
16mod history;
17mod identity;
18mod omnibox;
19mod port;
20mod runtime;
21mod scripting;
22mod sessions;
23#[cfg(feature = "firefox")]
24mod sidebar_action;
25mod storage;
26mod tabs;
27#[cfg(feature = "firefox")]
28mod theme;
29mod windows;
30
31pub use action::*;
32pub use bookmarks::*;
33#[cfg(feature = "firefox")]
34pub use browser_action::*;
35pub use cookies::*;
36pub use commands::*;
37#[cfg(feature = "firefox")]
38pub use contextual_identities::*;
39pub use context_menus::*;
40pub use downloads::*;
41pub use history::*;
42pub use identity::*;
43pub use omnibox::*;
44pub use port::*;
45pub use runtime::*;
46pub use scripting::*;
47pub use sessions::*;
48#[cfg(feature = "firefox")]
49pub use sidebar_action::*;
50pub use storage::*;
51pub use tabs::*;
52#[cfg(feature = "firefox")]
53pub use theme::*;
54pub use windows::*;
55
56pub mod traits {
57    pub use crate::storage::{StorageArea, StorageAreaRead};
58}
59
60#[cfg(feature = "firefox")]
61pub fn browser() -> &'static JsStatic<Browser> {
62    &BROWSER
63}
64
65#[cfg(not(feature = "firefox"))]
66pub fn chrome() -> &'static JsStatic<Browser> {
67    &CHROME
68}
69
70#[wasm_bindgen]
71extern "C" {
72    pub type Browser;
73
74    // This is used for Mozilla Firefox Addons
75    #[cfg(feature = "firefox")]
76    #[wasm_bindgen(js_name = browser)]
77    static BROWSER: Browser;
78
79    // This is used for Google Chrome Extensions
80    #[cfg(not(feature = "firefox"))]
81    #[wasm_bindgen(js_name = chrome)]
82    static CHROME: Browser;
83
84    #[wasm_bindgen(method, getter)]
85    pub fn action(this: &Browser) -> Action;
86
87    #[cfg(feature = "firefox")]
88    #[wasm_bindgen(method, getter, js_name = browserAction)]
89    pub fn browser_action(this: &Browser) -> BrowserAction;
90
91    #[wasm_bindgen(method, getter)]
92    pub fn cookies(this: &Browser) -> Cookies;
93
94    #[cfg(feature = "firefox")]
95    #[wasm_bindgen(method, getter, js_name = contextualIdentities)]
96    pub fn contextual_identities(this: &Browser) -> ContextualIdentities;
97
98    #[wasm_bindgen(method, getter)]
99    pub fn downloads(this: &Browser) -> Downloads;
100
101    #[wasm_bindgen(method, getter)]
102    pub fn runtime(this: &Browser) -> Runtime;
103
104    #[wasm_bindgen(method, getter)]
105    pub fn sessions(this: &Browser) -> Sessions;
106
107    #[cfg(feature = "firefox")]
108    #[wasm_bindgen(method, getter, js_name = sidebarAction)]
109    pub fn sidebar_action(this: &Browser) -> SidebarAction;
110
111    #[wasm_bindgen(method, getter)]
112    pub fn storage(this: &Browser) -> Storage;
113
114    #[wasm_bindgen(method, getter)]
115    pub fn tabs(this: &Browser) -> Tabs;
116
117    #[cfg(feature = "firefox")]
118    #[wasm_bindgen(method, getter)]
119    pub fn theme(this: &Browser) -> BrowserTheme;
120
121    #[wasm_bindgen(method, getter)]
122    pub fn windows(this: &Browser) -> Windows;
123
124    #[wasm_bindgen(method, getter)]
125    pub fn scripting(this: &Browser) -> Scripting;
126
127    #[wasm_bindgen(method, getter)]
128    pub fn history(this: &Browser) -> History;
129
130    #[wasm_bindgen(method, getter)]
131    pub fn bookmarks(this: &Browser) -> Bookmarks;
132
133    #[wasm_bindgen(method, getter)]
134    pub fn commands(this: &Browser) -> Commands;
135
136    #[wasm_bindgen(method, getter)]
137    pub fn identity(this: &Browser) -> Identity;
138
139    #[wasm_bindgen(method, getter)]
140    pub fn omnibox(this: &Browser) -> Omnibox;
141
142    #[wasm_bindgen(method, getter, js_name = contextMenus)]
143    pub fn context_menus(this: &Browser) -> ContextMenus;
144}
145
146#[wasm_bindgen]
147extern "C" {
148    pub type EventTarget;
149
150    #[wasm_bindgen(method, js_name = addListener)]
151    pub fn add_listener(this: &EventTarget, listener: &Function);
152
153    #[wasm_bindgen(method, js_name = removeListener)]
154    pub fn remove_listener(this: &EventTarget, listener: &Function);
155
156    #[wasm_bindgen(method, js_name = hasListener)]
157    pub fn has_listener(this: &EventTarget, listener: &Function) -> bool;
158}