actor-registry.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 protocol = require("devtools/shared/protocol");
  6. const { method, custom, Arg, Option, RetVal } = protocol;
  7. const { Cu, CC, components } = require("chrome");
  8. const Services = require("Services");
  9. const { DebuggerServer } = require("devtools/server/main");
  10. const { registerActor, unregisterActor } = require("devtools/server/actors/utils/actor-registry-utils");
  11. const { actorActorSpec, actorRegistrySpec } = require("devtools/shared/specs/actor-registry");
  12. /**
  13. * The ActorActor gives you a handle to an actor you've dynamically
  14. * registered and allows you to unregister it.
  15. */
  16. const ActorActor = protocol.ActorClassWithSpec(actorActorSpec, {
  17. initialize: function (conn, options) {
  18. protocol.Actor.prototype.initialize.call(this, conn);
  19. this.options = options;
  20. },
  21. unregister: function () {
  22. unregisterActor(this.options);
  23. }
  24. });
  25. /*
  26. * The ActorRegistryActor allows clients to define new actors on the
  27. * server. This is particularly useful for addons.
  28. */
  29. const ActorRegistryActor = protocol.ActorClassWithSpec(actorRegistrySpec, {
  30. initialize: function (conn) {
  31. protocol.Actor.prototype.initialize.call(this, conn);
  32. },
  33. registerActor: function (sourceText, fileName, options) {
  34. return registerActor(sourceText, fileName, options).then(() => {
  35. let { constructor, type } = options;
  36. return ActorActor(this.conn, {
  37. name: constructor,
  38. tab: type.tab,
  39. global: type.global
  40. });
  41. });
  42. }
  43. });
  44. exports.ActorRegistryActor = ActorRegistryActor;