Skip to content

Commit

Permalink
Bug 1875001 - Remove unused features from nsDirIndexParser. r=necko-r…
Browse files Browse the repository at this point in the history
…eviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D198797
  • Loading branch information
vyv03354 committed Jan 27, 2024
1 parent fa09c95 commit 2f27be1
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 125 deletions.
10 changes: 1 addition & 9 deletions modules/libjar/nsIZipReader.idl
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,13 @@ interface nsIZipReader : nsISupports
*/
nsIUTF8StringEnumerator findEntries(in AUTF8String aPattern);

/**
* Returns an input stream containing the contents of the specified zip
* entry.
* @param zipEntry the name of the entry to open the stream from
*/
nsIInputStream getInputStream(in AUTF8String zipEntry);

/**
* Returns an input stream containing the contents of the specified zip
* entry. If the entry refers to a directory (ends with '/'), a directory stream
* is opened, otherwise the contents of the file entry is returned.
* @param aJarSpec the Spec of the URI for the JAR (only used for directory streams)
* @param zipEntry the name of the entry to open the stream from
*/
nsIInputStream getInputStreamWithSpec(in AUTF8String aJarSpec, in AUTF8String zipEntry);
nsIInputStream getInputStream(in AUTF8String zipEntry);
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 3 additions & 12 deletions modules/libjar/nsJAR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,14 @@ nsJAR::FindEntries(const nsACString& aPattern,
}

NS_IMETHODIMP
nsJAR::GetInputStream(const nsACString& aFilename, nsIInputStream** result) {
return GetInputStreamWithSpec(""_ns, aFilename, result);
}

NS_IMETHODIMP
nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,
const nsACString& aEntryName,
nsIInputStream** result) {
nsJAR::GetInputStream(const nsACString& aEntryName, nsIInputStream** result) {
NS_ENSURE_ARG_POINTER(result);
RecursiveMutexAutoLock lock(mLock);
if (!mZip) {
return NS_ERROR_FAILURE;
}

LOG(("GetInputStreamWithSpec[%p] %s %s", this,
PromiseFlatCString(aJarDirSpec).get(),
PromiseFlatCString(aEntryName).get()));
LOG(("GetInputStream[%p] %s", this, PromiseFlatCString(aEntryName).get()));
// Watch out for the jar:foo.zip!/ (aDir is empty) top-level special case!
nsZipItem* item = nullptr;
const nsCString& entry = PromiseFlatCString(aEntryName);
Expand All @@ -318,7 +309,7 @@ nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,

nsresult rv = NS_OK;
if (!item || item->IsDirectory()) {
rv = jis->InitDirectory(this, aJarDirSpec, entry.get());
rv = jis->InitDirectory(this, entry.get());
} else {
RefPtr<nsZipHandle> fd = mZip->GetFD();
rv = jis->InitFile(fd, mZip->GetData(item), item);
Expand Down
49 changes: 11 additions & 38 deletions modules/libjar/nsJARChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,13 @@ class nsJARInputThunk : public nsIInputStream {
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIINPUTSTREAM

nsJARInputThunk(nsIZipReader* zipReader, nsIURI* fullJarURI,
const nsACString& jarEntry, bool usingJarCache)
nsJARInputThunk(nsIZipReader* zipReader, const nsACString& jarEntry,
bool usingJarCache)
: mUsingJarCache(usingJarCache),
mJarReader(zipReader),
mJarEntry(jarEntry),
mContentLength(-1) {
MOZ_DIAGNOSTIC_ASSERT(zipReader, "zipReader must not be null");
if (ENTRY_IS_DIRECTORY(mJarEntry) && fullJarURI) {
nsCOMPtr<nsIURI> urlWithoutQueryRef;
nsresult rv = NS_MutateURI(fullJarURI)
.SetQuery(""_ns)
.SetRef(""_ns)
.Finalize(urlWithoutQueryRef);
if (NS_SUCCEEDED(rv) && urlWithoutQueryRef) {
rv = urlWithoutQueryRef->GetAsciiSpec(mJarDirSpec);
MOZ_ASSERT(NS_SUCCEEDED(rv), "Finding a jar dir spec shouldn't fail.");
} else {
MOZ_CRASH("Shouldn't fail to strip query and ref off jar URI.");
}
}
}

int64_t GetContentLength() { return mContentLength; }
Expand All @@ -102,7 +89,6 @@ class nsJARInputThunk : public nsIInputStream {

bool mUsingJarCache;
nsCOMPtr<nsIZipReader> mJarReader;
nsCString mJarDirSpec;
nsCOMPtr<nsIInputStream> mJarStream;
nsCString mJarEntry;
int64_t mContentLength;
Expand All @@ -114,18 +100,8 @@ nsresult nsJARInputThunk::Init() {
if (!mJarReader) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv;
if (ENTRY_IS_DIRECTORY(mJarEntry)) {
// A directory stream also needs the Spec of the FullJarURI
// because is included in the stream data itself.

NS_ENSURE_STATE(!mJarDirSpec.IsEmpty());

rv = mJarReader->GetInputStreamWithSpec(mJarDirSpec, mJarEntry,
getter_AddRefs(mJarStream));
} else {
rv = mJarReader->GetInputStream(mJarEntry, getter_AddRefs(mJarStream));
}
nsresult rv =
mJarReader->GetInputStream(mJarEntry, getter_AddRefs(mJarStream));
if (NS_FAILED(rv)) {
return rv;
}
Expand Down Expand Up @@ -290,7 +266,7 @@ nsresult nsJARChannel::CreateJarInput(nsIZipReaderCache* jarCache,
if (NS_FAILED(rv)) return rv;

RefPtr<nsJARInputThunk> input =
new nsJARInputThunk(reader, mJarURI, mJarEntry, jarCache != nullptr);
new nsJARInputThunk(reader, mJarEntry, jarCache != nullptr);
rv = input->Init();
if (NS_FAILED(rv)) {
return rv;
Expand Down Expand Up @@ -354,7 +330,7 @@ nsresult nsJARChannel::LookupFile() {

nsresult CreateLocalJarInput(nsIZipReaderCache* aJarCache, nsIFile* aFile,
const nsACString& aInnerJarEntry,
nsIJARURI* aJarURI, const nsACString& aJarEntry,
const nsACString& aJarEntry,
nsJARInputThunk** aResultInput) {
LOG(("nsJARChannel::CreateLocalJarInput [aJarCache=%p, %s, %s]\n", aJarCache,
PromiseFlatCString(aInnerJarEntry).get(),
Expand All @@ -377,7 +353,7 @@ nsresult CreateLocalJarInput(nsIZipReaderCache* aJarCache, nsIFile* aFile,
}

RefPtr<nsJARInputThunk> input =
new nsJARInputThunk(reader, aJarURI, aJarEntry, aJarCache != nullptr);
new nsJARInputThunk(reader, aJarEntry, aJarCache != nullptr);
rv = input->Init();
if (NS_FAILED(rv)) {
return rv;
Expand Down Expand Up @@ -425,19 +401,16 @@ nsresult nsJARChannel::OpenLocalFile() {
return rv;
}

nsCOMPtr<nsIJARURI> localJARURI = mJarURI;

nsAutoCString jarEntry(mJarEntry);
nsAutoCString innerJarEntry(mInnerJarEntry);

RefPtr<nsJARChannel> self = this;
return mWorker->Dispatch(NS_NewRunnableFunction(
"nsJARChannel::OpenLocalFile", [self, jarCache, clonedFile, localJARURI,
jarEntry, innerJarEntry]() mutable {
"nsJARChannel::OpenLocalFile",
[self, jarCache, clonedFile, jarEntry, innerJarEntry]() mutable {
RefPtr<nsJARInputThunk> input;
nsresult rv =
CreateLocalJarInput(jarCache, clonedFile, innerJarEntry,
localJARURI, jarEntry, getter_AddRefs(input));
nsresult rv = CreateLocalJarInput(jarCache, clonedFile, innerJarEntry,
jarEntry, getter_AddRefs(input));

nsCOMPtr<nsIRunnable> target;
if (NS_SUCCEEDED(rv)) {
Expand Down
8 changes: 2 additions & 6 deletions modules/libjar/nsJARInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ nsresult nsJARInputStream::InitFile(nsZipHandle* aFd, const uint8_t* aData,
return NS_OK;
}

nsresult nsJARInputStream::InitDirectory(nsJAR* aJar,
const nsACString& aJarDirSpec,
const char* aDir) {
nsresult nsJARInputStream::InitDirectory(nsJAR* aJar, const char* aDir) {
MOZ_ASSERT(aJar, "Argument may not be null");
MOZ_ASSERT(aDir, "Argument may not be null");

Expand Down Expand Up @@ -141,10 +139,8 @@ nsresult nsJARInputStream::InitDirectory(nsJAR* aJar,
// Sort it
mArray.Sort();

mBuffer.AssignLiteral("300: ");
mBuffer.Append(aJarDirSpec);
mBuffer.AppendLiteral(
"\n200: filename content-length last-modified file-type\n");
"200: filename content-length last-modified file-type\n");

// Open for reading
mMode = MODE_DIRECTORY;
Expand Down
3 changes: 1 addition & 2 deletions modules/libjar/nsJARInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class nsJARInputStream final : public nsIInputStream {
// takes ownership of |fd|, even on failure
nsresult InitFile(nsZipHandle* aFd, const uint8_t* aData, nsZipItem* item);

nsresult InitDirectory(nsJAR* aJar, const nsACString& aJarDirSpec,
const char* aDir);
nsresult InitDirectory(nsJAR* aJar, const char* aDir);

private:
~nsJARInputStream() { Close(); }
Expand Down
8 changes: 0 additions & 8 deletions netwerk/base/nsDirectoryIndexStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "mozilla/Logging.h"
#include "prtime.h"
#include "nsIFile.h"
#include "nsURLHelper.h"
#include "nsNativeCharsetUtils.h"

// NOTE: This runs on the _file transport_ thread.
Expand Down Expand Up @@ -95,13 +94,6 @@ nsresult nsDirectoryIndexStream::Init(nsIFile* aDir) {

mArray.Sort(compare);

mBuf.AppendLiteral("300: ");
nsAutoCString url;
rv = net_GetURLSpecFromFile(aDir, url);
if (NS_FAILED(rv)) return rv;
mBuf.Append(url);
mBuf.Append('\n');

mBuf.AppendLiteral("200: filename content-length last-modified file-type\n");

return NS_OK;
Expand Down
11 changes: 0 additions & 11 deletions netwerk/protocol/gio/nsGIOProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,10 @@ nsresult nsGIOInputStream::DoOpenDirectory() {
mDirList = g_list_sort(mDirList, FileInfoComparator);
mDirListPtr = mDirList;

// Write base URL (make sure it ends with a '/')
mDirBuf.AppendLiteral("300: ");
mDirBuf.Append(mSpec);
if (mSpec.get()[mSpec.Length() - 1] != '/') {
mDirBuf.Append('/');
}
mDirBuf.Append('\n');

// Write column names
mDirBuf.AppendLiteral(
"200: filename content-length last-modified file-type\n");

// Write charset (assume UTF-8)
// XXX is this correct?
mDirBuf.AppendLiteral("301: UTF-8\n");
SetContentTypeOfChannel(APPLICATION_HTTP_INDEX_FORMAT);
return NS_OK;
}
Expand Down
14 changes: 1 addition & 13 deletions netwerk/streamconv/converters/nsDirIndexParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,7 @@ nsresult nsDirIndexParser::ProcessData(nsIRequest* aRequest) {
if (lineLen >= 4) {
const char* buf = line;

if (buf[0] == '1') {
if (buf[1] == '0') {
if (buf[2] == '0' && buf[3] == ':') {
// 100. Human-readable comment line. Ignore
} else if (buf[2] == '1' && buf[3] == ':') {
// 101. Human-readable information line.
char* value = ((char*)buf) + 4;
nsUnescape(value);
mListener->OnInformationAvailable(aRequest,
NS_ConvertUTF8toUTF16(value));
}
}
} else if (buf[0] == '2') {
if (buf[0] == '2') {
if (buf[1] == '0') {
if (buf[2] == '0' && buf[3] == ':') {
// 200. Define field names
Expand Down
16 changes: 0 additions & 16 deletions netwerk/streamconv/converters/nsIndexedToHTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,22 +813,6 @@ nsIndexedToHTML::OnIndexAvailable(nsIRequest* aRequest, nsIDirIndex* aIndex) {
return SendToListener(aRequest, pushBuffer);
}

NS_IMETHODIMP
nsIndexedToHTML::OnInformationAvailable(nsIRequest* aRequest,
const nsAString& aInfo) {
nsAutoCString pushBuffer;
nsAutoCString escapedUtf8;
nsAppendEscapedHTML(NS_ConvertUTF16toUTF8(aInfo), escapedUtf8);
pushBuffer.AppendLiteral("<tr>\n <td>");
// escaped is provided in Unicode, so write hex NCRs as necessary
// to prevent the HTML parser from applying a character set.
AppendNonAsciiToNCR(NS_ConvertUTF8toUTF16(escapedUtf8), pushBuffer);
pushBuffer.AppendLiteral(
"</td>\n <td></td>\n <td></td>\n <td></td>\n</tr>\n");

return SendToListener(aRequest, pushBuffer);
}

void nsIndexedToHTML::FormatSizeString(int64_t inSize,
nsCString& outSizeString) {
outSizeString.Truncate();
Expand Down
10 changes: 0 additions & 10 deletions netwerk/streamconv/nsIDirIndexListener.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ interface nsIDirIndexListener : nsISupports {
*/
void onIndexAvailable(in nsIRequest aRequest,
in nsIDirIndex aIndex);

/**
* Called for each information line
*
* @param request - the request
* @param info - new info to add
*/
void onInformationAvailable(in nsIRequest aRequest,
in AString aInfo);

};

/**
Expand Down

0 comments on commit 2f27be1

Please sign in to comment.