highlighters.js (1340B)
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 { 8 FrontClassWithSpec, 9 registerFront, 10 } = require("resource://devtools/shared/protocol.js"); 11 const { 12 customHighlighterSpec, 13 } = require("resource://devtools/shared/specs/highlighters.js"); 14 const { 15 safeAsyncMethod, 16 } = require("resource://devtools/shared/async-utils.js"); 17 18 class CustomHighlighterFront extends FrontClassWithSpec(customHighlighterSpec) { 19 constructor(client, targetFront, parentFront) { 20 super(client, targetFront, parentFront); 21 22 // show/hide requests can be triggered while DevTools are closing. 23 this.show = safeAsyncMethod(this.show.bind(this), () => this.isDestroyed()); 24 this.hide = safeAsyncMethod(this.hide.bind(this), () => this.isDestroyed()); 25 26 this._isShown = false; 27 } 28 29 show(...args) { 30 this._isShown = true; 31 return super.show(...args); 32 } 33 34 hide() { 35 this._isShown = false; 36 return super.hide(); 37 } 38 39 isShown() { 40 return this._isShown; 41 } 42 43 destroy() { 44 if (this.isDestroyed()) { 45 return; 46 } 47 super.finalize(); // oneway call, doesn't expect a response. 48 super.destroy(); 49 } 50 } 51 52 registerFront(CustomHighlighterFront);