worker.js (1778B)
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 "use strict"; 5 6 const { 7 workerTargetSpec, 8 } = require("resource://devtools/shared/specs/targets/worker.js"); 9 const { 10 FrontClassWithSpec, 11 registerFront, 12 } = require("resource://devtools/shared/protocol.js"); 13 const { 14 TargetMixin, 15 } = require("resource://devtools/client/fronts/targets/target-mixin.js"); 16 17 class WorkerTargetFront extends TargetMixin( 18 FrontClassWithSpec(workerTargetSpec) 19 ) { 20 get isDedicatedWorker() { 21 return this._type === Ci.nsIWorkerDebugger.TYPE_DEDICATED; 22 } 23 24 get isSharedWorker() { 25 return this._type === Ci.nsIWorkerDebugger.TYPE_SHARED; 26 } 27 28 get isServiceWorker() { 29 return this._type === Ci.nsIWorkerDebugger.TYPE_SERVICE; 30 } 31 32 // If the worker doesn't have a custom name, 33 // display file name instead of absolute URL in the context selector/threads panel 34 get name() { 35 return this._name || this._url.split("/").pop(); 36 } 37 38 form(json) { 39 this.actorID = json.actor; 40 41 // Save the full form for Target class usage. 42 // Do not use `form` name to avoid colliding with protocol.js's `form` method 43 this.targetForm = json; 44 45 this._title = json.title; 46 this._url = json.url; 47 this._type = json.type; 48 // Expose the WorkerDebugger's `id` so that we can match the target with the descriptor 49 this.id = json.id; 50 this._name = json.name; 51 52 // Expose the inner Window ID of the document which may have spawned this worker 53 this.relatedDocumentInnerWindowId = json.relatedDocumentInnerWindowId; 54 } 55 } 56 57 exports.WorkerTargetFront = WorkerTargetFront; 58 registerFront(exports.WorkerTargetFront);