mirror of
https://github.com/roytam1/basilisk55.git
synced 2026-05-26 14:30:37 +00:00
partly import changes from tenfourfox:
- #565: implement nsASCIIMask from M1358297 (41b1fc937) - #565: M1358297 parts 3 and 4 (3fd15a87a) - #632: M1424915 M1354233 M1324114 M1343008 M1236277(just backbugs) M1328955 (d87db7e16) - #632: M1362498 M1397686 M136178 M1320252 M1355875 (82cb3b59e) - #632: M241788 M1271955 M1249352(p1) + additional local optimizations (438bdb726) - #632: M1249352 part 2 (2c61821e4) - #632: M1249352(remaining) M1358297(backbugs) M1369317(pp1,3,4) M1426996 (1eab6170b)
This commit is contained in:
@@ -176,7 +176,7 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI,
|
||||
nsAutoCString uriString(aStringURI);
|
||||
|
||||
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||
uriString.StripChars("\r\n");
|
||||
uriString.StripCRLF();
|
||||
// Cleanup the empty spaces and tabs that might be on each end:
|
||||
uriString.Trim(" \t");
|
||||
|
||||
|
||||
@@ -4740,7 +4740,7 @@ nsDocShell::LoadURIWithOptions(const char16_t* aURI,
|
||||
// Cleanup the empty spaces that might be on each end.
|
||||
uriString.Trim(" ");
|
||||
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||
uriString.StripChars("\r\n");
|
||||
uriString.StripCRLF();
|
||||
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriString);
|
||||
|
||||
@@ -6504,9 +6504,7 @@ nsContentUtils::FlushLayoutForTree(nsPIDOMWindowOuter* aWindow)
|
||||
|
||||
void nsContentUtils::RemoveNewlines(nsString &aString)
|
||||
{
|
||||
// strip CR/LF and null
|
||||
static const char badChars[] = {'\r', '\n', 0};
|
||||
aString.StripChars(badChars);
|
||||
aString.StripCRLF();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -5211,15 +5211,13 @@ HTMLInputElement::SanitizeValue(nsAString& aValue)
|
||||
case NS_FORM_INPUT_TEL:
|
||||
case NS_FORM_INPUT_PASSWORD:
|
||||
{
|
||||
char16_t crlf[] = { char16_t('\r'), char16_t('\n'), 0 };
|
||||
aValue.StripChars(crlf);
|
||||
aValue.StripCRLF();
|
||||
}
|
||||
break;
|
||||
case NS_FORM_INPUT_EMAIL:
|
||||
case NS_FORM_INPUT_URL:
|
||||
{
|
||||
char16_t crlf[] = { char16_t('\r'), char16_t('\n'), 0 };
|
||||
aValue.StripChars(crlf);
|
||||
aValue.StripCRLF();
|
||||
|
||||
aValue = nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(aValue);
|
||||
}
|
||||
|
||||
@@ -1586,7 +1586,7 @@ pref("network.http.spdy.enabled.http2", true);
|
||||
pref("network.http.spdy.enabled.deps", true);
|
||||
pref("network.http.spdy.enforce-tls-profile", false);
|
||||
pref("network.http.spdy.chunk-size", 16000);
|
||||
pref("network.http.spdy.timeout", 180);
|
||||
pref("network.http.spdy.timeout", 170);
|
||||
pref("network.http.spdy.coalesce-hostnames", true);
|
||||
pref("network.http.spdy.persistent-settings", false);
|
||||
pref("network.http.spdy.ping-threshold", 58);
|
||||
@@ -3568,7 +3568,7 @@ pref("intl.imm.vertical_writing.always_assume_not_supported", false);
|
||||
// We cannot retrieve active IME name with IMM32 API if a TIP of TSF is active.
|
||||
// This pref can specify active IME name when Japanese TIP is active.
|
||||
// For example:
|
||||
// Google Japanese Input: "Google ?¥æœ¬èªžå…¥??IMM32 ?¢ã‚¸?¥ãƒ¼??
|
||||
// Google Japanese Input: "Google 日本語入力 IMM32 モジュール"
|
||||
// ATOK 2011: "ATOK 2011" (similarly, e.g., ATOK 2013 is "ATOK 2013")
|
||||
pref("intl.imm.japanese.assume_active_tip_name_as", "");
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ struct PRFileDesc;
|
||||
[ptr] native PRFileDescPtr(PRFileDesc);
|
||||
[ptr] native nsASocketHandlerPtr(nsASocketHandler);
|
||||
|
||||
[scriptable, uuid(ad56b25f-e6bb-4db3-9f7b-5b7db33fd2b1)]
|
||||
[builtinclass, scriptable, uuid(ad56b25f-e6bb-4db3-9f7b-5b7db33fd2b1)]
|
||||
interface nsISocketTransportService : nsISupports
|
||||
{
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ interface nsISocketTransportService : nsISupports
|
||||
[noscript] void notifyWhenCanAttachSocket(in nsIRunnable aEvent);
|
||||
};
|
||||
|
||||
[scriptable, uuid(c5204623-5b58-4a16-8b2e-67c34dd02e3f)]
|
||||
[builtinclass, scriptable, uuid(c5204623-5b58-4a16-8b2e-67c34dd02e3f)]
|
||||
interface nsIRoutedSocketTransportService : nsISocketTransportService
|
||||
{
|
||||
// use this instead of createTransport when you have a transport
|
||||
|
||||
@@ -15,7 +15,7 @@ interface nsIOutputStream;
|
||||
* into a fully asynchronous stream that can be read/written without
|
||||
* blocking the main thread.
|
||||
*/
|
||||
[scriptable, uuid(5e0adf7d-9785-45c3-a193-04f25a75da8f)]
|
||||
[builtinclass, scriptable, uuid(5e0adf7d-9785-45c3-a193-04f25a75da8f)]
|
||||
interface nsIStreamTransportService : nsISupports
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* This is a private interface used by the internals of the networking library.
|
||||
* It will never be frozen. Do not use it in external code.
|
||||
*/
|
||||
[scriptable, uuid(18f73bf1-b35b-4b7b-aa9a-11bcbdbc389c)]
|
||||
[builtinclass, scriptable, uuid(18f73bf1-b35b-4b7b-aa9a-11bcbdbc389c)]
|
||||
|
||||
interface nsPISocketTransportService : nsIRoutedSocketTransportService
|
||||
{
|
||||
|
||||
@@ -1273,6 +1273,16 @@ nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags
|
||||
nsCOMPtr<nsIProxyInfo> pi;
|
||||
bool usePACThread;
|
||||
|
||||
// adapt to realtime changes in the system proxy service
|
||||
if (mProxyConfig == PROXYCONFIG_SYSTEM) {
|
||||
nsCOMPtr<nsISystemProxySettings> sp2 =
|
||||
do_GetService(NS_SYSTEMPROXYSETTINGS_CONTRACTID);
|
||||
if (sp2 != mSystemProxySettings) {
|
||||
mSystemProxySettings = sp2;
|
||||
ResetPACThread();
|
||||
}
|
||||
}
|
||||
|
||||
// SystemProxySettings and PAC files can block the main thread
|
||||
// but if neither of them are in use, we can just do the work
|
||||
// right here and directly invoke the callback
|
||||
|
||||
@@ -254,27 +254,22 @@ nsSimpleURI::SetSpec(const nsACString &aSpec)
|
||||
{
|
||||
NS_ENSURE_STATE(mMutable);
|
||||
|
||||
// filter out unexpected chars "\r\n\t" if necessary
|
||||
nsAutoCString filteredSpec;
|
||||
net_FilterURIString(aSpec, filteredSpec);
|
||||
nsresult rv = net_ExtractURLScheme(aSpec, mScheme);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
ToLowerCase(mScheme);
|
||||
|
||||
// nsSimpleURI currently restricts the charset to US-ASCII
|
||||
nsAutoCString spec;
|
||||
nsresult rv = NS_EscapeURL(filteredSpec, esc_OnlyNonASCII, spec, fallible);
|
||||
rv = net_FilterAndEscapeURI(aSpec, esc_OnlyNonASCII, spec);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
int32_t colonPos = spec.FindChar(':');
|
||||
if (colonPos < 0 || !net_IsValidScheme(spec.get(), colonPos))
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
|
||||
mScheme.Truncate();
|
||||
DebugOnly<int32_t> n = spec.Left(mScheme, colonPos);
|
||||
NS_ASSERTION(n == colonPos, "Left failed");
|
||||
ToLowerCase(mScheme);
|
||||
|
||||
MOZ_ASSERT(colonPos != kNotFound, "A colon should be in this string");
|
||||
// This sets mPath, mQuery and mRef.
|
||||
// If changed, see bug 1369317, especially part 2 -- Cameron
|
||||
return SetPath(Substring(spec, colonPos + 1));
|
||||
}
|
||||
|
||||
@@ -658,12 +653,12 @@ nsSimpleURI::Resolve(const nsACString &relativePath, nsACString &result)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSimpleURI::GetAsciiSpec(nsACString &result)
|
||||
nsSimpleURI::GetAsciiSpec(nsACString &aResult)
|
||||
{
|
||||
nsAutoCString buf;
|
||||
nsresult rv = GetSpec(buf);
|
||||
nsresult rv = GetSpec(aResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return NS_EscapeURL(buf, esc_OnlyNonASCII|esc_AlwaysCopy, result, fallible);
|
||||
MOZ_ASSERT(IsASCII(aResult), "The spec should be ASCII");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -1379,8 +1379,11 @@ nsStandardURL::SetSpec(const nsACString &input)
|
||||
{
|
||||
ENSURE_MUTABLE();
|
||||
|
||||
#if DEBUG
|
||||
// Don't pay the flat tax in optimized builds.
|
||||
const nsPromiseFlatCString &flat = PromiseFlatCString(input);
|
||||
LOG(("nsStandardURL::SetSpec [spec=%s]\n", flat.get()));
|
||||
#endif
|
||||
|
||||
if (input.Length() > (uint32_t) net_GetURLMaxLength()) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
@@ -1388,12 +1391,17 @@ nsStandardURL::SetSpec(const nsACString &input)
|
||||
|
||||
// filter out unexpected chars "\r\n\t" if necessary
|
||||
nsAutoCString filteredURI;
|
||||
net_FilterURIString(flat, filteredURI);
|
||||
net_FilterURIString(input, filteredURI);
|
||||
|
||||
if (filteredURI.Length() == 0) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
// NUL characters aren't allowed in the filtered URI.
|
||||
if (filteredURI.Contains('\0')) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
// Make a backup of the curent URL
|
||||
nsStandardURL prevURL(false,false);
|
||||
prevURL.CopyMembers(this, eHonorRef, EmptyCString());
|
||||
@@ -2241,11 +2249,9 @@ nsresult nsStandardURL::CopyMembers(nsStandardURL * source,
|
||||
NS_IMETHODIMP
|
||||
nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
{
|
||||
const nsPromiseFlatCString &flat = PromiseFlatCString(in);
|
||||
// filter out unexpected chars "\r\n\t" if necessary
|
||||
nsAutoCString buf;
|
||||
net_FilterURIString(flat, buf);
|
||||
|
||||
net_FilterURIString(in, buf);
|
||||
const char *relpath = buf.get();
|
||||
int32_t relpathLen = buf.Length();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "nsASCIIMask.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIURLParser.h"
|
||||
@@ -18,6 +19,7 @@
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "prnetdb.h"
|
||||
#include "mozilla/Tokenizer.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
@@ -522,7 +524,7 @@ net_ExtractURLScheme(const nsACString &inURI,
|
||||
}
|
||||
|
||||
p.Claim(scheme);
|
||||
scheme.StripChars("\r\n\t");
|
||||
scheme.StripTaggedASCII(ASCIIMask::MaskCRLFTab());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -591,8 +593,6 @@ net_IsAbsoluteURL(const nsACString& uri)
|
||||
void
|
||||
net_FilterURIString(const nsACString& input, nsACString& result)
|
||||
{
|
||||
const char kCharsToStrip[] = "\r\n\t";
|
||||
|
||||
result.Truncate();
|
||||
|
||||
auto start = input.BeginReading();
|
||||
@@ -607,9 +607,14 @@ net_FilterURIString(const nsACString& input, nsACString& result)
|
||||
charFilter).base();
|
||||
|
||||
// Check if chars need to be stripped.
|
||||
auto itr = std::find_first_of(
|
||||
newStart, newEnd, std::begin(kCharsToStrip), std::end(kCharsToStrip));
|
||||
const bool needsStrip = itr != newEnd;
|
||||
bool needsStrip = false;
|
||||
const ASCIIMaskArray& mask = ASCIIMask::MaskCRLFTab();
|
||||
for (auto itr = start; itr != end; ++itr) {
|
||||
if (ASCIIMask::IsMasked(mask, *itr)) {
|
||||
needsStrip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Just use the passed in string rather than creating new copies if no
|
||||
// changes are necessary.
|
||||
@@ -620,10 +625,31 @@ net_FilterURIString(const nsACString& input, nsACString& result)
|
||||
|
||||
result.Assign(Substring(newStart, newEnd));
|
||||
if (needsStrip) {
|
||||
result.StripChars(kCharsToStrip);
|
||||
result.StripTaggedASCII(mask);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
net_FilterAndEscapeURI(const nsACString& aInput, uint32_t aFlags, nsACString& aResult)
|
||||
{
|
||||
aResult.Truncate();
|
||||
|
||||
auto start = aInput.BeginReading();
|
||||
auto end = aInput.EndReading();
|
||||
|
||||
// Trim off leading and trailing invalid chars.
|
||||
auto charFilter = [](char c) { return static_cast<uint8_t>(c) > 0x20; };
|
||||
auto newStart = std::find_if(start, end, charFilter);
|
||||
auto newEnd = std::find_if(
|
||||
std::reverse_iterator<decltype(end)>(end),
|
||||
std::reverse_iterator<decltype(newStart)>(newStart),
|
||||
charFilter).base();
|
||||
|
||||
const ASCIIMaskArray& mask = ASCIIMask::MaskCRLFTab();
|
||||
return NS_EscapeAndFilterURL(Substring(newStart, newEnd), aFlags,
|
||||
&mask, aResult, fallible);
|
||||
}
|
||||
|
||||
|
||||
#if defined(XP_WIN)
|
||||
bool
|
||||
|
||||
@@ -115,6 +115,18 @@ inline bool net_IsValidScheme(const nsAFlatCString &scheme)
|
||||
*/
|
||||
void net_FilterURIString(const nsACString& input, nsACString& result);
|
||||
|
||||
/**
|
||||
* This function performs character stripping just like net_FilterURIString,
|
||||
* with the added benefit of also performing percent escaping of dissallowed
|
||||
* characters, all in one pass. Saving one pass is very important when operating
|
||||
* on really large strings.
|
||||
*
|
||||
* @param aInput the URL spec we want to filter
|
||||
* @param aFlags the flags which control which characters we escape
|
||||
* @param aResult the out param to write to if filtering happens
|
||||
*/
|
||||
nsresult net_FilterAndEscapeURI(const nsACString& aInput, uint32_t aFlags, nsACString& aResult);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
/**
|
||||
* On Win32 and OS/2 system's a back-slash in a file:// URL is equivalent to a
|
||||
|
||||
@@ -521,7 +521,7 @@ nsMIMEHeaderParamImpl::DoParameterInternal(const char *aHeaderValue,
|
||||
// if the parameter spans across multiple lines we have to strip out the
|
||||
// line continuation -- jht 4/29/98
|
||||
nsAutoCString tempStr(valueStart, valueEnd - valueStart);
|
||||
tempStr.StripChars("\r\n");
|
||||
tempStr.StripCRLF();
|
||||
char *res = ToNewCString(tempStr);
|
||||
NS_ENSURE_TRUE(res, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
@@ -764,7 +764,7 @@ internalDecodeRFC2047Header(const char* aHeaderVal, const char* aDefaultCharset,
|
||||
nsAutoCString temp(aResult);
|
||||
temp.ReplaceSubstring("\n\t", " ");
|
||||
temp.ReplaceSubstring("\r\t", " ");
|
||||
temp.StripChars("\r\n");
|
||||
temp.StripCRLF();
|
||||
aResult = temp;
|
||||
}
|
||||
|
||||
|
||||
@@ -2415,15 +2415,14 @@ Http2Session::ReadSegmentsAgain(nsAHttpSegmentReader *reader,
|
||||
this, stream, stream->StreamID()));
|
||||
FlushOutputQueue();
|
||||
SetWriteCallbacks();
|
||||
if (!mCannotDo0RTTStreams.Contains(stream)) {
|
||||
mCannotDo0RTTStreams.AppendElement(stream);
|
||||
}
|
||||
// We can still send our preamble
|
||||
*countRead = mOutputQueueUsed - mOutputQueueSent;
|
||||
return *countRead ? NS_OK : NS_BASE_STREAM_WOULD_BLOCK;
|
||||
}
|
||||
|
||||
if (!m0RTTStreams.Contains(stream->StreamID())) {
|
||||
m0RTTStreams.AppendElement(stream->StreamID());
|
||||
}
|
||||
|
||||
// Need to adjust this to only take as much as we can fit in with the
|
||||
// preamble/settings/priority stuff
|
||||
count -= (mOutputQueueUsed - mOutputQueueSent);
|
||||
@@ -2446,6 +2445,12 @@ Http2Session::ReadSegmentsAgain(nsAHttpSegmentReader *reader,
|
||||
*countRead += earlyDataUsed;
|
||||
}
|
||||
|
||||
if (mAttemptingEarlyData && !m0RTTStreams.Contains(stream)) {
|
||||
LOG3(("Http2Session::ReadSegmentsAgain adding stream %d to m0RTTStreams\n",
|
||||
stream->StreamID()));
|
||||
m0RTTStreams.AppendElement(stream);
|
||||
}
|
||||
|
||||
// Not every permutation of stream->ReadSegents produces data (and therefore
|
||||
// tries to flush the output queue) - SENDING_FIN_STREAM can be an example
|
||||
// of that. But we might still have old data buffered that would be good
|
||||
@@ -2872,7 +2877,9 @@ Http2Session::WriteSegmentsAgain(nsAHttpSegmentWriter *writer,
|
||||
"stream->writeSegments returning code %x\n",
|
||||
this, streamID, mNeedsCleanup, rv));
|
||||
MOZ_ASSERT(!mNeedsCleanup || mNeedsCleanup->StreamID() == streamID);
|
||||
CleanupStream(streamID, NS_OK, CANCEL_ERROR);
|
||||
CleanupStream(streamID,
|
||||
(rv == NS_BINDING_RETARGETED) ? NS_BINDING_RETARGETED : NS_OK,
|
||||
CANCEL_ERROR);
|
||||
mNeedsCleanup = nullptr;
|
||||
*again = false;
|
||||
ResumeRecv();
|
||||
@@ -3015,9 +3022,8 @@ Http2Session::Finish0RTT(bool aRestart, bool aAlpnChanged)
|
||||
// the transaction rewind and read it all over again. We only need to rewind
|
||||
// the transaction if we're switching to a new protocol, because our buffer
|
||||
// won't get used in that case.
|
||||
Http2Stream *stream = mStreamIDHash.Get(m0RTTStreams[i]);
|
||||
if (stream) {
|
||||
stream->Finish0RTT(aAlpnChanged, aAlpnChanged);
|
||||
if (m0RTTStreams[i]) {
|
||||
m0RTTStreams[i]->Finish0RTT(aRestart, aAlpnChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3039,15 +3045,27 @@ Http2Session::Finish0RTT(bool aRestart, bool aAlpnChanged)
|
||||
// This is the easy case - early data failed, but we're speaking h2, so
|
||||
// we just need to rewind to the beginning of the preamble and try again.
|
||||
mOutputQueueSent = 0;
|
||||
|
||||
for (size_t i = 0; i < mCannotDo0RTTStreams.Length(); ++i) {
|
||||
if (mCannotDo0RTTStreams[i] && VerifyStream(mCannotDo0RTTStreams[i])) {
|
||||
TransactionHasDataToWrite(mCannotDo0RTTStreams[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 0RTT succeeded
|
||||
for (size_t i = 0; i < mCannotDo0RTTStreams.Length(); ++i) {
|
||||
if (mCannotDo0RTTStreams[i] && VerifyStream(mCannotDo0RTTStreams[i])) {
|
||||
TransactionHasDataToWrite(mCannotDo0RTTStreams[i]);
|
||||
}
|
||||
}
|
||||
// Make sure we look for any incoming data in repsonse to our early data.
|
||||
ResumeRecv();
|
||||
}
|
||||
|
||||
mAttemptingEarlyData = false;
|
||||
m0RTTStreams.Clear();
|
||||
mCannotDo0RTTStreams.Clear();
|
||||
RealignOutputQueue();
|
||||
|
||||
return NS_OK;
|
||||
|
||||
@@ -500,7 +500,10 @@ private:
|
||||
|
||||
bool mAttemptingEarlyData;
|
||||
// The ID(s) of the stream(s) that we are getting 0RTT data from.
|
||||
nsTArray<uint32_t> m0RTTStreams;
|
||||
nsTArray<WeakPtr<Http2Stream>> m0RTTStreams;
|
||||
// The ID(s) of the stream(s) that are not able to send 0RTT data. We need to
|
||||
// remember them put them into mReadyForWrite queue when 0RTT finishes.
|
||||
nsTArray<WeakPtr<Http2Stream>> mCannotDo0RTTStreams;
|
||||
|
||||
private:
|
||||
/// connect tunnels
|
||||
|
||||
@@ -1495,8 +1495,8 @@ bool
|
||||
Http2Stream::Do0RTT()
|
||||
{
|
||||
MOZ_ASSERT(mTransaction);
|
||||
mAttempting0RTT = true;
|
||||
return mTransaction->Do0RTT();
|
||||
mAttempting0RTT = mTransaction->Do0RTT();
|
||||
return mAttempting0RTT;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
||||
@@ -127,8 +127,6 @@ static uint64_t gNumIntercepted = 0;
|
||||
(result) == NS_ERROR_OUT_OF_MEMORY)
|
||||
|
||||
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
|
||||
static NS_DEFINE_CID(kStreamTransportServiceCID,
|
||||
NS_STREAMTRANSPORTSERVICE_CID);
|
||||
|
||||
enum CacheDisposition {
|
||||
kCacheHit = 1,
|
||||
@@ -3552,9 +3550,10 @@ nsHttpChannel::OpenCacheEntry(bool isHttps)
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICacheStorageService> cacheStorageService =
|
||||
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService());
|
||||
if (!cacheStorageService) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICacheStorage> cacheStorage;
|
||||
nsCOMPtr<nsIURI> openURI;
|
||||
@@ -4717,8 +4716,8 @@ nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBufferi
|
||||
nsCOMPtr<nsITransport> transport;
|
||||
nsCOMPtr<nsIInputStream> wrapper;
|
||||
|
||||
nsCOMPtr<nsIStreamTransportService> sts =
|
||||
do_GetService(kStreamTransportServiceCID, &rv);
|
||||
nsCOMPtr<nsIStreamTransportService> sts(services::GetStreamTransportService());
|
||||
rv = sts ? NS_OK : NS_ERROR_NOT_AVAILABLE;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = sts->CreateInputTransport(stream, int64_t(-1), int64_t(-1),
|
||||
true, getter_AddRefs(transport));
|
||||
@@ -5256,9 +5255,10 @@ nsHttpChannel::InstallCacheListener(int64_t offset)
|
||||
|
||||
nsCOMPtr<nsIEventTarget> cacheIOTarget;
|
||||
if (!CacheObserver::UseNewCache()) {
|
||||
nsCOMPtr<nsICacheStorageService> serv =
|
||||
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsICacheStorageService> serv(services::GetCacheStorageService());
|
||||
if (!serv) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
serv->GetIoTarget(getter_AddRefs(cacheIOTarget));
|
||||
}
|
||||
@@ -6106,7 +6106,7 @@ nsHttpChannel::BeginConnectContinue()
|
||||
// Check to see if this principal exists on local blocklists.
|
||||
RefPtr<nsChannelClassifier> channelClassifier = new nsChannelClassifier(this);
|
||||
if (mLoadFlags & LOAD_CLASSIFY_URI) {
|
||||
nsCOMPtr<nsIURIClassifier> classifier = do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID);
|
||||
nsCOMPtr<nsIURIClassifier> classifier(services::GetURIClassifier());
|
||||
bool tpEnabled = false;
|
||||
channelClassifier->ShouldEnableTrackingProtection(&tpEnabled);
|
||||
if (classifier && tpEnabled) {
|
||||
@@ -8020,8 +8020,8 @@ nsHttpChannel::DoInvalidateCacheEntry(nsIURI* aURI)
|
||||
|
||||
LOG(("DoInvalidateCacheEntry [channel=%p key=%s]", this, key.get()));
|
||||
|
||||
nsCOMPtr<nsICacheStorageService> cacheStorageService =
|
||||
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
|
||||
nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService());
|
||||
rv = cacheStorageService ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsICacheStorage> cacheStorage;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsISSLSocketControl.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/net/DashboardTypes.h"
|
||||
#include "NullHttpTransaction.h"
|
||||
@@ -102,11 +103,13 @@ nsHttpConnectionMgr::~nsHttpConnectionMgr()
|
||||
nsresult
|
||||
nsHttpConnectionMgr::EnsureSocketThreadTarget()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIEventTarget> sts;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIIOService> ioService = services::GetIOService();
|
||||
if (ioService) {
|
||||
nsCOMPtr<nsISocketTransportService> realSTS =
|
||||
services::GetSocketTransportService();
|
||||
sts = do_QueryInterface(realSTS);
|
||||
}
|
||||
|
||||
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
||||
|
||||
@@ -116,7 +119,7 @@ nsHttpConnectionMgr::EnsureSocketThreadTarget()
|
||||
|
||||
mSocketThreadTarget = sts;
|
||||
|
||||
return rv;
|
||||
return sts ? NS_OK : NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -855,7 +858,7 @@ nsHttpConnectionMgr::GetSpdyPreferredEnt(nsConnectionEntry *aOriginalEntry)
|
||||
"with %s connections. rv=%x isJoined=%d",
|
||||
preferred->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(),
|
||||
rv, isJoined));
|
||||
Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, false);
|
||||
//Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -865,7 +868,7 @@ nsHttpConnectionMgr::GetSpdyPreferredEnt(nsConnectionEntry *aOriginalEntry)
|
||||
"so %s will be coalesced with %s",
|
||||
preferred->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(),
|
||||
aOriginalEntry->mConnInfo->Origin(), preferred->mConnInfo->Origin()));
|
||||
Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, true);
|
||||
//Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, true);
|
||||
return preferred;
|
||||
}
|
||||
|
||||
@@ -1197,6 +1200,7 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
|
||||
transport->SetConnectionFlags(flags);
|
||||
}
|
||||
|
||||
#if(0)
|
||||
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_USED_SPECULATIVE_CONN> usedSpeculativeConn;
|
||||
++usedSpeculativeConn;
|
||||
|
||||
@@ -1204,6 +1208,7 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
|
||||
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_USED> totalPreconnectsUsed;
|
||||
++totalPreconnectsUsed;
|
||||
}
|
||||
#endif
|
||||
|
||||
// return OK because we have essentially opened a new connection
|
||||
// by converting a speculative half-open to general use
|
||||
@@ -1843,6 +1848,7 @@ nsHttpConnectionMgr::BuildPipeline(nsConnectionEntry *ent,
|
||||
void
|
||||
nsHttpConnectionMgr::ReportProxyTelemetry(nsConnectionEntry *ent)
|
||||
{
|
||||
#if(0)
|
||||
enum { PROXY_NONE = 1, PROXY_HTTP = 2, PROXY_SOCKS = 3, PROXY_HTTPS = 4 };
|
||||
|
||||
if (!ent->mConnInfo->UsingProxy())
|
||||
@@ -1853,6 +1859,7 @@ nsHttpConnectionMgr::ReportProxyTelemetry(nsConnectionEntry *ent)
|
||||
Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_HTTP);
|
||||
else
|
||||
Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_SOCKS);
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -1902,7 +1909,7 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans)
|
||||
ent = preferredEntry;
|
||||
}
|
||||
|
||||
ReportProxyTelemetry(ent);
|
||||
//ReportProxyTelemetry(ent);
|
||||
|
||||
// Check if the transaction already has a sticky reference to a connection.
|
||||
// If so, then we can just use it directly by transferring its reference
|
||||
@@ -2000,13 +2007,13 @@ nsHttpConnectionMgr::CreateTransport(nsConnectionEntry *ent,
|
||||
if (speculative) {
|
||||
sock->SetSpeculative(true);
|
||||
sock->SetAllow1918(allow1918);
|
||||
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN> totalSpeculativeConn;
|
||||
++totalSpeculativeConn;
|
||||
//Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN> totalSpeculativeConn;
|
||||
//++totalSpeculativeConn;
|
||||
|
||||
if (isFromPredictor) {
|
||||
sock->SetIsFromPredictor(true);
|
||||
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_CREATED> totalPreconnectsCreated;
|
||||
++totalPreconnectsCreated;
|
||||
//Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_CREATED> totalPreconnectsCreated;
|
||||
//++totalPreconnectsCreated;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3035,8 +3042,10 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport,
|
||||
nsCOMPtr<nsISocketTransport> socketTransport;
|
||||
nsCOMPtr<nsISocketTransportService> sts;
|
||||
|
||||
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
sts = services::GetSocketTransportService();
|
||||
if (!sts) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
LOG(("nsHalfOpenSocket::SetupStreams [this=%p ent=%s] "
|
||||
"setup routed transport to origin %s:%d via %s:%d\n",
|
||||
@@ -3118,8 +3127,10 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport,
|
||||
rv = socketTransport->SetSecurityCallbacks(this);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
/*
|
||||
Telemetry::Accumulate(Telemetry::HTTP_CONNECTION_ENTRY_CACHE_HIT_1,
|
||||
mEnt->mUsedForConnection);
|
||||
*/
|
||||
mEnt->mUsedForConnection = true;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> sout;
|
||||
@@ -3919,6 +3930,7 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen)
|
||||
// will result in it not being present in the halfopen table. That's expected.
|
||||
if (mHalfOpens.RemoveElement(halfOpen)) {
|
||||
|
||||
#if(0)
|
||||
if (halfOpen->IsSpeculative()) {
|
||||
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_UNUSED_SPECULATIVE_CONN> unusedSpeculativeConn;
|
||||
++unusedSpeculativeConn;
|
||||
@@ -3928,6 +3940,7 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen)
|
||||
++totalPreconnectsUnused;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MOZ_ASSERT(gHttpHandler->ConnMgr()->mNumHalfOpenConns);
|
||||
if (gHttpHandler->ConnMgr()->mNumHalfOpenConns) { // just in case
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "nsStringStream.h"
|
||||
|
||||
#include "nsComponentManagerUtils.h" // do_CreateInstance
|
||||
#include "nsServiceManagerUtils.h" // do_GetService
|
||||
#include "nsIHttpActivityObserver.h"
|
||||
#include "nsSocketTransportService2.h"
|
||||
#include "nsICancelable.h"
|
||||
@@ -240,8 +239,10 @@ nsHttpTransaction::Init(uint32_t caps,
|
||||
MOZ_ASSERT(target);
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mActivityDistributor = do_GetService(NS_HTTPACTIVITYDISTRIBUTOR_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mActivityDistributor = services::GetActivityDistributor();
|
||||
if (!mActivityDistributor) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
bool activityDistributorActive;
|
||||
rv = mActivityDistributor->GetIsActive(&activityDistributorActive);
|
||||
|
||||
@@ -33,6 +33,16 @@ MOZ_SERVICE(UUIDGenerator, nsIUUIDGenerator,
|
||||
"@mozilla.org/uuid-generator;1");
|
||||
MOZ_SERVICE(GfxInfo, nsIGfxInfo,
|
||||
"@mozilla.org/gfx/info;1");
|
||||
MOZ_SERVICE(SocketTransportService, nsISocketTransportService,
|
||||
"@mozilla.org/network/socket-transport-service;1");
|
||||
MOZ_SERVICE(StreamTransportService, nsIStreamTransportService,
|
||||
"@mozilla.org/network/stream-transport-service;1");
|
||||
MOZ_SERVICE(CacheStorageService, nsICacheStorageService,
|
||||
"@mozilla.org/netwerk/cache-storage-service;1");
|
||||
MOZ_SERVICE(URIClassifier, nsIURIClassifier,
|
||||
"@mozilla.org/uriclassifierservice");
|
||||
MOZ_SERVICE(ActivityDistributor, nsIHttpActivityDistributor,
|
||||
"@mozilla.org/network/http-activity-distributor;1");
|
||||
|
||||
#ifdef MOZ_USE_NAMESPACE
|
||||
namespace mozilla {
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
#include "inIDOMUtils.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIServiceWorkerManager.h"
|
||||
#include "nsICacheStorageService.h"
|
||||
#include "nsIStreamTransportService.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsIURIClassifier.h"
|
||||
#include "nsIHttpActivityObserver.h"
|
||||
#include "nsIAsyncShutdown.h"
|
||||
#include "nsIUUIDGenerator.h"
|
||||
#include "nsIGfxInfo.h"
|
||||
|
||||
+40
-4
@@ -11,6 +11,7 @@
|
||||
#include "nsTArray.h"
|
||||
#include "nsCRT.h"
|
||||
#include "plstr.h"
|
||||
#include "nsASCIIMask.h"
|
||||
|
||||
static const char hexCharsUpper[] = "0123456789ABCDEF";
|
||||
static const char hexCharsUpperLower[] = "0123456789ABCDEFabcdef";
|
||||
@@ -382,7 +383,8 @@ static uint16_t dontNeedEscape(uint16_t aChar, uint32_t aFlags)
|
||||
template<class T>
|
||||
static nsresult
|
||||
T_EscapeURL(const typename T::char_type* aPart, size_t aPartLen,
|
||||
uint32_t aFlags, T& aResult, bool& aDidAppend)
|
||||
uint32_t aFlags, const ASCIIMaskArray* aFilterMask,
|
||||
T& aResult, bool& aDidAppend)
|
||||
{
|
||||
typedef nsCharTraits<typename T::char_type> traits;
|
||||
typedef typename traits::unsigned_char_type unsigned_char_type;
|
||||
@@ -409,6 +411,19 @@ T_EscapeURL(const typename T::char_type* aPart, size_t aPartLen,
|
||||
for (size_t i = 0; i < aPartLen; ++i) {
|
||||
unsigned_char_type c = *src++;
|
||||
|
||||
// If there is a filter, we wish to skip any characters which match it.
|
||||
// This is needed so we don't perform an extra pass just to extract the
|
||||
// filtered characters.
|
||||
if (aFilterMask && ASCIIMask::IsMasked(*aFilterMask, c)) {
|
||||
if (!writing) {
|
||||
if (!aResult.Append(aPart, i, fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
writing = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// if the char has not to be escaped or whatever follows % is
|
||||
// a valid escaped string, just copy the char.
|
||||
//
|
||||
@@ -474,7 +489,7 @@ NS_EscapeURL(const char* aPart, int32_t aPartLen, uint32_t aFlags,
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
nsresult rv = T_EscapeURL(aPart, aPartLen, aFlags, aResult, result);
|
||||
nsresult rv = T_EscapeURL(aPart, aPartLen, aFlags, nullptr, aResult, result);
|
||||
if (NS_FAILED(rv)) {
|
||||
::NS_ABORT_OOM(aResult.Length() * sizeof(nsACString::char_type));
|
||||
}
|
||||
@@ -487,7 +502,28 @@ NS_EscapeURL(const nsCSubstring& aStr, uint32_t aFlags, nsCSubstring& aResult,
|
||||
const mozilla::fallible_t&)
|
||||
{
|
||||
bool appended = false;
|
||||
nsresult rv = T_EscapeURL(aStr.Data(), aStr.Length(), aFlags, aResult, appended);
|
||||
nsresult rv = T_EscapeURL(aStr.Data(), aStr.Length(), aFlags, nullptr, aResult, appended);
|
||||
if (NS_FAILED(rv)) {
|
||||
aResult.Truncate();
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!appended) {
|
||||
if (!aResult.Assign(aStr, fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_EscapeAndFilterURL(const nsACString& aStr, uint32_t aFlags,
|
||||
const ASCIIMaskArray* aFilterMask,
|
||||
nsACString& aResult, const mozilla::fallible_t&)
|
||||
{
|
||||
bool appended = false;
|
||||
nsresult rv = T_EscapeURL(aStr.Data(), aStr.Length(), aFlags, aFilterMask, aResult, appended);
|
||||
if (NS_FAILED(rv)) {
|
||||
aResult.Truncate();
|
||||
return rv;
|
||||
@@ -504,7 +540,7 @@ const nsSubstring&
|
||||
NS_EscapeURL(const nsSubstring& aStr, uint32_t aFlags, nsSubstring& aResult)
|
||||
{
|
||||
bool result = false;
|
||||
nsresult rv = T_EscapeURL<nsSubstring>(aStr.Data(), aStr.Length(), aFlags, aResult, result);
|
||||
nsresult rv = T_EscapeURL<nsSubstring>(aStr.Data(), aStr.Length(), aFlags, nullptr, aResult, result);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
::NS_ABORT_OOM(aResult.Length() * sizeof(nsSubstring::char_type));
|
||||
|
||||
@@ -169,6 +169,19 @@ nsresult
|
||||
NS_EscapeURL(const nsCSubstring& aStr, uint32_t aFlags, nsCSubstring& aResult,
|
||||
const mozilla::fallible_t&);
|
||||
|
||||
// Forward declaration for nsASCIIMask.h
|
||||
typedef std::array<bool, 128> ASCIIMaskArray;
|
||||
|
||||
/**
|
||||
* The same as NS_EscapeURL, except it also filters out characters that match
|
||||
* aFilterMask.
|
||||
*/
|
||||
nsresult
|
||||
NS_EscapeAndFilterURL(const nsACString& aStr, uint32_t aFlags,
|
||||
const ASCIIMaskArray* aFilterMask,
|
||||
nsACString& aResult, const mozilla::fallible_t&);
|
||||
|
||||
|
||||
inline const nsCSubstring&
|
||||
NS_UnescapeURL(const nsCSubstring& aStr, uint32_t aFlags, nsCSubstring& aResult)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ with Files('**'):
|
||||
BUG_COMPONENT = ('Core', 'String')
|
||||
|
||||
EXPORTS += [
|
||||
'nsASCIIMask.h',
|
||||
'nsAString.h',
|
||||
'nsCharTraits.h',
|
||||
'nsDependentString.h',
|
||||
@@ -39,6 +40,7 @@ EXPORTS += [
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsASCIIMask.cpp',
|
||||
'nsDependentString.cpp',
|
||||
'nsDependentSubstring.cpp',
|
||||
'nsPromiseFlatString.cpp',
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* 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 "nsASCIIMask.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
constexpr bool TestWhitespace(char c)
|
||||
{
|
||||
return c == '\f' || c == '\t' || c == '\r' || c == '\n' || c == ' ';
|
||||
}
|
||||
constexpr ASCIIMaskArray sWhitespaceMask = CreateASCIIMask(TestWhitespace);
|
||||
|
||||
constexpr bool TestCRLF(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n';
|
||||
}
|
||||
constexpr ASCIIMaskArray sCRLFMask = CreateASCIIMask(TestCRLF);
|
||||
|
||||
constexpr bool TestCRLFTab(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n' || c == '\t';
|
||||
}
|
||||
constexpr ASCIIMaskArray sCRLFTabMask = CreateASCIIMask(TestCRLFTab);
|
||||
|
||||
constexpr bool TestZeroToNine(char c)
|
||||
{
|
||||
return c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
|
||||
c == '5' || c == '6' || c == '7' || c == '8' || c == '9';
|
||||
}
|
||||
constexpr ASCIIMaskArray sZeroToNineMask = CreateASCIIMask(TestZeroToNine);
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::MaskWhitespace()
|
||||
{
|
||||
return sWhitespaceMask;
|
||||
}
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::MaskCRLF()
|
||||
{
|
||||
return sCRLFMask;
|
||||
}
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::MaskCRLFTab()
|
||||
{
|
||||
return sCRLFTabMask;
|
||||
}
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::Mask0to9()
|
||||
{
|
||||
return sZeroToNineMask;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
@@ -0,0 +1,70 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* 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 nsASCIIMask_h_
|
||||
#define nsASCIIMask_h_
|
||||
|
||||
#include <array>
|
||||
#include "mozilla/IndexSequence.h"
|
||||
|
||||
typedef std::array<bool, 128> ASCIIMaskArray;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// Boolean arrays, fixed size and filled in at compile time, meant to
|
||||
// record something about each of the (standard) ASCII characters.
|
||||
// No extended ASCII for now, there has been no use case.
|
||||
// If you have loops that go through a string character by character
|
||||
// and test for equality to a certain set of characters before deciding
|
||||
// on a course of action, chances are building up one of these arrays
|
||||
// and using it is going to be faster, especially if the set of
|
||||
// characters is more than one long, and known at compile time.
|
||||
class ASCIIMask
|
||||
{
|
||||
public:
|
||||
// Preset masks for some common character groups
|
||||
// When testing, you must check if the index is < 128 or use IsMasked()
|
||||
//
|
||||
// if (someChar < 128 && MaskCRLF()[someChar]) this is \r or \n
|
||||
|
||||
static const ASCIIMaskArray& MaskCRLF();
|
||||
static const ASCIIMaskArray& Mask0to9();
|
||||
static const ASCIIMaskArray& MaskCRLFTab();
|
||||
static const ASCIIMaskArray& MaskWhitespace();
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool IsMasked(const ASCIIMaskArray& aMask, uint32_t aChar)
|
||||
{
|
||||
return aChar < 128 && aMask[aChar];
|
||||
}
|
||||
};
|
||||
|
||||
// Outside of the preset ones, use these templates to create more masks.
|
||||
//
|
||||
// The example creation will look like this:
|
||||
//
|
||||
// constexpr bool TestABC(char c) { return c == 'A' || c == 'B' || c == 'C'; }
|
||||
// constexpr std::array<bool, 128> sABCMask = CreateASCIIMask(TestABC);
|
||||
// ...
|
||||
// if (someChar < 128 && sABCMask[someChar]) this is A or B or C
|
||||
|
||||
|
||||
namespace details
|
||||
{
|
||||
template<typename F, size_t... Indices>
|
||||
constexpr std::array<bool, 128> CreateASCIIMask(F fun, mozilla::IndexSequence<Indices...>)
|
||||
{
|
||||
return {{ fun(Indices)... }};
|
||||
}
|
||||
} // namespace details
|
||||
|
||||
template<typename F>
|
||||
constexpr std::array<bool, 128> CreateASCIIMask(F fun)
|
||||
{
|
||||
return details::CreateASCIIMask(fun, mozilla::MakeIndexSequence<128>::Type{});
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // nsASCIIMask_h_
|
||||
@@ -540,8 +540,6 @@ StripChars2(char16_t* aString,uint32_t aLength,const char* aSet) {
|
||||
|
||||
/* ***** END RICKG BLOCK ***** */
|
||||
|
||||
static const char* kWhitespace="\f\t\r\n ";
|
||||
|
||||
// This function is used to implement FindCharInSet and friends
|
||||
template <class CharT>
|
||||
#ifndef __SUNPRO_CC
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "nsASCIIMask.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
|
||||
/**
|
||||
@@ -401,10 +402,9 @@ nsTString_CharT::SetCharAt( char16_t aChar, uint32_t aIndex )
|
||||
void
|
||||
nsTString_CharT::StripChars( const char* aSet )
|
||||
{
|
||||
if (!EnsureMutable())
|
||||
if (!StripChars(aSet, mozilla::fallible)) {
|
||||
AllocFailed(mLength);
|
||||
|
||||
mLength = nsBufferRoutines<CharT>::strip_chars(mData, mLength, aSet);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -421,13 +421,20 @@ nsTString_CharT::StripChars( const char* aSet, const fallible_t& )
|
||||
void
|
||||
nsTString_CharT::StripWhitespace()
|
||||
{
|
||||
StripChars(kWhitespace);
|
||||
if (!StripWhitespace(mozilla::fallible)) {
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
nsTString_CharT::StripWhitespace(const fallible_t& aFallible)
|
||||
nsTString_CharT::StripWhitespace( const fallible_t& )
|
||||
{
|
||||
return StripChars(kWhitespace, aFallible);
|
||||
if (!EnsureMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StripTaggedASCII(mozilla::ASCIIMask::MaskWhitespace());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -672,13 +679,44 @@ nsTString_CharT::Trim( const char* aSet, bool aTrimLeading, bool aTrimTrailing,
|
||||
void
|
||||
nsTString_CharT::CompressWhitespace( bool aTrimLeading, bool aTrimTrailing )
|
||||
{
|
||||
const char* set = kWhitespace;
|
||||
// Quick exit
|
||||
if (mLength == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReplaceChar(set, ' ');
|
||||
Trim(set, aTrimLeading, aTrimTrailing);
|
||||
if (!EnsureMutable())
|
||||
AllocFailed(mLength);
|
||||
|
||||
// this one does some questionable fu... just copying the old code!
|
||||
mLength = nsBufferRoutines<char_type>::compress_chars(mData, mLength, set);
|
||||
const ASCIIMaskArray& mask = mozilla::ASCIIMask::MaskWhitespace();
|
||||
|
||||
char_type* to = mData;
|
||||
char_type* from = mData;
|
||||
char_type* end = mData + mLength;
|
||||
|
||||
// Compresses runs of whitespace down to a normal space ' ' and convert
|
||||
// any whitespace to a normal space. This assumes that whitespace is
|
||||
// all standard 7-bit ASCII.
|
||||
bool skipWS = aTrimLeading;
|
||||
while (from < end) {
|
||||
uint32_t theChar = *from++;
|
||||
if (mozilla::ASCIIMask::IsMasked(mask, theChar)) {
|
||||
if (!skipWS) {
|
||||
*to++ = ' ';
|
||||
skipWS = true;
|
||||
}
|
||||
} else {
|
||||
*to++ = theChar;
|
||||
skipWS = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If we need to trim the trailing whitespace, back up one character.
|
||||
if (aTrimTrailing && skipWS && to > mData) {
|
||||
to--;
|
||||
}
|
||||
|
||||
*to = char_type(0); // add the null
|
||||
mLength = to - mData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* 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 "nsASCIIMask.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/double-conversion.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
@@ -852,7 +853,8 @@ nsTSubstring_CharT::FindChar(char_type aChar, index_type aOffset) const
|
||||
void
|
||||
nsTSubstring_CharT::StripChar(char_type aChar, int32_t aOffset)
|
||||
{
|
||||
if (mLength == 0 || aOffset >= int32_t(mLength)) {
|
||||
// Note that this implicitly guarantees mLength > 0
|
||||
if (aOffset >= int32_t(mLength)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -879,6 +881,7 @@ nsTSubstring_CharT::StripChar(char_type aChar, int32_t aOffset)
|
||||
void
|
||||
nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset)
|
||||
{
|
||||
// Note that this implicitly guarantees mLength > 0
|
||||
if (aOffset >= uint32_t(mLength)) {
|
||||
return;
|
||||
}
|
||||
@@ -908,6 +911,45 @@ nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset)
|
||||
mLength = to - mData;
|
||||
}
|
||||
|
||||
void
|
||||
nsTSubstring_CharT::StripTaggedASCII(const ASCIIMaskArray& aToStrip,
|
||||
uint32_t aOffset)
|
||||
{
|
||||
// Note that this implicitly guarantees mLength > 0
|
||||
if (aOffset >= uint32_t(mLength)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnsureMutable()) {
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
char_type* to = mData + aOffset;
|
||||
char_type* from = mData + aOffset;
|
||||
char_type* end = mData + mLength;
|
||||
|
||||
while (from < end) {
|
||||
uint32_t theChar = (uint32_t)*from++;
|
||||
// Replacing this with a call to ASCIIMask::IsMasked
|
||||
// regresses performance somewhat, so leaving it inlined.
|
||||
if (!mozilla::ASCIIMask::IsMasked(aToStrip, theChar)) {
|
||||
// Not stripped, copy this char.
|
||||
*to++ = (char_type)theChar;
|
||||
}
|
||||
}
|
||||
*to = char_type(0); // add the null
|
||||
mLength = to - mData;
|
||||
}
|
||||
|
||||
void
|
||||
nsTSubstring_CharT::StripCRLF(uint32_t aOffset)
|
||||
{
|
||||
// Expanding this call to copy the code from StripTaggedASCII
|
||||
// instead of just calling it does somewhat help with performance
|
||||
// but it is not worth it given the duplicated code.
|
||||
StripTaggedASCII(mozilla::ASCIIMask::MaskCRLF(), aOffset);
|
||||
}
|
||||
|
||||
int
|
||||
nsTSubstring_CharT::AppendFunc(void* aArg, const char* aStr, uint32_t aLen)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
// IWYU pragma: private, include "nsString.h"
|
||||
|
||||
#include <array>
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
||||
@@ -826,6 +827,31 @@ public:
|
||||
|
||||
void StripChars(const char_type* aChars, uint32_t aOffset = 0);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurrences of some characters this
|
||||
* from this string. The characters removed have the corresponding
|
||||
* entries in the bool array set to true; we retain all characters
|
||||
* with code beyond 127.
|
||||
* THE CALLER IS RESPONSIBLE for making sure the complete boolean
|
||||
* array, 128 entries, is properly initialized.
|
||||
*
|
||||
* See also: ASCIIMask class.
|
||||
*
|
||||
* @param aToStrip -- Array where each entry is true if the
|
||||
* corresponding ASCII character is to be stripped. All
|
||||
* characters beyond code 127 are retained. Note that this
|
||||
* parameter is of ASCIIMaskArray type, but we expand the typedef
|
||||
* to avoid having to include nsASCIIMask.h in this include file
|
||||
* as it brings other includes.
|
||||
* @param aOffset -- where in this string to start stripping chars
|
||||
*/
|
||||
void StripTaggedASCII(const std::array<bool, 128>& aToStrip, uint32_t aOffset = 0);
|
||||
|
||||
/**
|
||||
* A shortcut to strip \r and \n.
|
||||
*/
|
||||
void StripCRLF(uint32_t aOffset = 0);
|
||||
|
||||
/**
|
||||
* If the string uses a shared buffer, this method
|
||||
* clears the pointer without releasing the buffer.
|
||||
|
||||
@@ -913,7 +913,7 @@ NS_IMETHODIMP nsXULWindow::SetTitle(const char16_t* aTitle)
|
||||
{
|
||||
NS_ENSURE_STATE(mWindow);
|
||||
mTitle.Assign(aTitle);
|
||||
mTitle.StripChars("\n\r");
|
||||
mTitle.StripCRLF();
|
||||
NS_ENSURE_SUCCESS(mWindow->SetTitle(mTitle), NS_ERROR_FAILURE);
|
||||
|
||||
// Tell the window mediator that a title has changed
|
||||
|
||||
Reference in New Issue
Block a user