@@ -11,7 +11,8 @@ const self = require("sdk/self");
11
11
const { Cu, Ci } = require ( "chrome" ) ;
12
12
const { Class } = require ( "sdk/core/heritage" ) ;
13
13
const { loadSheet, removeSheet } = require ( "sdk/stylesheet/utils" ) ;
14
- const { on, off } = require ( "sdk/event/core" ) ;
14
+ const { on, off, once } = require ( "sdk/event/core" ) ;
15
+ const { defer } = require ( "sdk/core/promise" ) ;
15
16
16
17
// DevTools
17
18
const { devtools } = Cu . import ( "resource://gre/modules/devtools/Loader.jsm" , { } ) ;
@@ -70,20 +71,12 @@ const InspectorOverlay = Class(
70
71
// Tooltip events
71
72
this . onClickTooltip = this . onClickTooltip . bind ( this ) ;
72
73
73
- // FireQueryToolboxOverlay events
74
- this . onAttach = this . onAttach . bind ( this ) ;
75
- this . onDetach = this . onDetach . bind ( this ) ;
76
-
77
74
// Backend events
78
75
this . onDataModified = this . onDataModified . bind ( this ) ;
79
76
} ,
80
77
81
78
destroy : function ( ) {
82
79
Trace . sysout ( "InspectorOverlay.destroy;" , arguments ) ;
83
-
84
- let toolboxOverlay = this . context . getOverlay ( ToolboxOverlayId ) ;
85
- off ( toolboxOverlay , "attach" , this . onAttach ) ;
86
- off ( toolboxOverlay , "detach" , this . onDetach ) ;
87
80
} ,
88
81
89
82
// Overlay Events
@@ -99,11 +92,27 @@ const InspectorOverlay = Class(
99
92
this . panel . on ( "inspector-updated" , this . onInspectorUpdated ) ;
100
93
this . panel . on ( "container-created" , this . onMarkupViewContainerCreated )
101
94
102
- // Listen to {@FireQueryToolboxOverlay } events related to
103
- // backend actor attach and detach.
95
+ // Listen to data-modified events from the backend actor. These
96
+ // events are used to update the indicator icon for elements
97
+ // with jQuery.data
98
+ this . getFrontWhenReady ( ) . then ( front => {
99
+ front . on ( "data-modified" , this . onDataModified ) ;
100
+ } ) ;
101
+
102
+ // Update the Inspector panel when 'attach' is fired. The event
103
+ // might be already gone at this point, which is fine and in
104
+ // that case the panel will be properly initialized since
105
+ // the backend is already setup.
106
+ // Otherwise, if the 'Inspector' panel is the default the backend
107
+ // registration needs usually more time and happens when the
108
+ // content is already there. In this case we need to refresh
109
+ // panel content to make sure jQuery.data indicators (icons) are
110
+ // also rendered.
111
+ // xxxHonza: request better API (e.g. this.panel.refresh());
104
112
let toolboxOverlay = this . context . getOverlay ( ToolboxOverlayId ) ;
105
- on ( toolboxOverlay , "attach" , this . onAttach ) ;
106
- on ( toolboxOverlay , "detach" , this . onDetach ) ;
113
+ once ( toolboxOverlay , "attach" , ( ) => {
114
+ this . panel . onNewRoot ( ) ;
115
+ } ) ;
107
116
108
117
// Monkey patch the InspectorPanel.
109
118
// xxxHonza: what about extension uninstall/disable?
@@ -117,6 +126,22 @@ const InspectorOverlay = Class(
117
126
Trace . sysout ( "InspectorOverlay.onReady;" , options ) ;
118
127
} ,
119
128
129
+ // FireQueryFront
130
+
131
+ getFrontWhenReady : function ( ) {
132
+ let deferred = defer ( ) ;
133
+ let toolboxOverlay = this . context . getOverlay ( ToolboxOverlayId ) ;
134
+ let front = toolboxOverlay . front ;
135
+ if ( front ) {
136
+ deferred . resolve ( front ) ;
137
+ } else {
138
+ once ( toolboxOverlay , "attach" , ( front ) => {
139
+ deferred . resolve ( front ) ;
140
+ } ) ;
141
+ }
142
+ return deferred . promise ;
143
+ } ,
144
+
120
145
// MarkupView Event Handlers
121
146
122
147
/**
@@ -255,36 +280,17 @@ const InspectorOverlay = Class(
255
280
} ) ;
256
281
} ,
257
282
258
- // ToolboxOverlay Events
259
-
260
- onAttach : function ( front ) {
261
- Trace . sysout ( "InspectorOverlay.onAttach;" , arguments ) ;
262
-
263
- front . on ( "data-modified" , this . onDataModified ) ;
264
-
265
- // Update the markup view. It might happen that the backend
266
- // registration is done after the panel is already displayed.
267
- // To improve the first-time experience - the panel is auto
268
- // refreshed so, all jQuery.data indicators are properly
269
- // rendered within the panel.
270
- // xxxHonza: request better API (e.g. this.panel.refresh());
271
- this . panel . onNewRoot ( ) ;
272
- } ,
273
-
274
- onDetach : function ( ) {
275
- Trace . sysout ( "InspectorOverlay.onDetach;" , arguments ) ;
276
- } ,
277
-
278
283
// Backend Events
279
284
280
285
onDataModified : function ( nodeData , hasJQueryData ) {
281
- Trace . sysout ( "InspectorOverlay.onDataModified; has data: " +
282
- hasJQueryData ) ;
283
-
284
286
let markupView = this . panel . markup ;
285
287
let client = this . toolbox . target . client ;
286
288
let nodeFront = nodeData . node ;
287
289
290
+ Trace . sysout ( "InspectorOverlay.onDataModified; " +
291
+ nodeFront . nodeName + "#" + nodeFront . id +
292
+ ", has data: " + hasJQueryData , nodeFront ) ;
293
+
288
294
// The container doesn't have to be always visible/available.
289
295
let container = markupView . getContainer ( nodeFront ) ;
290
296
if ( ! container ) {
0 commit comments