зеркало из https://github.com/mozilla/pjs.git
Fix bug 74832, sr=darin.
This commit is contained in:
Родитель
6aa3e847e6
Коммит
f2a27deafb
|
@ -116,10 +116,14 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result)
|
|||
rv = storageStream->GetOutputStream(0, getter_AddRefs(outputStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mBuffer.Assign("<html>\n<head>\n<title>Information about the Cache Manager</title>\n</head>\n<body>\n");
|
||||
mBuffer.Assign("<html>\n<head>\n<title>Information about the Cache Service</title>\n</head>\n<body>\n");
|
||||
|
||||
outputStream->Write(mBuffer, mBuffer.Length(), &bytesWritten);
|
||||
|
||||
#ifdef MOZ_NEW_CACHE
|
||||
rv = ParseURI(aURI, mDeviceID);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mStream = outputStream;
|
||||
rv = cacheService->VisitEntries(this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -185,47 +189,60 @@ nsAboutCache::VisitDevice(const char *deviceID,
|
|||
PRUint32 bytesWritten, value;
|
||||
nsXPIDLCString str;
|
||||
|
||||
// Write out the Cache Name
|
||||
deviceInfo->GetDescription(getter_Copies(str));
|
||||
*visitEntries = PR_FALSE;
|
||||
|
||||
mBuffer.Assign("<h2>");
|
||||
mBuffer.Append(str);
|
||||
mBuffer.Append("</h2><br>\n");
|
||||
if (mDeviceID.IsEmpty() || mDeviceID.Equals(deviceID)) {
|
||||
|
||||
// Write out cache info
|
||||
|
||||
mBuffer.Append("<table>\n<tr><td><b>Usage report:</b></td>\n");
|
||||
deviceInfo->GetUsageReport(getter_Copies(str));
|
||||
mBuffer.Append("<td>");
|
||||
mBuffer.Append(str);
|
||||
mBuffer.Append("</td>\n</tr>\n");
|
||||
// Write out the Cache Name
|
||||
deviceInfo->GetDescription(getter_Copies(str));
|
||||
|
||||
mBuffer.Append("\n<tr><td><b>Number of entries:</b></td>\n");
|
||||
value = 0;
|
||||
deviceInfo->GetEntryCount(&value);
|
||||
mBuffer.Append("<td>");
|
||||
mBuffer.AppendInt(value);
|
||||
mBuffer.Append("</td>\n</tr>\n");
|
||||
mBuffer.Assign("<h2>");
|
||||
mBuffer.Append(str);
|
||||
mBuffer.Append("</h2><br>\n");
|
||||
|
||||
mBuffer.Append("\n<tr><td><b>Maximum storage size:</b></td>\n");
|
||||
value = 0;
|
||||
deviceInfo->GetMaximumSize(&value);
|
||||
mBuffer.Append("<td>");
|
||||
mBuffer.AppendInt(value);
|
||||
mBuffer.Append("</td>\n</tr>\n");
|
||||
// Write out cache info
|
||||
|
||||
mBuffer.Append("\n<tr><td><b>Storage in use:</b></td>\n");
|
||||
mBuffer.Append("<td>");
|
||||
value = 0;
|
||||
deviceInfo->GetTotalSize(&value);
|
||||
mBuffer.AppendInt(value);
|
||||
mBuffer.Append(" Bytes</td>\n</tr>\n");
|
||||
mBuffer.Append("<table>\n<tr><td><b>Usage report:</b></td>\n");
|
||||
deviceInfo->GetUsageReport(getter_Copies(str));
|
||||
mBuffer.Append("<td>");
|
||||
mBuffer.Append(str);
|
||||
mBuffer.Append("</td>\n</tr>\n");
|
||||
|
||||
mBuffer.Append("</table>\n<hr>\n");
|
||||
mBuffer.Append("\n<tr><td><b>Number of entries:</b></td>\n");
|
||||
value = 0;
|
||||
deviceInfo->GetEntryCount(&value);
|
||||
mBuffer.Append("<td><tt>");
|
||||
mBuffer.AppendInt(value);
|
||||
mBuffer.Append("</tt></td>\n</tr>\n");
|
||||
|
||||
mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten);
|
||||
mBuffer.Append("\n<tr><td><b>Maximum storage size:</b></td>\n");
|
||||
value = 0;
|
||||
deviceInfo->GetMaximumSize(&value);
|
||||
mBuffer.Append("<td><tt>");
|
||||
mBuffer.AppendInt(value);
|
||||
mBuffer.Append("</tt></td>\n</tr>\n");
|
||||
|
||||
mBuffer.Append("\n<tr><td><b>Storage in use:</b></td>\n");
|
||||
mBuffer.Append("<td><tt>");
|
||||
value = 0;
|
||||
deviceInfo->GetTotalSize(&value);
|
||||
mBuffer.AppendInt(value);
|
||||
mBuffer.Append(" Bytes</tt></td>\n</tr>\n");
|
||||
|
||||
mBuffer.Append("</table>\n");
|
||||
|
||||
if (mDeviceID.IsEmpty()) {
|
||||
mBuffer.Append("\n<a href=\"about:cache?device=");
|
||||
mBuffer.Append(deviceID);
|
||||
mBuffer.Append("\">List Cache Entries</a>\n");
|
||||
} else {
|
||||
*visitEntries = PR_TRUE;
|
||||
}
|
||||
|
||||
mBuffer.Append("<hr>\n");
|
||||
mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten);
|
||||
}
|
||||
|
||||
*visitEntries = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -259,28 +276,22 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
|||
url += key; // key
|
||||
|
||||
// Entry start...
|
||||
mBuffer.Assign("<p>\n");
|
||||
mBuffer.Assign("<p><tt>\n");
|
||||
|
||||
// URI
|
||||
mBuffer.Append("<tt> "
|
||||
" Key: </tt>");
|
||||
mBuffer.Append("<b> "
|
||||
" Key: </b>");
|
||||
mBuffer.Append("<a href=\"");
|
||||
mBuffer.Append(url);
|
||||
mBuffer.Append("\">");
|
||||
mBuffer.Append(key);
|
||||
mBuffer.Append("</a><br>\n");
|
||||
|
||||
// Client
|
||||
mBuffer.Append("<tt> "
|
||||
" Client: </tt>");
|
||||
mBuffer.Append(clientID);
|
||||
mBuffer.Append("<br>\n");
|
||||
|
||||
// Content length
|
||||
PRUint32 length = 0;
|
||||
entryInfo->GetDataSize(&length);
|
||||
|
||||
mBuffer.Append("<tt> Data size: </tt>");
|
||||
mBuffer.Append("<b> Data size: </b>");
|
||||
mBuffer.AppendInt(length);
|
||||
mBuffer.Append(" Bytes<br>\n");
|
||||
|
||||
|
@ -288,24 +299,16 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
|||
PRInt32 fetchCount = 0;
|
||||
entryInfo->GetFetchCount(&fetchCount);
|
||||
|
||||
mBuffer.Append("<tt> Fetch count: </tt>");
|
||||
mBuffer.Append("<b> Fetch count: </b>");
|
||||
mBuffer.AppendInt(fetchCount);
|
||||
mBuffer.Append("<br>\n");
|
||||
|
||||
// Last modified time
|
||||
// vars for reporting time
|
||||
char buf[255];
|
||||
PRUint32 t;
|
||||
|
||||
mBuffer.Append("<tt> Last Fetched: </tt>");
|
||||
entryInfo->GetLastFetched(&t);
|
||||
if (t) {
|
||||
PrintTimeString(buf, sizeof(buf), t);
|
||||
mBuffer.Append(buf);
|
||||
} else
|
||||
mBuffer.Append("No last fetched time");
|
||||
mBuffer.Append("<br>");
|
||||
|
||||
mBuffer.Append("<tt> Last Modified: </tt>");
|
||||
// Last modified time
|
||||
mBuffer.Append("<b> Last Modified: </b>");
|
||||
entryInfo->GetLastModified(&t);
|
||||
if (t) {
|
||||
PrintTimeString(buf, sizeof(buf), t);
|
||||
|
@ -315,8 +318,8 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
|||
mBuffer.Append("<br>");
|
||||
|
||||
// Expires time
|
||||
mBuffer.Append("<tt> "
|
||||
"Expires: </tt>");
|
||||
mBuffer.Append("<b> "
|
||||
"Expires: </b>");
|
||||
entryInfo->GetExpirationTime(&t);
|
||||
if (t) {
|
||||
PrintTimeString(buf, sizeof(buf), t);
|
||||
|
@ -327,7 +330,7 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
|||
mBuffer.Append("<br>");
|
||||
|
||||
// Entry is done...
|
||||
mBuffer.Append("</p>\n");
|
||||
mBuffer.Append("</p></tt>\n");
|
||||
|
||||
mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten);
|
||||
|
||||
|
@ -335,6 +338,35 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsAboutCache::ParseURI(nsIURI * uri, nsCString &deviceID)
|
||||
{
|
||||
//
|
||||
// about:cache[?device=string]
|
||||
//
|
||||
nsresult rv;
|
||||
|
||||
deviceID.Truncate();
|
||||
|
||||
nsXPIDLCString path;
|
||||
rv = uri->GetPath(getter_Copies(path));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString p(path);
|
||||
|
||||
nsReadingIterator<char> start, valueStart, end;
|
||||
p.BeginReading(start);
|
||||
p.EndReading(end);
|
||||
|
||||
valueStart = end;
|
||||
if (!FindInReadable(NS_LITERAL_CSTRING("?device="), start, valueStart))
|
||||
return NS_OK;
|
||||
|
||||
deviceID.Assign(Substring(valueStart, end));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void nsAboutCache::DumpCacheInfo(nsIOutputStream *aStream, nsINetDataCache *aCache)
|
||||
|
@ -553,4 +585,6 @@ nsAboutCache::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -56,7 +56,10 @@ public:
|
|||
|
||||
protected:
|
||||
#ifdef MOZ_NEW_CACHE
|
||||
nsresult ParseURI(nsIURI * uri, nsCString &deviceID);
|
||||
|
||||
nsCOMPtr<nsIOutputStream> mStream;
|
||||
nsCString mDeviceID;
|
||||
#else
|
||||
void DumpCacheInfo(nsIOutputStream *aStream,
|
||||
nsINetDataCache *aCache);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsIStorageStream.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prtime.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsISupports implementation
|
||||
|
@ -329,6 +330,22 @@ nsAboutCacheEntry::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
|
|||
// helper methods
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static PRTime SecondsToPRTime(PRUint32 t_sec)
|
||||
{
|
||||
PRTime t_usec, usec_per_sec;
|
||||
LL_I2L(t_usec, t_sec);
|
||||
LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
|
||||
LL_MUL(t_usec, t_usec, usec_per_sec);
|
||||
return t_usec;
|
||||
}
|
||||
static void PrintTimeString(char *buf, PRUint32 bufsize, PRUint32 t_sec)
|
||||
{
|
||||
PRExplodedTime et;
|
||||
PRTime t_usec = SecondsToPRTime(t_sec);
|
||||
PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et);
|
||||
PR_FormatTime(buf, bufsize, "%c", &et);
|
||||
}
|
||||
|
||||
#define TD_RIGHT_ALIGN "<td valign=top align=right>"
|
||||
|
||||
#define APPEND_ROW(label, value) \
|
||||
|
@ -372,23 +389,85 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream,
|
|||
buffer.Append(str);
|
||||
buffer.Append("</td></tr>");
|
||||
|
||||
// Since meta data enumeration is not hooked up yet, let's just look for some
|
||||
// well known (HTTP) meta data tags.
|
||||
|
||||
str = 0;
|
||||
descriptor->GetMetaDataElement("request-time", getter_Copies(str));
|
||||
if (str)
|
||||
APPEND_ROW("request-time", str);
|
||||
// temp vars for reporting
|
||||
char timeBuf[255];
|
||||
PRUint32 u = 0;
|
||||
PRInt32 i = 0;
|
||||
nsCAutoString s;
|
||||
|
||||
str = 0;
|
||||
descriptor->GetMetaDataElement("response-time", getter_Copies(str));
|
||||
if (str)
|
||||
APPEND_ROW("response-time", str);
|
||||
// Fetch Count
|
||||
s.Truncate();
|
||||
descriptor->GetFetchCount(&i);
|
||||
s.AppendInt(i);
|
||||
APPEND_ROW("fetch count", s);
|
||||
|
||||
// Last Fetched
|
||||
descriptor->GetLastFetched(&u);
|
||||
if (u) {
|
||||
PrintTimeString(timeBuf, sizeof(timeBuf), u);
|
||||
APPEND_ROW("last fetched", timeBuf);
|
||||
} else {
|
||||
APPEND_ROW("last fetched", "No last fetch time");
|
||||
}
|
||||
|
||||
// Last Modified
|
||||
descriptor->GetLastModified(&u);
|
||||
if (u) {
|
||||
PrintTimeString(timeBuf, sizeof(timeBuf), u);
|
||||
APPEND_ROW("last modified", timeBuf);
|
||||
} else {
|
||||
APPEND_ROW("last modified", "No last modified time");
|
||||
}
|
||||
|
||||
// Expiration Time
|
||||
descriptor->GetExpirationTime(&u);
|
||||
if (u) {
|
||||
PrintTimeString(timeBuf, sizeof(timeBuf), u);
|
||||
APPEND_ROW("expires", timeBuf);
|
||||
} else {
|
||||
APPEND_ROW("expires", "No expiration time");
|
||||
}
|
||||
|
||||
// Data Size
|
||||
s.Truncate();
|
||||
descriptor->GetDataSize(&u);
|
||||
s.AppendInt((PRInt32)u); // XXX nsICacheEntryInfo interfaces should be fixed.
|
||||
APPEND_ROW("Data size", s);
|
||||
|
||||
// Storage Policy
|
||||
|
||||
// XXX Stream Based?
|
||||
|
||||
// XXX Cache Device
|
||||
// File on disk
|
||||
|
||||
// Security Info
|
||||
str = 0;
|
||||
descriptor->GetMetaDataElement("http-headers", getter_Copies(str));
|
||||
if (str)
|
||||
APPEND_ROW("http-headers", str);
|
||||
nsCOMPtr<nsISupports> securityInfo;
|
||||
descriptor->GetSecurityInfo(getter_AddRefs(securityInfo));
|
||||
if (securityInfo) {
|
||||
APPEND_ROW("Security", "This is a secure document.");
|
||||
} else {
|
||||
APPEND_ROW("Security",
|
||||
"This document does not have any security info associated with it.");
|
||||
}
|
||||
|
||||
buffer.Append("</table>");
|
||||
// Meta Data
|
||||
// let's just look for some well known (HTTP) meta data tags, for now.
|
||||
buffer.Append("<hr><table>");
|
||||
|
||||
// Client ID
|
||||
str = 0;
|
||||
descriptor->GetClientID(getter_Copies(str));
|
||||
if (str) APPEND_ROW("Client", str);
|
||||
|
||||
|
||||
mBuffer = &buffer; // make it available for VisitMetaDataElement()
|
||||
descriptor->VisitMetaData(this);
|
||||
mBuffer = nsnull;
|
||||
|
||||
|
||||
buffer.Append("</table>");
|
||||
|
||||
|
@ -456,4 +535,25 @@ nsAboutCacheEntry::ParseURI(nsCString &clientID, PRBool &streamBased, nsCString
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsICacheMetaDataVisitor implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutCacheEntry::VisitMetaDataElement(const char * key,
|
||||
const char * value,
|
||||
PRBool * keepGoing)
|
||||
{
|
||||
mBuffer->Append("<tr><td valign=top align=right><tt><b>");
|
||||
mBuffer->Append(key);
|
||||
mBuffer->Append(":</b></tt></td>\n<td><pre>");
|
||||
mBuffer->Append(value);
|
||||
mBuffer->Append("</pre></td></tr>\n");
|
||||
|
||||
*keepGoing = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif // MOZ_NEW_CACHE
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "nsIChannel.h"
|
||||
#include "nsICacheListener.h"
|
||||
#include "nsICacheSession.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
@ -39,6 +40,7 @@ class nsICacheEntryDescriptor;
|
|||
class nsAboutCacheEntry : public nsIAboutModule
|
||||
, public nsIChannel
|
||||
, public nsICacheListener
|
||||
, public nsICacheMetaDataVisitor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -46,8 +48,12 @@ public:
|
|||
NS_DECL_NSIREQUEST
|
||||
NS_DECL_NSICHANNEL
|
||||
NS_DECL_NSICACHELISTENER
|
||||
NS_DECL_NSICACHEMETADATAVISITOR
|
||||
|
||||
nsAboutCacheEntry()
|
||||
: mBuffer(nsnull)
|
||||
{ NS_INIT_ISUPPORTS(); }
|
||||
|
||||
nsAboutCacheEntry() { NS_INIT_ISUPPORTS(); }
|
||||
virtual ~nsAboutCacheEntry() {}
|
||||
|
||||
private:
|
||||
|
@ -60,6 +66,7 @@ private:
|
|||
nsCOMPtr<nsIStreamListener> mListener;
|
||||
nsCOMPtr<nsISupports> mListenerContext;
|
||||
nsCOMPtr<nsICacheSession> mCacheSession;
|
||||
nsCString * mBuffer;
|
||||
};
|
||||
|
||||
#define NS_ABOUT_CACHE_ENTRY_MODULE_CID \
|
||||
|
|
Загрузка…
Ссылка в новой задаче