Closed Bug 331926 Opened 20 years ago Closed 7 years ago

Remove redundant and unnecessary code in dom.js - cmdInspectBrowser and cmdInspectBrowserIsValid

Categories

(Other Applications :: DOM Inspector, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: jason.barnabe, Unassigned)

Details

Attachments

(1 file)

cmdInspectBrowser and cmdInspectBrowserIsValid handle whether to show the "Inspect Contained Document" context menu item in the DOM Nodes panel. Right now, both functions are checking the node's name, sometimes checking the namespace, sometimes not. Instead of doing that, all the code really has to do is check for the existance of node.contentDocument.
Attached patch patch v1Splinter Review
Attachment #216482 - Flags: review?(timeless)
Comment on attachment 216482 [details] [diff] [review] patch v1 >Index: extensions/inspector/resources/content/viewers/dom/dom.js >@@ -304,42 +304,24 @@ DOMViewer.prototype = > cmdInspectBrowserIsValid: function() > { > var node = viewer.selectedNode; >+ if (!node || node.nodeType != Node.ELEMENT_NODE) >+ return false; that's kind of nice. but this introduces a strictwarning/reference to undefined property. you could do "contentDocument" in node i suppose... that might be scalable... >+ return !!node.contentDocument;
Attachment #216482 - Flags: review?(timeless) → review-
If you're referring to... JavaScript strict warning: chrome://inspector/content/inspector.xml, line 455: reference to undefined property event.originalTarget.nodeType That existed before this patch. If you're referring to !!node.contentDocument causing a warning, it doesn't.
On the matter of whether it *should* give a warning, I filed bug 332299, which was marked WONTFIX.
Comment on attachment 216482 [details] [diff] [review] patch v1 oh well
Attachment #216482 - Flags: review- → review+
Attachment #216482 - Flags: superreview?(neil)
Comment on attachment 216482 [details] [diff] [review] patch v1 Since DOM Inspector can't use XPC native wrappers by default, this change now makes it slightly more open to abuse; any chance you can address the issue?
Attachment #216482 - Flags: superreview?(neil) → superreview-
(In reply to comment #6) > (From update of attachment 216482 [details] [diff] [review] [edit]) > Since DOM Inspector can't use XPC native wrappers by default, this change now > makes it slightly more open to abuse; any chance you can address the issue? How would I do that? By adding a node instanceof nsIDOMNode check to cmdInspectBrowserIsValid?
(In reply to comment #7) >How would I do that? Well there are two problems. The first is that a web page can write anElement.contentDocument = something; and with your code DOM Inspector will try to inspect it, whereas with the original code it would only work with a well-known tag in a random namespace (in the correct namespace the property is readonly). Thus I don't think you should try to simplify the validity check; if anything you should check more strictly. There is a variant which is is harder to solve, and after some testing might not even be realistically possible, because of the way xul and xbl work^H^H^H^Hsuck.
(In reply to comment #8) > (in the correct namespace the property is readonly). So why don't we restrict it to namespaces where contentDocument is readonly? (HTML and XUL, I assume.) >Thus I don't think you should try to simplify the validity check; if anything you should check more strictly. Strict and simple aren't mutually exclusive.
Couldn't we create an XPCNativeWrapper to use for the check?
(In reply to comment #10) >Couldn't we create an XPCNativeWrapper to use for the check? That doesn't work on XUL elements (because XPCNativeWrapper bypasses XBL).
(In reply to comment #11) > That doesn't work on XUL elements (because XPCNativeWrapper bypasses XBL). That seems to scream "security hole" to me if someone is using remote XUL.
QA Contact: timeless → dom-inspector
Assignee: jason.barnabe → nobody
cmdInspectBrowserIsValid function was removed from code in http://hg.mozilla.org/dom-inspector/rev/257b43aa4180
Note that the logic was moved to isCommandEnabled.
Bulk close. This component is no longer supported or maintained. https://bugzilla.mozilla.org/show_bug.cgi?id=1499023
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → INCOMPLETE
Bulk close. This component is no longer supported or maintained. https://bugzilla.mozilla.org/show_bug.cgi?id=1499023
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: