Bug 1413854 - Remove nsTXTToHTMLConv as it is no longer used. r=dragana

--HG--
extra : rebase_source : 29f8a6eaf02fa406499ac48fda99bb67df444506
This commit is contained in:
Marco Castelluccio 2018-03-31 16:08:37 +02:00
Родитель cec649f670
Коммит fd5bc8ec6c
4 изменённых файлов: 0 добавлений и 416 удалений

Просмотреть файл

@ -402,13 +402,6 @@ nsresult NS_NewFTPDirListingConv(nsFTPDirListingConv** result);
#include "mozTXTToHTMLConv.h"
#include "nsUnknownDecoder.h"
#include "nsTXTToHTMLConv.h"
namespace mozilla {
namespace net {
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsTXTToHTMLConv, Init)
} // namespace net
} // namespace mozilla
///////////////////////////////////////////////////////////////////////////////
#ifdef BUILD_NETWORK_INFO_SERVICE
@ -437,7 +430,6 @@ nsresult NS_NewStreamConv(nsStreamConverterService **aStreamConv);
#define COMPRESS_TO_UNCOMPRESSED "?from=compress&to=uncompressed"
#define XCOMPRESS_TO_UNCOMPRESSED "?from=x-compress&to=uncompressed"
#define DEFLATE_TO_UNCOMPRESSED "?from=deflate&to=uncompressed"
#define PLAIN_TO_HTML "?from=text/plain&to=text/html"
static const mozilla::Module::CategoryEntry kNeckoCategories[] = {
{ NS_ISTREAMCONVERTER_KEY, FTP_TO_INDEX, "" },
@ -452,7 +444,6 @@ static const mozilla::Module::CategoryEntry kNeckoCategories[] = {
{ NS_ISTREAMCONVERTER_KEY, COMPRESS_TO_UNCOMPRESSED, "" },
{ NS_ISTREAMCONVERTER_KEY, XCOMPRESS_TO_UNCOMPRESSED, "" },
{ NS_ISTREAMCONVERTER_KEY, DEFLATE_TO_UNCOMPRESSED, "" },
{ NS_ISTREAMCONVERTER_KEY, PLAIN_TO_HTML, "" },
NS_BINARYDETECTOR_CATEGORYENTRY,
{ nullptr }
};
@ -720,7 +711,6 @@ NS_DEFINE_NAMED_CID(NS_MULTIMIXEDCONVERTER_CID);
NS_DEFINE_NAMED_CID(NS_UNKNOWNDECODER_CID);
NS_DEFINE_NAMED_CID(NS_BINARYDETECTOR_CID);
NS_DEFINE_NAMED_CID(NS_HTTPCOMPRESSCONVERTER_CID);
NS_DEFINE_NAMED_CID(NS_NSTXTTOHTMLCONVERTER_CID);
NS_DEFINE_NAMED_CID(MOZITXTTOHTMLCONV_CID);
NS_DEFINE_NAMED_CID(NS_DIRINDEX_CID);
NS_DEFINE_NAMED_CID(NS_MIMEHEADERPARAM_CID);
@ -844,7 +834,6 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_UNKNOWNDECODER_CID, false, nullptr, CreateNewUnknownDecoderFactory },
{ &kNS_BINARYDETECTOR_CID, false, nullptr, CreateNewBinaryDetectorFactory },
{ &kNS_HTTPCOMPRESSCONVERTER_CID, false, nullptr, CreateNewHTTPCompressConvFactory },
{ &kNS_NSTXTTOHTMLCONVERTER_CID, false, nullptr, mozilla::net::nsTXTToHTMLConvConstructor },
{ &kMOZITXTTOHTMLCONV_CID, false, nullptr, CreateNewTXTToHTMLConvFactory },
{ &kNS_DIRINDEX_CID, false, nullptr, nsDirIndexConstructor },
{ &kNS_MIMEHEADERPARAM_CID, false, nullptr, nsMIMEHeaderParamImplConstructor },
@ -975,7 +964,6 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_ISTREAMCONVERTER_KEY COMPRESS_TO_UNCOMPRESSED, &kNS_HTTPCOMPRESSCONVERTER_CID },
{ NS_ISTREAMCONVERTER_KEY XCOMPRESS_TO_UNCOMPRESSED, &kNS_HTTPCOMPRESSCONVERTER_CID },
{ NS_ISTREAMCONVERTER_KEY DEFLATE_TO_UNCOMPRESSED, &kNS_HTTPCOMPRESSCONVERTER_CID },
{ NS_ISTREAMCONVERTER_KEY PLAIN_TO_HTML, &kNS_NSTXTTOHTMLCONVERTER_CID },
{ MOZ_TXTTOHTMLCONV_CONTRACTID, &kMOZITXTTOHTMLCONV_CID },
{ "@mozilla.org/dirIndex;1", &kNS_DIRINDEX_CID },
{ NS_MIMEHEADERPARAM_CONTRACTID, &kNS_MIMEHEADERPARAM_CID },

Просмотреть файл

@ -18,7 +18,6 @@ UNIFIED_SOURCES += [
'nsHTTPCompressConv.cpp',
'nsIndexedToHTML.cpp',
'nsMultiMixedConv.cpp',
'nsTXTToHTMLConv.cpp',
'nsUnknownDecoder.cpp',
'ParseFTPList.cpp',
]

Просмотреть файл

@ -1,314 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#include "nsTXTToHTMLConv.h"
#include "nsEscape.h"
#include "nsStringStream.h"
#include "nsAutoPtr.h"
#include "nsIChannel.h"
#include <algorithm>
#include "mozilla/UniquePtrExtensions.h"
#define TOKEN_DELIMITERS u"\t\r\n "
using namespace mozilla;
// nsISupports methods
NS_IMPL_ISUPPORTS(nsTXTToHTMLConv,
nsIStreamConverter,
nsITXTToHTMLConv,
nsIRequestObserver,
nsIStreamListener)
// nsIStreamConverter methods
NS_IMETHODIMP
nsTXTToHTMLConv::Convert(nsIInputStream *aFromStream,
const char *aFromType, const char *aToType,
nsISupports *aCtxt, nsIInputStream * *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsTXTToHTMLConv::AsyncConvertData(const char *aFromType,
const char *aToType,
nsIStreamListener *aListener,
nsISupports *aCtxt)
{
NS_ASSERTION(aListener, "null pointer");
mListener = aListener;
return NS_OK;
}
// nsIRequestObserver methods
NS_IMETHODIMP
nsTXTToHTMLConv::OnStartRequest(nsIRequest* request, nsISupports *aContext)
{
mBuffer.AssignLiteral("<html>\n<head><title>");
mBuffer.Append(mPageTitle);
mBuffer.AppendLiteral("</title></head>\n<body>\n");
if (mPreFormatHTML) { // Use <pre> tags
mBuffer.AppendLiteral("<pre>\n");
}
// Push mBuffer to the listener now, so the initial HTML will not
// be parsed in OnDataAvailable().
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel)
channel->SetContentType(NS_LITERAL_CSTRING("text/html"));
// else, assume there is a channel somewhere that knows what it is doing!
nsresult rv = mListener->OnStartRequest(request, aContext);
if (NS_FAILED(rv)) return rv;
// The request may have been canceled, and if that happens, we want to
// suppress calls to OnDataAvailable.
request->GetStatus(&rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> inputData;
rv = NS_NewCStringInputStream(getter_AddRefs(inputData),
NS_LossyConvertUTF16toASCII(mBuffer));
if (NS_FAILED(rv)) return rv;
rv = mListener->OnDataAvailable(request, aContext,
inputData, 0, mBuffer.Length());
if (NS_FAILED(rv)) return rv;
mBuffer.Truncate();
return rv;
}
NS_IMETHODIMP
nsTXTToHTMLConv::OnStopRequest(nsIRequest* request, nsISupports *aContext,
nsresult aStatus)
{
nsresult rv = NS_OK;
if (mToken) {
// we still have an outstanding token
NS_ASSERTION(mToken->prepend,
"Non prepending tokens should be handled in "
"OnDataAvailable. There should only be a single "
"prepending token left to be processed.");
(void)CatHTML(0, mBuffer.Length());
}
if (mPreFormatHTML) {
mBuffer.AppendLiteral("</pre>\n");
}
mBuffer.AppendLiteral("\n</body></html>");
nsCOMPtr<nsIInputStream> inputData;
rv = NS_NewCStringInputStream(getter_AddRefs(inputData),
NS_LossyConvertUTF16toASCII(mBuffer));
if (NS_FAILED(rv)) return rv;
rv = mListener->OnDataAvailable(request, aContext,
inputData, 0, mBuffer.Length());
if (NS_FAILED(rv)) return rv;
return mListener->OnStopRequest(request, aContext, aStatus);
}
// nsITXTToHTMLConv methods
NS_IMETHODIMP
nsTXTToHTMLConv::SetTitle(const char16_t *aTitle)
{
mPageTitle.Assign(aTitle);
return NS_OK;
}
NS_IMETHODIMP
nsTXTToHTMLConv::PreFormatHTML(bool value)
{
mPreFormatHTML = value;
return NS_OK;
}
// nsIStreamListener method
NS_IMETHODIMP
nsTXTToHTMLConv::OnDataAvailable(nsIRequest* request, nsISupports *aContext,
nsIInputStream *aInStream,
uint64_t aOffset, uint32_t aCount)
{
nsresult rv = NS_OK;
nsString pushBuffer;
uint32_t amtRead = 0;
auto buffer = MakeUniqueFallible<char[]>(aCount+1);
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
do {
uint32_t read = 0;
// XXX readSegments, to avoid the first copy?
rv = aInStream->Read(buffer.get(), aCount-amtRead, &read);
if (NS_FAILED(rv)) return rv;
buffer[read] = '\0';
// XXX charsets?? non-latin1 characters?? utf-16??
AppendASCIItoUTF16(buffer.get(), mBuffer);
amtRead += read;
int32_t front = -1, back = -1, tokenLoc = -1, cursor = 0;
while ( (tokenLoc = FindToken(cursor, &mToken)) > -1) {
if (mToken->prepend) {
front = mBuffer.RFindCharInSet(TOKEN_DELIMITERS, tokenLoc);
front++;
back = mBuffer.FindCharInSet(TOKEN_DELIMITERS, tokenLoc);
} else {
front = tokenLoc;
back = front + mToken->token.Length();
}
if (back == -1) {
// didn't find an ending, buffer up.
mBuffer.Left(pushBuffer, front);
cursor = front;
break;
}
// found the end of the token.
cursor = CatHTML(front, back);
}
int32_t end = mBuffer.RFind(TOKEN_DELIMITERS, mBuffer.Length());
mBuffer.Left(pushBuffer, std::max(cursor, end));
mBuffer.Cut(0, std::max(cursor, end));
cursor = 0;
if (!pushBuffer.IsEmpty()) {
nsCOMPtr<nsIInputStream> inputData;
rv = NS_NewCStringInputStream(getter_AddRefs(inputData),
NS_LossyConvertUTF16toASCII(pushBuffer));
if (NS_FAILED(rv))
return rv;
rv = mListener->OnDataAvailable(request, aContext,
inputData, 0, pushBuffer.Length());
if (NS_FAILED(rv))
return rv;
}
} while (amtRead < aCount);
return rv;
}
// nsTXTToHTMLConv methods
nsTXTToHTMLConv::nsTXTToHTMLConv()
{
mToken = nullptr;
mPreFormatHTML = false;
}
nsTXTToHTMLConv::~nsTXTToHTMLConv()
{
mTokens.Clear();
}
nsresult
nsTXTToHTMLConv::Init()
{
nsresult rv = NS_OK;
// build up the list of tokens to handle
convToken *token = new convToken;
if (!token) return NS_ERROR_OUT_OF_MEMORY;
token->prepend = false;
token->token.Assign(char16_t('<'));
token->modText.AssignLiteral("&lt;");
mTokens.AppendElement(token);
token = new convToken;
if (!token) return NS_ERROR_OUT_OF_MEMORY;
token->prepend = false;
token->token.Assign(char16_t('>'));
token->modText.AssignLiteral("&gt;");
mTokens.AppendElement(token);
token = new convToken;
if (!token) return NS_ERROR_OUT_OF_MEMORY;
token->prepend = false;
token->token.Assign(char16_t('&'));
token->modText.AssignLiteral("&amp;");
mTokens.AppendElement(token);
token = new convToken;
if (!token) return NS_ERROR_OUT_OF_MEMORY;
token->prepend = true;
token->token.AssignLiteral("http://"); // XXX need to iterate through all protos
mTokens.AppendElement(token);
token = new convToken;
if (!token) return NS_ERROR_OUT_OF_MEMORY;
token->prepend = true;
token->token.Assign(char16_t('@'));
token->modText.AssignLiteral("mailto:");
mTokens.AppendElement(token);
return rv;
}
int32_t
nsTXTToHTMLConv::FindToken(int32_t cursor, convToken* *_retval)
{
int32_t loc = -1, firstToken = mBuffer.Length();
int8_t token = -1;
for (uint8_t i=0; i < mTokens.Length(); i++) {
loc = mBuffer.Find(mTokens[i]->token, cursor);
if (loc != -1)
if (loc < firstToken) {
firstToken = loc;
token = i;
}
}
if (token == -1)
return -1;
*_retval = mTokens[token];
return firstToken;
}
int32_t
nsTXTToHTMLConv::CatHTML(int32_t front, int32_t back)
{
int32_t cursor = 0;
int32_t modLen = mToken->modText.Length();
if (!mToken->prepend) {
// replace the entire token (from delimiter to delimiter)
mBuffer.Cut(front, back - front);
mBuffer.Insert(mToken->modText, front);
cursor = front+modLen;
} else {
nsString linkText;
// href is implied
mBuffer.Mid(linkText, front, back-front);
mBuffer.InsertLiteral(u"<a href=\"", front);
cursor += front+9;
if (modLen) {
mBuffer.Insert(mToken->modText, cursor);
cursor += modLen;
}
NS_ConvertUTF16toUTF8 linkTextUTF8(linkText);
nsCString escaped;
if (NS_EscapeURL(linkTextUTF8.Data(), linkTextUTF8.Length(), esc_Minimal, escaped)) {
mBuffer.Cut(cursor, back - front);
CopyUTF8toUTF16(escaped, linkText);
mBuffer.Insert(linkText, cursor);
back = front + linkText.Length();
}
cursor += back-front;
mBuffer.InsertLiteral(u"\">", cursor);
cursor += 2;
mBuffer.Insert(linkText, cursor);
cursor += linkText.Length();
mBuffer.InsertLiteral(u"</a>", cursor);
cursor += 4;
}
mToken = nullptr; // indicates completeness
return cursor;
}

Просмотреть файл

@ -1,89 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#ifndef ____nstxttohtmlconv___h___
#define ____nstxttohtmlconv___h___
#include "nsITXTToHTMLConv.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsString.h"
#define NS_NSTXTTOHTMLCONVERTER_CID \
{ /* 9ef9fa14-1dd1-11b2-9d65-d72d6d1f025e */ \
0x9ef9fa14, \
0x1dd1, \
0x11b2, \
{0x9d, 0x65, 0xd7, 0x2d, 0x6d, 0x1f, 0x02, 0x5e} \
}
// Internal representation of a "token"
typedef struct convToken {
nsString token; // the actual string (i.e. "http://")
nsString modText; // replacement text or href prepend text.
bool prepend; // flag indicating how the modText should be used.
} convToken;
template<class T> class nsAutoPtr;
/**
* Convert plain text to HTML.
*
* OVERVIEW OF HOW THIS CLASS WORKS:
*
* This class stores an array of tokens that should be replaced by something,
* or something that should be prepended.
* The "token" member of convToken is the text to search for. This is a
* substring of the desired token. Tokens are delimited by TOKEN_DELIMITERS.
* That entire token will be replaced by modText (if prepend is false); or it
* will be linkified and modText will be prepended to the token if prepend is
* true.
*
* Note that all of the text will be in a preformatted block, so there is no
* need to emit line-end tags, or set the font face to monospace.
*
* This works as a stream converter, so data will arrive by
* OnStartRequest/OnDataAvailable/OnStopRequest calls.
*
* OStopR will possibly process a remaining token.
*
* If the data of one pass contains a part of a token, that part will be stored
* in mBuffer. The rest of the data will be sent to the next listener.
*
* XXX this seems suboptimal. this means that this design will only work for
* links. and it is impossible to append anything to the token. this means that,
* for example, making *foo* bold is not possible.
*/
class nsTXTToHTMLConv : public nsITXTToHTMLConv {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISTREAMCONVERTER
NS_DECL_NSITXTTOHTMLCONV
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
nsTXTToHTMLConv();
nsresult Init();
protected:
virtual ~nsTXTToHTMLConv();
// return the token and it's location in the underlying buffer.
int32_t FindToken(int32_t cursor, convToken* *_retval);
// return the cursor location after munging HTML into the
// underlying buffer, according to mToken
int32_t CatHTML(int32_t front, int32_t back);
nsCOMPtr<nsIStreamListener> mListener; // final listener (consumer)
nsString mBuffer; // any carry over data
nsTArray<nsAutoPtr<convToken> > mTokens; // list of tokens to search for
convToken *mToken; // current token (if any)
nsString mPageTitle; // Page title
bool mPreFormatHTML; // Whether to use <pre> tags
};
#endif // ____nstxttohtmlconv___h___