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