webextension-inspected-window.js (3553B)
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 Arg, 9 RetVal, 10 generateActorSpec, 11 types, 12 } = require("resource://devtools/shared/protocol.js"); 13 14 /** 15 * Sent with the eval and reload requests, used to inform the 16 * webExtensionInspectedWindowActor about the caller information 17 * to be able to evaluate code as being executed from the caller 18 * WebExtension sources, or log errors with information that can 19 * help the addon developer to more easily identify the affected 20 * lines in his own addon code. 21 */ 22 types.addDictType("webExtensionCallerInfo", { 23 // Information related to the line of code that has originated 24 // the request. 25 url: "string", 26 lineNumber: "nullable:number", 27 28 // The called addonId. 29 addonId: "string", 30 }); 31 32 /** 33 * RDP type related to the inspectedWindow.eval method request. 34 */ 35 types.addDictType("webExtensionEvalOptions", { 36 frameURL: "nullable:string", 37 contextSecurityOrigin: "nullable:string", 38 useContentScriptContext: "nullable:boolean", 39 40 // Return the evalResult as a grip (used by the WebExtensions 41 // devtools inspector's sidebar.setExpression API method). 42 evalResultAsGrip: "nullable:boolean", 43 44 // The actor ID of the node selected in the inspector if any, 45 // used to provide the '$0' binding. 46 toolboxSelectedNodeActorID: "nullable:string", 47 48 // The actor ID of the console actor, 49 // used to provide the 'inspect' binding. 50 toolboxConsoleActorID: "nullable:string", 51 }); 52 53 /** 54 * RDP type related to the inspectedWindow.eval method result errors. 55 * 56 * This type has been modelled on the same data format 57 * used in the corresponding chrome API method. 58 */ 59 types.addDictType("webExtensionEvalExceptionInfo", { 60 // The following properties are set if the error has not occurred 61 // in the evaluated JS code. 62 isError: "nullable:boolean", 63 code: "nullable:string", 64 description: "nullable:string", 65 details: "nullable:array:json", 66 67 // The following properties are set if the error has occurred 68 // in the evaluated JS code. 69 isException: "nullable:string", 70 value: "nullable:string", 71 }); 72 73 /** 74 * RDP type related to the inspectedWindow.eval method result. 75 */ 76 types.addDictType("webExtensionEvalResult", { 77 // The following properties are set if the evaluation has been 78 // completed successfully. 79 value: "nullable:json", 80 valueGrip: "nullable:json", 81 // The following properties are set if the evalutation has been 82 // completed with errors. 83 exceptionInfo: "nullable:webExtensionEvalExceptionInfo", 84 }); 85 86 /** 87 * RDP type related to the inspectedWindow.reload method request. 88 */ 89 types.addDictType("webExtensionReloadOptions", { 90 ignoreCache: "nullable:boolean", 91 userAgent: "nullable:string", 92 injectedScript: "nullable:string", 93 }); 94 95 const webExtensionInspectedWindowSpec = generateActorSpec({ 96 typeName: "webExtensionInspectedWindow", 97 98 methods: { 99 reload: { 100 request: { 101 webExtensionCallerInfo: Arg(0, "webExtensionCallerInfo"), 102 options: Arg(1, "webExtensionReloadOptions"), 103 }, 104 }, 105 eval: { 106 request: { 107 webExtensionCallerInfo: Arg(0, "webExtensionCallerInfo"), 108 expression: Arg(1, "string"), 109 options: Arg(2, "webExtensionEvalOptions"), 110 }, 111 112 response: { 113 evalResult: RetVal("webExtensionEvalResult"), 114 }, 115 }, 116 }, 117 }); 118 119 exports.webExtensionInspectedWindowSpec = webExtensionInspectedWindowSpec;