зеркало из https://github.com/mozilla/gecko-dev.git
bug 98092 r=db48x sr=bzbarsky [RFE] Show image file size in image property [properties] dialog
This commit is contained in:
Родитель
0136116798
Коммит
ba3bd61cac
|
@ -55,6 +55,15 @@ var onTable = false;
|
|||
var onTitle = false;
|
||||
var onLang = false;
|
||||
|
||||
const nsICacheService = Components.interfaces.nsICacheService;
|
||||
const cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
|
||||
.getService(nsICacheService);
|
||||
var httpCacheSession = cacheService.createSession("HTTP", 0, true);
|
||||
httpCacheSession.doomEntriesIfExpired = false;
|
||||
var ftpCacheSession = cacheService.createSession("FTP", 0, true);
|
||||
ftpCacheSession.doomEntriesIfExpired = false;
|
||||
|
||||
|
||||
function onLoad()
|
||||
{
|
||||
gMetadataBundle = document.getElementById("bundle_metadata");
|
||||
|
@ -167,6 +176,13 @@ function checkForImage(elem, htmllocalname)
|
|||
|
||||
if (img) {
|
||||
setInfo("image-url", img.src);
|
||||
|
||||
var size = getSize(img.src);
|
||||
if (size != -1) {
|
||||
var kbSize = size / 1024;
|
||||
kbSize = Math.round(kbSize*100)/100;
|
||||
setInfo("image-filesize", gMetadataBundle.getFormattedString("imageSize", [kbSize, size]));
|
||||
}
|
||||
if ("width" in img) {
|
||||
setInfo("image-width", img.width);
|
||||
setInfo("image-height", img.height);
|
||||
|
@ -531,3 +547,22 @@ function convertLanguageCode(abbr)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns the size of the URL in bytes; must be cached and therefore an HTTP or FTP URL
|
||||
function getSize(url) {
|
||||
try
|
||||
{
|
||||
var cacheEntryDescriptor = httpCacheSession.openCacheEntry(url, Components.interfaces.nsICache.ACCESS_READ, false);
|
||||
if(cacheEntryDescriptor)
|
||||
return cacheEntryDescriptor.dataSize;
|
||||
}
|
||||
catch(ex) {}
|
||||
try
|
||||
{
|
||||
cacheEntryDescriptor = ftpCacheSession.openCacheEntry(url, Components.interfaces.nsICache.ACCESS_READ, false);
|
||||
if (cacheEntryDescriptor)
|
||||
return cacheEntryDescriptor.dataSize;
|
||||
}
|
||||
catch(ex) {}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -137,6 +137,10 @@
|
|||
<spacer flex="1"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row id="image-filesize">
|
||||
<label value="&image-filesize.label; "/>
|
||||
<label id="image-filesize-text" value="&filesize-unknown.label;"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</groupbox>
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
<!ENTITY image-width.label "Width:">
|
||||
<!ENTITY image-height.label "Height:">
|
||||
<!ENTITY image-pixels.label "pixels">
|
||||
<!ENTITY image-filesize.label "Size of File:">
|
||||
<!ENTITY filesize-unknown.label "Unknown (not cached)">
|
||||
<!ENTITY insdel-sec.label "Insert/Delete Properties">
|
||||
<!ENTITY insdel-cite.label "Info:">
|
||||
<!ENTITY insdel-date.label "Date:">
|
||||
|
|
|
@ -4,3 +4,5 @@ parentFrameText=Parent frame
|
|||
sameFrameText=Same frame
|
||||
embeddedText=Embedded
|
||||
unableToShowProps=No properties available.
|
||||
|
||||
imageSize=%S KB (%S bytes)
|
||||
|
|
Загрузка…
Ссылка в новой задаче