MarionetteEventsChild.sys.mjs (2323B)
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 const lazy = {}; 6 7 ChromeUtils.defineESModuleGetters(lazy, { 8 Log: "chrome://remote/content/shared/Log.sys.mjs", 9 }); 10 11 ChromeUtils.defineLazyGetter(lazy, "logger", () => 12 lazy.Log.get(lazy.Log.TYPES.MARIONETTE) 13 ); 14 15 export class MarionetteEventsChild extends JSWindowActorChild { 16 get innerWindowId() { 17 return this.manager.innerWindowId; 18 } 19 20 actorCreated() { 21 // Prevent the logger from being created if the current log level 22 // isn't set to 'trace'. This is important for a faster content process 23 // creation when Marionette is running. 24 if (lazy.Log.isTraceLevelOrOrMore) { 25 lazy.logger.trace( 26 `[${this.browsingContext.id}] MarionetteEvents actor created ` + 27 `for window id ${this.innerWindowId}` 28 ); 29 } 30 } 31 32 handleEvent({ target, type }) { 33 if (!Services.cpmm.sharedData.get("MARIONETTE_EVENTS_ENABLED")) { 34 // The parent process will set MARIONETTE_EVENTS_ENABLED to false when 35 // the Marionette session ends to avoid unnecessary inter process 36 // communications 37 return; 38 } 39 40 // Ignore invalid combinations of load events and document's readyState. 41 if ( 42 (type === "DOMContentLoaded" && 43 target.readyState != "interactive" && 44 !target.isInitialDocument) || 45 (type === "pageshow" && target.readyState != "complete") 46 ) { 47 lazy.logger.warn( 48 `Ignoring event '${type}' because document has an invalid ` + 49 `readyState of '${target.readyState}'.` 50 ); 51 return; 52 } 53 54 switch (type) { 55 case "beforeunload": 56 case "DOMContentLoaded": 57 case "hashchange": 58 case "pagehide": 59 case "pageshow": 60 case "popstate": 61 this.sendAsyncMessage("MarionetteEventsChild:PageLoadEvent", { 62 browsingContext: this.browsingContext, 63 documentURI: target.documentURI, 64 readyState: target.readyState, 65 isInitialDocument: target.isInitialDocument, 66 isUncommittedInitialDocument: target.isUncommittedInitialDocument, 67 type, 68 windowId: this.innerWindowId, 69 }); 70 break; 71 } 72 } 73 }