diff --git a/extensions/inspector/resources/content/commandOverlay.xul b/extensions/inspector/resources/content/commandOverlay.xul
index ecbf023c107e..f3a854791c31 100644
--- a/extensions/inspector/resources/content/commandOverlay.xul
+++ b/extensions/inspector/resources/content/commandOverlay.xul
@@ -20,6 +20,7 @@
+
diff --git a/extensions/inspector/resources/content/inspector.js b/extensions/inspector/resources/content/inspector.js
index f412923cfea4..c59ac1a4ff2a 100644
--- a/extensions/inspector/resources/content/inspector.js
+++ b/extensions/inspector/resources/content/inspector.js
@@ -20,6 +20,7 @@
*
* Contributor(s):
* Joe Hewitt (original author)
+ * Jason Barnabe
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -48,10 +49,11 @@ var inspector;
const kSearchRegURL = "resource:///res/inspector/search-registry.rdf";
-const kWindowDataSourceCID = "@mozilla.org/rdf/datasource;1?name=window-mediator";
const kClipboardHelperCID = "@mozilla.org/widget/clipboardhelper;1";
const kPromptServiceCID = "@mozilla.org/embedcomp/prompt-service;1";
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
+const nsIDocShellTreeItem = Components.interfaces.nsIDocShellTreeItem;
+const nsIDocShell = Components.interfaces.nsIDocShell;
//////////////////////////////////////////////////
@@ -122,6 +124,11 @@ InspectorApp.prototype =
this.mPanelSet.addObserver("panelsetready", this, false);
this.mPanelSet.initialize();
+ this.mInspectDocumentMenu = document.getElementById("listDocuments-popup");
+
+ document.getElementById("cmdToggleChrome").setAttribute("checked",
+ PrefUtils.getPref("inspector.showChrome"));
+
if (aURI) {
this.gotoURL(aURI);
}
@@ -207,6 +214,17 @@ InspectorApp.prototype =
cmd.setAttribute("checked", aValue);
},
+ /**
+ * Toggles inspector.showChrome
+ */
+ toggleChrome: function()
+ {
+ var newValue = !PrefUtils.getPref("inspector.showChrome");
+ PrefUtils.setPref("inspector.showChrome", newValue);
+ var cmd = document.getElementById("cmdToggleChrome");
+ cmd.setAttribute("checked", newValue);
+ },
+
toggleSearch: function(aToggleSplitter)
{
this.setSearch(!this.mShowSearch, aToggleSplitter);
@@ -351,27 +369,122 @@ InspectorApp.prototype =
}
},
- goToWindow: function(aMenuitem)
+ /**
+ * Creates the submenu for Inspect Document
+ */
+ showInspectDocumentList: function()
{
- this.setTargetWindowById(aMenuitem.id);
+ const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+ var showChrome = PrefUtils.getPref("inspector.showChrome");
+ var ww = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var windows = ww.getXULWindowEnumerator(null);
+ var contentDocs = [];
+ var chromeDocs = [];
+
+ while (windows.hasMoreElements()) {
+ try {
+ // Get the window's main docshell
+ var windowDocShell = windows.getNext()
+ .QueryInterface(Components.interfaces.nsIXULWindow).docShell;
+
+ // Put the window's documents into the appropriate arrays
+ this.appendContainedDocuments(contentDocs, windowDocShell,
+ nsIDocShellTreeItem.typeContent);
+ if (showChrome) {
+ this.appendContainedDocuments(chromeDocs, windowDocShell,
+ nsIDocShellTreeItem.typeChrome);
+ }
+ }
+ catch (ex) {
+ // We've failed with this window somehow, but we're catching the error so the
+ // others will still work
+ dump(ex + "\n");
+ }
+ }
+
+ // Now add what we found to the menu
+ var docNumber = 0;
+ for (var i = 0; i < contentDocs.length; i++) {
+ this.addInspectDocumentMenuItem(contentDocs[i], ++docNumber);
+ }
+ if (showChrome) {
+ // Put a seperator in if there were content docs
+ if (contentDocs.length > 0) {
+ this.mInspectDocumentMenu.appendChild(document.createElementNS(XULNS, "menuseparator"));
+ }
+ for (var i = 0; i < chromeDocs.length; i++) {
+ this.addInspectDocumentMenuItem(chromeDocs[i], ++docNumber);
+ }
+ } else {
+ // If we're not showing chrome, there's a possibility there are no documents
+ // at all.
+ if (contentDocs.length == 0) {
+ var noneMenuItem = document.createElementNS(XULNS, "menuitem");
+ noneMenuItem.setAttribute("label", this.mPanelSet.stringBundle
+ .getString("inspectWindow.noDocuments.message"));
+ noneMenuItem.setAttribute("disabled", true);
+ this.mInspectDocumentMenu.appendChild(noneMenuItem);
+ }
+ }
},
- setTargetWindowById: function(aResId)
+ /**
+ * Appends to the array the documents contained in docShell (including the passed
+ * docShell itself).
+ *
+ * @param array the array to append to
+ * @param docShell the docshell to look for documents in
+ * @param type one of the types defined in nsIDocShellTreeItem
+ */
+ appendContainedDocuments: function(array, docShell, type)
{
- var windowManager = XPCU.getService(kWindowDataSourceCID, "nsIWindowDataSource");
- var win = windowManager.getWindowForResource(aResId);
+ // Load all the window's content docShells
+ var containedDocShells = docShell.getDocShellEnumerator(type,
+ nsIDocShell.ENUMERATE_FORWARDS);
+ while (containedDocShells.hasMoreElements()) {
+ try {
+ // Get the corresponding document for this docshell
+ var childDoc = containedDocShells.getNext().QueryInterface(nsIDocShell)
+ .contentViewer.DOMDocument;
- if (win) {
- this.setTargetWindow(win);
- this.setBrowser(false, true);
- } else {
- var bundle = this.mPanelSet.stringBundle;
- var msg = bundle.getString("inspectWindow.error.message");
- var title = bundle.getString("inspectWindow.error.title");
- this.mPromptService.alert(window, title, msg);
+ // Ignore the DOM Insector's browser docshell if it's not being used
+ if (docShell.contentViewer.DOMDocument.location.href != document.location.href ||
+ childDoc.location.href != "about:blank") {
+ array.push(childDoc);
+ }
+ }
+ catch (ex) {
+ // We've failed with this document somehow, but we're catching the error so
+ // the others will still work
+ dump(ex + "\n");
+ }
}
},
+ /**
+ * Creates a menu item for Inspect Document.
+ *
+ * @param doc document related to this menu item
+ * @param docNumber the position of the document
+ */
+ addInspectDocumentMenuItem: function(doc, docNumber)
+ {
+ const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+ var menuItem = document.createElementNS(XULNS, "menuitem");
+ menuItem.doc = doc;
+ // Use the URL if there's no title
+ var title = doc.title || doc.location.href;
+ // The first ten items get numeric access keys
+ if (docNumber < 10) {
+ menuItem.setAttribute("label", docNumber + " " + title);
+ menuItem.setAttribute("accesskey", docNumber);
+ } else {
+ menuItem.setAttribute("label", title);
+ }
+ this.mInspectDocumentMenu.appendChild(menuItem);
+ },
+
setTargetWindow: function(aWindow)
{
this.setTargetDocument(aWindow.document);
diff --git a/extensions/inspector/resources/content/popupOverlay.xul b/extensions/inspector/resources/content/popupOverlay.xul
index e9f1f3505faa..7fae52ceb8c7 100644
--- a/extensions/inspector/resources/content/popupOverlay.xul
+++ b/extensions/inspector/resources/content/popupOverlay.xul
@@ -27,16 +27,10 @@
-
+
+
diff --git a/extensions/inspector/resources/content/prefs/inspector.js b/extensions/inspector/resources/content/prefs/inspector.js
index 3e835d7100cb..1533cd4335ae 100644
--- a/extensions/inspector/resources/content/prefs/inspector.js
+++ b/extensions/inspector/resources/content/prefs/inspector.js
@@ -43,4 +43,4 @@ pref("inspector.blink.speed", 100);
pref("inspector.blink.invert", false);
pref("inspector.dom.showAnon", true);
pref("inspector.dom.showWhitespaceNodes", true);
-
+pref("inspector.showChrome", false);
diff --git a/extensions/inspector/resources/locale/en-US/inspector.dtd b/extensions/inspector/resources/locale/en-US/inspector.dtd
index 97d2269106ab..17dcb720de08 100644
--- a/extensions/inspector/resources/locale/en-US/inspector.dtd
+++ b/extensions/inspector/resources/locale/en-US/inspector.dtd
@@ -11,42 +11,45 @@
-
-
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
diff --git a/extensions/inspector/resources/locale/en-US/inspector.properties b/extensions/inspector/resources/locale/en-US/inspector.properties
index 09944d7d3d2d..df373ceba530 100644
--- a/extensions/inspector/resources/locale/en-US/inspector.properties
+++ b/extensions/inspector/resources/locale/en-US/inspector.properties
@@ -37,8 +37,7 @@
inspectURL.title = Inspect URL
inspectURL.message = Enter a URL:
-inspectWindow.error.message = Unable to switch to the requested window.
-inspectWindow.error.title = Inspect Window Error
+inspectWindow.noDocuments.message = (None)
styleRuleNewProperty.title = New Style Rule
styleRuleEditProperty.title = Edit Style Rule
styleRulePropertyValue.message = Enter the property value: