diff --git a/browser/base/content/pageInfo.js b/browser/base/content/pageInfo.js index be3f45e11172..296fffb74a01 100644 --- a/browser/base/content/pageInfo.js +++ b/browser/base/content/pageInfo.js @@ -123,7 +123,7 @@ pageInfoTreeView.prototype = { handleCopy: function(row) { - return (row < 0 || copycol < 0) ? "" : (this.data[row][this.copycol] || ""); + return (row < 0 || this.copycol < 0) ? "" : (this.data[row][this.copycol] || ""); }, performActionOnRow: function(action, row) @@ -211,11 +211,30 @@ catch(e) // do nothing, later code will handle the error } +// interfaces for the different html elements +const nsIAnchorElement = Components.interfaces.nsIDOMHTMLAnchorElement +const nsIImageElement = Components.interfaces.nsIDOMHTMLImageElement +const nsIAreaElement = Components.interfaces.nsIDOMHTMLAreaElement +const nsILinkElement = Components.interfaces.nsIDOMHTMLLinkElement +const nsIInputElement = Components.interfaces.nsIDOMHTMLInputElement +const nsIFormElement = Components.interfaces.nsIDOMHTMLFormElement +const nsIAppletElement = Components.interfaces.nsIDOMHTMLAppletElement +const nsIObjectElement = Components.interfaces.nsIDOMHTMLObjectElement +const nsIEmbedElement = Components.interfaces.nsIDOMHTMLEmbedElement +const nsIButtonElement = Components.interfaces.nsIDOMHTMLButtonElement +const nsISelectElement = Components.interfaces.nsIDOMHTMLSelectElement +const nsITextareaElement = Components.interfaces.nsIDOMHTMLTextAreaElement + // namespaces, don't need all of these yet... -const XLinkNS = "http://www.w3.org/1999/xlink"; -const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -const XMLNS = "http://www.w3.org/XML/1998/namespace"; -const XHTMLNS = "http://www.w3.org/1999/xhtml"; +const XLinkNS = "http://www.w3.org/1999/xlink"; +const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; +const XMLNS = "http://www.w3.org/XML/1998/namespace"; +const XHTMLNS = "http://www.w3.org/1999/xhtml"; +const XHTML2NS = "http://www.w3.org/2002/06/xhtml2" + +const XHTMLNSre = "^http\:\/\/www\.w3\.org\/1999\/xhtml$"; +const XHTML2NSre = "^http\:\/\/www\.w3\.org\/2002\/06\/xhtml2$"; +const XHTMLre = RegExp(XHTMLNSre + "|" + XHTML2NSre, ""); /* Overlays register init functions here. * Add functions to call by invoking "onLoadRegistry.append(XXXLoadFunc);" @@ -253,7 +272,7 @@ function onLoadPageInfo() gStrings.mediaInput = theBundle.getString("mediaInput"); var docTitle = ""; - if("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) + if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) { theWindow = null; theDocument = window.arguments[0]; @@ -377,7 +396,7 @@ function makeGeneralTab() try { var cacheEntryDescriptor = httpCacheSession.openCacheEntry(url, Components.interfaces.nsICache.ACCESS_READ, false); - if(cacheEntryDescriptor) + if (cacheEntryDescriptor) { switch(cacheEntryDescriptor.deviceID) { @@ -483,79 +502,74 @@ function grabAll(elem) // check for background images, any node may have one var url = elem.ownerDocument.defaultView.getComputedStyle(elem, "").getPropertyCSSValue("background-image"); if (url && url.primitiveType == CSSPrimitiveValue.CSS_URI) - { imageView.addRow([url.getStringValue(), gStrings.mediaBGImg, gStrings.notSet, elem, true]); - } - // one switch to rule them all + // one swi^H^H^Hif-else to rule them all // XXX: these tests should use regexes to be a little more lenient wrt whitespace, see bug 177047 - switch (elem.nodeName.toLowerCase()) + if (elem instanceof nsIAnchorElement) { - // form tab - case "form": - formView.addRow([elem.name, elem.method, elem.getAttribute("action"), elem]); // use getAttribute() because of bug 122128 - break; - - // link tab - case "a": - linktext = getValueText(elem); - linkView.addRow([linktext, elem.href, gStrings.linkAnchor, elem.target]); - break; - case "area": - linkView.addRow([elem.alt, elem.href, gStrings.linkArea, elem.target]); - break; - case "input": - linkView.addRow([elem.value || gStrings.linkSubmit, elem.form.getAttribute("action"), gStrings.linkSubmission, elem.form.getAttribute("target")]); // use getAttribute() due to bug 122128 - break; - case "link": - if (elem.rel) - { - var rel = elem.rel.toLowerCase(); - if (rel == "icon") - { - imageView.addRow([elem.href, gStrings.mediaLink, "", elem]); - break; - } - if (rel == "stylesheet" || rel == "alternate stylesheet") - linktext = gStrings.linkStylesheet; - else - linktext = gStrings.linkRel; - } - else - linktext = gStrings.linkRev; - linkView.addRow([elem.rel || elem.rev, elem.href, linktext, elem.target]); - break; - - // media tab - case "img": - imageView.addRow([elem.src, gStrings.mediaImg, (elem.hasAttribute("alt")) ? elem.alt : gStrings.notSet, elem]); - break; - case "input": - if (elem.type == "image") - imageView.addRow([elem.src, gStrings.mediaInput, (elem.hasAttribute("alt")) ? elem.alt : gStrings.notSet, elem]); - break; - case "applet": - //XXX When Java is enabled, the DOM model for is broken. Bug #59686. - // Also, some reports of a crash with Java in Media tab (bug 136535), and mixed - // content from two hosts (bug 136539) so just drop applets from Page Info when - // Java is on. For the 1.0.1 branch; get a real fix on the trunk. - if (!navigator.javaEnabled()) - imageView.addRow([elem.code || elem.object, gStrings.mediaApplet, "",elem]); - break; - case "object": - imageView.addRow([elem.data, gStrings.mediaObject, getValueText(elem), elem]); - break; - case "embed": - imageView.addRow([elem.src, gStrings.mediaEmbed, "", elem]); - break; - default: - if (elem.hasAttributeNS(XLinkNS, "href")) - { - linktext = getValueText(elem); - linkView.addRow([linktext, elem.href, gStrings.linkX, ""]); - } - break; + linktext = getValueText(elem); + linkView.addRow([linktext, getAbsoluteURL(elem.href, elem), gStrings.linkAnchor, elem.target]); } + else if (elem instanceof nsIImageElement) + { + imageView.addRow([getAbsoluteURL(elem.src, elem), gStrings.mediaImg, (elem.hasAttribute("alt")) ? elem.alt : gStrings.notSet, elem, false]); + } + else if (elem instanceof nsIAreaElement) + { + linkView.addRow([elem.alt, getAbsoluteURL(elem.href, elem), gStrings.linkArea, elem.target]); + } + else if (elem instanceof nsILinkElement) + { + if (elem.rel) + { + var rel = elem.rel; + if (/\bicon\b/i.test(rel)) + imageView.addRow([getAbsoluteURL(elem.href, elem), gStrings.mediaLink, "", elem, false]); + else if (/\bstylesheet\b/i.test(rel)) + linkView.addRow([elem.rel, getAbsoluteURL(elem.href, elem), gStrings.linkStylesheet, elem.target]); + else + linkView.addRow([elem.rel, getAbsoluteURL(elem.href, elem), gStrings.linkRel, elem.target]); + } + else + linkView.addRow([elem.rev, getAbsoluteURL(elem.href, elem), gStrings.linkRev, elem.target]); + + } + else if (elem instanceof nsIInputElement) + { + if (/^image$/i.test(elem.type)) + imageView.addRow([getAbsoluteURL(elem.src, elem), gStrings.mediaInput, (elem.hasAttribute("alt")) ? elem.alt : gStrings.notSet, elem, false]); + else if (/^submit$/i.test(elem.type)) + linkView.addRow([elem.value || gStrings.linkSubmit, getAbsoluteURL(elem.form.getAttribute("action"), elem), gStrings.linkSubmission, elem.form.getAttribute("target")]); // use getAttribute() due to bug 122128 + } + else if (elem instanceof nsIFormElement) + { + formView.addRow([elem.name, elem.method, getAbsoluteURL(elem.getAttribute("action"), elem), elem]); // use getAttribute() because of bug 122128 + } + else if (elem instanceof nsIAppletElement) + { + //XXX When Java is enabled, the DOM model for is broken. Bug #59686. + // Also, some reports of a crash with Java in Media tab (bug 136535), and mixed + // content from two hosts (bug 136539) so just drop applets from Page Info when + // Java is on. For the 1.0.1 branch; get a real fix on the trunk. + if (!navigator.javaEnabled()) + imageView.addRow([getAbsoluteURL(elem.code || elem.object, elem), gStrings.mediaApplet, "", elem, false]); + } + else if (elem instanceof nsIObjectElement) + { + imageView.addRow([getAbsoluteURL(elem.data, elem), gStrings.mediaObject, getValueText(elem), elem, false]); + } + else if (elem instanceof nsIEmbedElement) + { + imageView.addRow([getAbsoluteURL(elem.src, elem), gStrings.mediaEmbed, "", elem, false]); + } + else + if (elem.hasAttributeNS(XLinkNS, "href")) + { + linktext = getValueText(elem); + linkView.addRow([linktext, getAbsoluteURL(elem.href, elem), gStrings.linkX, ""]); + } + return NodeFilter.FILTER_SKIP; } @@ -584,7 +598,7 @@ function onFormSelect() document.getElementById("formenctype").value = form.encoding || theBundle.getString("default"); document.getElementById("formtarget").value = form.target || theBundle.getString("formDefaultTarget"); - var formfields = form.elements; + var formfields = findFormControls(form); var length = formfields.length; var i = 0; @@ -594,15 +608,14 @@ function onFormSelect() for (i = 0; i < length; i++) { - var elem = formfields[i]; + var elem = formfields[i], val; - if(elem.nodeName.toLowerCase() == "button") - fieldView.addRow(["", elem.name, elem.type, getValueText(elem)]); + if (elem instanceof nsIButtonElement) + val = getValueText(elem); else - { - var val = (elem.type == "password") ? theBundle.getString("formPassword") : elem.value; - fieldView.addRow(["", elem.name, elem.type, val]); - } + val = (/^password$/i.test(elem.type)) ? theBundle.getString("formPassword") : elem.value; + + fieldView.addRow(["", elem.id || elem.name, elem.type, val]); } var labels = form.getElementsByTagName("label"); @@ -626,28 +639,33 @@ function onFormSelect() } } +function FormControlFilter(node) +{ + if (node instanceof nsIInputElement || node instanceof nsISelectElement || + node instanceof nsIButtonElement || node instanceof nsITextareaElement || + node instanceof nsIObjectElement) + return NodeFilter.FILTER_ACCEPT; + return NodeFilter.FILTER_SKIP; +} + function findFirstControl(node) { - function FormControlFilter() - { - switch (node.nodeName.toLowerCase()) - { - case "input": - case "select": - case "button": - case "textarea": - case "object": - return NodeFilter.FILTER_ACCEPT; - default: - return NodeFilter.FILTER_SKIP; - } - } - var iterator = theDocument.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, FormControlFilter, true); return iterator.nextNode(); } +function findFormControls(node) +{ + var iterator = theDocument.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, FormControlFilter, true); + + var list = []; + while (iterator.nextNode()) + list.push(iterator.currentNode); + + return list; +} + //******** Link Stuff function openURL(target) { @@ -757,7 +775,7 @@ function makePreview(row) // IMO all text that is not really the value text should go in italics // What if somebody has Not specified? =) // We can't use textbox.style because of bug 7639 - if (altText=="") { + if (!altText) { textbox.value = gStrings.emptyString; textbox.setAttribute("style","font-style:italic"); } else { @@ -766,15 +784,6 @@ function makePreview(row) } document.getElementById("imagelongdesctext").value = ("longDesc" in item && item.longDesc) || gStrings.notSet; - // find out the mime type - var mimeType = gStrings.unknown; - if (item.nodeName.toLowerCase() != "input") - mimeType = ("type" in item && item.type) || - ("codeType" in item && item.codeType) || - ("contentType" in item && item.contentType) || - gStrings.unknown; - document.getElementById("imagetypetext").value = mimeType; - // get cache info var sourceText = theBundle.getString("generalNotCached"); var expirationText = gStrings.unknown; @@ -802,12 +811,6 @@ function makePreview(row) sourceText = cacheEntryDescriptor.deviceID; break; } - - pageSize = cacheEntryDescriptor.dataSize; - kbSize = pageSize / 1024; - sizeText = theBundle.getFormattedString("generalSize", [Math.round(kbSize*100)/100, pageSize]); - - expirationText = formatDate(cacheEntryDescriptor.expirationTime*1000, gStrings.notSet); } } catch(ex) @@ -829,12 +832,6 @@ function makePreview(row) sourceText = cacheEntryDescriptor.deviceID; break; } - - pageSize = cacheEntryDescriptor.dataSize; - kbSize = pageSize / 1024; - sizeText = theBundle.getFormattedString("generalSize", [Math.round(kbSize*100)/100, pageSize]); - - expirationText = formatDate(cacheEntryDescriptor.expirationTime*1000, gStrings.notSet); } } catch(ex2) @@ -842,6 +839,33 @@ function makePreview(row) sourceText = theBundle.getString("generalNotCached"); } } + + // find out the mime type, file size and expiration date + var mimeType = gStrings.unknown, httpType; + if (cacheEntryDescriptor) + { + var headers, match; + + pageSize = cacheEntryDescriptor.dataSize; + kbSize = pageSize / 1024; + sizeText = theBundle.getFormattedString("generalSize", [Math.round(kbSize*100)/100, pageSize]); + + expirationText = formatDate(cacheEntryDescriptor.expirationTime*1000, gStrings.notSet); + + headers = cacheEntryDescriptor.getMetaDataElement("response-head"); + + match = /^Content-Type:\s*(.*?)\s*(?:\;|$)/mi.exec(headers); + if (match) + httpType = match[1]; + } + + if (!(item instanceof nsIInputElement)) + mimeType = ("type" in item && item.type) || + ("codeType" in item && item.codeType) || + ("contentType" in item && item.contentType) || + httpType || gStrings.unknown; + + document.getElementById("imagetypetext").value = mimeType; document.getElementById("imagesourcetext").value = sourceText; document.getElementById("imageexpirestext").value = expirationText; document.getElementById("imagesizetext").value = sizeText; @@ -849,16 +873,20 @@ function makePreview(row) var imageContainer = document.getElementById("theimagecontainer"); var oldImage = document.getElementById("thepreviewimage"); - var nn = item.nodeName.toLowerCase(); var regex = new RegExp("^(https?|ftp|file|gopher)://"); var absoluteURL = getAbsoluteURL(url, item); var isProtocolAllowed = regex.test(absoluteURL); var newImage = new Image(); newImage.setAttribute("id", "thepreviewimage"); - if ((nn == "link" || nn == "input" || nn == "img" || isBG) && - isProtocolAllowed) + var physWidth = 0, physHeight = 0; + + if ((item instanceof nsILinkElement || item instanceof nsIInputElement || + item instanceof nsIImageElement || isBG) && isProtocolAllowed) { newImage.src = absoluteURL; + physWidth = newImage.width; + physHeight = newImage.height; + if ("width" in item && item.width) newImage.width = item.width; if ("height" in item && item.height) @@ -875,8 +903,17 @@ function makePreview(row) var width = ("width" in item && item.width) || ("width" in newImage && newImage.width) || "0"; var height = ("height" in item && item.height) || ("height" in newImage && newImage.height) || "0"; - document.getElementById("imagewidth").value = theBundle.getFormattedString("mediaWidth", [width]); - document.getElementById("imageheight").value = theBundle.getFormattedString("mediaHeight", [height]); + + document.getElementById("imageSize").value = theBundle.getFormattedString("mediaSize", [width, height]); + + if (width != physWidth || height != physHeight) + { + document.getElementById("physSize").removeAttribute("hidden"); + document.getElementById("physSize").value = theBundle.getFormattedString("mediaPhysSize", [physWidth, physHeight]); + } + else + document.getElementById("physSize").setAttribute("hidden", "true"); + imageContainer.removeChild(oldImage); imageContainer.appendChild(newImage); @@ -900,7 +937,7 @@ function getValueText(linkNode) valueText += " " + childNode.nodeValue; else if (nodeType == Node.ELEMENT_NODE) { - if (childNode.nodeName.toLowerCase() == "img") + if (childNode instanceof nsIImageElement) valueText += " " + getAltText(childNode); else valueText += " " + getValueText(childNode); @@ -952,7 +989,8 @@ function formatDate(datestr, unknown) * * for node==null or url=="", empty string is returned * - * This is basically just copied from http://lxr.mozilla.org/seamonkey/source/xpfe/browser/resources/content/metadata.js + * This is basically just copied from http://lxr.mozilla.org/seamonkey/source/xpfe/browser/resources/content/metadata.js, + * though I've modified it so that it doesn't assign to .spec */ function getAbsoluteURL(url, node) @@ -988,7 +1026,14 @@ function getAbsoluteURL(url, node) for (var i=0; i