2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-09-13 10:10:03 +04:00
|
|
|
|
|
|
|
#include "nsAboutCache.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIStorageStream.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIPipe.h"
|
2014-10-16 22:14:35 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-07-25 17:27:16 +04:00
|
|
|
#include "nsEscape.h"
|
2013-12-09 17:17:11 +04:00
|
|
|
#include "nsAboutProtocolUtils.h"
|
2014-05-01 15:28:12 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2000-09-13 10:10:03 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
#include "nsICacheStorageService.h"
|
|
|
|
#include "nsICacheStorage.h"
|
|
|
|
#include "CacheFileUtils.h"
|
|
|
|
#include "CacheObserver.h"
|
2000-09-13 10:10:03 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla::net;
|
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsAboutCache, nsIAboutModule)
|
|
|
|
NS_IMPL_ISUPPORTS(nsAboutCache::Channel, nsIChannel, nsIRequest,
|
|
|
|
nsICacheStorageVisitor)
|
2000-09-13 10:10:03 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-23 04:18:26 +04:00
|
|
|
nsAboutCache::NewChannel(nsIURI *aURI, nsILoadInfo *aLoadInfo,
|
|
|
|
nsIChannel **result) {
|
2016-05-17 12:20:00 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2005-12-18 04:50:50 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2014-05-01 15:28:12 +04:00
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
RefPtr<Channel> channel = new Channel();
|
|
|
|
rv = channel->Init(aURI, aLoadInfo);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-09-13 10:10:03 +04:00
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
channel.forget(result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAboutCache::Channel::Init(nsIURI *aURI, nsILoadInfo *aLoadInfo) {
|
|
|
|
nsresult rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-12 17:19:00 +03:00
|
|
|
mCancel = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsCOMPtr<nsIInputStream> inputStream;
|
|
|
|
rv = NS_NewPipe(getter_AddRefs(inputStream), getter_AddRefs(mStream), 16384,
|
|
|
|
(uint32_t)-1,
|
|
|
|
true, // non-blocking input
|
|
|
|
false // blocking output
|
|
|
|
);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsAutoCString storageName;
|
|
|
|
rv = ParseURI(aURI, storageName);
|
2000-09-13 10:10:03 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
mOverview = storageName.IsEmpty();
|
|
|
|
if (mOverview) {
|
|
|
|
// ...and visit all we can
|
|
|
|
mStorageList.AppendElement(NS_LITERAL_CSTRING("memory"));
|
|
|
|
mStorageList.AppendElement(NS_LITERAL_CSTRING("disk"));
|
|
|
|
mStorageList.AppendElement(NS_LITERAL_CSTRING("appcache"));
|
|
|
|
} else {
|
|
|
|
// ...and visit just the specified storage, entries will output too
|
|
|
|
mStorageList.AppendElement(storageName);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// The entries header is added on encounter of the first entry
|
|
|
|
mEntriesHeaderAdded = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
rv = NS_NewInputStreamChannelInternal(
|
|
|
|
getter_AddRefs(mChannel), aURI, inputStream.forget(),
|
2015-02-19 22:47:59 +03:00
|
|
|
NS_LITERAL_CSTRING("text/html"), NS_LITERAL_CSTRING("utf-8"), aLoadInfo);
|
2014-04-30 14:39:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-30 15:05:43 +04:00
|
|
|
mBuffer.AssignLiteral(
|
2014-05-01 15:28:12 +04:00
|
|
|
"<!DOCTYPE html>\n"
|
|
|
|
"<html>\n"
|
|
|
|
"<head>\n"
|
|
|
|
" <title>Network Cache Storage Information</title>\n"
|
|
|
|
" <meta charset=\"utf-8\">\n"
|
2018-04-28 16:50:45 +03:00
|
|
|
" <meta http-equiv=\"Content-Security-Policy\" content=\"default-src "
|
|
|
|
"chrome:\"/>\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
" <link rel=\"stylesheet\" href=\"chrome://global/skin/about.css\"/>\n"
|
|
|
|
" <link rel=\"stylesheet\" "
|
|
|
|
"href=\"chrome://global/skin/aboutCache.css\"/>\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body class=\"aboutPageWideContainer\">\n"
|
|
|
|
"<h1>Information about the Network Cache Storage Service</h1>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// Add the context switch controls
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
"<label><input id='priv' type='checkbox'/> Private</label>\n"
|
|
|
|
"<label><input id='anon' type='checkbox'/> Anonymous</label>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-24 11:25:38 +03:00
|
|
|
// Visit scoping by browser and appid is not implemented for
|
|
|
|
// the old cache, simply don't add these controls.
|
|
|
|
// The appid/inbrowser entries are already mixed in the default
|
|
|
|
// view anyway.
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
"<label><input id='appid' type='text' size='6'/> AppID</label>\n"
|
|
|
|
"<label><input id='inbrowser' type='checkbox'/> In Browser "
|
|
|
|
"Element</label>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral(
|
2018-04-28 16:50:45 +03:00
|
|
|
"<label><input id='submit' type='button' value='Update'/></label>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
if (!mOverview) {
|
|
|
|
mBuffer.AppendLiteral("<a href=\"about:cache?storage=&context=");
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAppendEscapedHTML(mContextString, mBuffer);
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral("\">Back to overview</a>");
|
2014-04-30 15:05:43 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-03 09:53:30 +03:00
|
|
|
rv = FlushBuffer();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to flush buffer");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-01 08:20:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:08:25 +03:00
|
|
|
NS_IMETHODIMP nsAboutCache::Channel::AsyncOpen(nsIStreamListener *aListener) {
|
2016-06-01 08:20:17 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kick the walk loop.
|
2014-05-01 15:28:12 +04:00
|
|
|
rv = VisitNextStorage();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2019-02-12 19:08:25 +03:00
|
|
|
rv = NS_MaybeOpenChannelUsingAsyncOpen(mChannel, aListener);
|
2016-06-01 08:20:17 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-01 08:20:17 +03:00
|
|
|
NS_IMETHODIMP nsAboutCache::Channel::Open(nsIInputStream **_retval) {
|
2016-06-29 16:42:13 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2016-06-01 08:20:17 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
nsresult nsAboutCache::Channel::ParseURI(nsIURI *uri, nsACString &storage) {
|
2014-05-01 15:28:12 +04:00
|
|
|
//
|
|
|
|
// about:cache[?storage=<storage-name>[&context=<context-key>]]
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-05-01 15:28:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoCString path;
|
|
|
|
rv = uri->GetPathQueryRef(path);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mContextString.Truncate();
|
|
|
|
mLoadInfo = CacheFileUtils::ParseKey(NS_LITERAL_CSTRING(""));
|
|
|
|
storage.Truncate();
|
|
|
|
|
|
|
|
nsACString::const_iterator start, valueStart, end;
|
|
|
|
path.BeginReading(start);
|
|
|
|
path.EndReading(end);
|
|
|
|
|
|
|
|
valueStart = end;
|
|
|
|
if (!FindInReadable(NS_LITERAL_CSTRING("?storage="), start, valueStart)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsACString::const_iterator storageNameBegin = valueStart;
|
2010-07-03 00:56:09 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
start = valueStart;
|
2016-05-17 12:20:00 +03:00
|
|
|
valueStart = end;
|
|
|
|
if (!FindInReadable(NS_LITERAL_CSTRING("&context="), start, valueStart))
|
2014-05-01 15:28:12 +04:00
|
|
|
start = end;
|
2000-09-13 10:10:03 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsACString::const_iterator storageNameEnd = start;
|
2000-09-13 10:10:03 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
mContextString = Substring(valueStart, end);
|
|
|
|
mLoadInfo = CacheFileUtils::ParseKey(mContextString);
|
|
|
|
storage.Assign(Substring(storageNameBegin, storageNameEnd));
|
2000-09-13 10:10:03 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
return NS_OK;
|
2000-09-13 10:10:03 +04:00
|
|
|
}
|
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsresult nsAboutCache::Channel::VisitNextStorage() {
|
|
|
|
if (!mStorageList.Length()) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
mStorageName = mStorageList[0];
|
|
|
|
mStorageList.RemoveElementAt(0);
|
2001-03-10 12:35:44 +03:00
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
// Must re-dispatch since we cannot start another visit cycle
|
|
|
|
// from visitor callback. The cache v1 service doesn't like it.
|
|
|
|
// TODO - mayhemer, bug 913828, remove this dispatch and call
|
2014-05-01 15:28:12 +04:00
|
|
|
// directly.
|
2016-05-17 12:20:00 +03:00
|
|
|
return NS_DispatchToMainThread(mozilla::NewRunnableMethod(
|
|
|
|
"nsAboutCache::Channel::FireVisitStorage", this,
|
|
|
|
&nsAboutCache::Channel::FireVisitStorage));
|
2014-05-01 15:28:12 +04:00
|
|
|
}
|
|
|
|
|
2017-12-21 22:39:42 +03:00
|
|
|
void nsAboutCache::Channel::FireVisitStorage() {
|
2014-05-01 15:28:12 +04:00
|
|
|
nsresult rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
rv = VisitStorage(mStorageName);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (mLoadInfo) {
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAutoCString escaped;
|
2014-05-01 15:28:12 +04:00
|
|
|
nsAppendEscapedHTML(mStorageName, escaped);
|
|
|
|
mBuffer.Append(nsPrintfCString(
|
|
|
|
"<p>Unrecognized storage name '%s' in about:cache URL</p>",
|
|
|
|
escaped.get()));
|
|
|
|
} else {
|
2017-12-21 22:39:42 +03:00
|
|
|
nsAutoCString escaped;
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAppendEscapedHTML(mContextString, escaped);
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.Append(nsPrintfCString(
|
|
|
|
"<p>Unrecognized context key '%s' in about:cache URL</p>",
|
|
|
|
escaped.get()));
|
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
|
2016-10-03 09:53:30 +03:00
|
|
|
rv = FlushBuffer();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to flush buffer");
|
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
|
|
|
|
// Simulate finish of a visit cycle, this tries the next storage
|
|
|
|
// or closes the output stream (i.e. the UI loader will stop spinning)
|
|
|
|
OnCacheEntryVisitCompleted();
|
2001-04-06 04:57:36 +04:00
|
|
|
}
|
2001-03-10 12:35:44 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
nsresult nsAboutCache::Channel::VisitStorage(nsACString const &storageName) {
|
2014-05-01 15:28:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = GetStorage(storageName, mLoadInfo, getter_AddRefs(mStorage));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-04 11:25:58 +04:00
|
|
|
|
2001-03-13 23:06:42 +03:00
|
|
|
rv = mStorage->AsyncVisitStorage(this, !mOverview);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2014-05-01 15:28:12 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
|
|
|
|
// static
|
2017-08-18 05:00:59 +03:00
|
|
|
nsresult nsAboutCache::GetStorage(nsACString const &storageName,
|
|
|
|
nsILoadContextInfo *loadInfo,
|
2014-05-01 15:28:12 +04:00
|
|
|
nsICacheStorage **storage) {
|
|
|
|
nsresult rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-18 05:00:59 +03:00
|
|
|
nsCOMPtr<nsICacheStorageService> cacheService =
|
2014-05-01 15:28:12 +04:00
|
|
|
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
|
2017-08-18 05:00:59 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsCOMPtr<nsICacheStorage> cacheStorage;
|
|
|
|
if (storageName == "disk") {
|
|
|
|
rv = cacheService->DiskCacheStorage(loadInfo, false,
|
|
|
|
getter_AddRefs(cacheStorage));
|
|
|
|
} else if (storageName == "memory") {
|
|
|
|
rv = cacheService->MemoryCacheStorage(loadInfo,
|
2017-08-18 05:00:59 +03:00
|
|
|
getter_AddRefs(cacheStorage));
|
|
|
|
} else if (storageName == "appcache") {
|
|
|
|
rv = cacheService->AppCacheStorage(loadInfo, nullptr,
|
2014-05-01 15:28:12 +04:00
|
|
|
getter_AddRefs(cacheStorage));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-08-18 05:00:59 +03:00
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
cacheStorage.forget(storage);
|
2006-06-20 01:02:12 +04:00
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
|
2001-03-10 12:35:44 +03:00
|
|
|
NS_IMETHODIMP
|
2014-05-01 15:28:12 +04:00
|
|
|
nsAboutCache::Channel::OnCacheStorageInfo(uint32_t aEntryCount,
|
|
|
|
uint64_t aConsumption,
|
2016-05-17 12:20:00 +03:00
|
|
|
uint64_t aCapacity,
|
2014-05-01 15:28:12 +04:00
|
|
|
nsIFile *aDirectory) {
|
|
|
|
// We need mStream for this
|
|
|
|
if (!mStream) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AssignLiteral("<h2>");
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAppendEscapedHTML(mStorageName, mBuffer);
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral(
|
2018-11-30 13:46:48 +03:00
|
|
|
"</h2>\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
"<table id=\"");
|
|
|
|
mBuffer.AppendLiteral("\">\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// Write out cache info
|
|
|
|
// Number of entries
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" <tr>\n"
|
|
|
|
" <th>Number of entries:</th>\n"
|
|
|
|
" <td>");
|
|
|
|
mBuffer.AppendInt(aEntryCount);
|
|
|
|
mBuffer.AppendLiteral(
|
2018-11-30 13:46:48 +03:00
|
|
|
"</td>\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
" </tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// Maximum storage size
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" <tr>\n"
|
|
|
|
" <th>Maximum storage size:</th>\n"
|
|
|
|
" <td>");
|
|
|
|
mBuffer.AppendInt(aCapacity / 1024);
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" KiB</td>\n"
|
|
|
|
" </tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// Storage in use
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" <tr>\n"
|
|
|
|
" <th>Storage in use:</th>\n"
|
|
|
|
" <td>");
|
|
|
|
mBuffer.AppendInt(aConsumption / 1024);
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" KiB</td>\n"
|
|
|
|
" </tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// Storage disk location
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" <tr>\n"
|
|
|
|
" <th>Storage disk location:</th>\n"
|
|
|
|
" <td>");
|
|
|
|
if (aDirectory) {
|
|
|
|
nsAutoString path;
|
|
|
|
aDirectory->GetPath(path);
|
|
|
|
mBuffer.Append(NS_ConvertUTF16toUTF8(path));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral("none, only stored in memory");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" </td>\n"
|
|
|
|
" </tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
if (mOverview) { // The about:cache case
|
|
|
|
if (aEntryCount != 0) { // Add the "List Cache Entries" link
|
|
|
|
mBuffer.AppendLiteral(
|
|
|
|
" <tr>\n"
|
|
|
|
" <th><a href=\"about:cache?storage=");
|
2017-12-21 22:39:42 +03:00
|
|
|
nsAppendEscapedHTML(mStorageName, mBuffer);
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral("&context=");
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAppendEscapedHTML(mContextString, mBuffer);
|
|
|
|
mBuffer.AppendLiteral(
|
2014-05-01 15:28:12 +04:00
|
|
|
"\">List Cache Entries</a></th>\n"
|
|
|
|
" </tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
|
|
|
|
mBuffer.AppendLiteral("</table>\n");
|
2001-03-13 23:06:42 +03:00
|
|
|
|
2001-03-10 12:35:44 +03:00
|
|
|
// The entries header is added on encounter of the first entry
|
2014-05-01 15:28:12 +04:00
|
|
|
mEntriesHeaderAdded = false;
|
2001-03-10 12:35:44 +03:00
|
|
|
|
2017-12-21 22:39:42 +03:00
|
|
|
nsresult rv = FlushBuffer();
|
2014-05-01 15:28:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2016-07-25 17:26:00 +03:00
|
|
|
NS_WARNING("Failed to flush buffer");
|
2017-04-28 22:54:29 +03:00
|
|
|
}
|
2001-03-10 12:35:44 +03:00
|
|
|
|
2015-10-30 10:12:00 +03:00
|
|
|
if (mOverview) {
|
2017-09-08 04:25:25 +03:00
|
|
|
// OnCacheEntryVisitCompleted() is not called when we do not iterate
|
2001-03-10 12:35:44 +03:00
|
|
|
// cache entries. Since this moves forward to the next storage in
|
2010-07-03 00:56:09 +04:00
|
|
|
// the list we want to visit, artificially call it here.
|
|
|
|
OnCacheEntryVisitCompleted();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-03-10 12:35:44 +03:00
|
|
|
|
2016-05-12 17:19:00 +03:00
|
|
|
return NS_OK;
|
2001-03-10 12:35:44 +03:00
|
|
|
}
|
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
NS_IMETHODIMP
|
2016-05-17 12:20:00 +03:00
|
|
|
nsAboutCache::Channel::OnCacheEntryInfo(nsIURI *aURI,
|
2014-05-01 15:28:12 +04:00
|
|
|
const nsACString &aIdEnhance,
|
2016-05-17 12:20:00 +03:00
|
|
|
int64_t aDataSize, int32_t aFetchCount,
|
|
|
|
uint32_t aLastModified,
|
|
|
|
uint32_t aExpirationTime, bool aPinned,
|
|
|
|
nsILoadContextInfo *aInfo) {
|
|
|
|
// We need mStream for this
|
2014-05-01 15:28:12 +04:00
|
|
|
if (!mStream || mCancel) {
|
2016-05-12 17:19:00 +03:00
|
|
|
// Returning a failure from this callback stops the iteration
|
2014-05-01 15:28:12 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
if (!mEntriesHeaderAdded) {
|
|
|
|
mBuffer.AppendLiteral(
|
2018-11-30 13:46:48 +03:00
|
|
|
"<hr/>\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
"<table id=\"entries\">\n"
|
|
|
|
" <colgroup>\n"
|
|
|
|
" <col id=\"col-key\">\n"
|
|
|
|
" <col id=\"col-dataSize\">\n"
|
|
|
|
" <col id=\"col-fetchCount\">\n"
|
|
|
|
" <col id=\"col-lastModified\">\n"
|
|
|
|
" <col id=\"col-expires\">\n"
|
2015-10-30 10:12:00 +03:00
|
|
|
" <col id=\"col-pinned\">\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
" </colgroup>\n"
|
|
|
|
" <thead>\n"
|
|
|
|
" <tr>\n"
|
|
|
|
" <th>Key</th>\n"
|
|
|
|
" <th>Data size</th>\n"
|
|
|
|
" <th>Fetch count</th>\n"
|
|
|
|
" <th>Last Modifed</th>\n"
|
|
|
|
" <th>Expires</th>\n"
|
2015-10-30 10:12:00 +03:00
|
|
|
" <th>Pinning</th>\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
" </tr>\n"
|
|
|
|
" </thead>\n");
|
|
|
|
mEntriesHeaderAdded = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2001-03-13 23:06:42 +03:00
|
|
|
// Generate a about:cache-entry URL for this entry...
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsAutoCString url;
|
|
|
|
url.AssignLiteral("about:cache-entry?storage=");
|
2017-12-21 22:39:42 +03:00
|
|
|
nsAppendEscapedHTML(mStorageName, url);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
url.AppendLiteral("&context=");
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAppendEscapedHTML(mContextString, url);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
url.AppendLiteral("&eid=");
|
2017-12-21 22:39:42 +03:00
|
|
|
nsAppendEscapedHTML(aIdEnhance, url);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
nsAutoCString cacheUriSpec;
|
|
|
|
aURI->GetAsciiSpec(cacheUriSpec);
|
2017-08-18 05:00:59 +03:00
|
|
|
nsAutoCString escapedCacheURI;
|
|
|
|
nsAppendEscapedHTML(cacheUriSpec, escapedCacheURI);
|
2014-05-01 15:28:12 +04:00
|
|
|
url.AppendLiteral("&uri=");
|
|
|
|
url += escapedCacheURI;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-03-13 23:06:42 +03:00
|
|
|
// Entry start...
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral(" <tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
// URI
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" <td><a href=\"");
|
2001-03-13 23:06:42 +03:00
|
|
|
mBuffer.Append(url);
|
2004-12-04 13:19:29 +03:00
|
|
|
mBuffer.AppendLiteral("\">");
|
2014-05-01 15:28:12 +04:00
|
|
|
if (!aIdEnhance.IsEmpty()) {
|
2017-12-21 22:39:42 +03:00
|
|
|
nsAppendEscapedHTML(aIdEnhance, mBuffer);
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.Append(':');
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.Append(escapedCacheURI);
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral("</a></td>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-03-10 12:35:44 +03:00
|
|
|
// Content length
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" <td>");
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendInt(aDataSize);
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" bytes</td>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-03-10 12:35:44 +03:00
|
|
|
// Number of accesses
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" <td>");
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendInt(aFetchCount);
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral("</td>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-04-06 04:57:36 +04:00
|
|
|
// vars for reporting time
|
2001-03-10 12:35:44 +03:00
|
|
|
char buf[255];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-04-06 04:57:36 +04:00
|
|
|
// Last modified time
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" <td>");
|
2014-05-01 15:28:12 +04:00
|
|
|
if (aLastModified) {
|
|
|
|
PrintTimeString(buf, sizeof(buf), aLastModified);
|
2001-03-10 12:35:44 +03:00
|
|
|
mBuffer.Append(buf);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2016-07-25 17:26:00 +03:00
|
|
|
mBuffer.AppendLiteral("No last modified time");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral("</td>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-03-10 12:35:44 +03:00
|
|
|
// Expires time
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" <td>");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-28 22:54:29 +03:00
|
|
|
// Bug - 633747.
|
2017-05-02 18:18:34 +03:00
|
|
|
// When expiration time is 0, we show 1970-01-01 01:00:00 which is confusing.
|
|
|
|
// So we check if time is 0, then we show a message, "Expired Immediately"
|
2017-04-28 22:54:29 +03:00
|
|
|
if (aExpirationTime == 0) {
|
|
|
|
mBuffer.AppendLiteral("Expired Immediately");
|
|
|
|
} else if (aExpirationTime < 0xFFFFFFFF) {
|
2014-05-01 15:28:12 +04:00
|
|
|
PrintTimeString(buf, sizeof(buf), aExpirationTime);
|
2001-03-10 12:35:44 +03:00
|
|
|
mBuffer.Append(buf);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2004-12-04 13:19:29 +03:00
|
|
|
mBuffer.AppendLiteral("No expiration time");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral("</td>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-30 10:12:00 +03:00
|
|
|
// Pinning
|
|
|
|
mBuffer.AppendLiteral(" <td>");
|
2018-11-30 13:46:48 +03:00
|
|
|
if (aPinned) {
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.AppendLiteral("Pinned");
|
|
|
|
} else {
|
2017-09-08 04:25:25 +03:00
|
|
|
mBuffer.AppendLiteral(" ");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral("</td>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-03-13 23:06:42 +03:00
|
|
|
// Entry is done...
|
2010-07-03 00:56:09 +04:00
|
|
|
mBuffer.AppendLiteral(" </tr>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-03 09:53:30 +03:00
|
|
|
return FlushBuffer();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-04-06 04:57:36 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAboutCache::Channel::OnCacheEntryVisitCompleted() {
|
|
|
|
if (!mStream) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-04-06 04:57:36 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
if (mEntriesHeaderAdded) {
|
|
|
|
mBuffer.AppendLiteral("</table>\n");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-28 16:50:45 +03:00
|
|
|
// Kick another storage visiting (from a storage that allows us.)
|
|
|
|
while (mStorageList.Length()) {
|
2016-10-03 09:53:30 +03:00
|
|
|
nsresult rv = VisitNextStorage();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Expecting new round of OnCache* calls.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
// We are done!
|
2015-10-30 10:12:00 +03:00
|
|
|
mBuffer.AppendLiteral(
|
2018-11-30 13:46:48 +03:00
|
|
|
"</body>\n"
|
2018-04-28 16:50:45 +03:00
|
|
|
"<script src=\"chrome://global/content/aboutCache.js\">"
|
|
|
|
"</script>\n"
|
2014-05-01 15:28:12 +04:00
|
|
|
"</html>\n");
|
2016-10-03 09:53:30 +03:00
|
|
|
nsresult rv = FlushBuffer();
|
2016-05-12 17:19:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2016-10-03 09:53:30 +03:00
|
|
|
NS_WARNING("Failed to flush buffer");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-05-01 15:28:12 +04:00
|
|
|
mStream->Close();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-30 14:39:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-17 12:20:00 +03:00
|
|
|
nsresult nsAboutCache::Channel::FlushBuffer() {
|
2016-05-12 17:19:00 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
uint32_t bytesWritten;
|
2016-05-12 17:19:00 +03:00
|
|
|
rv = mStream->Write(mBuffer.get(), mBuffer.Length(), &bytesWritten);
|
2014-05-01 15:28:12 +04:00
|
|
|
mBuffer.Truncate();
|
2016-05-12 17:19:00 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mCancel = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2014-05-01 15:28:12 +04:00
|
|
|
}
|
2014-04-30 15:05:43 +04:00
|
|
|
|
2014-05-01 15:28:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAboutCache::GetURIFlags(nsIURI *aURI, uint32_t *result) {
|
2017-02-02 18:10:11 +03:00
|
|
|
*result = nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT;
|
2014-05-01 15:28:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2000-09-13 10:10:03 +04:00
|
|
|
nsresult nsAboutCache::Create(nsISupports *aOuter, REFNSIID aIID,
|
|
|
|
void **aResult) {
|
2019-03-05 21:43:02 +03:00
|
|
|
RefPtr<nsAboutCache> about = new nsAboutCache();
|
|
|
|
return about->QueryInterface(aIID, aResult);
|
2000-09-13 10:10:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|