simulator-content.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /* globals addMessageListener, sendAsyncMessage */
  5. "use strict";
  6. const { utils: Cu } = Components;
  7. const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
  8. const { SimulatorCore } = require("devtools/shared/touch/simulator-core");
  9. /**
  10. * Launches SimulatorCore in the content window to simulate touch events
  11. * This frame script is managed by `simulator.js`.
  12. */
  13. var simulator = {
  14. messages: [
  15. "TouchEventSimulator:Start",
  16. "TouchEventSimulator:Stop",
  17. ],
  18. init() {
  19. this.simulatorCore = new SimulatorCore(docShell.chromeEventHandler);
  20. this.messages.forEach(msgName => {
  21. addMessageListener(msgName, this);
  22. });
  23. },
  24. receiveMessage(msg) {
  25. switch (msg.name) {
  26. case "TouchEventSimulator:Start":
  27. this.simulatorCore.start();
  28. sendAsyncMessage("TouchEventSimulator:Started");
  29. break;
  30. case "TouchEventSimulator:Stop":
  31. this.simulatorCore.stop();
  32. sendAsyncMessage("TouchEventSimulator:Stopped");
  33. break;
  34. }
  35. },
  36. };
  37. simulator.init();