1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#![doc = include_str!("../README.md")]

use js_sys::Function;
use wasm_bindgen::{prelude::*, JsStatic};

mod action;
mod bookmarks;
#[cfg(feature = "firefox")]
mod browser_action;
mod commands;
#[cfg(feature = "firefox")]
mod contextual_identities;
mod downloads;
mod history;
mod identity;
mod omnibox;
mod port;
mod runtime;
mod scripting;
mod sessions;
#[cfg(feature = "firefox")]
mod sidebar_action;
mod storage;
mod tabs;
#[cfg(feature = "firefox")]
mod theme;
mod windows;

pub use action::*;
pub use bookmarks::*;
#[cfg(feature = "firefox")]
pub use browser_action::*;
pub use commands::*;
#[cfg(feature = "firefox")]
pub use contextual_identities::*;
pub use downloads::*;
pub use history::*;
pub use identity::*;
pub use omnibox::*;
pub use port::*;
pub use runtime::*;
pub use scripting::*;
pub use sessions::*;
#[cfg(feature = "firefox")]
pub use sidebar_action::*;
pub use storage::*;
pub use tabs::*;
#[cfg(feature = "firefox")]
pub use theme::*;
pub use windows::*;

pub mod traits {
    pub use crate::storage::{StorageArea, StorageAreaRead};
}

#[cfg(feature = "firefox")]
pub fn browser() -> &'static JsStatic<Browser> {
    &BROWSER
}

#[cfg(not(feature = "firefox"))]
pub fn chrome() -> &'static JsStatic<Browser> {
    &CHROME
}

#[wasm_bindgen]
extern "C" {
    pub type Browser;

    // This is used for Mozilla Firefox Addons
    #[cfg(feature = "firefox")]
    #[wasm_bindgen(js_name = browser)]
    static BROWSER: Browser;

    // This is used for Google Chrome Extensions
    #[cfg(not(feature = "firefox"))]
    #[wasm_bindgen(js_name = chrome)]
    static CHROME: Browser;

    #[wasm_bindgen(method, getter)]
    pub fn action(this: &Browser) -> Action;

    #[cfg(feature = "firefox")]
    #[wasm_bindgen(method, getter, js_name = browserAction)]
    pub fn browser_action(this: &Browser) -> BrowserAction;

    #[cfg(feature = "firefox")]
    #[wasm_bindgen(method, getter, js_name = contextualIdentities)]
    pub fn contextual_identities(this: &Browser) -> ContextualIdentities;

    #[wasm_bindgen(method, getter)]
    pub fn downloads(this: &Browser) -> Downloads;

    #[wasm_bindgen(method, getter)]
    pub fn runtime(this: &Browser) -> Runtime;

    #[wasm_bindgen(method, getter)]
    pub fn sessions(this: &Browser) -> Sessions;

    #[cfg(feature = "firefox")]
    #[wasm_bindgen(method, getter, js_name = sidebarAction)]
    pub fn sidebar_action(this: &Browser) -> SidebarAction;

    #[wasm_bindgen(method, getter)]
    pub fn storage(this: &Browser) -> Storage;

    #[wasm_bindgen(method, getter)]
    pub fn tabs(this: &Browser) -> Tabs;

    #[cfg(feature = "firefox")]
    #[wasm_bindgen(method, getter)]
    pub fn theme(this: &Browser) -> BrowserTheme;

    #[wasm_bindgen(method, getter)]
    pub fn windows(this: &Browser) -> Windows;

    #[wasm_bindgen(method, getter)]
    pub fn scripting(this: &Browser) -> Scripting;

    #[wasm_bindgen(method, getter)]
    pub fn history(this: &Browser) -> History;

    #[wasm_bindgen(method, getter)]
    pub fn bookmarks(this: &Browser) -> Bookmarks;

    #[wasm_bindgen(method, getter)]
    pub fn commands(this: &Browser) -> Commands;

    #[wasm_bindgen(method, getter)]
    pub fn identity(this: &Browser) -> Identity;

    #[wasm_bindgen(method, getter)]
    pub fn omnibox(this: &Browser) -> Omnibox;
}

#[wasm_bindgen]
extern "C" {
    pub type EventTarget;

    #[wasm_bindgen(method, js_name = addListener)]
    pub fn add_listener(this: &EventTarget, listener: &Function);

    #[wasm_bindgen(method, js_name = removeListener)]
    pub fn remove_listener(this: &EventTarget, listener: &Function);

    #[wasm_bindgen(method, js_name = hasListener)]
    pub fn has_listener(this: &EventTarget, listener: &Function) -> bool;
}