@@ -23,6 +23,8 @@ const MyPanel = Class(
23
23
icon : "./icon-16.png" ,
24
24
url : "./myPanel.html" ,
25
25
26
+ // Initialization
27
+
26
28
/**
27
29
* Executed by the framework when an instance of this panel is created.
28
30
* There is one instance of this panel per {@Toolbox }. The panel is
@@ -43,6 +45,9 @@ const MyPanel = Class(
43
45
* ready (document state == interactive).
44
46
*/
45
47
onReady : function ( ) {
48
+ // This is the way how to get access to the inner <iframe> element.
49
+ // The frame is using type="content" and so, the access to the inner
50
+ // document must be done through a message manager.
46
51
this . panelFrame = viewFor ( this ) ;
47
52
48
53
// Get frame's message manager. Read more about message managers on MDN:
@@ -51,7 +56,7 @@ const MyPanel = Class(
51
56
messageManager . addMessageListener ( "message/from/content" ,
52
57
this . onMessage ) ;
53
58
54
- // Load frame script with content API for receiving
59
+ // Load helper frame script with content API for receiving
55
60
// and sending messages.
56
61
let url = self . data . url ( "frame-script.js" ) ;
57
62
messageManager . loadFrameScript ( url , false ) ;
@@ -62,12 +67,20 @@ const MyPanel = Class(
62
67
63
68
// Chrome <-> Content Communication
64
69
70
+ /**
71
+ * Handle messages coming from the content scope (see 'frame-script.js'
72
+ * that is responsible for sending them).
73
+ */
65
74
onMessage : function ( message ) {
66
75
const { type, data } = message . data ;
67
76
68
77
console . log ( "Message from content: " + data ) ;
69
78
} ,
70
79
80
+ /**
81
+ * Send message to the content scope (see 'frame-script.js'
82
+ * that is responsible for handling them).
83
+ */
71
84
postContentMessage : function ( type , data ) {
72
85
let { messageManager } = this . panelFrame . frameLoader ;
73
86
messageManager . sendAsyncMessage ( "message/from/chrome" , {
@@ -77,6 +90,7 @@ const MyPanel = Class(
77
90
} ,
78
91
} ) ;
79
92
93
+ // Register panel
80
94
const myTool = new Tool ( {
81
95
name : "MyTool" ,
82
96
panels : {
0 commit comments