director-manager.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. const {
  6. types,
  7. Arg,
  8. Option,
  9. RetVal,
  10. generateActorSpec,
  11. } = require("devtools/shared/protocol");
  12. /**
  13. * Type describing a messageport event
  14. */
  15. types.addDictType("messageportevent", {
  16. isTrusted: "boolean",
  17. data: "nullable:primitive",
  18. origin: "nullable:string",
  19. lastEventId: "nullable:string",
  20. source: "messageport",
  21. ports: "nullable:array:messageport"
  22. });
  23. const messagePortSpec = generateActorSpec({
  24. typeName: "messageport",
  25. /**
  26. * Events emitted by this actor.
  27. */
  28. events: {
  29. message: {
  30. type: "message",
  31. msg: Arg(0, "nullable:messageportevent")
  32. }
  33. },
  34. methods: {
  35. postMessage: {
  36. oneway: true,
  37. request: {
  38. msg: Arg(0, "nullable:json")
  39. }
  40. },
  41. start: {
  42. oneway: true,
  43. request: {}
  44. },
  45. close: {
  46. oneway: true,
  47. request: {}
  48. },
  49. finalize: {
  50. oneway: true
  51. },
  52. },
  53. });
  54. exports.messagePortSpec = messagePortSpec;
  55. /**
  56. * Type describing a director-script error
  57. */
  58. types.addDictType("director-script-error", {
  59. directorScriptId: "string",
  60. message: "nullable:string",
  61. stack: "nullable:string",
  62. fileName: "nullable:string",
  63. lineNumber: "nullable:number",
  64. columnNumber: "nullable:number"
  65. });
  66. /**
  67. * Type describing a director-script attach event
  68. */
  69. types.addDictType("director-script-attach", {
  70. directorScriptId: "string",
  71. url: "string",
  72. innerId: "number",
  73. port: "nullable:messageport"
  74. });
  75. /**
  76. * Type describing a director-script detach event
  77. */
  78. types.addDictType("director-script-detach", {
  79. directorScriptId: "string",
  80. innerId: "number"
  81. });
  82. const directorScriptSpec = generateActorSpec({
  83. typeName: "director-script",
  84. /**
  85. * Events emitted by this actor.
  86. */
  87. events: {
  88. error: {
  89. type: "error",
  90. data: Arg(0, "director-script-error")
  91. },
  92. attach: {
  93. type: "attach",
  94. data: Arg(0, "director-script-attach")
  95. },
  96. detach: {
  97. type: "detach",
  98. data: Arg(0, "director-script-detach")
  99. }
  100. },
  101. methods: {
  102. setup: {
  103. request: {
  104. reload: Option(0, "boolean"),
  105. skipAttach: Option(0, "boolean")
  106. },
  107. oneway: true
  108. },
  109. getMessagePort: {
  110. request: { },
  111. response: {
  112. port: RetVal("nullable:messageport")
  113. }
  114. },
  115. finalize: {
  116. oneway: true
  117. },
  118. },
  119. });
  120. exports.directorScriptSpec = directorScriptSpec;
  121. const directorManagerSpec = generateActorSpec({
  122. typeName: "director-manager",
  123. /**
  124. * Events emitted by this actor.
  125. */
  126. events: {
  127. "director-script-error": {
  128. type: "error",
  129. data: Arg(0, "director-script-error")
  130. },
  131. "director-script-attach": {
  132. type: "attach",
  133. data: Arg(0, "director-script-attach")
  134. },
  135. "director-script-detach": {
  136. type: "detach",
  137. data: Arg(0, "director-script-detach")
  138. }
  139. },
  140. methods: {
  141. list: {
  142. response: {
  143. directorScripts: RetVal("json")
  144. }
  145. },
  146. enableByScriptIds: {
  147. oneway: true,
  148. request: {
  149. selectedIds: Arg(0, "array:string"),
  150. reload: Option(1, "boolean")
  151. }
  152. },
  153. disableByScriptIds: {
  154. oneway: true,
  155. request: {
  156. selectedIds: Arg(0, "array:string"),
  157. reload: Option(1, "boolean")
  158. }
  159. },
  160. getByScriptId: {
  161. request: {
  162. scriptId: Arg(0, "string")
  163. },
  164. response: {
  165. directorScript: RetVal("director-script")
  166. }
  167. },
  168. finalize: {
  169. oneway: true
  170. },
  171. },
  172. });
  173. exports.directorManagerSpec = directorManagerSpec;