Skip to content

Commit

Permalink
Issue 7145: getEventListeners includes the HTML panel mutation observer
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlindholm committed Jan 27, 2014
1 parent b7fd83f commit 84e1376
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
12 changes: 8 additions & 4 deletions extension/content/firebug/console/commands/getEventListeners.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* See license.txt for terms of usage */
/*global define:1*/
/*global define:1, window:1*/

define([
"firebug/firebug",
Expand Down Expand Up @@ -198,7 +198,6 @@ function onExecuteCommand(context, args)
* Get sorted list of listeners registered for the target and list of listeners
* registered for all ancestor elements (if required).
*
* @param context {TabContext} The current Firebug context.
* @param target {Object} The event target for which listeners should be returned.
* @param includeParents {Boolean} True if parent listeners should also be returned.
*/
Expand Down Expand Up @@ -360,7 +359,7 @@ function getMutationObserversForTarget(target, parent)
var result = [];

// getBoundMutationObservers() API has been introduced in Firefox 23
// Also |window| that can be passed as an event target doeesn't implement
// Also |window| that can be passed as an event target doesn't implement
// the method.
if (typeof(target.getBoundMutationObservers) != "function")
return result;
Expand All @@ -381,6 +380,11 @@ function getMutationObserversForTarget(target, parent)
if (parent && !info.subtree)
continue;

// Prevent chrome observers from leaking into the page.
var callback = observer.mutationCallback;
if (!callback || Wrapper.isChromeObject(callback, window))
continue;

// OK, insert the observer into the result array.
result.push({
attributeOldValue: info.attributeOldValue,
Expand All @@ -390,7 +394,7 @@ function getMutationObserversForTarget(target, parent)
childList: info.childList,
subtree: info.subtree,
observedNode: info.observedNode,
mutationCallback: observer.mutationCallback,
mutationCallback: callback,
});
}
}
Expand Down
20 changes: 8 additions & 12 deletions extension/content/firebug/lib/events.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* See license.txt for terms of usage */
/*global define:1, Components:1, MouseEvent:1, Window: 1, Firebug:1*/
/*global define:1, Components:1, MouseEvent:1, Firebug:1, window:1*/

define([
"firebug/lib/trace",
"firebug/lib/xpcom"
"firebug/lib/wrapper",
],
function(FBTrace, Xpcom) {
function(FBTrace, Wrapper) {

"use strict";

// ********************************************************************************************* //
// Constants

var Cu = Components.utils;

var elService = Xpcom.CCSV("@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
var Cc = Components.classes;
var Ci = Components.interfaces;
var elService = Cc["@mozilla.org/eventlistenerservice;1"].getService(Ci.nsIEventListenerService);

// ********************************************************************************************* //
// Implementation
Expand Down Expand Up @@ -233,7 +233,7 @@ Events.isShift = function(event)
// ********************************************************************************************* //
// DOM Events

const eventTypes =
var eventTypes =
{
composition: [
"composition",
Expand Down Expand Up @@ -604,11 +604,7 @@ Events.getEventListenersForTarget = function(target)
if (!listener.func || rawListener.inSystemEventGroup)
continue;

var funcGlobal = Cu.getGlobalForObject(listener.func);
if (!(funcGlobal instanceof Window))
continue;

if (funcGlobal.document.nodePrincipal.subsumes(document.nodePrincipal))
if (Wrapper.isChromeObject(listener.func, window))
continue;

ret.push(listener);
Expand Down
12 changes: 12 additions & 0 deletions extension/content/firebug/lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ Wrapper.unwrapIValueObject = function(scope, viewChrome)
return scopeVars;
};

Wrapper.isChromeObject = function(obj, chromeWin)
{
var global = Cu.getGlobalForObject(obj);
if (!(global instanceof chromeWin.Window))
return true;

if (global.document.nodePrincipal.subsumes(chromeWin.document.nodePrincipal))
return true;

return false;
};

/**
* Create a content-accessible view of a simple chrome object. All properties
* are marked as non-writable, except if they have explicit getters/setters.
Expand Down

0 comments on commit 84e1376

Please sign in to comment.