Bug 792735 Remove calls to nsICacheSession::openCacheEntry r=IanN
This commit is contained in:
Родитель
1bd5f7d93c
Коммит
69f4bcc765
|
@ -24,14 +24,8 @@ var onTable = false;
|
|||
var onTitle = false;
|
||||
var onLang = false;
|
||||
|
||||
const nsICache = Components.interfaces.nsICache;
|
||||
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()
|
||||
{
|
||||
|
@ -108,6 +102,19 @@ function showMetadataFor(elem)
|
|||
hideNode("no-properties")
|
||||
}
|
||||
|
||||
var cacheListener = {
|
||||
onCacheEntryAvailable: function onCacheEntryAvailable(descriptor) {
|
||||
if (descriptor) {
|
||||
var kbSize = descriptor.dataSize / 1024;
|
||||
kbSize = Math.round(kbSize * 100) / 100;
|
||||
setInfo("image-filesize", gMetadataBundle.getFormattedString("imageSize",
|
||||
[formatNumber(kbSize),
|
||||
formatNumber(descriptor.dataSize)]));
|
||||
} else {
|
||||
setInfo("image-filesize", gMetadataBundle.getString("imageSizeUnknown"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function checkForImage(elem, htmllocalname)
|
||||
{
|
||||
|
@ -157,17 +164,13 @@ function checkForImage(elem, htmllocalname)
|
|||
|
||||
var imgURL = imgType == "object" ? img.data : img.src;
|
||||
setInfo("image-url", imgURL);
|
||||
var size = getSize(imgURL);
|
||||
|
||||
if (size != -1) {
|
||||
var kbSize = size / 1024;
|
||||
kbSize = Math.round(kbSize*100)/100;
|
||||
setInfo("image-filesize", gMetadataBundle.getFormattedString("imageSize",
|
||||
[formatNumber(kbSize),
|
||||
formatNumber(size)]));
|
||||
} else {
|
||||
setInfo("image-filesize", gMetadataBundle.getString("imageSizeUnknown"));
|
||||
}
|
||||
const cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
|
||||
.getService(nsICacheService);
|
||||
var httpCacheSession = cacheService.createSession("HTTP", nsICache.STORE_ANYWHERE, true);
|
||||
httpCacheSession.doomEntriesIfExpired = false;
|
||||
httpCacheSession.asyncOpenCacheEntry(imgURL, nsICache.ACCESS_READ, cacheListener);
|
||||
|
||||
if ("width" in img && img.width != "") {
|
||||
setInfo("image-width", gMetadataBundle.getFormattedString("imageWidth", [formatNumber(img.width)]));
|
||||
setInfo("image-height", gMetadataBundle.getFormattedString("imageHeight", [formatNumber(img.height)]));
|
||||
|
@ -486,25 +489,6 @@ 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;
|
||||
}
|
||||
|
||||
function setAlt(elem) {
|
||||
var altText = document.getElementById("image-alt-text");
|
||||
if (elem.hasAttribute("alt")) {
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
<row id="image-filesize">
|
||||
<separator orient="vertical"/>
|
||||
<label value="&image-filesize.label; " control="image-filesize-text"/>
|
||||
<textbox readonly="true" id="image-filesize-text"/>
|
||||
<textbox readonly="true" id="image-filesize-text" value="&image-filesize.value;"/>
|
||||
</row>
|
||||
<row id="image-alt">
|
||||
<separator orient="vertical"/>
|
||||
|
|
|
@ -157,6 +157,8 @@ const COL_IMAGE_COUNT = 4;
|
|||
const COL_IMAGE_NODE = 5;
|
||||
const COL_IMAGE_BG = 6;
|
||||
const COL_IMAGE_SIZENUM = 7;
|
||||
const COL_IMAGE_DEVICE = 8;
|
||||
const COL_IMAGE_MIME = 9;
|
||||
|
||||
// column number to copy from, second argument to pageInfoTreeView's constructor
|
||||
const COPYCOL_NONE = -1;
|
||||
|
@ -454,6 +456,19 @@ function onClickMore()
|
|||
showTab("securityTab");
|
||||
}
|
||||
|
||||
var cacheListener = {
|
||||
onCacheEntryAvailable: function onCacheEntryAvailable(descriptor) {
|
||||
if (descriptor) {
|
||||
var pageSize = descriptor.dataSize;
|
||||
var kbSize = Math.round(pageSize / 1024 * 100) / 100;
|
||||
var sizeText = gBundle.getFormattedString("generalSize",
|
||||
[formatNumber(kbSize),
|
||||
formatNumber(pageSize)]);
|
||||
setItemValue("sizetext", sizeText);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function makeGeneralTab()
|
||||
{
|
||||
var title = (gDocument.title) ? gBundle.getFormattedString("pageTitle", [gDocument.title]) : gBundle.getString("noPageTitle");
|
||||
|
@ -496,26 +511,16 @@ function makeGeneralTab()
|
|||
document.getElementById("modifiedtext").value = modifiedText;
|
||||
|
||||
// get cache info
|
||||
setItemValue("sizetext", null);
|
||||
var cacheKey = url.replace(/#.*$/, "");
|
||||
try {
|
||||
var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
|
||||
httpCacheSession.asyncOpenCacheEntry(cacheKey, ACCESS_READ, cacheListener);
|
||||
}
|
||||
catch(ex) {
|
||||
try {
|
||||
cacheEntryDescriptor = ftpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
|
||||
}
|
||||
catch(ex2) { }
|
||||
catch(ex) { }
|
||||
try {
|
||||
ftpCacheSession.asyncOpenCacheEntry(cacheKey, ACCESS_READ, cacheListener);
|
||||
}
|
||||
|
||||
var sizeText;
|
||||
if (cacheEntryDescriptor) {
|
||||
var pageSize = cacheEntryDescriptor.dataSize;
|
||||
var kbSize = Math.round(pageSize / 1024 * 100) / 100;
|
||||
sizeText = gBundle.getFormattedString("generalSize",
|
||||
[formatNumber(kbSize),
|
||||
formatNumber(pageSize)]);
|
||||
}
|
||||
setItemValue("sizetext", sizeText);
|
||||
catch(ex) { }
|
||||
|
||||
securityOnLoad();
|
||||
}
|
||||
|
@ -576,10 +581,22 @@ function ensureSelection(view)
|
|||
view.selection.select(0);
|
||||
}
|
||||
|
||||
function addImage(url, type, alt, elem, isBg)
|
||||
function imgCacheListener(url, type, alt, elem, isBg)
|
||||
{
|
||||
if (!url)
|
||||
return;
|
||||
this.url = url;
|
||||
this.type = type;
|
||||
this.alt = alt;
|
||||
this.elem = elem;
|
||||
this.isBg = isBg;
|
||||
}
|
||||
|
||||
imgCacheListener.prototype.onCacheEntryAvailable =
|
||||
function onCacheEntryAvailable(cacheEntryDescriptor) {
|
||||
var url = this.url;
|
||||
var type = this.type;
|
||||
var alt = this.alt;
|
||||
var elem = this.elem;
|
||||
var isBg = this.isBg;
|
||||
|
||||
if (!gImageHash.hasOwnProperty(url))
|
||||
gImageHash[url] = { };
|
||||
|
@ -587,28 +604,21 @@ function addImage(url, type, alt, elem, isBg)
|
|||
gImageHash[url][type] = { };
|
||||
if (!gImageHash[url][type].hasOwnProperty(alt)) {
|
||||
gImageHash[url][type][alt] = gImageView.data.length;
|
||||
try {
|
||||
// open for READ, in non-blocking mode
|
||||
var cacheEntryDescriptor = httpCacheSession.openCacheEntry(url, ACCESS_READ, false);
|
||||
}
|
||||
catch(ex) {
|
||||
try {
|
||||
// open for READ, in non-blocking mode
|
||||
cacheEntryDescriptor = ftpCacheSession.openCacheEntry(url, ACCESS_READ, false);
|
||||
}
|
||||
catch(ex2) { }
|
||||
}
|
||||
|
||||
var sizeText;
|
||||
var pageSize;
|
||||
var deviceID;
|
||||
var mimeType;
|
||||
if (cacheEntryDescriptor) {
|
||||
mimeType = getContentTypeFromHeaders(cacheEntryDescriptor);
|
||||
deviceID = cacheEntryDescriptor.deviceID;
|
||||
pageSize = cacheEntryDescriptor.dataSize;
|
||||
var kbSize = Math.round(pageSize / 1024 * 100) / 100;
|
||||
sizeText = gBundle.getFormattedString("mediaFileSize", [formatNumber(kbSize)]);
|
||||
}
|
||||
else
|
||||
sizeText = gStrings.unknown;
|
||||
gImageView.addRow([url, type, sizeText, alt, 1, elem, isBg, pageSize]);
|
||||
gImageView.addRow([url, type, sizeText, alt, 1, elem, isBg, pageSize, deviceID, mimeType]);
|
||||
|
||||
// Add the observer, only once.
|
||||
if (gImageView.data.length == 1) {
|
||||
|
@ -621,6 +631,15 @@ function addImage(url, type, alt, elem, isBg)
|
|||
}
|
||||
}
|
||||
|
||||
function addImage(url, type, alt, elem, isBg)
|
||||
{
|
||||
if (url) try {
|
||||
var listener = new imgCacheListener(url, type, alt, elem, isBg);
|
||||
httpCacheSession.asyncOpenCacheEntry(url, ACCESS_READ, listener);
|
||||
}
|
||||
catch (ex) { }
|
||||
}
|
||||
|
||||
function grabAll(elem)
|
||||
{
|
||||
// check for background images, any node may have multiple
|
||||
|
@ -974,12 +993,7 @@ function onImageSelect()
|
|||
|
||||
function makePreview(row)
|
||||
{
|
||||
var imageTree = document.getElementById("imagetree");
|
||||
var item = getSelectedImage(imageTree);
|
||||
var col = imageTree.columns["image-address"];
|
||||
var url = gImageView.getCellText(row, col);
|
||||
// image-bg
|
||||
var isBG = gImageView.data[row][COL_IMAGE_BG];
|
||||
var [url, type, sizeText, alt, count, item, isBG, pageSize, deviceID, cachedType] = gImageView.data[row];
|
||||
var isAudio = false;
|
||||
|
||||
setItemValue("imageurltext", url);
|
||||
|
@ -1007,48 +1021,23 @@ function makePreview(row)
|
|||
|
||||
// get cache info
|
||||
var sourceText = gBundle.getString("generalNotCached");
|
||||
var cacheKey = url.replace(/#.*$/, "");
|
||||
try {
|
||||
// open for READ, in non-blocking mode
|
||||
var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
|
||||
if (cacheEntryDescriptor)
|
||||
switch (cacheEntryDescriptor.deviceID) {
|
||||
case "disk":
|
||||
sourceText = gBundle.getString("generalDiskCache");
|
||||
break;
|
||||
case "memory":
|
||||
sourceText = gBundle.getString("generalMemoryCache");
|
||||
break;
|
||||
default:
|
||||
sourceText = cacheEntryDescriptor.deviceID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(ex) {
|
||||
try {
|
||||
// open for READ, in non-blocking mode
|
||||
cacheEntryDescriptor = ftpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
|
||||
if (cacheEntryDescriptor)
|
||||
switch (cacheEntryDescriptor.deviceID) {
|
||||
case "disk":
|
||||
sourceText = gBundle.getString("generalDiskCache");
|
||||
break;
|
||||
case "memory":
|
||||
sourceText = gBundle.getString("generalMemoryCache");
|
||||
break;
|
||||
default:
|
||||
sourceText = cacheEntryDescriptor.deviceID;
|
||||
break;
|
||||
}
|
||||
if (deviceID) {
|
||||
switch (deviceID) {
|
||||
case "disk":
|
||||
sourceText = gBundle.getString("generalDiskCache");
|
||||
break;
|
||||
case "memory":
|
||||
sourceText = gBundle.getString("generalMemoryCache");
|
||||
break;
|
||||
default:
|
||||
sourceText = cacheEntryDescriptor.deviceID;
|
||||
break;
|
||||
}
|
||||
catch(ex2) { }
|
||||
}
|
||||
setItemValue("imagesourcetext", sourceText);
|
||||
|
||||
// find out the file size
|
||||
var sizeText;
|
||||
if (cacheEntryDescriptor) {
|
||||
var pageSize = cacheEntryDescriptor.dataSize;
|
||||
if (pageSize) {
|
||||
var kbSize = Math.round(pageSize / 1024 * 100) / 100;
|
||||
sizeText = gBundle.getFormattedString("generalSize",
|
||||
[formatNumber(kbSize),
|
||||
|
@ -1065,7 +1054,7 @@ function makePreview(row)
|
|||
if (!mimeType && item instanceof nsIImageLoadingContent)
|
||||
[mimeType, numFrames] = getContentTypeFromImgRequest(item);
|
||||
if (!mimeType)
|
||||
mimeType = getContentTypeFromHeaders(cacheEntryDescriptor);
|
||||
mimeType = cachedType;
|
||||
|
||||
// if we have a data url, get the MIME type from the url
|
||||
if (!mimeType) {
|
||||
|
|
|
@ -107,7 +107,8 @@
|
|||
</field>
|
||||
<field name="mFaviconService" readonly="true">
|
||||
Components.classes["@mozilla.org/browser/favicon-service;1"]
|
||||
.getService(Components.interfaces.nsIFaviconService);
|
||||
.getService(Components.interfaces.nsIFaviconService)
|
||||
.QueryInterface(Components.interfaces.mozIAsyncFavicons);
|
||||
</field>
|
||||
<field name="mIOService" readonly="true">
|
||||
Components.classes["@mozilla.org/network/io-service;1"]
|
||||
|
@ -776,14 +777,10 @@
|
|||
if (this.mFaviconService) {
|
||||
let uri = this.mIOService.newURI(iconURL, null, null);
|
||||
this.mFaviconService.setAndFetchFaviconForPage(aURI, uri, false, this.mFaviconService.FAVICON_LOAD_NON_PRIVATE);
|
||||
if (this.mFaviconService.isFailedFavicon(uri))
|
||||
return;
|
||||
}
|
||||
var entry = this.openCacheEntry(iconURL, Components.interfaces.nsICache.ACCESS_READ);
|
||||
if (!entry)
|
||||
aElt.setAttribute(aAttr, iconURL);
|
||||
else {
|
||||
entry.close();
|
||||
entry = null;
|
||||
}
|
||||
aElt.setAttribute(aAttr, iconURL);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -792,36 +789,8 @@
|
|||
<parameter name="aURI"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var entry = this.openCacheEntry(aURI, Components.interfaces.nsICache.ACCESS_READ_WRITE);
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
if (entry.accessGranted == Components.interfaces.nsICache.ACCESS_WRITE)
|
||||
// It's a new entry. Just write a bit of metadata in to the entry.
|
||||
entry.setMetaDataElement("Icon", "Missed");
|
||||
entry.markValid();
|
||||
entry.close();
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="openCacheEntry">
|
||||
<parameter name="key"/>
|
||||
<parameter name="access"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
try {
|
||||
if (!this.mMissedIconCache) {
|
||||
var cacheService = Components.classes['@mozilla.org/network/cache-service;1'].getService(Components.interfaces.nsICacheService);
|
||||
this.mMissedIconCache = cacheService.createSession("MissedIconCache", Components.interfaces.nsICache.STORE_ANYWHERE, true);
|
||||
if (!this.mMissedIconCache)
|
||||
return null;
|
||||
}
|
||||
return this.mMissedIconCache.openCacheEntry(key, access, true);
|
||||
}
|
||||
catch (e) {
|
||||
return null;
|
||||
}
|
||||
if (this.mFaviconService)
|
||||
this.mFaviconService.addFailedFavicon(aURI);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<!ENTITY image-width.label "Width:">
|
||||
<!ENTITY image-height.label "Height:">
|
||||
<!ENTITY image-filesize.label "Size of File:">
|
||||
<!ENTITY image-filesize.value "Unknown">
|
||||
<!ENTITY insdel-sec.label "Insert/Delete Properties">
|
||||
<!ENTITY insdel-cite.label "Info:">
|
||||
<!ENTITY insdel-date.label "Date:">
|
||||
|
|
Загрузка…
Ссылка в новой задаче