responsive.js (2825B)
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 "use strict"; 6 7 const { Actor } = require("resource://devtools/shared/protocol.js"); 8 const { 9 responsiveSpec, 10 } = require("resource://devtools/shared/specs/responsive.js"); 11 12 /** 13 * This actor overrides various browser features to simulate different environments to 14 * test how pages perform under various conditions. 15 * 16 * The design below, which saves the previous value of each property before setting, is 17 * needed because it's possible to have multiple copies of this actor for a single page. 18 * When some instance of this actor changes a property, we want it to be able to restore 19 * that property to the way it was found before the change. 20 * 21 * A subtle aspect of the code below is that all get* methods must return non-undefined 22 * values, so that the absence of a previous value can be distinguished from the value for 23 * "no override" for each of the properties. 24 */ 25 class ResponsiveActor extends Actor { 26 constructor(conn, targetActor) { 27 super(conn, responsiveSpec); 28 this.targetActor = targetActor; 29 this.docShell = targetActor.docShell; 30 } 31 32 destroy() { 33 this.targetActor = null; 34 this.docShell = null; 35 36 super.destroy(); 37 } 38 39 get win() { 40 return this.docShell.chromeEventHandler.ownerGlobal; 41 } 42 43 /* Touch events override */ 44 45 _previousTouchEventsOverride = undefined; 46 47 /** 48 * Set the current element picker state. 49 * 50 * True means the element picker is currently active and we should not be emulating 51 * touch events. 52 * False means the element picker is not active and it is ok to emulate touch events. 53 * 54 * This actor method is meant to be called by the DevTools front-end. The reason for 55 * this is the following: 56 * RDM is the only current consumer of the touch simulator. RDM instantiates this actor 57 * on its own, whether or not the Toolbox is opened. That means it does so in its own 58 * DevTools Server instance. 59 * When the Toolbox is running, it uses a different DevToolsServer. Therefore, it is not 60 * possible for the touch simulator to know whether the picker is active or not. This 61 * state has to be sent by the client code of the Toolbox to this actor. 62 * If a future use case arises where we want to use the touch simulator from the Toolbox 63 * too, then we could add code in here to detect the picker mode as described in 64 * https://bugzilla.mozilla.org/show_bug.cgi?id=1409085#c3 65 66 * @param {boolean} state 67 * @param {string} pickerType 68 */ 69 setElementPickerState(state, pickerType) { 70 this.targetActor.touchSimulator.setElementPickerState(state, pickerType); 71 } 72 } 73 74 exports.ResponsiveActor = ResponsiveActor;