api.js (2443B)
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 /* globals ExtensionAPI, Services, XPCOMUtils */ 6 7 ChromeUtils.defineESModuleGetters(this, { 8 SpecialPowersParent: "resource://testing-common/SpecialPowersParent.sys.mjs", 9 }); 10 11 XPCOMUtils.defineLazyServiceGetter( 12 this, 13 "resProto", 14 "@mozilla.org/network/protocol;1?name=resource", 15 Ci.nsISubstitutingProtocolHandler 16 ); 17 18 this.specialpowers = class extends ExtensionAPI { 19 onStartup() { 20 // Register special testing modules. 21 let manifest = Services.dirsvc.get("ProfD", Ci.nsIFile); 22 manifest.append("tests.manifest"); 23 Components.manager 24 .QueryInterface(Ci.nsIComponentRegistrar) 25 .autoRegister(manifest); 26 27 { 28 let uri = Services.io.newURI("content/", null, this.extension.rootURI); 29 resProto.setSubstitutionWithFlags( 30 "specialpowers", 31 uri, 32 resProto.ALLOW_CONTENT_ACCESS 33 ); 34 } 35 36 if (!resProto.hasSubstitution("testing-common")) { 37 let uri = Services.io.newURI("modules/", null, this.extension.rootURI); 38 resProto.setSubstitution( 39 "testing-common", 40 uri, 41 resProto.ALLOW_CONTENT_ACCESS 42 ); 43 } else { 44 // This is a hack! 45 // For some reason, this specific substituion has an extra `/` in the path. 46 // This is a workaround to fix it. 47 // 48 // TODO (#43545): Remove this once we have a proper fix. 49 let uri = resProto.getSubstitution("testing-common"); 50 resProto.setSubstitution( 51 "testing-common", 52 Services.io.newURI(uri.spec.replace("file:////", "file:///")), 53 resProto.ALLOW_CONTENT_ACCESS 54 ); 55 } 56 57 SpecialPowersParent.registerActor(); 58 59 ChromeUtils.registerWindowActor("AppTestDelegate", { 60 parent: { 61 esModuleURI: "resource://specialpowers/AppTestDelegateParent.sys.mjs", 62 }, 63 child: { 64 esModuleURI: "resource://specialpowers/AppTestDelegateChild.sys.mjs", 65 events: { 66 DOMContentLoaded: { capture: true }, 67 load: { capture: true }, 68 }, 69 }, 70 allFrames: true, 71 includeChrome: true, 72 }); 73 } 74 75 onShutdown() { 76 SpecialPowersParent.unregisterActor(); 77 ChromeUtils.unregisterWindowActor("AppTestDelegate"); 78 resProto.setSubstitution("specialpowers", null); 79 } 80 };