emulation.sys.mjs (2466B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { WindowGlobalBiDiModule } from "chrome://remote/content/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs"; 6 7 class EmulationModule extends WindowGlobalBiDiModule { 8 constructor(messageHandler) { 9 super(messageHandler); 10 } 11 12 destroy() {} 13 14 /** 15 * Internal commands 16 */ 17 18 _applySessionData() {} 19 20 /** 21 * Set the geolocation override to the navigable. 22 * 23 * @param {object=} params 24 * @param {(GeolocationCoordinates|null)} params.coordinates 25 * Geolocation coordinates which have to override 26 * the return result of geolocation APIs. 27 * Null value resets the override. 28 */ 29 async _setGeolocationOverride(params = {}) { 30 const { coordinates } = params; 31 32 if (coordinates === null) { 33 this.messageHandler.context.setGeolocationServiceOverride(); 34 } else { 35 this.messageHandler.context.setGeolocationServiceOverride({ 36 coords: coordinates, 37 // The timestamp attribute represents the time 38 // when the geographic position of the device was acquired. 39 timestamp: Date.now(), 40 }); 41 } 42 } 43 44 /** 45 * Set the locale override to the sandboxes, 46 * which belongs to this navigable. 47 * 48 * @param {object} params 49 * @param {(string|null)} params.locale 50 * Locale string which have to override 51 * the return result of JavaScript Intl APIs. 52 * Null value resets the override. 53 */ 54 async _setLocaleOverrideToSandboxes(params) { 55 const { locale } = params; 56 this.messageHandler.realms.forEach(realm => { 57 if (realm.isSandbox) { 58 Cu.setSandboxLocaleOverride(realm.globalObject, locale); 59 } 60 }); 61 } 62 63 /** 64 * Set the timezone override to the sandboxes, 65 * which belongs to this navigable. 66 * 67 * @param {object} params 68 * @param {(string|null)} params.locale 69 * Timezone string which has to override 70 * the return result of JavaScript Intl/Date APIs. 71 * Null value resets the override. 72 */ 73 async _setTimezoneOverrideToSandboxes(params) { 74 const { timezone } = params; 75 this.messageHandler.realms.forEach(realm => { 76 if (realm.isSandbox) { 77 Cu.setSandboxTimezoneOverride(realm.globalObject, timezone); 78 } 79 }); 80 } 81 } 82 83 export const emulation = EmulationModule;