blob: a37b39469328dccc6e74e07eee990dc72e72cc89 [file] [log] [blame]
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +01001import MainWorldContentScriptBridgeClient from '../mainWorldContentScriptBridge/Client.js';
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01002
3// Main World OptionsWatcher client (used in scripts injected into the Main
4// World (MW) to get the options).
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +01005export default class MWOptionsWatcherClient extends
6 MainWorldContentScriptBridgeClient {
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01007 constructor(options, CSTarget, MWTarget, timeout) {
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +01008 super(CSTarget, MWTarget, timeout);
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01009 this.#setUp(options);
10 }
11
12 #setUp(options) {
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +010013 this._sendRequestWithoutCallback('setUp', {options});
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010014 }
15
16 async getOption(option) {
17 if (!option) return null;
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +010018 return this._sendRequest('getOption', {option});
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010019 }
20
21 async getOptions(options) {
22 if (!options || options?.length === 0) return [];
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +010023 return this._sendRequest('getOptions', {options});
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010024 }
25
26 async isEnabled(option) {
27 if (!option) return null;
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +010028 return this._sendRequest('isEnabled', {option});
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010029 }
30
31 async areEnabled(options) {
32 if (!options || options?.length === 0) return [];
Adrià Vilanova Martínez2548e442023-03-05 18:45:30 +010033 return this._sendRequest('areEnabled', {options});
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010034 }
35}