1 # -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
15 # The Original Code is mozilla.org code.
17 # The Initial Developer of the Original Code is
18 # Netscape Communications Corporation.
19 # Portions created by the Initial Developer are Copyright (C) 1998-2004
20 # the Initial Developer. All Rights Reserved.
24 # Terry Hayes <thayes@netscape.com>
25 # Daniel Brooks <db48x@yahoo.com>
26 # Florian QUEZE <f.qu@queze.net>
27 # Erik Fabert <jerfa@yahoo.com>
29 # Alternatively, the contents of this file may be used under the terms of
30 # either the GNU General Public License Version 2 or later (the "GPL"), or
31 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 # in which case the provisions of the GPL or the LGPL are applicable instead
33 # of those above. If you wish to allow use of your version of this file only
34 # under the terms of either the GPL or the LGPL, and not to allow others to
35 # use your version of this file under the terms of the MPL, indicate your
36 # decision by deleting the provisions above and replace them with the notice
37 # and other provisions required by the GPL or the LGPL. If you do not delete
38 # the provisions above, a recipient may use your version of this file under
39 # the terms of any one of the MPL, the GPL or the LGPL.
41 # ***** END LICENSE BLOCK *****
48 this.copycol = copycol;
52 this.selection =
null;
58 set rowCount(c) {
throw "rowCount is a readonly property"; },
59 get rowCount() {
return this.rows; },
61 setTree:
function(tree)
66 getCellText:
function(row, column)
72 return this.
data[row][column.index] ||
"";
75 setCellValue:
function(row, column,
value)
79 setCellText:
function(row, column,
value)
86 this.rows = this.
data.push(row);
87 this.rowCountChanged(this.rows - 1, 1);
88 if (this.selection.count == 0 &&
this.rowCount && !
gImageElement)
89 this.selection.select(0);
92 rowCountChanged:
function(index,
count)
94 this.tree.rowCountChanged(index,
count);
97 invalidate:
function()
99 this.tree.invalidate();
105 this.tree.rowCountChanged(0, -this.rows);
110 handleCopy:
function(row)
112 return (row < 0 || this.copycol < 0) ?
"" : (this.
data[row][this.copycol] ||
"");
115 performActionOnRow:
function(action, row)
117 if (action ==
"copy") {
118 var
data = this.handleCopy(row)
119 this.tree.treeBody.parentNode.setAttribute(
"copybuffer", data);
123 getRowProperties:
function(row, prop) { },
125 getColumnProperties:
function(column, prop) { },
126 isContainer:
function(index) {
return false; },
127 isContainerOpen:
function(index) {
return false; },
128 isSeparator:
function(index) {
return false; },
129 isSorted:
function() { },
130 canDrop:
function(index, orientation) {
return false; },
131 drop:
function(row, orientation) {
return false; },
132 getParentIndex:
function(index) {
return 0; },
133 hasNextSibling:
function(index, after) {
return false; },
134 getLevel:
function(index) {
return 0; },
135 getImageSrc:
function(row, column) { },
136 getProgressMode:
function(row, column) { },
137 getCellValue:
function(row, column) { },
138 toggleOpenState:
function(index) { },
139 cycleHeader:
function(col) { },
140 selectionChanged:
function() { },
141 cycleCell:
function(row, column) { },
142 isEditable:
function(row, column) {
return false; },
143 isSelectable:
function(row, column) {
return false; },
144 performAction:
function(action) { },
145 performActionOnCell:
function(action, row, column) { }
173 .getService(Components.interfaces.nsIAtomService);
177 props.AppendElement(aserv.getAtom(
"broken"));
197 httpCacheSession.doomEntriesIfExpired =
false;
199 ftpCacheSession.doomEntriesIfExpired =
false;
209 const gClipboardHelper = Components.classes[
"@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
216 const nsIImageLoadingContent = Components.interfaces.nsIImageLoadingContent;
219 const XLinkNS =
"http://www.w3.org/1999/xlink";
220 const XULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
221 const XMLNS =
"http://www.w3.org/XML/1998/namespace";
222 const XHTMLNS =
"http://www.w3.org/1999/xhtml";
223 const XHTML2NS =
"http://www.w3.org/2002/06/xhtml2"
225 const XHTMLNSre =
"^http\:\/\/www\.w3\.org\/1999\/xhtml$";
226 const XHTML2NSre =
"^http\:\/\/www\.w3\.org\/2002\/06\/xhtml2$";
272 gBundle = document.getElementById(
"pageinfobundle");
283 window.arguments.length >= 1 &&
286 if (!args || !args.doc) {
292 var imageTree = document.getElementById(
"imagetree");
297 Components.classes[
"@mozilla.org/observer-service;1"]
298 .getService(Components.interfaces.nsIObserverService)
299 .notifyObservers(
window,
"page-info-dialog-loaded",
null);
305 :
"pageInfo.page.title";
306 document.title =
gBundle.getFormattedString(titleFormat, [
gDocument.location]);
308 document.getElementById(
"main-window").setAttribute(
"relatedUrl",
gDocument.location);
320 onLoadRegistry.forEach(
function(func) { func(); });
329 var mediaTab = document.getElementById(
"mediaTab");
330 if (!mediaTab.hidden) {
331 Components.classes[
"@mozilla.org/observer-service;1"]
332 .getService(Components.interfaces.nsIObserverService)
333 .removeObserver(imagePermissionObserver,
"perm-changed");
334 mediaTab.hidden =
true;
340 var feedListbox = document.getElementById(
"feedListbox");
341 while (feedListbox.firstChild)
342 feedListbox.removeChild(feedListbox.firstChild);
345 onResetRegistry.forEach(
function(func) { func(); });
354 if (!document.getElementById(
"mediaTab").hidden) {
355 Components.classes[
"@mozilla.org/observer-service;1"]
356 .getService(Components.interfaces.nsIObserverService)
357 .removeObserver(imagePermissionObserver,
"perm-changed");
361 onUnloadRegistry.forEach(
function(func) { func(); });
367 "generalPanel":
"pageinfo_general",
368 "mediaPanel":
"pageinfo_media",
369 "feedPanel":
"pageinfo_feed",
370 "permPanel":
"pageinfo_permissions",
371 "securityPanel":
"pageinfo_security"
374 var deck = document.getElementById(
"mainDeck");
375 var helpdoc = helpTopics[deck.selectedPanel.id] ||
"pageinfo_general";
381 var deck = document.getElementById(
"mainDeck");
382 var pagel = document.getElementById(
id +
"Panel");
383 deck.selectedPanel = pagel;
398 var initialTab = (
args &&
args.initialTab) ||
"generalTab";
399 var radioGroup = document.getElementById(
"viewGroup");
400 initialTab = document.getElementById(initialTab) || document.getElementById(
"generalTab");
401 radioGroup.selectedItem = initialTab;
402 radioGroup.selectedItem.doCommand();
408 var radioGrp = document.getElementById(
"viewGroup");
409 var radioElt = document.getElementById(
"securityTab");
410 radioGrp.selectedItem = radioElt;
416 var elt = document.getElementById(
id);
417 if (elt.hasAttribute(
"closed")) {
418 elt.removeAttribute(
"closed");
419 if (elt.flexWhenOpened)
420 elt.flex = elt.flexWhenOpened;
423 elt.setAttribute(
"closed",
"true");
425 elt.flexWhenOpened = elt.flex;
434 document.getElementById(
"titletext").value = title;
442 var mode = (
"compatMode" in
gDocument &&
gDocument.compatMode ==
"BackCompat") ?
"generalQuirksMode" :
"generalStrictMode";
443 document.getElementById(
"modetext").value =
gBundle.getString(mode);
451 document.getElementById(
"encodingtext").value = encoding;
454 var metaNodes =
gDocument.getElementsByTagName(
"meta");
455 var length = metaNodes.length;
457 var metaGroup = document.getElementById(
"metaTags");
459 metaGroup.collapsed =
true;
461 var metaTagsCaption = document.getElementById(
"metaTagsCaption");
463 metaTagsCaption.label =
gBundle.getString(
"generalMetaTag");
465 metaTagsCaption.label =
gBundle.getFormattedString(
"generalMetaTags", [length]);
466 var metaTree = document.getElementById(
"metatree");
469 for (var
i = 0;
i < length;
i++)
470 gMetaView.addRow([metaNodes[
i].name || metaNodes[
i].httpEquiv, metaNodes[i].content]);
472 metaGroup.collapsed =
false;
477 document.getElementById(
"modifiedtext").value = modifiedText;
480 var cacheKey = url.replace(/#.*$/,
"");
482 var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey,
ACCESS_READ,
false);
486 cacheEntryDescriptor = ftpCacheSession.openCacheEntry(cacheKey,
ACCESS_READ,
false);
492 if (cacheEntryDescriptor) {
493 var pageSize = cacheEntryDescriptor.dataSize;
494 var kbSize =
formatNumber(Math.round(pageSize / 1024 * 100) / 100);
519 if (aWindow && aWindow.frames.length > 0) {
520 var
num = aWindow.frames.length;
521 for (var
i = 0;
i <
num;
i++)
528 if (gFrameList.length) {
529 var
doc = gFrameList[0];
530 onProcessFrame.forEach(
function(func) { func(doc); });
531 var iterator = doc.createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
grabAll,
true);
534 onFinished.push(selectImage);
537 onFinished.forEach(
function(func) { func(); });
542 for (var
i = 0;
i < 50; ++
i)
543 if (!iterator.nextNode()) {
564 var cacheEntryDescriptor = httpCacheSession.openCacheEntry(
url,
ACCESS_READ,
false);
569 cacheEntryDescriptor = ftpCacheSession.openCacheEntry(
url,
ACCESS_READ,
false);
575 if (cacheEntryDescriptor) {
576 var pageSize = cacheEntryDescriptor.dataSize;
577 var kbSize =
formatNumber(Math.round(pageSize / 1024 * 100) / 100);
578 sizeText =
gBundle.getFormattedString(
"mediaFileSize", [kbSize]);
586 document.getElementById(
"mediaTab").hidden =
false;
587 Components.classes[
"@mozilla.org/observer-service;1"]
588 .getService(Components.interfaces.nsIObserverService)
589 .addObserver(imagePermissionObserver,
"perm-changed",
false);
603 var computedStyle =
elem.ownerDocument.defaultView.getComputedStyle(
elem,
"");
605 Array.forEach(computedStyle.getPropertyCSSValue(
"background-image"),
function (
url) {
606 if (
url.primitiveType == CSSPrimitiveValue.CSS_URI)
612 if (
elem instanceof HTMLImageElement)
616 else if (
elem instanceof SVGImageElement) {
625 else if (
elem instanceof HTMLLinkElement) {
626 if (
elem.rel && /\bicon\b/
i.test(
elem.rel))
629 else if (
elem instanceof HTMLInputElement ||
elem instanceof HTMLButtonElement) {
630 if (
elem.type.toLowerCase() ==
"image")
634 else if (
elem instanceof HTMLObjectElement)
636 else if (
elem instanceof HTMLEmbedElement)
639 onProcessElement.forEach(
function(func) { func(
elem); });
641 return NodeFilter.FILTER_ACCEPT;
647 var
url =
target.parentNode.childNodes[2].value;
648 window.open(url,
"_blank",
"chrome");
653 if (
event.originalTarget.localName !=
"treechildren")
656 var tree =
event.target;
657 if (!(
"treeBoxObject" in tree))
658 tree = tree.parentNode;
660 var row = tree.treeBoxObject.getRowAt(
event.clientX,
event.clientY);
665 var col = tree.columns[urlField];
666 var
url = tree.view.getCellText(row, col);
667 col = tree.columns[descField];
668 var desc = tree.view.getCellText(row, col);
670 var dt =
event.dataTransfer;
671 dt.setData(
"text/x-moz-url", url +
"\n" + desc);
672 dt.setData(
"text/url-list", url);
673 dt.setData(
"text/plain", url);
683 var clickedRow = tree.currentIndex;
690 const nsILocalFile = Components.interfaces.nsILocalFile;
692 var fp = Components.classes[
"@mozilla.org/filepicker;1"]
695 var titleText =
gBundle.getString(
"mediaSelectFolder");
699 .getService(Components.interfaces.nsIPrefBranch2);
701 var initialDir = prefs.getComplexValue(
"browser.download.dir", nsILocalFile);
703 fp.displayDirectory = initialDir;
711 return fp.file.QueryInterface(nsILocalFile);
717 var tree = document.getElementById(
"imagetree");
718 var
count = tree.view.selection.count;
724 saveURL(url,
null,
"SaveImageTitle",
false,
false,
makeURI(item.baseURI));
730 var numRanges = tree.view.selection.getRangeCount();
733 for (var
t = 0;
t < numRanges;
t++) {
734 tree.view.selection.getRangeAt(
t, start, end);
735 for (var v = start.value; v <= end.value; v++)
739 var saveAnImage =
function(aURIString, aChosenData, aBaseURI) {
741 aChosenData, aBaseURI);
744 for (var
i = 0;
i < rowArray.length;
i++) {
746 var
dir = odir.clone();
752 uri.QueryInterface(Components.interfaces.nsIURL);
753 dir.append(decodeURIComponent(uri.fileName));
758 saveAnImage(uriString,
new AutoChosen(dir, uri),
makeURI(item.baseURI));
762 setTimeout(saveAnImage, 200, uriString,
new AutoChosen(dir, uri),
774 var checkbox = document.getElementById(
"blockImage");
775 var
uri =
makeURI(document.getElementById(
"imageurltext").value);
776 if (checkbox.checked)
779 permissionManager.remove(uri.host,
"image");
784 var previewBox = document.getElementById(
"mediaPreviewBox");
785 var mediaSaveBox = document.getElementById(
"mediaSaveBox");
786 var splitter = document.getElementById(
"mediaSplitter");
787 var tree = document.getElementById(
"imagetree");
788 var
count = tree.view.selection.count;
790 previewBox.collapsed =
true;
791 mediaSaveBox.collapsed =
true;
792 splitter.collapsed =
true;
795 else if (count > 1) {
796 splitter.collapsed =
true;
797 previewBox.collapsed =
true;
798 mediaSaveBox.collapsed =
false;
802 mediaSaveBox.collapsed =
true;
803 splitter.collapsed =
false;
804 previewBox.collapsed =
false;
812 var imageTree = document.getElementById(
"imagetree");
822 !(item instanceof SVGImageElement) &&
825 imageText = item.title || item.alt;
827 if (!imageText && !(item instanceof HTMLImageElement))
828 imageText = getValueText(item);
835 var cacheKey = url.replace(/#.*$/,
"");
838 var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey,
ACCESS_READ,
false);
843 cacheEntryDescriptor = ftpCacheSession.openCacheEntry(cacheKey,
ACCESS_READ,
false);
850 if (cacheEntryDescriptor) {
851 var
imageSize = cacheEntryDescriptor.dataSize;
852 var kbSize = Math.round(imageSize / 1024 * 100) / 100;
853 sizeText =
gBundle.getFormattedString(
"generalSize",
857 sizeText =
gBundle.getString(
"mediaUnknownNotCached");
862 if (item instanceof HTMLObjectElement ||
863 item instanceof HTMLEmbedElement ||
864 item instanceof HTMLLinkElement)
865 mimeType = item.type;
867 if (!mimeType && !isBG && item instanceof nsIImageLoadingContent) {
868 var imageRequest = item.getRequest(nsIImageLoadingContent.CURRENT_REQUEST);
870 mimeType = imageRequest.mimeType;
871 var image = imageRequest.image;
873 numFrames = image.numFrames;
877 mimeType = getContentTypeFromHeaders(cacheEntryDescriptor);
882 var imageMimeType = /^image\/(.*)/.exec(mimeType);
884 imageType = imageMimeType[1].toUpperCase();
886 imageType =
gBundle.getFormattedString(
"mediaAnimatedImageType",
887 [imageType, numFrames]);
889 imageType =
gBundle.getFormattedString(
"mediaImageType", [imageType]);
893 imageType = mimeType;
902 var imageContainer = document.getElementById(
"theimagecontainer");
903 var oldImage = document.getElementById(
"thepreviewimage");
905 const regex = /^(https?|ftp|
file|gopher|about|chrome|resource):/;
906 var isProtocolAllowed = regex.test(url);
908 isProtocolAllowed =
true;
910 var newImage =
new Image();
911 newImage.setAttribute(
"id",
"thepreviewimage");
912 var physWidth = 0, physHeight = 0;
915 if ((item instanceof HTMLLinkElement || item instanceof HTMLInputElement ||
916 item instanceof HTMLImageElement ||
918 item instanceof SVGImageElement ||
920 (item instanceof HTMLObjectElement && /^image\
921 newImage.setAttribute(
"src", url);
922 physWidth = newImage.width || 0;
923 physHeight = newImage.height || 0;
929 newImage.width = (
"width" in item && item.width) || newImage.naturalWidth;
930 newImage.height = (
"height" in item && item.height) || newImage.naturalHeight;
935 newImage.width = newImage.naturalWidth;
936 newImage.height = newImage.naturalHeight;
940 if (item instanceof SVGImageElement) {
941 newImage.width = item.width.baseVal.value;
942 newImage.height = item.height.baseVal.value;
946 width = newImage.width;
949 document.getElementById(
"theimagecontainer").collapsed =
false
950 document.getElementById(
"brokenimagecontainer").collapsed =
true;
955 document.getElementById(
"brokenimagecontainer").collapsed =
false;
956 document.getElementById(
"theimagecontainer").collapsed =
true;
962 imageSize =
gBundle.getFormattedString(
"mediaDimensionsScaled",
969 imageSize =
gBundle.getFormattedString(
"mediaDimensions",
978 imageContainer.removeChild(oldImage);
979 imageContainer.appendChild(newImage);
987 .getService(Components.interfaces.nsIPrefBranch2);
989 var checkbox = document.getElementById(
"blockImage");
990 var imagePref = prefs.getIntPref(
"permissions.default.image");
991 if (!(/^https?:/.
test(
url)) || imagePref == 2)
994 checkbox.hidden =
true;
998 checkbox.hidden =
false;
999 checkbox.label =
gBundle.getFormattedString(
"mediaBlockImage", [uri.host]);
1000 var perm = permissionManager.testPermission(uri,
"image");
1004 checkbox.hidden =
true;
1008 var imagePermissionObserver = {
1011 if (document.getElementById(
"mediaPreviewBox").collapsed)
1014 if (aTopic ==
"perm-changed") {
1015 var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
1016 if (permission.type ==
"image") {
1017 var imageTree = document.getElementById(
"imagetree");
1018 var row = imageTree.currentIndex;
1021 if (
makeURI(url).host == permission.host)
1028 function getContentTypeFromHeaders(cacheEntryDescriptor)
1030 if (!cacheEntryDescriptor)
1033 return (/^Content-Type:\s*(.*?)\s*(?:\;|$)/mi
1034 .exec(cacheEntryDescriptor.getMetaDataElement(
"response-head")))[1];
1040 function getValueText(
node)
1045 if (
node instanceof HTMLInputElement ||
1046 node instanceof HTMLSelectElement ||
1047 node instanceof HTMLTextAreaElement)
1051 var length =
node.childNodes.length;
1052 for (var
i = 0;
i < length;
i++) {
1053 var childNode =
node.childNodes[
i];
1054 var nodeType = childNode.nodeType;
1057 if (nodeType == Node.TEXT_NODE)
1058 valueText +=
" " + childNode.nodeValue;
1060 else if (nodeType == Node.ELEMENT_NODE) {
1062 if (childNode instanceof HTMLImageElement)
1063 valueText +=
" " + getAltText(childNode);
1065 valueText +=
" " + getValueText(childNode);
1069 return stripWS(valueText);
1074 function getAltText(
node)
1080 var length =
node.childNodes.length;
1081 for (var
i = 0;
i < length;
i++)
1082 if ((altText = getAltText(
node.childNodes[
i]) != undefined))
1089 function stripWS(text)
1091 var middleRE = /\s+/g;
1092 var endRE = /(^\s+)|(\s+$)/g;
1094 text = text.replace(middleRE,
" ");
1095 return text.replace(endRE,
"");
1100 var item = document.getElementById(
id);
1102 item.parentNode.collapsed =
false;
1106 item.parentNode.collapsed =
true;
1111 return (+number).toLocaleString();
1117 var dateService = Components.classes[
"@mozilla.org/intl/scriptabledateformat;1"]
1118 .getService(Components.interfaces.nsIScriptableDateFormat);
1120 var
date =
new Date(datestr);
1121 if (!date.valueOf())
1124 return dateService.FormatDateTime(
"", dateService.dateFormatLong,
1125 dateService.timeFormatSeconds,
1126 date.getFullYear(), date.getMonth()+1, date.getDate(),
1127 date.getHours(), date.getMinutes(), date.getSeconds());
1132 if (!gClipboardHelper)
1135 var
elem = document.commandDispatcher.focusedElement;
1137 if (elem &&
"treeBoxObject" in elem) {
1138 var view = elem.view;
1139 var selection = view.selection;
1140 var text = [], tmp =
'';
1141 var
min = {}, max = {};
1143 var
count = selection.getRangeCount();
1146 selection.getRangeAt(
i, min, max);
1148 for (var row = min.value; row <= max.value; row++) {
1149 view.performActionOnRow(
"copy", row);
1151 tmp = elem.getAttribute(
"copybuffer");
1154 elem.removeAttribute(
"copybuffer");
1157 gClipboardHelper.copyString(text.join(
"\n"));
1161 function doSelectAll()
1163 var elem = document.commandDispatcher.focusedElement;
1165 if (elem &&
"treeBoxObject" in elem)
1166 elem.view.selection.selectAll();
1169 function selectImage() {
1173 var tree = document.getElementById(
"imagetree");
1174 for (var
i = 0;
i < tree.view.rowCount;
i++) {
1177 tree.view.selection.select(
i);
1178 tree.treeBoxObject.ensureRowIsVisible(
i);
const PREFERENCES_CONTRACTID
function doGrab(iterator)
function pageInfoTreeView(copycol)
function securityOnLoad()
function toggleGroupbox(id)
function makeTabs(aDocument, aWindow)
function doc() browser.contentDocument
const CERTIFICATEDIALOGS_CONTRACTID
const COPYCOL_META_CONTENT
function openHelpLink(aHelpTopic, aCalledFromModal)
function makeURLAbsolute(aBase, aUrl)
function addImage(url, type, alt, elem, isBg)
ATOM dd M d M dd M d M d M d M d M formatDate
function getSelectedImage(tree)
const nsICertificateDialogs
function addRow(name, type, url)
gImageView getCellProperties
function makeGeneralTab()
_collectFormDataForFrame aDocument
function makeURI(aURLSpec, aCharset)
setItemValue("imagedimensiontext", imageSize)
function onUnloadPageInfo()
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function onBeginLinkDrag(event, urlField, descField)
function makePreview(row)
function goThroughFrames(aDocument, aWindow)
const nsIPermissionManager
function onLoadPermission()
function onLoadPageInfo()
function selectSaveFolder()
const PERMISSION_CONTRACTID
function resetPageInfo(args)
_getSelectedPageStyle s i
const nsICookiePermission
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe