Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 5316: Break on HTML mutation works only if the HTML panel is se…

…lected
  • Loading branch information...
commit d96d0e9a6f4f240dfa96aff70a8d8db0dc259d56 1 parent e1be572
Jan Odvarko authored April 04, 2012
122  extension/content/firebug/html/htmlPanel.js
... ...
@@ -1,4 +1,3 @@
1  
-/* See license.txt for terms of usage */
2 1
 
3 2
 define([
4 3
     "firebug/lib/object",
@@ -76,6 +75,16 @@ Firebug.HTMLModule = Obj.extend(Firebug.Module,
76 75
     loadedContext: function(context, persistedState)
77 76
     {
78 77
         context.mutationBreakpoints.load(context);
  78
+
  79
+        // If there are mutation breakpoints, make sure the HTML panel
  80
+        // is automatically created and mutation listeners registered.
  81
+        // Mutation breakpoints should work even if the HTML panel has
  82
+        // never been selected by the user since the page load.
  83
+        if (!context.mutationBreakpoints.isEmpty())
  84
+        {
  85
+            var panel = context.getPanel("html");
  86
+            panel.registerMutationListeners();
  87
+        }
79 88
     },
80 89
 
81 90
     destroyContext: function(context, persistedState)
@@ -345,6 +354,64 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
345 354
 
346 355
     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 356
 
  357
+    registerMutationListeners: function(win)
  358
+    {
  359
+        if (this.context.attachedMutation)
  360
+            return;
  361
+
  362
+        this.context.attachedMutation = true;
  363
+
  364
+        var self = this;
  365
+        function addListeners(win)
  366
+        {
  367
+            var doc = win.document;
  368
+
  369
+            // xxxHonza: an iframe doesn't have to be loaded yet so, do not
  370
+            // register mutation elements in such cases since they wouldn't
  371
+            // be removed.
  372
+            // The listeners can be registered later in watchWindowDelayed,
  373
+            // but it's also risky. Mutation listeners should be registered
  374
+            // at the moment when it's clear that the window/frame has been
  375
+            // loaded.
  376
+            if (doc.location == "about:blank")
  377
+                return;
  378
+
  379
+            Events.addEventListener(doc, "DOMAttrModified", self.onMutateAttr, false);
  380
+            Events.addEventListener(doc, "DOMCharacterDataModified", self.onMutateText, false);
  381
+            Events.addEventListener(doc, "DOMNodeInserted", self.onMutateNode, false);
  382
+            Events.addEventListener(doc, "DOMNodeRemoved", self.onMutateNode, false);
  383
+
  384
+            FBTrace.sysout("registering " + self.name);
  385
+        }
  386
+
  387
+        // If a window is specified use it, otherwise register listeners for all
  388
+        // context windows (including the main window and all embedded iframes).
  389
+        if (win)
  390
+            addListeners(win);
  391
+        else
  392
+            Win.iterateWindows(this.context.window, addListeners);
  393
+    },
  394
+
  395
+    unregisterMutationListeners: function(win)
  396
+    {
  397
+        var self = this;
  398
+        function removeListeners(win)
  399
+        {
  400
+            var doc = win.document;
  401
+            Events.removeEventListener(doc, "DOMAttrModified", self.onMutateAttr, false);
  402
+            Events.removeEventListener(doc, "DOMCharacterDataModified", self.onMutateText, false);
  403
+            Events.removeEventListener(doc, "DOMNodeInserted", self.onMutateNode, false);
  404
+            Events.removeEventListener(doc, "DOMNodeRemoved", self.onMutateNode, false);
  405
+        }
  406
+
  407
+        if (win)
  408
+            removeListeners(win);
  409
+        else
  410
+            Win.iterateWindows(this.context.window, removeListeners);
  411
+    },
  412
+
  413
+    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  414
+
348 415
     mutateAttr: function(target, attrChange, attrName, attrValue)
349 416
     {
350 417
         // Every time the user scrolls we get this pointless mutation event, which
@@ -1077,14 +1144,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
1077 1144
             delete this.inspectorHistory[i];
1078 1145
         delete this.inspectorHistory;
1079 1146
 
1080  
-        Win.iterateWindows(this.context.window, Obj.bind(function(win)
1081  
-        {
1082  
-            var doc = win.document;
1083  
-            Events.removeEventListener(doc, "DOMAttrModified", this.onMutateAttr, false);
1084  
-            Events.removeEventListener(doc, "DOMCharacterDataModified", this.onMutateText, false);
1085  
-            Events.removeEventListener(doc, "DOMNodeInserted", this.onMutateNode, false);
1086  
-            Events.removeEventListener(doc, "DOMNodeRemoved", this.onMutateNode, false);
1087  
-        }, this));
  1147
+        this.unregisterMutationListeners();
1088 1148
     },
1089 1149
 
1090 1150
     initializeNode: function(oldPanelNode)
@@ -1124,30 +1184,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
1124 1184
 
1125 1185
         if (this.context.loaded)
1126 1186
         {
1127  
-            if (!this.context.attachedMutation)
1128  
-            {
1129  
-                this.context.attachedMutation = true;
1130  
-
1131  
-                Win.iterateWindows(this.context.window, Obj.bind(function(win)
1132  
-                {
1133  
-                    var doc = win.document;
1134  
-
1135  
-                    // xxxHonza: an iframe doesn't have to be loaded yet so, do not
1136  
-                    // register mutation elements in such cases since they wouldn't
1137  
-                    // be removed.
1138  
-                    // The listeners can be registered later in watchWindowDelayed,
1139  
-                    // but it's also risky. Mutation listeners should be registered
1140  
-                    // at the moment when it's clear that the window/frame has been
1141  
-                    // loaded.
1142  
-                    if (doc.location == "about:blank")
1143  
-                        return;
1144  
-
1145  
-                    Events.addEventListener(doc, "DOMAttrModified", this.onMutateAttr, false);
1146  
-                    Events.addEventListener(doc, "DOMCharacterDataModified", this.onMutateText, false);
1147  
-                    Events.addEventListener(doc, "DOMNodeInserted", this.onMutateNode, false);
1148  
-                    Events.addEventListener(doc, "DOMNodeRemoved", this.onMutateNode, false);
1149  
-                }, this));
1150  
-            }
  1187
+            this.registerMutationListeners();
1151 1188
 
1152 1189
             Persist.restoreObjects(this, state);
1153 1190
         }
@@ -1189,18 +1226,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
1189 1226
         }
1190 1227
 
1191 1228
         if (this.context.attachedMutation)
1192  
-        {
1193  
-            var doc = win.document;
1194  
-
1195  
-            // See HTMLPanel.show
1196  
-            if (doc.location == "about:blank")
1197  
-                return;
1198  
-
1199  
-            Events.addEventListener(doc, "DOMAttrModified", this.onMutateAttr, false);
1200  
-            Events.addEventListener(doc, "DOMCharacterDataModified", this.onMutateText, false);
1201  
-            Events.addEventListener(doc, "DOMNodeInserted", this.onMutateNode, false);
1202  
-            Events.addEventListener(doc, "DOMNodeRemoved", this.onMutateNode, false);
1203  
-        }
  1229
+            this.registerMutationListeners(win);
1204 1230
     },
1205 1231
 
1206 1232
     unwatchWindow: function(context, win)
@@ -1222,11 +1248,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
1222 1248
             });
1223 1249
         }
1224 1250
 
1225  
-        var doc = win.document;
1226  
-        Events.removeEventListener(doc, "DOMAttrModified", this.onMutateAttr, false);
1227  
-        Events.removeEventListener(doc, "DOMCharacterDataModified", this.onMutateText, false);
1228  
-        Events.removeEventListener(doc, "DOMNodeInserted", this.onMutateNode, false);
1229  
-        Events.removeEventListener(doc, "DOMNodeRemoved", this.onMutateNode, false);
  1251
+        this.unregisterMutationListeners(win);
1230 1252
     },
1231 1253
 
1232 1254
     mutateDocumentEmbedded: function(win, remove)

0 notes on commit d96d0e9

Please sign in to comment.
Something went wrong with that request. Please try again.