summaryrefslogtreecommitdiffstats
path: root/netwerk/base
diff options
context:
space:
mode:
Diffstat (limited to 'netwerk/base')
-rw-r--r--netwerk/base/LoadInfo.cpp10
-rw-r--r--netwerk/base/http-sfv/nsIStructuredFieldValues.idl2
-rw-r--r--netwerk/base/mozurl/src/lib.rs10
-rw-r--r--netwerk/base/nsIBackgroundFileSaver.idl2
-rw-r--r--netwerk/base/nsICaptivePortalService.idl2
-rw-r--r--netwerk/base/nsIChannel.idl2
-rw-r--r--netwerk/base/nsIClassOfService.idl2
-rw-r--r--netwerk/base/nsIInterceptionInfo.idl4
-rw-r--r--netwerk/base/nsINetworkInterceptController.idl6
-rw-r--r--netwerk/base/nsIOService.cpp13
-rw-r--r--netwerk/base/nsIParentChannel.idl2
-rw-r--r--netwerk/base/nsIParentRedirectingChannel.idl2
-rw-r--r--netwerk/base/nsIPermissionManager.idl8
-rw-r--r--netwerk/base/nsISecureBrowserUI.idl2
-rw-r--r--netwerk/base/nsISocketFilter.idl8
-rw-r--r--netwerk/base/nsISocketTransport.idl4
-rw-r--r--netwerk/base/nsIStreamTransportService.idl10
-rw-r--r--netwerk/base/nsISystemProxySettings.idl4
-rw-r--r--netwerk/base/nsIUDPSocket.idl2
-rw-r--r--netwerk/base/nsIncrementalStreamLoader.cpp4
-rw-r--r--netwerk/base/nsNetUtil.cpp77
-rw-r--r--netwerk/base/nsNetUtil.h28
-rw-r--r--netwerk/base/nsPACMan.cpp1
-rw-r--r--netwerk/base/nsPISocketTransportService.idl2
-rw-r--r--netwerk/base/nsStandardURL.cpp4
-rw-r--r--netwerk/base/nsStandardURL.h2
-rw-r--r--netwerk/base/nsStreamTransportService.cpp56
-rw-r--r--netwerk/base/nsURLHelper.cpp108
-rw-r--r--netwerk/base/nsURLHelper.h44
29 files changed, 232 insertions, 189 deletions
diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp
index eb90324c37..6be031113f 100644
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -20,6 +20,7 @@
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/WindowGlobalParent.h"
+#include "mozilla/dom/nsHTTPSOnlyUtils.h"
#include "mozilla/net/CookieJarSettings.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/StaticPrefs_network.h"
@@ -216,8 +217,9 @@ LoadInfo::LoadInfo(
mDocumentHasUserInteracted =
aLoadingContext->OwnerDoc()->UserHasInteracted();
- // Inherit HTTPS-Only Mode flags from parent document
- mHttpsOnlyStatus |= aLoadingContext->OwnerDoc()->HttpsOnlyStatus();
+ // Inherit HTTPS-Only Mode flags from parent document.
+ mHttpsOnlyStatus |= nsHTTPSOnlyUtils::GetStatusForSubresourceLoad(
+ aLoadingContext->OwnerDoc()->HttpsOnlyStatus());
// When the element being loaded is a frame, we choose the frame's window
// for the window ID and the frame element's window as the parent
@@ -528,7 +530,9 @@ LoadInfo::LoadInfo(dom::WindowGlobalParent* aParentWGP,
parentBC->UsePrivateBrowsing());
}
- mHttpsOnlyStatus |= aParentWGP->HttpsOnlyStatus();
+ // Inherit HTTPS-Only Mode flags from embedder document.
+ mHttpsOnlyStatus |= nsHTTPSOnlyUtils::GetStatusForSubresourceLoad(
+ aParentWGP->HttpsOnlyStatus());
// For chrome BC, the mPrivateBrowsingId remains 0 even its
// UsePrivateBrowsing() is true, so we only update the mPrivateBrowsingId in
diff --git a/netwerk/base/http-sfv/nsIStructuredFieldValues.idl b/netwerk/base/http-sfv/nsIStructuredFieldValues.idl
index 3f02b33953..20b0392ac9 100644
--- a/netwerk/base/http-sfv/nsIStructuredFieldValues.idl
+++ b/netwerk/base/http-sfv/nsIStructuredFieldValues.idl
@@ -256,7 +256,7 @@ interface nsISFVService: nsISupports
* The following functions create bare item of specific type.
*/
nsISFVInteger newInteger(in long long value);
- nsISFVBool newBool(in bool value);
+ nsISFVBool newBool(in boolean value);
nsISFVDecimal newDecimal(in double value);
nsISFVString newString(in ACString value);
nsISFVByteSeq newByteSequence(in ACString value);
diff --git a/netwerk/base/mozurl/src/lib.rs b/netwerk/base/mozurl/src/lib.rs
index 21be5f7e8b..ac33f0f8a8 100644
--- a/netwerk/base/mozurl/src/lib.rs
+++ b/netwerk/base/mozurl/src/lib.rs
@@ -214,7 +214,10 @@ pub extern "C" fn mozurl_real_port(url: &MozURL) -> i32 {
#[no_mangle]
pub extern "C" fn mozurl_host_port(url: &MozURL) -> SpecSlice {
- (&url[Position::BeforeHost..Position::BeforePath]).into()
+ if url.port().is_some() {
+ return (&url[Position::BeforeHost..Position::BeforePath]).into();
+ }
+ url.host_str().unwrap_or("").into()
}
#[no_mangle]
@@ -436,6 +439,11 @@ pub extern "C" fn mozurl_set_hostname(url: &mut MozURL, host: &nsACString) -> ns
#[no_mangle]
pub extern "C" fn mozurl_set_port_no(url: &mut MozURL, new_port: i32) -> nsresult {
debug_assert_mut!(url);
+
+ if new_port > u16::MAX as i32 {
+ return NS_ERROR_UNEXPECTED;
+ }
+
if url.cannot_be_a_base() {
return NS_ERROR_MALFORMED_URI;
}
diff --git a/netwerk/base/nsIBackgroundFileSaver.idl b/netwerk/base/nsIBackgroundFileSaver.idl
index 0b26852c28..d9a5ba20a5 100644
--- a/netwerk/base/nsIBackgroundFileSaver.idl
+++ b/netwerk/base/nsIBackgroundFileSaver.idl
@@ -130,7 +130,7 @@ interface nsIBackgroundFileSaver : nsISupports
* rather than deleted, if the operation fails or is canceled. This is
* generally set for downloads that use temporary ".part" files.
*/
- void setTarget(in nsIFile aTarget, in bool aKeepPartial);
+ void setTarget(in nsIFile aTarget, in boolean aKeepPartial);
/**
* Terminates access to the output file, then notifies the observer with the
diff --git a/netwerk/base/nsICaptivePortalService.idl b/netwerk/base/nsICaptivePortalService.idl
index e4867765d7..0814ecb665 100644
--- a/netwerk/base/nsICaptivePortalService.idl
+++ b/netwerk/base/nsICaptivePortalService.idl
@@ -10,7 +10,7 @@ interface nsICaptivePortalServiceCallback : nsISupports
/**
* Invoke callbacks after captive portal detection finished.
*/
- void complete(in bool success, in nsresult error);
+ void complete(in boolean success, in nsresult error);
};
/**
diff --git a/netwerk/base/nsIChannel.idl b/netwerk/base/nsIChannel.idl
index 2269c4faa8..a29bd1a463 100644
--- a/netwerk/base/nsIChannel.idl
+++ b/netwerk/base/nsIChannel.idl
@@ -359,7 +359,7 @@ interface nsIChannel : nsIRequest
* Note: May have the wrong value if called before OnStartRequest as we
* don't know the MIME type yet.
*/
- readonly attribute bool isDocument;
+ readonly attribute boolean isDocument;
%{ C++
inline bool IsDocument()
diff --git a/netwerk/base/nsIClassOfService.idl b/netwerk/base/nsIClassOfService.idl
index 5426eabbcc..7b133107de 100644
--- a/netwerk/base/nsIClassOfService.idl
+++ b/netwerk/base/nsIClassOfService.idl
@@ -26,7 +26,7 @@ native ClassOfService(mozilla::net::ClassOfService);
interface nsIClassOfService : nsISupports
{
attribute unsigned long classFlags;
- attribute bool incremental;
+ attribute boolean incremental;
void clearClassFlags(in unsigned long flags);
void addClassFlags(in unsigned long flags);
diff --git a/netwerk/base/nsIInterceptionInfo.idl b/netwerk/base/nsIInterceptionInfo.idl
index d3c1b030ac..ca2549adbd 100644
--- a/netwerk/base/nsIInterceptionInfo.idl
+++ b/netwerk/base/nsIInterceptionInfo.idl
@@ -66,8 +66,8 @@ interface nsIInterceptionInfo : nsISupports
* The InterceptedHttpChannel is a third party channel or not.
*/
[noscript, notxpcom, nostdcall, binaryname(FromThirdParty)]
- bool binaryFromThirdParty();
+ boolean binaryFromThirdParty();
[noscript, notxpcom, nostdcall, binaryname(SetFromThirdParty)]
- void binarySetFromThirdParty(in bool aFromThirdParty);
+ void binarySetFromThirdParty(in boolean aFromThirdParty);
};
diff --git a/netwerk/base/nsINetworkInterceptController.idl b/netwerk/base/nsINetworkInterceptController.idl
index 155daa5cd5..946cc95a88 100644
--- a/netwerk/base/nsINetworkInterceptController.idl
+++ b/netwerk/base/nsINetworkInterceptController.idl
@@ -97,7 +97,7 @@ interface nsIInterceptedChannel : nsISupports
in nsIInterceptedBodyCallback callback,
in nsICacheInfoChannel channel,
in ACString finalURLSpec,
- in bool responseRedirected);
+ in boolean responseRedirected);
/**
* Instruct a channel that has been intercepted that response synthesis
@@ -155,7 +155,7 @@ interface nsIInterceptedChannel : nsISupports
* network or not.
*/
[noscript]
- bool GetIsReset();
+ boolean GetIsReset();
%{C++
already_AddRefed<nsIConsoleReportCollector>
@@ -239,7 +239,7 @@ interface nsINetworkInterceptController : nsISupports
* @param aChannel The channel that may be intercepted. It will
* be in the state prior to calling OnStartRequest().
*/
- bool shouldPrepareForIntercept(in nsIURI aURI, in nsIChannel aChannel);
+ boolean shouldPrepareForIntercept(in nsIURI aURI, in nsIChannel aChannel);
/**
* Notification when a given intercepted channel is prepared to accept a synthesized
diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp
index 8450a59b4a..998c389ace 100644
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -87,6 +87,7 @@ using mozilla::dom::ServiceWorkerDescriptor;
#define WEBRTC_PREF_PREFIX "media.peerconnection."
#define NETWORK_DNS_PREF "network.dns."
#define FORCE_EXTERNAL_PREF_PREFIX "network.protocol-handler.external."
+#define SIMPLE_URI_SCHEMES_PREF "network.url.simple_uri_schemes"
nsIOService* gIOService;
static bool gHasWarnedUploadChannel2;
@@ -171,6 +172,7 @@ int16_t gBadPortList[] = {
2049, // nfs
3659, // apple-sasl
4045, // lockd
+ 4160, // sieve
5060, // sip
5061, // sips
6000, // x11
@@ -180,6 +182,7 @@ int16_t gBadPortList[] = {
6667, // irc (default)
6668, // irc (alternate)
6669, // irc (alternate)
+ 6679, // osaut
6697, // irc+tls
10080, // amanda
0, // Sentinel value: This MUST be zero
@@ -211,6 +214,7 @@ static const char* gCallbackPrefs[] = {
NECKO_BUFFER_CACHE_SIZE_PREF,
NETWORK_CAPTIVE_PORTAL_PREF,
FORCE_EXTERNAL_PREF_PREFIX,
+ SIMPLE_URI_SCHEMES_PREF,
nullptr,
};
@@ -1528,6 +1532,15 @@ void nsIOService::PrefsChanged(const char* pref) {
AutoWriteLock lock(mLock);
mForceExternalSchemes = std::move(forceExternalSchemes);
}
+
+ if (!pref || strncmp(pref, SIMPLE_URI_SCHEMES_PREF,
+ strlen(SIMPLE_URI_SCHEMES_PREF)) == 0) {
+ LOG((
+ "simple_uri_schemes pref change observed, updating the scheme list\n"));
+ nsAutoCString schemeList;
+ Preferences::GetCString(SIMPLE_URI_SCHEMES_PREF, schemeList);
+ mozilla::net::ParseSimpleURISchemes(schemeList);
+ }
}
void nsIOService::ParsePortList(const char* pref, bool remove) {
diff --git a/netwerk/base/nsIParentChannel.idl b/netwerk/base/nsIParentChannel.idl
index a351019d7d..92af600493 100644
--- a/netwerk/base/nsIParentChannel.idl
+++ b/netwerk/base/nsIParentChannel.idl
@@ -62,7 +62,7 @@ interface nsIParentChannel : nsIStreamListener
* with the URI of the window.
*/
[noscript] void notifyClassificationFlags(in uint32_t aClassificationFlags,
- in bool aIsThirdParty);
+ in boolean aIsThirdParty);
/**
* Called to invoke deletion of the IPC protocol.
diff --git a/netwerk/base/nsIParentRedirectingChannel.idl b/netwerk/base/nsIParentRedirectingChannel.idl
index 6302775c51..4dacaf70b6 100644
--- a/netwerk/base/nsIParentRedirectingChannel.idl
+++ b/netwerk/base/nsIParentRedirectingChannel.idl
@@ -26,7 +26,7 @@ interface nsIAsyncVerifyRedirectReadyCallback : nsISupports
* Implemented by chrome side of IPC protocols that support redirect responses.
*/
-[scriptable, uuid(3ed1d288-5324-46ee-8a98-33ac37d1080b)]
+[uuid(3ed1d288-5324-46ee-8a98-33ac37d1080b)]
interface nsIParentRedirectingChannel : nsIParentChannel
{
/**
diff --git a/netwerk/base/nsIPermissionManager.idl b/netwerk/base/nsIPermissionManager.idl
index f234958010..e9b990c019 100644
--- a/netwerk/base/nsIPermissionManager.idl
+++ b/netwerk/base/nsIPermissionManager.idl
@@ -117,6 +117,14 @@ interface nsIPermissionManager : nsISupports
[optional] in int64_t expireTime);
/**
+ * Test method to add a permission for a given principal with custom modification time.
+ */
+ void testAddFromPrincipalByTime(in nsIPrincipal principal, in ACString type,
+ in uint32_t permission,
+ in int64_t modificationTime
+ );
+
+ /**
* Add permanent permission information for a given principal in private
* browsing.
*
diff --git a/netwerk/base/nsISecureBrowserUI.idl b/netwerk/base/nsISecureBrowserUI.idl
index 6197a9adff..b0e9c9e32d 100644
--- a/netwerk/base/nsISecureBrowserUI.idl
+++ b/netwerk/base/nsISecureBrowserUI.idl
@@ -12,6 +12,6 @@ interface nsITransportSecurityInfo;
interface nsISecureBrowserUI : nsISupports
{
readonly attribute unsigned long state;
- readonly attribute bool isSecureContext;
+ readonly attribute boolean isSecureContext;
readonly attribute nsITransportSecurityInfo secInfo;
};
diff --git a/netwerk/base/nsISocketFilter.idl b/netwerk/base/nsISocketFilter.idl
index 0846fa2eda..40d58d086a 100644
--- a/netwerk/base/nsISocketFilter.idl
+++ b/netwerk/base/nsISocketFilter.idl
@@ -22,10 +22,10 @@ interface nsISocketFilter : nsISupports
const long SF_INCOMING = 0;
const long SF_OUTGOING = 1;
- bool filterPacket([const]in NetAddrPtr remote_addr,
- [const, array, size_is(len)]in uint8_t data,
- in unsigned long len,
- in long direction);
+ boolean filterPacket([const]in NetAddrPtr remote_addr,
+ [const, array, size_is(len)]in uint8_t data,
+ in unsigned long len,
+ in long direction);
};
/**
diff --git a/netwerk/base/nsISocketTransport.idl b/netwerk/base/nsISocketTransport.idl
index 58b869203e..c0f26f5c66 100644
--- a/netwerk/base/nsISocketTransport.idl
+++ b/netwerk/base/nsISocketTransport.idl
@@ -132,7 +132,7 @@ interface nsISocketTransport : nsITransport
/**
* True to set addr and port reuse socket options.
*/
- void setReuseAddrPort(in bool reuseAddrPort);
+ void setReuseAddrPort(in boolean reuseAddrPort);
/**
* Values for the aType parameter passed to get/setTimeout.
@@ -349,7 +349,7 @@ interface nsISocketTransport : nsITransport
/**
* IP address resolved using TRR.
*/
- bool resolvedByTRR();
+ boolean resolvedByTRR();
/**
* Returns the effectiveTRRMode used for the DNS resolution.
diff --git a/netwerk/base/nsIStreamTransportService.idl b/netwerk/base/nsIStreamTransportService.idl
index 3a1c5a4239..3df8d4c127 100644
--- a/netwerk/base/nsIStreamTransportService.idl
+++ b/netwerk/base/nsIStreamTransportService.idl
@@ -36,14 +36,4 @@ interface nsIStreamTransportService : nsISupports
*/
nsITransport createInputTransport(in nsIInputStream aStream,
in boolean aCloseWhenDone);
-
- void InputAvailable(in nsIInputStream aStream,
- in nsIInputAvailableCallback aCallback);
-};
-
-[uuid(ff2da731-44d0-4dd9-8236-c99387fec721)]
-interface nsIInputAvailableCallback : nsISupports
-{
- void onInputAvailableComplete(in unsigned long long available,
- in nsresult available_return_code);
};
diff --git a/netwerk/base/nsISystemProxySettings.idl b/netwerk/base/nsISystemProxySettings.idl
index 935da146af..0b24b0a83a 100644
--- a/netwerk/base/nsISystemProxySettings.idl
+++ b/netwerk/base/nsISystemProxySettings.idl
@@ -22,7 +22,7 @@ interface nsISystemProxySettings : nsISupports
* provided for implementations that do not block but use other main thread only
* functions such as dbus.
*/
- readonly attribute bool mainThreadOnly;
+ readonly attribute boolean mainThreadOnly;
/**
* If non-empty, use this PAC file. If empty, call getProxyForURI instead.
@@ -43,5 +43,5 @@ interface nsISystemProxySettings : nsISupports
/**
* Check if system settings are configured to use WPAD
*/
- readonly attribute bool systemWPADSetting;
+ readonly attribute boolean systemWPADSetting;
};
diff --git a/netwerk/base/nsIUDPSocket.idl b/netwerk/base/nsIUDPSocket.idl
index 41bd0ebc17..5c23c1bb6f 100644
--- a/netwerk/base/nsIUDPSocket.idl
+++ b/netwerk/base/nsIUDPSocket.idl
@@ -116,7 +116,7 @@ interface nsIUDPSocket : nsISupports
* If it is used off the socket thread there is a risk of triggering a bug
* in OS thatcan cause a crash.
*/
- void syncListen(in nsIUDPSocketSyncListener aListener);
+ [noscript] void syncListen(in nsIUDPSocketSyncListener aListener);
/**
* connect
diff --git a/netwerk/base/nsIncrementalStreamLoader.cpp b/netwerk/base/nsIncrementalStreamLoader.cpp
index f4437b5269..1b74000871 100644
--- a/netwerk/base/nsIncrementalStreamLoader.cpp
+++ b/netwerk/base/nsIncrementalStreamLoader.cpp
@@ -182,7 +182,9 @@ nsIncrementalStreamLoader::OnDataAvailable(nsIRequest* request,
void nsIncrementalStreamLoader::ReleaseData() { mData.clearAndFree(); }
NS_IMETHODIMP
-nsIncrementalStreamLoader::CheckListenerChain() { return NS_OK; }
+nsIncrementalStreamLoader::CheckListenerChain() {
+ return NS_ERROR_NO_INTERFACE;
+}
NS_IMETHODIMP
nsIncrementalStreamLoader::OnDataFinished(nsresult aStatus) { return NS_OK; }
diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp
index ac86d8fa32..413fbd3ed6 100644
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -693,17 +693,6 @@ int32_t NS_GetDefaultPort(const char* scheme,
return NS_SUCCEEDED(rv) ? port : -1;
}
-/**
- * This function is a helper function to apply the ToAscii conversion
- * to a string
- */
-bool NS_StringToACE(const nsACString& idn, nsACString& result) {
- nsCOMPtr<nsIIDNService> idnSrv = do_GetService(NS_IDNSERVICE_CONTRACTID);
- if (!idnSrv) return false;
- nsresult rv = idnSrv->ConvertUTF8toACE(idn, result);
- return NS_SUCCEEDED(rv);
-}
-
int32_t NS_GetRealPort(nsIURI* aURI) {
int32_t port;
nsresult rv = aURI->GetPort(&port);
@@ -721,6 +710,20 @@ int32_t NS_GetRealPort(nsIURI* aURI) {
return NS_GetDefaultPort(scheme.get());
}
+nsresult NS_DomainToASCII(const nsACString& aHost, nsACString& aASCII) {
+ return nsStandardURL::GetIDNService()->ConvertUTF8toACE(aHost, aASCII);
+}
+
+nsresult NS_DomainToDisplay(const nsACString& aHost, nsACString& aDisplay) {
+ bool ignored;
+ return nsStandardURL::GetIDNService()->ConvertToDisplayIDN(aHost, &ignored,
+ aDisplay);
+}
+
+nsresult NS_DomainToUnicode(const nsACString& aHost, nsACString& aUnicode) {
+ return nsStandardURL::GetIDNService()->ConvertACEtoUTF8(aHost, aUnicode);
+}
+
nsresult NS_NewInputStreamChannelInternal(
nsIChannel** outChannel, nsIURI* aUri,
already_AddRefed<nsIInputStream> aStream, const nsACString& aContentType,
@@ -1813,6 +1816,26 @@ class TlsAutoIncrement {
T& mVar;
};
+static nsTHashSet<nsCString> sSimpleURISchemes;
+static StaticRWLock sSchemeLock;
+
+namespace mozilla::net {
+
+void ParseSimpleURISchemes(const nsACString& schemeList) {
+ StaticAutoWriteLock lock(sSchemeLock);
+
+ sSimpleURISchemes.Clear();
+ for (const auto& scheme : schemeList.Split(',')) {
+ nsAutoCString s(scheme);
+ s.CompressWhitespace();
+ if (!s.IsEmpty()) {
+ sSimpleURISchemes.Insert(s);
+ }
+ }
+}
+
+} // namespace mozilla::net
+
nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec,
const char* aCharset /* = nullptr */,
nsIURI* aBaseURI /* = nullptr */) {
@@ -2000,6 +2023,14 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec,
}
#endif
+ auto mustUseSimpleURI = [](const nsCString& scheme) -> bool {
+ if (!StaticPrefs::network_url_some_schemes_bypass_defaultURI_fallback()) {
+ return false;
+ }
+ StaticAutoReadLock lock(sSchemeLock);
+ return sSimpleURISchemes.Contains(scheme);
+ };
+
if (aBaseURI) {
nsAutoCString newSpec;
rv = aBaseURI->Resolve(aSpec, newSpec);
@@ -2013,6 +2044,12 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec,
}
if (StaticPrefs::network_url_useDefaultURI()) {
+ if (mustUseSimpleURI(scheme)) {
+ return NS_MutateURI(new nsSimpleURI::Mutator())
+ .SetSpec(newSpec)
+ .Finalize(aURI);
+ }
+
return NS_MutateURI(new DefaultURI::Mutator())
.SetSpec(newSpec)
.Finalize(aURI);
@@ -2024,6 +2061,11 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec,
}
if (StaticPrefs::network_url_useDefaultURI()) {
+ if (mustUseSimpleURI(scheme)) {
+ return NS_MutateURI(new nsSimpleURI::Mutator())
+ .SetSpec(aSpec)
+ .Finalize(aURI);
+ }
return NS_MutateURI(new DefaultURI::Mutator())
.SetSpec(aSpec)
.Finalize(aURI);
@@ -3409,25 +3451,24 @@ bool IsSchemeChangePermitted(nsIURI* aOldURI, const nsACString& newScheme) {
}
already_AddRefed<nsIURI> TryChangeProtocol(nsIURI* aURI,
- const nsAString& aProtocol) {
+ const nsACString& aProtocol) {
MOZ_ASSERT(aURI);
- nsAString::const_iterator start;
+ nsACString::const_iterator start;
aProtocol.BeginReading(start);
- nsAString::const_iterator end;
+ nsACString::const_iterator end;
aProtocol.EndReading(end);
- nsAString::const_iterator iter(start);
+ nsACString::const_iterator iter(start);
FindCharInReadable(':', iter, end);
// Changing the protocol of a URL, changes the "nature" of the URI
// implementation. In order to do this properly, we have to serialize the
// existing URL and reparse it in a new object.
nsCOMPtr<nsIURI> clone;
- nsresult rv = NS_MutateURI(aURI)
- .SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter)))
- .Finalize(clone);
+ nsresult rv =
+ NS_MutateURI(aURI).SetScheme(Substring(start, iter)).Finalize(clone);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
diff --git a/netwerk/base/nsNetUtil.h b/netwerk/base/nsNetUtil.h
index c1f30a56ed..8058ae89d9 100644
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -294,10 +294,28 @@ int32_t NS_GetDefaultPort(const char* scheme,
nsIIOService* ioService = nullptr);
/**
- * This function is a helper function to apply the ToAscii conversion
- * to a string
+ * The UTS #46 ToASCII operation as parametrized by the WHATWG URL Standard.
+ *
+ * Use this function to prepare a host name for network protocols.
+ */
+nsresult NS_DomainToASCII(const nsACString& aHost, nsACString& aASCII);
+
+/**
+ * The UTS #46 ToUnicode operation as parametrized by the WHATWG URL Standard,
+ * except potentially misleading labels are treated according to ToASCII
+ * instead.
+ *
+ * Use this function to prepare a host name for display to the user.
*/
-bool NS_StringToACE(const nsACString& idn, nsACString& result);
+nsresult NS_DomainToDisplay(const nsACString& aHost, nsACString& aDisplay);
+
+/**
+ * The UTS #46 ToUnicode operation as parametrized by the WHATWG URL Standard.
+ *
+ * It's most likely incorrect to call this function, and `NS_DomainToDisplay`
+ * should typically be called instead.
+ */
+nsresult NS_DomainToUnicode(const nsACString& aHost, nsACString& aUnicode);
/**
* This function is a helper function to get a protocol's default port if the
@@ -1020,7 +1038,7 @@ bool SchemeIsFTP(nsIURI* aURI);
// step 2.1 in https://url.spec.whatwg.org/#scheme-state
bool SchemeIsSpecial(const nsACString&);
bool IsSchemeChangePermitted(nsIURI*, const nsACString&);
-already_AddRefed<nsIURI> TryChangeProtocol(nsIURI*, const nsAString&);
+already_AddRefed<nsIURI> TryChangeProtocol(nsIURI*, const nsACString&);
struct LinkHeader {
nsString mHref;
@@ -1099,6 +1117,8 @@ void CheckForBrokenChromeURL(nsILoadInfo* aLoadInfo, nsIURI* aURI);
bool IsCoepCredentiallessEnabled(bool aIsOriginTrialCoepCredentiallessEnabled);
+void ParseSimpleURISchemes(const nsACString& schemeList);
+
} // namespace net
} // namespace mozilla
diff --git a/netwerk/base/nsPACMan.cpp b/netwerk/base/nsPACMan.cpp
index d4c6c4bd79..28d8aa7df4 100644
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -713,6 +713,7 @@ void nsPACMan::ContinueLoadingAfterPACUriKnown() {
channel->SetLoadFlags(nsIRequest::LOAD_BYPASS_CACHE);
channel->SetNotificationCallbacks(this);
+ channel->SetTRRMode(nsIRequest::TRR_DISABLED_MODE);
if (NS_SUCCEEDED(channel->AsyncOpen(loader))) return;
}
}
diff --git a/netwerk/base/nsPISocketTransportService.idl b/netwerk/base/nsPISocketTransportService.idl
index e7c8ac5a60..8ea8d7ba55 100644
--- a/netwerk/base/nsPISocketTransportService.idl
+++ b/netwerk/base/nsPISocketTransportService.idl
@@ -17,7 +17,7 @@ interface nsPISocketTransportService : nsIRoutedSocketTransportService
* init/shutdown routines.
*/
void init();
- void shutdown(in bool aXpcomShutdown);
+ void shutdown(in boolean aXpcomShutdown);
/**
* controls the TCP sender window clamp
diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp
index d9b0c23ead..fac8e4ca7f 100644
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -622,6 +622,8 @@ nsresult nsStandardURL::NormalizeIPv4(const nsACString& host,
return NS_OK;
}
+nsIIDNService* nsStandardURL::GetIDNService() { return gIDN.get(); }
+
nsresult nsStandardURL::NormalizeIDN(const nsCString& host, nsCString& result) {
result.Truncate();
mDisplayHost.Truncate();
@@ -1104,7 +1106,7 @@ nsresult nsStandardURL::BuildNormalizedSpec(const char* spec,
}
}
- if (mDirectory.mLen > 1) {
+ if (mDirectory.mLen > 0) {
netCoalesceFlags coalesceFlag = NET_COALESCE_NORMAL;
if (SegmentIs(buf, mScheme, "ftp")) {
coalesceFlag =
diff --git a/netwerk/base/nsStandardURL.h b/netwerk/base/nsStandardURL.h
index a4f644e722..5e49088fbc 100644
--- a/netwerk/base/nsStandardURL.h
+++ b/netwerk/base/nsStandardURL.h
@@ -198,6 +198,8 @@ class nsStandardURL : public nsIFileURL,
static nsresult NormalizeIPv4(const nsACString& host, nsCString& result);
+ static nsIIDNService* GetIDNService();
+
protected:
// enum used in a few places to specify how .ref attribute should be handled
enum RefHandlingEnum { eIgnoreRef, eHonorRef, eReplaceRef };
diff --git a/netwerk/base/nsStreamTransportService.cpp b/netwerk/base/nsStreamTransportService.cpp
index e1369bbcb5..19776b2ac2 100644
--- a/netwerk/base/nsStreamTransportService.cpp
+++ b/netwerk/base/nsStreamTransportService.cpp
@@ -369,61 +369,5 @@ nsStreamTransportService::Observe(nsISupports* subject, const char* topic,
return NS_OK;
}
-class AvailableEvent final : public Runnable {
- public:
- AvailableEvent(nsIInputStream* stream, nsIInputAvailableCallback* callback)
- : Runnable("net::AvailableEvent"),
- mStream(stream),
- mCallback(callback),
- mDoingCallback(false),
- mSize(0),
- mResultForCallback(NS_OK) {
- mCallbackTarget = GetCurrentSerialEventTarget();
- }
-
- NS_IMETHOD Run() override {
- if (mDoingCallback) {
- // pong
- mCallback->OnInputAvailableComplete(mSize, mResultForCallback);
- mCallback = nullptr;
- } else {
- // ping
- mResultForCallback = mStream->Available(&mSize);
- mStream = nullptr;
- mDoingCallback = true;
-
- nsCOMPtr<nsIRunnable> event(this); // overly cute
- mCallbackTarget->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
- mCallbackTarget = nullptr;
- }
- return NS_OK;
- }
-
- private:
- virtual ~AvailableEvent() = default;
-
- nsCOMPtr<nsIInputStream> mStream;
- nsCOMPtr<nsIInputAvailableCallback> mCallback;
- nsCOMPtr<nsIEventTarget> mCallbackTarget;
- bool mDoingCallback;
- uint64_t mSize;
- nsresult mResultForCallback;
-};
-
-NS_IMETHODIMP
-nsStreamTransportService::InputAvailable(nsIInputStream* stream,
- nsIInputAvailableCallback* callback) {
- nsCOMPtr<nsIThreadPool> pool;
- {
- mozilla::MutexAutoLock lock(mShutdownLock);
- if (mIsShutdown) {
- return NS_ERROR_NOT_INITIALIZED;
- }
- pool = mPool;
- }
- nsCOMPtr<nsIRunnable> event = new AvailableEvent(stream, callback);
- return pool->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
-}
-
} // namespace net
} // namespace mozilla
diff --git a/netwerk/base/nsURLHelper.cpp b/netwerk/base/nsURLHelper.cpp
index ca82b0cd00..109df8f6d1 100644
--- a/netwerk/base/nsURLHelper.cpp
+++ b/netwerk/base/nsURLHelper.cpp
@@ -219,6 +219,11 @@ void net_CoalesceDirs(netCoalesceFlags flags, char* path) {
uint32_t traversal = 0;
uint32_t special_ftp_len = 0;
+ MOZ_ASSERT(*path == '/', "We expect the path to begin with /");
+ if (*path != '/') {
+ return;
+ }
+
/* Remember if this url is a special ftp one: */
if (flags & NET_COALESCE_DOUBLE_SLASH_IS_ROOT) {
/* some schemes (for example ftp) have the speciality that
@@ -249,7 +254,7 @@ void net_CoalesceDirs(netCoalesceFlags flags, char* path) {
fwdPtr = path;
/* replace all %2E or %2e with . in the path */
- /* but stop at lastchar if non null */
+ /* but stop at lastslash if non null */
for (; (*fwdPtr != '\0') && (*fwdPtr != '?') && (*fwdPtr != '#') &&
(*lastslash == '\0' || fwdPtr != lastslash);
++fwdPtr) {
@@ -346,6 +351,14 @@ void net_CoalesceDirs(netCoalesceFlags flags, char* path) {
urlPtr--;
}
+ // Before we start copying past ?#, we must make sure we don't overwrite
+ // the first / character. If fwdPtr is also unchanged, just copy everything
+ // (this shouldn't happen unless we could get in here without a leading
+ // slash).
+ if (urlPtr == path && fwdPtr != path) {
+ urlPtr++;
+ }
+
// Copy remaining stuff past the #?;
for (; *fwdPtr != '\0'; ++fwdPtr) {
*urlPtr++ = *fwdPtr;
@@ -1097,24 +1110,32 @@ bool net_GetDefaultStatusTextForCode(uint16_t aCode, nsACString& aOutText) {
return true;
}
-namespace mozilla {
-static auto MakeNameMatcher(const nsAString& aName) {
+static auto MakeNameMatcher(const nsACString& aName) {
return [&aName](const auto& param) { return param.mKey.Equals(aName); };
}
-bool URLParams::Has(const nsAString& aName) {
+static void AssignMaybeInvalidUTF8String(const nsACString& aSource,
+ nsACString& aDest) {
+ if (NS_FAILED(UTF_8_ENCODING->DecodeWithoutBOMHandling(aSource, aDest))) {
+ MOZ_CRASH("Out of memory when converting URL params.");
+ }
+}
+
+namespace mozilla {
+
+bool URLParams::Has(const nsACString& aName) {
return std::any_of(mParams.cbegin(), mParams.cend(), MakeNameMatcher(aName));
}
-bool URLParams::Has(const nsAString& aName, const nsAString& aValue) {
+bool URLParams::Has(const nsACString& aName, const nsACString& aValue) {
return std::any_of(
mParams.cbegin(), mParams.cend(), [&aName, &aValue](const auto& param) {
return param.mKey.Equals(aName) && param.mValue.Equals(aValue);
});
}
-void URLParams::Get(const nsAString& aName, nsString& aRetval) {
- SetDOMStringToNull(aRetval);
+void URLParams::Get(const nsACString& aName, nsACString& aRetval) {
+ aRetval.SetIsVoid(true);
const auto end = mParams.cend();
const auto it = std::find_if(mParams.cbegin(), end, MakeNameMatcher(aName));
@@ -1123,7 +1144,7 @@ void URLParams::Get(const nsAString& aName, nsString& aRetval) {
}
}
-void URLParams::GetAll(const nsAString& aName, nsTArray<nsString>& aRetval) {
+void URLParams::GetAll(const nsACString& aName, nsTArray<nsCString>& aRetval) {
aRetval.Clear();
for (uint32_t i = 0, len = mParams.Length(); i < len; ++i) {
@@ -1133,13 +1154,13 @@ void URLParams::GetAll(const nsAString& aName, nsTArray<nsString>& aRetval) {
}
}
-void URLParams::Append(const nsAString& aName, const nsAString& aValue) {
+void URLParams::Append(const nsACString& aName, const nsACString& aValue) {
Param* param = mParams.AppendElement();
param->mKey = aName;
param->mValue = aValue;
}
-void URLParams::Set(const nsAString& aName, const nsAString& aValue) {
+void URLParams::Set(const nsACString& aName, const nsACString& aValue) {
Param* param = nullptr;
for (uint32_t i = 0, len = mParams.Length(); i < len;) {
if (!mParams[i].mKey.Equals(aName)) {
@@ -1164,34 +1185,24 @@ void URLParams::Set(const nsAString& aName, const nsAString& aValue) {
param->mValue = aValue;
}
-void URLParams::Delete(const nsAString& aName) {
+void URLParams::Delete(const nsACString& aName) {
mParams.RemoveElementsBy(
[&aName](const auto& param) { return param.mKey.Equals(aName); });
}
-void URLParams::Delete(const nsAString& aName, const nsAString& aValue) {
+void URLParams::Delete(const nsACString& aName, const nsACString& aValue) {
mParams.RemoveElementsBy([&aName, &aValue](const auto& param) {
return param.mKey.Equals(aName) && param.mValue.Equals(aValue);
});
}
/* static */
-void URLParams::ConvertString(const nsACString& aInput, nsAString& aOutput) {
- if (NS_FAILED(UTF_8_ENCODING->DecodeWithoutBOMHandling(aInput, aOutput))) {
- MOZ_CRASH("Out of memory when converting URL params.");
- }
-}
-
-/* static */
-void URLParams::DecodeString(const nsACString& aInput, nsAString& aOutput) {
+void URLParams::DecodeString(const nsACString& aInput, nsACString& aOutput) {
const char* const end = aInput.EndReading();
-
- nsAutoCString unescaped;
-
for (const char* iter = aInput.BeginReading(); iter != end;) {
// replace '+' with U+0020
if (*iter == '+') {
- unescaped.Append(' ');
+ aOutput.Append(' ');
++iter;
continue;
}
@@ -1214,30 +1225,26 @@ void URLParams::DecodeString(const nsACString& aInput, nsAString& aOutput) {
if (first != end && second != end && asciiHexDigit(*first) &&
asciiHexDigit(*second)) {
- unescaped.Append(hexDigit(*first) * 16 + hexDigit(*second));
+ aOutput.Append(hexDigit(*first) * 16 + hexDigit(*second));
iter = second + 1;
} else {
- unescaped.Append('%');
+ aOutput.Append('%');
++iter;
}
continue;
}
- unescaped.Append(*iter);
+ aOutput.Append(*iter);
++iter;
}
-
- // XXX It seems rather wasteful to first decode into a UTF-8 nsCString and
- // then convert the whole string to UTF-16, at least if we exceed the inline
- // storage size.
- ConvertString(unescaped, aOutput);
+ AssignMaybeInvalidUTF8String(aOutput, aOutput);
}
/* static */
bool URLParams::ParseNextInternal(const char*& aStart, const char* const aEnd,
- bool aShouldDecode, nsAString* aOutputName,
- nsAString* aOutputValue) {
+ bool aShouldDecode, nsACString* aOutputName,
+ nsACString* aOutputValue) {
nsDependentCSubstring string;
const char* const iter = std::find(aStart, aEnd, '&');
@@ -1273,17 +1280,18 @@ bool URLParams::ParseNextInternal(const char*& aStart, const char* const aEnd,
return true;
}
- ConvertString(name, *aOutputName);
- ConvertString(value, *aOutputValue);
+ AssignMaybeInvalidUTF8String(name, *aOutputName);
+ AssignMaybeInvalidUTF8String(value, *aOutputValue);
return true;
}
/* static */
-bool URLParams::Extract(const nsACString& aInput, const nsAString& aName,
- nsAString& aValue) {
+bool URLParams::Extract(const nsACString& aInput, const nsACString& aName,
+ nsACString& aValue) {
aValue.SetIsVoid(true);
return !URLParams::Parse(
- aInput, true, [&aName, &aValue](const nsAString& name, nsString&& value) {
+ aInput, true,
+ [&aName, &aValue](const nsACString& name, nsCString&& value) {
if (aName == name) {
aValue = std::move(value);
return false;
@@ -1296,16 +1304,14 @@ void URLParams::ParseInput(const nsACString& aInput) {
// Remove all the existing data before parsing a new input.
DeleteAll();
- URLParams::Parse(aInput, true, [this](nsString&& name, nsString&& value) {
+ URLParams::Parse(aInput, true, [this](nsCString&& name, nsCString&& value) {
mParams.AppendElement(Param{std::move(name), std::move(value)});
return true;
});
}
-namespace {
-
-void SerializeString(const nsCString& aInput, nsAString& aValue) {
- const unsigned char* p = (const unsigned char*)aInput.get();
+void URLParams::SerializeString(const nsACString& aInput, nsACString& aValue) {
+ const unsigned char* p = (const unsigned char*)aInput.BeginReading();
const unsigned char* end = p + aInput.Length();
while (p != end) {
@@ -1325,9 +1331,7 @@ void SerializeString(const nsCString& aInput, nsAString& aValue) {
}
}
-} // namespace
-
-void URLParams::Serialize(nsAString& aValue, bool aEncode) const {
+void URLParams::Serialize(nsACString& aValue, bool aEncode) const {
aValue.Truncate();
bool first = true;
@@ -1341,9 +1345,9 @@ void URLParams::Serialize(nsAString& aValue, bool aEncode) const {
// XXX Actually, it's not necessary to build a new string object. Generally,
// such cases could just convert each codepoint one-by-one.
if (aEncode) {
- SerializeString(NS_ConvertUTF16toUTF8(mParams[i].mKey), aValue);
+ SerializeString(mParams[i].mKey, aValue);
aValue.Append('=');
- SerializeString(NS_ConvertUTF16toUTF8(mParams[i].mValue), aValue);
+ SerializeString(mParams[i].mValue, aValue);
} else {
aValue.Append(mParams[i].mKey);
aValue.Append('=');
@@ -1354,7 +1358,11 @@ void URLParams::Serialize(nsAString& aValue, bool aEncode) const {
void URLParams::Sort() {
mParams.StableSort([](const Param& lhs, const Param& rhs) {
- return Compare(lhs.mKey, rhs.mKey);
+ // FIXME(emilio, bug 1888901): The URLSearchParams.sort() spec requires
+ // comparing by utf-16 code points... That's a bit unfortunate, maybe we
+ // can optimize the string conversions here?
+ return Compare(NS_ConvertUTF8toUTF16(lhs.mKey),
+ NS_ConvertUTF8toUTF16(rhs.mKey));
});
}
diff --git a/netwerk/base/nsURLHelper.h b/netwerk/base/nsURLHelper.h
index 36844e6e4b..b9b81a8eb0 100644
--- a/netwerk/base/nsURLHelper.h
+++ b/netwerk/base/nsURLHelper.h
@@ -251,7 +251,7 @@ class URLParams final {
* \param aInput the query string to parse
* \param aParamHandler the parameter handler as desribed above
* \tparam ParamHandler a function type compatible with signature
- * bool(nsString, nsString)
+ * bool(nsCString, nsCString)
*
* \return false if the parameter handler returned false for any parameter,
* true otherwise
@@ -263,8 +263,8 @@ class URLParams final {
const char* const end = aInput.EndReading();
while (start != end) {
- nsAutoString name;
- nsAutoString value;
+ nsAutoCString name;
+ nsAutoCString value;
if (!ParseNextInternal(start, end, aShouldDecode, &name, &value)) {
continue;
@@ -290,8 +290,8 @@ class URLParams final {
* there is no match \return true iff there was a parameter with with name
* \paramref aName
*/
- static bool Extract(const nsACString& aInput, const nsAString& aName,
- nsAString& aValue);
+ static bool Extract(const nsACString& aInput, const nsACString& aName,
+ nsACString& aValue);
/**
* \brief Resets the state of this instance and parses a new query string.
@@ -306,11 +306,12 @@ class URLParams final {
* \param[out] aValue will be assigned the result of the serialization
* \param aEncode If this is true, the serialization will encode the string.
*/
- void Serialize(nsAString& aValue, bool aEncode) const;
+ void Serialize(nsACString& aValue, bool aEncode) const;
- void Get(const nsAString& aName, nsString& aRetval);
+ static void SerializeString(const nsACString& aInput, nsACString& aValue);
+ void Get(const nsACString& aName, nsACString& aRetval);
- void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval);
+ void GetAll(const nsACString& aName, nsTArray<nsCString>& aRetval);
/**
* \brief Sets the value of a given parameter.
@@ -319,31 +320,32 @@ class URLParams final {
* replaced, and all further parameters of the name are deleted. Otherwise,
* the behaviour is the same as \ref Append.
*/
- void Set(const nsAString& aName, const nsAString& aValue);
+ void Set(const nsACString& aName, const nsACString& aValue);
- void Append(const nsAString& aName, const nsAString& aValue);
+ void Append(const nsACString& aName, const nsACString& aValue);
- bool Has(const nsAString& aName);
+ bool Has(const nsACString& aName);
- bool Has(const nsAString& aName, const nsAString& aValue);
+ bool Has(const nsACString& aName, const nsACString& aValue);
/**
* \brief Deletes all parameters with the given name.
*/
- void Delete(const nsAString& aName);
+ void Delete(const nsACString& aName);
- void Delete(const nsAString& aName, const nsAString& aValue);
+ void Delete(const nsACString& aName, const nsACString& aValue);
void DeleteAll() { mParams.Clear(); }
uint32_t Length() const { return mParams.Length(); }
- const nsAString& GetKeyAtIndex(uint32_t aIndex) const {
+ static void DecodeString(const nsACString& aInput, nsACString& aOutput);
+ const nsACString& GetKeyAtIndex(uint32_t aIndex) const {
MOZ_ASSERT(aIndex < mParams.Length());
return mParams[aIndex].mKey;
}
- const nsAString& GetValueAtIndex(uint32_t aIndex) const {
+ const nsACString& GetValueAtIndex(uint32_t aIndex) const {
MOZ_ASSERT(aIndex < mParams.Length());
return mParams[aIndex].mValue;
}
@@ -355,15 +357,13 @@ class URLParams final {
void Sort();
private:
- static void DecodeString(const nsACString& aInput, nsAString& aOutput);
- static void ConvertString(const nsACString& aInput, nsAString& aOutput);
static bool ParseNextInternal(const char*& aStart, const char* aEnd,
- bool aShouldDecode, nsAString* aOutputName,
- nsAString* aOutputValue);
+ bool aShouldDecode, nsACString* aOutputName,
+ nsACString* aOutputValue);
struct Param {
- nsString mKey;
- nsString mValue;
+ nsCString mKey;
+ nsCString mValue;
};
nsTArray<Param> mParams;