main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { Toolbar } = require("sdk/ui/toolbar");
  6. const { Frame } = require("sdk/ui/frame");
  7. const { ActionButton } = require("sdk/ui/button/action");
  8. let button = new ActionButton({
  9. id: "button",
  10. label: "send!",
  11. icon: "./favicon.ico",
  12. onClick: () => {
  13. frame.postMessage({
  14. hello: "content"
  15. });
  16. }
  17. });
  18. let frame = new Frame({
  19. url: "./index.html",
  20. onAttach: () => {
  21. console.log("frame was attached");
  22. },
  23. onReady: () => {
  24. console.log("frame document was loaded");
  25. },
  26. onLoad: () => {
  27. console.log("frame load complete");
  28. },
  29. onMessage: (event) => {
  30. console.log("got message from frame content", event);
  31. if (event.data === "ping!")
  32. event.source.postMessage("pong!", event.source.origin);
  33. }
  34. });
  35. let toolbar = new Toolbar({
  36. items: [frame],
  37. title: "Addon Demo",
  38. hidden: false,
  39. onShow: () => {
  40. console.log("toolbar was shown");
  41. },
  42. onHide: () => {
  43. console.log("toolbar was hidden");
  44. }
  45. });