Bug 1887719 - More consistently use UTF8String/nsCString for URLs. r=necko-reviewers,webidl,anti-tracking-reviewers,places-reviewers,jari,kershaw,janv,smaug,hsivonen

Sorry for the massive patch but I found it hard to split without
introducing a bunch of copies around...

This mostly makes necko and DOM agree on which strings to use, which
should result on less copies and conversions.

Differential Revision: https://phabricator.services.mozilla.com/D205601
This commit is contained in:
Emilio Cobos Álvarez 2024-04-04 11:49:57 +00:00
Родитель f4cc26bd0e
Коммит e4ddf24147
93 изменённых файлов: 722 добавлений и 914 удалений

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

@ -2240,7 +2240,7 @@ Relation LocalAccessible::RelationByType(RelationType aType) const {
}
// If this node is an anchor element, query its hash to find the
// target.
nsAutoString hash;
nsAutoCString hash;
anchor->GetHash(hash);
if (hash.IsEmpty()) {
return rel;
@ -2248,11 +2248,11 @@ Relation LocalAccessible::RelationByType(RelationType aType) const {
// GetHash returns an ID or name with a leading '#', trim it so we can
// search the doc by ID or name alone.
hash.Trim("#");
if (dom::Element* elm = mContent->OwnerDoc()->GetElementById(hash)) {
NS_ConvertUTF8toUTF16 hash16(Substring(hash, 1));
if (dom::Element* elm = mContent->OwnerDoc()->GetElementById(hash16)) {
rel.AppendTarget(mDoc->GetAccessibleOrContainer(elm));
} else if (nsCOMPtr<nsINodeList> list =
mContent->OwnerDoc()->GetElementsByName(hash)) {
mContent->OwnerDoc()->GetElementsByName(hash16)) {
// Loop through the named nodes looking for the first anchor
uint32_t length = list->Length();
for (uint32_t i = 0; i < length; i++) {

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

@ -233,7 +233,7 @@ void OriginAttributes::SetPartitionKey(const nsAString& aOther) {
void OriginAttributes::CreateSuffix(nsACString& aStr) const {
URLParams params;
nsAutoString value;
nsAutoCString value;
//
// Important: While serializing any string-valued attributes, perform a
@ -245,35 +245,34 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
if (mUserContextId != nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) {
value.Truncate();
value.AppendInt(mUserContextId);
params.Set(u"userContextId"_ns, value);
params.Set("userContextId"_ns, value);
}
if (mPrivateBrowsingId) {
value.Truncate();
value.AppendInt(mPrivateBrowsingId);
params.Set(u"privateBrowsingId"_ns, value);
params.Set("privateBrowsingId"_ns, value);
}
if (!mFirstPartyDomain.IsEmpty()) {
nsAutoString sanitizedFirstPartyDomain(mFirstPartyDomain);
sanitizedFirstPartyDomain.ReplaceChar(kSourceChar, kSanitizedChar);
params.Set(u"firstPartyDomain"_ns, sanitizedFirstPartyDomain);
params.Set("firstPartyDomain"_ns,
NS_ConvertUTF16toUTF8(sanitizedFirstPartyDomain));
}
if (!mGeckoViewSessionContextId.IsEmpty()) {
nsAutoString sanitizedGeckoViewUserContextId(mGeckoViewSessionContextId);
sanitizedGeckoViewUserContextId.ReplaceChar(
dom::quota::QuotaManager::kReplaceChars16, kSanitizedChar);
params.Set(u"geckoViewUserContextId"_ns, sanitizedGeckoViewUserContextId);
params.Set("geckoViewUserContextId"_ns,
NS_ConvertUTF16toUTF8(sanitizedGeckoViewUserContextId));
}
if (!mPartitionKey.IsEmpty()) {
nsAutoString sanitizedPartitionKey(mPartitionKey);
sanitizedPartitionKey.ReplaceChar(kSourceChar, kSanitizedChar);
params.Set(u"partitionKey"_ns, sanitizedPartitionKey);
params.Set("partitionKey"_ns, NS_ConvertUTF16toUTF8(sanitizedPartitionKey));
}
aStr.Truncate();
@ -281,7 +280,7 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
params.Serialize(value, true);
if (!value.IsEmpty()) {
aStr.AppendLiteral("^");
aStr.Append(NS_ConvertUTF16toUTF8(value));
aStr.Append(value);
}
// In debug builds, check the whole string for illegal characters too (just in
@ -338,7 +337,7 @@ bool OriginAttributes::PopulateFromSuffix(const nsACString& aStr) {
return URLParams::Parse(
Substring(aStr, 1, aStr.Length() - 1), true,
[this](const nsAString& aName, const nsAString& aValue) {
[this](const nsACString& aName, const nsACString& aValue) {
if (aName.EqualsLiteral("inBrowser")) {
if (!aValue.EqualsLiteral("1")) {
return false;
@ -374,21 +373,21 @@ bool OriginAttributes::PopulateFromSuffix(const nsACString& aStr) {
}
if (aName.EqualsLiteral("firstPartyDomain")) {
nsAutoString firstPartyDomain(aValue);
nsAutoCString firstPartyDomain(aValue);
firstPartyDomain.ReplaceChar(kSanitizedChar, kSourceChar);
mFirstPartyDomain.Assign(firstPartyDomain);
mFirstPartyDomain.Assign(NS_ConvertUTF8toUTF16(firstPartyDomain));
return true;
}
if (aName.EqualsLiteral("geckoViewUserContextId")) {
mGeckoViewSessionContextId.Assign(aValue);
mGeckoViewSessionContextId.Assign(NS_ConvertUTF8toUTF16(aValue));
return true;
}
if (aName.EqualsLiteral("partitionKey")) {
nsAutoString partitionKey(aValue);
nsAutoCString partitionKey(aValue);
partitionKey.ReplaceChar(kSanitizedChar, kSourceChar);
mPartitionKey.Assign(partitionKey);
mPartitionKey.Assign(NS_ConvertUTF8toUTF16(partitionKey));
return true;
}

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

@ -422,9 +422,10 @@ already_AddRefed<FormData> BodyUtil::ConsumeFormData(
if (isValidUrlEncodedMimeType) {
RefPtr<FormData> fd = new FormData(aParent);
DebugOnly<bool> status = URLParams::Parse(
aStr, true, [&fd](const nsAString& aName, const nsAString& aValue) {
ErrorResult rv;
fd->Append(aName, aValue, rv);
aStr, true, [&fd](const nsACString& aName, const nsACString& aValue) {
IgnoredErrorResult rv;
fd->Append(NS_ConvertUTF8toUTF16(aName),
NS_ConvertUTF8toUTF16(aValue), rv);
MOZ_ASSERT(!rv.Failed());
return true;
});

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

@ -6400,7 +6400,7 @@ void Document::SetLastFocusTime(const TimeStamp& aFocusTime) {
mLastFocusTime = aFocusTime;
}
void Document::GetReferrer(nsAString& aReferrer) const {
void Document::GetReferrer(nsACString& aReferrer) const {
aReferrer.Truncate();
if (!mReferrerInfo) {
return;
@ -6411,13 +6411,7 @@ void Document::GetReferrer(nsAString& aReferrer) const {
return;
}
nsAutoCString uri;
nsresult rv = URLDecorationStripper::StripTrackingIdentifiers(referrer, uri);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
CopyUTF8toUTF16(uri, aReferrer);
URLDecorationStripper::StripTrackingIdentifiers(referrer, aReferrer);
}
void Document::GetCookie(nsAString& aCookie, ErrorResult& aRv) {

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

@ -3272,7 +3272,7 @@ class Document : public nsINode,
void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);
void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
void GetReferrer(nsAString& aReferrer) const;
void GetReferrer(nsACString& aReferrer) const;
void GetLastModified(nsAString& aLastModified) const;
void GetReadyState(nsAString& aReadyState) const;

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

@ -6,26 +6,21 @@
#include "Link.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/SVGAElement.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "mozilla/IHistory.h"
#include "mozilla/StaticPrefs_layout.h"
#include "nsLayoutUtils.h"
#include "nsIURL.h"
#include "nsIURIMutator.h"
#include "nsISizeOf.h"
#include "nsEscape.h"
#include "nsGkAtoms.h"
#include "nsString.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/Components.h"
#include "nsAttrValueInlines.h"
#include "HTMLLinkElement.h"
namespace mozilla::dom {
@ -133,7 +128,7 @@ nsIURI* Link::GetURI() const {
return mCachedURI;
}
void Link::SetProtocol(const nsAString& aProtocol) {
void Link::SetProtocol(const nsACString& aProtocol) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
@ -146,111 +141,100 @@ void Link::SetProtocol(const nsAString& aProtocol) {
SetHrefAttribute(uri);
}
void Link::SetPassword(const nsAString& aPassword) {
void Link::SetPassword(const nsACString& aPassword) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv = NS_MutateURI(uri)
.SetPassword(NS_ConvertUTF16toUTF8(aPassword))
.Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetPassword(aPassword).Finalize(uri);
if (NS_SUCCEEDED(rv)) {
SetHrefAttribute(uri);
}
}
void Link::SetUsername(const nsAString& aUsername) {
void Link::SetUsername(const nsACString& aUsername) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv = NS_MutateURI(uri)
.SetUsername(NS_ConvertUTF16toUTF8(aUsername))
.Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetUsername(aUsername).Finalize(uri);
if (NS_SUCCEEDED(rv)) {
SetHrefAttribute(uri);
}
}
void Link::SetHost(const nsAString& aHost) {
void Link::SetHost(const nsACString& aHost) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv =
NS_MutateURI(uri).SetHostPort(NS_ConvertUTF16toUTF8(aHost)).Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetHostPort(aHost).Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
SetHrefAttribute(uri);
}
void Link::SetHostname(const nsAString& aHostname) {
void Link::SetHostname(const nsACString& aHostname) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv =
NS_MutateURI(uri).SetHost(NS_ConvertUTF16toUTF8(aHostname)).Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetHost(aHostname).Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
SetHrefAttribute(uri);
}
void Link::SetPathname(const nsAString& aPathname) {
void Link::SetPathname(const nsACString& aPathname) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv = NS_MutateURI(uri)
.SetFilePath(NS_ConvertUTF16toUTF8(aPathname))
.Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetFilePath(aPathname).Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
SetHrefAttribute(uri);
}
void Link::SetSearch(const nsAString& aSearch) {
void Link::SetSearch(const nsACString& aSearch) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv =
NS_MutateURI(uri).SetQuery(NS_ConvertUTF16toUTF8(aSearch)).Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetQuery(aSearch).Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
SetHrefAttribute(uri);
}
void Link::SetPort(const nsAString& aPort) {
void Link::SetPort(const nsACString& aPort) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv;
nsAutoString portStr(aPort);
// nsIURI uses -1 as default value.
nsresult rv;
int32_t port = -1;
if (!aPort.IsEmpty()) {
port = portStr.ToInteger(&rv);
port = aPort.ToInteger(&rv);
if (NS_FAILED(rv)) {
return;
}
@ -263,15 +247,14 @@ void Link::SetPort(const nsAString& aPort) {
SetHrefAttribute(uri);
}
void Link::SetHash(const nsAString& aHash) {
void Link::SetHash(const nsACString& aHash) {
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
nsresult rv =
NS_MutateURI(uri).SetRef(NS_ConvertUTF16toUTF8(aHash)).Finalize(uri);
nsresult rv = NS_MutateURI(uri).SetRef(aHash).Finalize(uri);
if (NS_FAILED(rv)) {
return;
}
@ -279,121 +262,102 @@ void Link::SetHash(const nsAString& aHash) {
SetHrefAttribute(uri);
}
void Link::GetOrigin(nsAString& aOrigin) {
void Link::GetOrigin(nsACString& aOrigin) {
aOrigin.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
return;
}
nsString origin;
nsContentUtils::GetWebExposedOriginSerialization(uri, origin);
aOrigin.Assign(origin);
nsContentUtils::GetWebExposedOriginSerialization(uri, aOrigin);
}
void Link::GetProtocol(nsAString& _protocol) {
nsCOMPtr<nsIURI> uri(GetURI());
if (uri) {
nsAutoCString scheme;
(void)uri->GetScheme(scheme);
CopyASCIItoUTF16(scheme, _protocol);
void Link::GetProtocol(nsACString& aProtocol) {
if (nsIURI* uri = GetURI()) {
(void)uri->GetScheme(aProtocol);
}
_protocol.Append(char16_t(':'));
aProtocol.Append(':');
}
void Link::GetUsername(nsAString& aUsername) {
void Link::GetUsername(nsACString& aUsername) {
aUsername.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
return;
}
nsAutoCString username;
uri->GetUsername(username);
CopyASCIItoUTF16(username, aUsername);
uri->GetUsername(aUsername);
}
void Link::GetPassword(nsAString& aPassword) {
void Link::GetPassword(nsACString& aPassword) {
aPassword.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
return;
}
nsAutoCString password;
uri->GetPassword(password);
CopyASCIItoUTF16(password, aPassword);
uri->GetPassword(aPassword);
}
void Link::GetHost(nsAString& _host) {
_host.Truncate();
void Link::GetHost(nsACString& aHost) {
aHost.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
// Do not throw! Not having a valid URI should result in an empty string.
return;
}
nsAutoCString hostport;
nsresult rv = uri->GetHostPort(hostport);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(hostport, _host);
}
uri->GetHostPort(aHost);
}
void Link::GetHostname(nsAString& _hostname) {
_hostname.Truncate();
void Link::GetHostname(nsACString& aHostname) {
aHostname.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
// Do not throw! Not having a valid URI should result in an empty string.
return;
}
nsContentUtils::GetHostOrIPv6WithBrackets(uri, _hostname);
nsContentUtils::GetHostOrIPv6WithBrackets(uri, aHostname);
}
void Link::GetPathname(nsAString& _pathname) {
_pathname.Truncate();
void Link::GetPathname(nsACString& aPathname) {
aPathname.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
// Do not throw! Not having a valid URI should result in an empty string.
return;
}
nsAutoCString file;
nsresult rv = uri->GetFilePath(file);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(file, _pathname);
}
uri->GetFilePath(aPathname);
}
void Link::GetSearch(nsAString& _search) {
_search.Truncate();
void Link::GetSearch(nsACString& aSearch) {
aSearch.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
// Do not throw! Not having a valid URI or URL should result in an empty
// string.
return;
}
nsAutoCString search;
nsresult rv = uri->GetQuery(search);
if (NS_SUCCEEDED(rv) && !search.IsEmpty()) {
_search.Assign(u'?');
AppendUTF8toUTF16(search, _search);
nsresult rv = uri->GetQuery(aSearch);
if (NS_SUCCEEDED(rv) && !aSearch.IsEmpty()) {
aSearch.Insert('?', 0);
}
}
void Link::GetPort(nsAString& _port) {
_port.Truncate();
void Link::GetPort(nsACString& aPort) {
aPort.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
// Do not throw! Not having a valid URI should result in an empty string.
return;
@ -404,27 +368,23 @@ void Link::GetPort(nsAString& _port) {
// Note that failure to get the port from the URI is not necessarily a bad
// thing. Some URIs do not have a port.
if (NS_SUCCEEDED(rv) && port != -1) {
nsAutoString portStr;
portStr.AppendInt(port, 10);
_port.Assign(portStr);
aPort.AppendInt(port, 10);
}
}
void Link::GetHash(nsAString& _hash) {
_hash.Truncate();
void Link::GetHash(nsACString& aHash) {
aHash.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
nsIURI* uri = GetURI();
if (!uri) {
// Do not throw! Not having a valid URI should result in an empty
// string.
return;
}
nsAutoCString ref;
nsresult rv = uri->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
_hash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, _hash);
nsresult rv = uri->GetRef(aHash);
if (NS_SUCCEEDED(rv) && !aHash.IsEmpty()) {
aHash.Insert('#', 0);
}
}

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

@ -64,25 +64,25 @@ class Link : public nsISupports {
/**
* Helper methods for modifying and obtaining parts of the URI of the Link.
*/
void SetProtocol(const nsAString& aProtocol);
void SetUsername(const nsAString& aUsername);
void SetPassword(const nsAString& aPassword);
void SetHost(const nsAString& aHost);
void SetHostname(const nsAString& aHostname);
void SetPathname(const nsAString& aPathname);
void SetSearch(const nsAString& aSearch);
void SetPort(const nsAString& aPort);
void SetHash(const nsAString& aHash);
void GetOrigin(nsAString& aOrigin);
void GetProtocol(nsAString& _protocol);
void GetUsername(nsAString& aUsername);
void GetPassword(nsAString& aPassword);
void GetHost(nsAString& _host);
void GetHostname(nsAString& _hostname);
void GetPathname(nsAString& _pathname);
void GetSearch(nsAString& _search);
void GetPort(nsAString& _port);
void GetHash(nsAString& _hash);
void SetProtocol(const nsACString& aProtocol);
void SetUsername(const nsACString& aUsername);
void SetPassword(const nsACString& aPassword);
void SetHost(const nsACString& aHost);
void SetHostname(const nsACString& aHostname);
void SetPathname(const nsACString& aPathname);
void SetSearch(const nsACString& aSearch);
void SetPort(const nsACString& aPort);
void SetHash(const nsACString& aHash);
void GetOrigin(nsACString& aOrigin);
void GetProtocol(nsACString& aProtocol);
void GetUsername(nsACString& aUsername);
void GetPassword(nsACString& aPassword);
void GetHost(nsACString& aHost);
void GetHostname(nsACString& aHostname);
void GetPathname(nsACString& aPathname);
void GetSearch(nsACString& aSearch);
void GetPort(nsACString& aPort);
void GetHash(nsACString& aHash);
/**
* Invalidates any link caching, and resets the state to the default.

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

@ -3703,7 +3703,7 @@ bool nsGlobalWindowInner::Confirm(const nsAString& aMessage,
}
already_AddRefed<Promise> nsGlobalWindowInner::Fetch(
const RequestOrUSVString& aInput, const RequestInit& aInit,
const RequestOrUTF8String& aInput, const RequestInit& aInit,
CallerType aCallerType, ErrorResult& aRv) {
return FetchRequest(this, aInput, aInit, aCallerType, aRv);
}

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

@ -120,7 +120,7 @@ class OwningExternalOrWindowProxy;
class Promise;
class PostMessageEvent;
struct RequestInit;
class RequestOrUSVString;
class RequestOrUTF8String;
class SharedWorker;
class Selection;
struct SizeToContentConstraints;
@ -671,7 +671,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
already_AddRefed<mozilla::dom::cache::CacheStorage> GetCaches(
mozilla::ErrorResult& aRv);
already_AddRefed<mozilla::dom::Promise> Fetch(
const mozilla::dom::RequestOrUSVString& aInput,
const mozilla::dom::RequestOrUTF8String& aInput,
const mozilla::dom::RequestInit& aInit,
mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void Print(mozilla::ErrorResult& aError);

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

@ -105,7 +105,6 @@ class PostMessageData;
class PostMessageEvent;
class PrintPreviewResultInfo;
struct RequestInit;
class RequestOrUSVString;
class Selection;
struct SizeToContentConstraints;
class SpeechSynthesis;

43
dom/cache/Cache.cpp поставляемый
Просмотреть файл

@ -34,12 +34,11 @@ namespace {
enum class PutStatusPolicy { Default, RequireOK };
bool IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv) {
bool IsValidPutRequestURL(const nsACString& aUrl, ErrorResult& aRv) {
bool validScheme = false;
// make a copy because ProcessURL strips the fragmet
NS_ConvertUTF16toUTF8 url(aUrl);
nsAutoCString url(aUrl);
TypeUtils::ProcessURL(url, &validScheme, nullptr, nullptr, aRv);
if (aRv.Failed()) {
return false;
@ -47,8 +46,7 @@ bool IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv) {
if (!validScheme) {
// `url` has been modified, so don't use it here.
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Request",
NS_ConvertUTF16toUTF8(aUrl));
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Request", aUrl);
return false;
}
@ -66,7 +64,7 @@ static bool IsValidPutRequestMethod(const Request& aRequest, ErrorResult& aRv) {
return true;
}
static bool IsValidPutRequestMethod(const RequestOrUSVString& aRequest,
static bool IsValidPutRequestMethod(const RequestOrUTF8String& aRequest,
ErrorResult& aRv) {
// If the provided request is a string URL, then it will default to
// a valid http method automatically.
@ -81,12 +79,10 @@ static bool IsValidPutResponseStatus(Response& aResponse,
ErrorResult& aRv) {
if ((aPolicy == PutStatusPolicy::RequireOK && !aResponse.Ok()) ||
aResponse.Status() == 206) {
nsAutoString url;
nsAutoCString url;
aResponse.GetUrl(url);
aRv.ThrowTypeError<MSG_CACHE_ADD_FAILED_RESPONSE>(
GetEnumString(aResponse.Type()), IntToCString(aResponse.Status()),
NS_ConvertUTF16toUTF8(url));
GetEnumString(aResponse.Type()), IntToCString(aResponse.Status()), url);
return false;
}
@ -228,7 +224,7 @@ Cache::Cache(nsIGlobalObject* aGlobal, CacheChild* aActor, Namespace aNamespace)
}
already_AddRefed<Promise> Cache::Match(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
const CacheQueryOptions& aOptions,
ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
@ -259,7 +255,7 @@ already_AddRefed<Promise> Cache::Match(JSContext* aCx,
}
already_AddRefed<Promise> Cache::MatchAll(
JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aOptions, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@ -291,7 +287,7 @@ already_AddRefed<Promise> Cache::MatchAll(
}
already_AddRefed<Promise> Cache::Add(JSContext* aContext,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
CallerType aCallerType, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@ -315,7 +311,7 @@ already_AddRefed<Promise> Cache::Add(JSContext* aContext,
return nullptr;
}
nsAutoString url;
nsAutoCString url;
request->GetUrl(url);
if (NS_WARN_IF(!IsValidPutRequestURL(url, aRv))) {
return nullptr;
@ -326,7 +322,8 @@ already_AddRefed<Promise> Cache::Add(JSContext* aContext,
}
already_AddRefed<Promise> Cache::AddAll(
JSContext* aContext, const Sequence<OwningRequestOrUSVString>& aRequestList,
JSContext* aContext,
const Sequence<OwningRequestOrUTF8String>& aRequestList,
CallerType aCallerType, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@ -340,7 +337,7 @@ already_AddRefed<Promise> Cache::AddAll(
nsTArray<SafeRefPtr<Request>> requestList(aRequestList.Length());
for (uint32_t i = 0; i < aRequestList.Length(); ++i) {
RequestOrUSVString requestOrString;
RequestOrUTF8String requestOrString;
if (aRequestList[i].IsRequest()) {
requestOrString.SetAsRequest() = aRequestList[i].GetAsRequest();
@ -349,8 +346,8 @@ already_AddRefed<Promise> Cache::AddAll(
return nullptr;
}
} else {
requestOrString.SetAsUSVString().ShareOrDependUpon(
aRequestList[i].GetAsUSVString());
requestOrString.SetAsUTF8String().ShareOrDependUpon(
aRequestList[i].GetAsUTF8String());
}
RootedDictionary<RequestInit> requestInit(aContext);
@ -360,7 +357,7 @@ already_AddRefed<Promise> Cache::AddAll(
return nullptr;
}
nsAutoString url;
nsAutoCString url;
request->GetUrl(url);
if (NS_WARN_IF(!IsValidPutRequestURL(url, aRv))) {
return nullptr;
@ -373,7 +370,7 @@ already_AddRefed<Promise> Cache::AddAll(
}
already_AddRefed<Promise> Cache::Put(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
Response& aResponse, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@ -418,7 +415,7 @@ already_AddRefed<Promise> Cache::Put(JSContext* aCx,
}
already_AddRefed<Promise> Cache::Delete(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
const CacheQueryOptions& aOptions,
ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
@ -448,7 +445,7 @@ already_AddRefed<Promise> Cache::Delete(JSContext* aCx,
}
already_AddRefed<Promise> Cache::Keys(
JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aOptions, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@ -552,7 +549,7 @@ already_AddRefed<Promise> Cache::AddAll(
// future once fetch supports it.
for (uint32_t i = 0; i < aRequestList.Length(); ++i) {
RequestOrUSVString requestOrString;
RequestOrUTF8String requestOrString;
requestOrString.SetAsRequest() = aRequestList[i].unsafeGetRawPtr();
RootedDictionary<RequestInit> requestInit(aGlobal.Context());
RefPtr<Promise> fetch =

18
dom/cache/Cache.h поставляемый
Просмотреть файл

@ -22,10 +22,10 @@ class ErrorResult;
namespace dom {
class OwningRequestOrUSVString;
class OwningRequestOrUTF8String;
class Promise;
struct CacheQueryOptions;
class RequestOrUSVString;
class RequestOrUTF8String;
class Response;
template <typename T>
class Optional;
@ -46,27 +46,27 @@ class Cache final : public nsISupports,
// webidl interface methods
already_AddRefed<Promise> Match(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
const CacheQueryOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> MatchAll(
JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aOptions, ErrorResult& aRv);
already_AddRefed<Promise> Add(JSContext* aContext,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
CallerType aCallerType, ErrorResult& aRv);
already_AddRefed<Promise> AddAll(
JSContext* aContext, const Sequence<OwningRequestOrUSVString>& aRequests,
JSContext* aContext, const Sequence<OwningRequestOrUTF8String>& aRequests,
CallerType aCallerType, ErrorResult& aRv);
already_AddRefed<Promise> Put(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
Response& aResponse, ErrorResult& aRv);
already_AddRefed<Promise> Delete(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
const CacheQueryOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> Keys(JSContext* aCx,
const Optional<RequestOrUSVString>& aRequest,
const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aParams,
ErrorResult& aRv);

2
dom/cache/CacheStorage.cpp поставляемый
Просмотреть файл

@ -298,7 +298,7 @@ CacheStorage::CacheStorage(nsresult aFailureResult)
}
already_AddRefed<Promise> CacheStorage::Match(
JSContext* aCx, const RequestOrUSVString& aRequest,
JSContext* aCx, const RequestOrUTF8String& aRequest,
const MultiCacheQueryOptions& aOptions, ErrorResult& aRv) {
NS_ASSERT_OWNINGTHREAD(CacheStorage);

2
dom/cache/CacheStorage.h поставляемый
Просмотреть файл

@ -56,7 +56,7 @@ class CacheStorage final : public nsISupports,
// webidl interface methods
already_AddRefed<Promise> Match(JSContext* aCx,
const RequestOrUSVString& aRequest,
const RequestOrUTF8String& aRequest,
const MultiCacheQueryOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> Has(const nsAString& aKey, ErrorResult& aRv);

2
dom/cache/CacheTypes.ipdlh поставляемый
Просмотреть файл

@ -59,7 +59,7 @@ struct CacheRequest
nsCString urlFragment;
HeadersEntry[] headers;
HeadersGuardEnum headersGuard;
nsString referrer;
nsCString referrer;
ReferrerPolicy referrerPolicy;
RequestMode mode;
RequestCredentials credentials;

10
dom/cache/DBSchema.cpp поставляемый
Просмотреть файл

@ -1794,8 +1794,8 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("request_url_fragment"_ns,
aRequest.urlFragment())));
QM_TRY(MOZ_TO_RESULT(
state->BindStringByName("request_referrer"_ns, aRequest.referrer())));
QM_TRY(MOZ_TO_RESULT(state->BindStringByName(
"request_referrer"_ns, NS_ConvertUTF8toUTF16(aRequest.referrer()))));
QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName(
"request_referrer_policy"_ns,
@ -2208,7 +2208,11 @@ Result<SavedRequest, nsresult> ReadRequest(mozIStorageConnection& aConn,
MOZ_TO_RESULT(state->GetUTF8String(2, savedRequest.mValue.urlQuery())));
QM_TRY(MOZ_TO_RESULT(
state->GetUTF8String(3, savedRequest.mValue.urlFragment())));
QM_TRY(MOZ_TO_RESULT(state->GetString(4, savedRequest.mValue.referrer())));
{
nsAutoString referrer;
QM_TRY(MOZ_TO_RESULT(state->GetString(4, referrer)));
CopyUTF16toUTF8(referrer, savedRequest.mValue.referrer());
}
QM_TRY_INSPECT(const int32_t& referrerPolicy,
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 5));

16
dom/cache/TypeUtils.cpp поставляемый
Просмотреть файл

@ -74,7 +74,7 @@ nsTArray<HeadersEntry> ToHeadersEntryList(InternalHeaders* aHeaders) {
} // namespace
SafeRefPtr<InternalRequest> TypeUtils::ToInternalRequest(
JSContext* aCx, const RequestOrUSVString& aIn, BodyAction aBodyAction,
JSContext* aCx, const RequestOrUTF8String& aIn, BodyAction aBodyAction,
ErrorResult& aRv) {
if (aIn.IsRequest()) {
Request& request = aIn.GetAsRequest();
@ -89,12 +89,12 @@ SafeRefPtr<InternalRequest> TypeUtils::ToInternalRequest(
return request.GetInternalRequest();
}
return ToInternalRequest(aIn.GetAsUSVString(), aRv);
return ToInternalRequest(aIn.GetAsUTF8String(), aRv);
}
SafeRefPtr<InternalRequest> TypeUtils::ToInternalRequest(
JSContext* aCx, const OwningRequestOrUSVString& aIn, BodyAction aBodyAction,
ErrorResult& aRv) {
JSContext* aCx, const OwningRequestOrUTF8String& aIn,
BodyAction aBodyAction, ErrorResult& aRv) {
if (aIn.IsRequest()) {
Request& request = aIn.GetAsRequest();
@ -108,7 +108,7 @@ SafeRefPtr<InternalRequest> TypeUtils::ToInternalRequest(
return request.GetInternalRequest();
}
return ToInternalRequest(aIn.GetAsUSVString(), aRv);
return ToInternalRequest(aIn.GetAsUTF8String(), aRv);
}
void TypeUtils::ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn,
@ -447,10 +447,10 @@ void TypeUtils::CheckAndSetBodyUsed(JSContext* aCx, Request& aRequest,
}
}
SafeRefPtr<InternalRequest> TypeUtils::ToInternalRequest(const nsAString& aIn,
SafeRefPtr<InternalRequest> TypeUtils::ToInternalRequest(const nsACString& aIn,
ErrorResult& aRv) {
RequestOrUSVString requestOrString;
requestOrString.SetAsUSVString().ShareOrDependUpon(aIn);
RequestOrUTF8String requestOrString;
requestOrString.SetAsUTF8String().ShareOrDependUpon(aIn);
// Re-create a GlobalObject stack object so we can use webidl Constructors.
AutoJSAPI jsapi;

10
dom/cache/TypeUtils.h поставляемый
Просмотреть файл

@ -30,9 +30,9 @@ struct MultiCacheQueryOptions;
class InternalHeaders;
class InternalRequest;
class InternalResponse;
class OwningRequestOrUSVString;
class OwningRequestOrUTF8String;
class Request;
class RequestOrUSVString;
class RequestOrUTF8String;
class Response;
namespace cache {
@ -64,12 +64,12 @@ class TypeUtils {
virtual mozilla::ipc::PBackgroundChild* GetIPCManager() = 0;
SafeRefPtr<InternalRequest> ToInternalRequest(JSContext* aCx,
const RequestOrUSVString& aIn,
const RequestOrUTF8String& aIn,
BodyAction aBodyAction,
ErrorResult& aRv);
SafeRefPtr<InternalRequest> ToInternalRequest(
JSContext* aCx, const OwningRequestOrUSVString& aIn,
JSContext* aCx, const OwningRequestOrUTF8String& aIn,
BodyAction aBodyAction, ErrorResult& aRv);
void ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn,
@ -120,7 +120,7 @@ class TypeUtils {
void CheckAndSetBodyUsed(JSContext* aCx, Request& aRequest,
BodyAction aBodyAction, ErrorResult& aRv);
SafeRefPtr<InternalRequest> ToInternalRequest(const nsAString& aIn,
SafeRefPtr<InternalRequest> ToInternalRequest(const nsACString& aIn,
ErrorResult& aRv);
void SerializeCacheStream(nsIInputStream* aStream,

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

@ -10,6 +10,6 @@
*/
[GenerateInitFromJSON]
dictionary StripRule {
sequence<DOMString> queryParams = [];
sequence<DOMString> topLevelSites = [];
sequence<UTF8String> queryParams = [];
sequence<UTF8String> topLevelSites = [];
};

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

@ -602,15 +602,14 @@ RefPtr<IdentityCredential::GetTokenPromise> IdentityCredential::FetchToken(
MakeSafeRefPtr<InternalRequest>(tokenLocation, fragment);
internalRequest->SetMethod("POST"_ns);
URLParams bodyValue;
bodyValue.Set(u"account_id"_ns, aAccount.mId);
bodyValue.Set(u"client_id"_ns, aProvider.mClientId);
bodyValue.Set("account_id"_ns, NS_ConvertUTF16toUTF8(aAccount.mId));
bodyValue.Set("client_id"_ns, aProvider.mClientId);
if (aProvider.mNonce.WasPassed()) {
bodyValue.Set(u"nonce"_ns, aProvider.mNonce.Value());
bodyValue.Set("nonce"_ns, aProvider.mNonce.Value());
}
bodyValue.Set(u"disclosure_text_shown"_ns, u"false"_ns);
nsString bodyString;
bodyValue.Serialize(bodyString, true);
nsCString bodyCString = NS_ConvertUTF16toUTF8(bodyString);
bodyValue.Set("disclosure_text_shown"_ns, "false"_ns);
nsAutoCString bodyCString;
bodyValue.Serialize(bodyCString, true);
nsCOMPtr<nsIInputStream> streamBody;
rv = NS_NewCStringInputStream(getter_AddRefs(streamBody), bodyCString);
if (NS_FAILED(rv)) {
@ -1097,7 +1096,7 @@ already_AddRefed<Promise> IdentityCredential::LogoutRPs(
nsContentPolicyType::TYPE_WEB_IDENTITY);
RefPtr<Request> domRequest =
new Request(global, std::move(internalRequest), nullptr);
RequestOrUSVString fetchInput;
RequestOrUTF8String fetchInput;
fetchInput.SetAsRequest() = domRequest;
RootedDictionary<RequestInit> requestInit(RootingCx());
IgnoredErrorResult error;

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

@ -28,7 +28,7 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
new typename TPromise::Private(__func__);
// Fetch the provided request
RequestOrUSVString fetchInput;
RequestOrUTF8String fetchInput;
fetchInput.SetAsRequest() = aRequest;
RootedDictionary<RequestInit> requestInit(RootingCx());
IgnoredErrorResult error;

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

@ -470,7 +470,7 @@ class MainThreadFetchRunnable : public Runnable {
};
already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
const RequestOrUSVString& aInput,
const RequestOrUTF8String& aInput,
const RequestInit& aInit,
CallerType aCallerType,
ErrorResult& aRv) {

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

@ -44,13 +44,13 @@ class
OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString;
class ReadableStreamDefaultReader;
class RequestOrUSVString;
class RequestOrUTF8String;
class WorkerPrivate;
enum class CallerType : uint32_t;
already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
const RequestOrUSVString& aInput,
const RequestOrUTF8String& aInput,
const RequestInit& aInit,
CallerType aCallerType,
ErrorResult& aRv);

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

@ -441,7 +441,7 @@ void FetchDriver::UpdateReferrerInfoFromNewChannel(nsIChannel* aChannel) {
return;
}
nsAutoString computedReferrerSpec;
nsAutoCString computedReferrerSpec;
mRequest->SetReferrerPolicy(referrerInfo->ReferrerPolicy());
Unused << referrerInfo->GetComputedReferrerSpec(computedReferrerSpec);
mRequest->SetReferrer(computedReferrerSpec);

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

@ -59,7 +59,7 @@ struct IPCInternalRequest {
int64_t bodySize;
nsCString preferredAlternativeDataType;
uint32_t contentPolicyType;
nsString referrer;
nsCString referrer;
ReferrerPolicy referrerPolicy;
ReferrerPolicy environmentReferrerPolicy;
RequestMode requestMode;

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

@ -128,7 +128,7 @@ nsresult FetchUtil::SetRequestReferrer(nsIPrincipal* aPrincipal, Document* aDoc,
MOZ_ASSERT(NS_IsMainThread());
nsresult rv = NS_OK;
nsAutoString referrer;
nsAutoCString referrer;
aRequest.GetReferrer(referrer);
ReferrerPolicy policy = aRequest.ReferrerPolicy_();
@ -154,7 +154,7 @@ nsresult FetchUtil::SetRequestReferrer(nsIPrincipal* aPrincipal, Document* aDoc,
rv = aChannel->SetReferrerInfoWithoutClone(referrerInfo);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString computedReferrerSpec;
nsAutoCString computedReferrerSpec;
referrerInfo = aChannel->GetReferrerInfo();
if (referrerInfo) {
Unused << referrerInfo->GetComputedReferrerSpec(computedReferrerSpec);
@ -719,7 +719,7 @@ bool FetchUtil::StreamResponseToJS(JSContext* aCx, JS::Handle<JSObject*> aObj,
switch (aMimeType) {
case JS::MimeType::Wasm:
nsAutoString url;
nsAutoCString url;
response->GetUrl(url);
IgnoredErrorResult result;
@ -728,9 +728,8 @@ bool FetchUtil::StreamResponseToJS(JSContext* aCx, JS::Handle<JSObject*> aObj,
if (NS_WARN_IF(result.Failed())) {
return ThrowException(aCx, JSMSG_WASM_ERROR_CONSUMING_RESPONSE);
}
NS_ConvertUTF16toUTF8 urlUTF8(url);
aConsumer->noteResponseURLs(
urlUTF8.get(), sourceMapUrl.IsVoid() ? nullptr : sourceMapUrl.get());
url.get(), sourceMapUrl.IsVoid() ? nullptr : sourceMapUrl.get());
break;
}

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

@ -86,7 +86,7 @@ InternalRequest::InternalRequest(const nsACString& aURL,
mHeaders(new InternalHeaders(HeadersGuardEnum::None)),
mBodyLength(InternalResponse::UNKNOWN_BODY_SIZE),
mContentPolicyType(nsIContentPolicy::TYPE_FETCH),
mReferrer(NS_LITERAL_STRING_FROM_CSTRING(kFETCH_CLIENT_REFERRER_STR)),
mReferrer(nsLiteralCString(kFETCH_CLIENT_REFERRER_STR)),
mReferrerPolicy(ReferrerPolicy::_empty),
mEnvironmentReferrerPolicy(ReferrerPolicy::_empty),
mMode(RequestMode::No_cors),
@ -102,7 +102,7 @@ InternalRequest::InternalRequest(
const nsACString& aMethod, already_AddRefed<InternalHeaders> aHeaders,
RequestCache aCacheMode, RequestMode aMode,
RequestRedirect aRequestRedirect, RequestCredentials aRequestCredentials,
const nsAString& aReferrer, ReferrerPolicy aReferrerPolicy,
const nsACString& aReferrer, ReferrerPolicy aReferrerPolicy,
RequestPriority aPriority, nsContentPolicyType aContentPolicyType,
const nsAString& aIntegrity)
: mMethod(aMethod),

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

@ -92,7 +92,7 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
RequestCache aCacheMode, RequestMode aMode,
RequestRedirect aRequestRedirect,
RequestCredentials aRequestCredentials,
const nsAString& aReferrer, ReferrerPolicy aReferrerPolicy,
const nsACString& aReferrer, ReferrerPolicy aReferrerPolicy,
RequestPriority aPriority,
nsContentPolicyType aContentPolicyType,
const nsAString& aIntegrity);
@ -159,9 +159,9 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
void GetURLListWithoutFragment(nsTArray<nsCString>& aURLList) {
aURLList.Assign(mURLList);
}
void GetReferrer(nsAString& aReferrer) const { aReferrer.Assign(mReferrer); }
void GetReferrer(nsACString& aReferrer) const { aReferrer.Assign(mReferrer); }
void SetReferrer(const nsAString& aReferrer) {
void SetReferrer(const nsACString& aReferrer) {
#ifdef DEBUG
bool validReferrer = false;
if (aReferrer.IsEmpty() ||
@ -179,10 +179,9 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
uint32_t pathPos;
int32_t pathLen;
NS_ConvertUTF16toUTF8 ref(aReferrer);
nsresult rv =
parser->ParseURL(ref.get(), ref.Length(), &schemePos, &schemeLen,
&authorityPos, &authorityLen, &pathPos, &pathLen);
nsresult rv = parser->ParseURL(
aReferrer.BeginReading(), aReferrer.Length(), &schemePos,
&schemeLen, &authorityPos, &authorityLen, &pathPos, &pathLen);
if (NS_FAILED(rv)) {
NS_WARNING("Invalid referrer URL!");
} else if (schemeLen < 0 || authorityLen < 0) {
@ -444,7 +443,7 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
// Empty string: no-referrer
// "about:client": client (default)
// URL: an URL
nsString mReferrer;
nsCString mReferrer;
ReferrerPolicy mReferrerPolicy;
// This will be used for request created from Window or Worker contexts

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

@ -78,29 +78,22 @@ SafeRefPtr<InternalRequest> Request::GetInternalRequest() {
namespace {
already_AddRefed<nsIURI> ParseURLFromDocument(Document* aDocument,
const nsAString& aInput,
const nsACString& aInput,
ErrorResult& aRv) {
MOZ_ASSERT(aDocument);
MOZ_ASSERT(NS_IsMainThread());
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString input;
if (!AppendUTF16toUTF8(aInput, input, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> resolvedURI;
nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), input, nullptr,
nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), aInput, nullptr,
aDocument->GetBaseURI());
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(input);
aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
}
return resolvedURI.forget();
}
void GetRequestURLFromDocument(Document* aDocument, const nsAString& aInput,
nsAString& aRequestURL, nsACString& aURLfragment,
ErrorResult& aRv) {
void GetRequestURLFromDocument(Document* aDocument, const nsACString& aInput,
nsACString& aRequestURL,
nsACString& aURLfragment, ErrorResult& aRv) {
nsCOMPtr<nsIURI> resolvedURI = ParseURLFromDocument(aDocument, aInput, aRv);
if (aRv.Failed()) {
return;
@ -110,7 +103,7 @@ void GetRequestURLFromDocument(Document* aDocument, const nsAString& aInput,
nsAutoCString credentials;
Unused << resolvedURI->GetUserPass(credentials);
if (!credentials.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(NS_ConvertUTF16toUTF8(aInput));
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
return;
}
@ -119,12 +112,10 @@ void GetRequestURLFromDocument(Document* aDocument, const nsAString& aInput,
if (NS_WARN_IF(aRv.Failed())) {
return;
}
nsAutoCString spec;
aRv = resolvedURIClone->GetSpec(spec);
aRv = resolvedURIClone->GetSpec(aRequestURL);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
CopyUTF8toUTF16(spec, aRequestURL);
// Get the fragment from nsIURI.
aRv = resolvedURI->GetRef(aURLfragment);
@ -132,24 +123,18 @@ void GetRequestURLFromDocument(Document* aDocument, const nsAString& aInput,
return;
}
}
already_AddRefed<nsIURI> ParseURLFromChrome(const nsAString& aInput,
already_AddRefed<nsIURI> ParseURLFromChrome(const nsACString& aInput,
ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString input;
if (!AppendUTF16toUTF8(aInput, input, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), input);
nsresult rv = NS_NewURI(getter_AddRefs(uri), aInput);
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(input);
aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
}
return uri.forget();
}
void GetRequestURLFromChrome(const nsAString& aInput, nsAString& aRequestURL,
void GetRequestURLFromChrome(const nsACString& aInput, nsACString& aRequestURL,
nsACString& aURLfragment, ErrorResult& aRv) {
nsCOMPtr<nsIURI> uri = ParseURLFromChrome(aInput, aRv);
if (aRv.Failed()) {
@ -160,7 +145,7 @@ void GetRequestURLFromChrome(const nsAString& aInput, nsAString& aRequestURL,
nsAutoCString credentials;
Unused << uri->GetUserPass(credentials);
if (!credentials.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(NS_ConvertUTF16toUTF8(aInput));
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
return;
}
@ -169,12 +154,10 @@ void GetRequestURLFromChrome(const nsAString& aInput, nsAString& aRequestURL,
if (NS_WARN_IF(aRv.Failed())) {
return;
}
nsAutoCString spec;
aRv = uriClone->GetSpec(spec);
aRv = uriClone->GetSpec(aRequestURL);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
CopyUTF8toUTF16(spec, aRequestURL);
// Get the fragment from nsIURI.
aRv = uri->GetRef(aURLfragment);
@ -183,55 +166,55 @@ void GetRequestURLFromChrome(const nsAString& aInput, nsAString& aRequestURL,
}
}
already_AddRefed<URL> ParseURLFromWorker(nsIGlobalObject* aGlobal,
const nsAString& aInput,
const nsACString& aInput,
ErrorResult& aRv) {
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
worker->AssertIsOnWorkerThread();
NS_ConvertUTF8toUTF16 baseURL(worker->GetLocationInfo().mHref);
const auto& baseURL = worker->GetLocationInfo().mHref;
RefPtr<URL> url = URL::Constructor(aGlobal, aInput, baseURL, aRv);
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_URL>(NS_ConvertUTF16toUTF8(aInput));
aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
}
return url.forget();
}
void GetRequestURLFromWorker(nsIGlobalObject* aGlobal, const nsAString& aInput,
nsAString& aRequestURL, nsACString& aURLfragment,
void GetRequestURLFromWorker(nsIGlobalObject* aGlobal, const nsACString& aInput,
nsACString& aRequestURL, nsACString& aURLfragment,
ErrorResult& aRv) {
RefPtr<URL> url = ParseURLFromWorker(aGlobal, aInput, aRv);
if (aRv.Failed()) {
return;
}
nsString username;
nsCString username;
url->GetUsername(username);
nsString password;
nsCString password;
url->GetPassword(password);
if (!username.IsEmpty() || !password.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(NS_ConvertUTF16toUTF8(aInput));
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
return;
}
// Get the fragment from URL.
nsAutoString fragment;
nsAutoCString fragment;
url->GetHash(fragment);
// Note: URL::GetHash() includes the "#" and we want the fragment with out
// the hash symbol.
if (!fragment.IsEmpty()) {
CopyUTF16toUTF8(Substring(fragment, 1), aURLfragment);
aURLfragment = Substring(fragment, 1);
}
url->SetHash(u""_ns);
url->SetHash(""_ns);
url->GetHref(aRequestURL);
}
class ReferrerSameOriginChecker final : public WorkerMainThreadRunnable {
public:
ReferrerSameOriginChecker(WorkerPrivate* aWorkerPrivate,
const nsAString& aReferrerURL, nsresult& aResult)
const nsACString& aReferrerURL, nsresult& aResult)
: WorkerMainThreadRunnable(aWorkerPrivate,
"Fetch :: Referrer same origin check"_ns),
mReferrerURL(aReferrerURL),
@ -242,8 +225,7 @@ class ReferrerSameOriginChecker final : public WorkerMainThreadRunnable {
bool MainThreadRun() override {
nsCOMPtr<nsIURI> uri;
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), mReferrerURL))) {
nsCOMPtr<nsIPrincipal> principal = mWorkerPrivate->GetPrincipal();
if (principal) {
if (nsCOMPtr<nsIPrincipal> principal = mWorkerPrivate->GetPrincipal()) {
mResult = principal->CheckMayLoad(uri,
/* allowIfInheritsPrincipal */ false);
}
@ -252,7 +234,7 @@ class ReferrerSameOriginChecker final : public WorkerMainThreadRunnable {
}
private:
const nsString mReferrerURL;
const nsCString mReferrerURL;
nsresult& mResult;
};
@ -260,7 +242,7 @@ class ReferrerSameOriginChecker final : public WorkerMainThreadRunnable {
/*static*/
SafeRefPtr<Request> Request::Constructor(const GlobalObject& aGlobal,
const RequestOrUSVString& aInput,
const RequestOrUTF8String& aInput,
const RequestInit& aInit,
ErrorResult& aRv) {
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
@ -270,7 +252,7 @@ SafeRefPtr<Request> Request::Constructor(const GlobalObject& aGlobal,
/*static*/
SafeRefPtr<Request> Request::Constructor(
nsIGlobalObject* aGlobal, JSContext* aCx, const RequestOrUSVString& aInput,
nsIGlobalObject* aGlobal, JSContext* aCx, const RequestOrUTF8String& aInput,
const RequestInit& aInit, CallerType aCallerType, ErrorResult& aRv) {
bool hasCopiedBody = false;
SafeRefPtr<InternalRequest> request;
@ -301,11 +283,10 @@ SafeRefPtr<Request> Request::Constructor(
request = inputReq->GetInternalRequest();
signal = inputReq->GetOrCreateSignal();
} else {
// aInput is USVString.
// aInput is UTF8String.
// We need to get url before we create a InternalRequest.
nsAutoString input;
input.Assign(aInput.GetAsUSVString());
nsAutoString requestURL;
const nsACString& input = aInput.GetAsUTF8String();
nsAutoCString requestURL;
nsCString fragment;
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> inner(do_QueryInterface(aGlobal));
@ -322,8 +303,7 @@ SafeRefPtr<Request> Request::Constructor(
if (aRv.Failed()) {
return nullptr;
}
request = MakeSafeRefPtr<InternalRequest>(NS_ConvertUTF16toUTF8(requestURL),
fragment);
request = MakeSafeRefPtr<InternalRequest>(requestURL, fragment);
}
request = request->GetRequestConstructorCopy(aGlobal, aRv);
if (NS_WARN_IF(aRv.Failed())) {
@ -346,7 +326,7 @@ SafeRefPtr<Request> Request::Constructor(
if (aInit.mCache.WasPassed()) {
cache.emplace(aInit.mCache.Value());
}
if (aInput.IsUSVString()) {
if (aInput.IsUTF8String()) {
if (mode.isNothing()) {
mode.emplace(RequestMode::Cors);
}
@ -368,16 +348,15 @@ SafeRefPtr<Request> Request::Constructor(
}
if (aInit.IsAnyMemberPresent()) {
request->SetReferrer(
NS_LITERAL_STRING_FROM_CSTRING(kFETCH_CLIENT_REFERRER_STR));
request->SetReferrer(nsLiteralCString(kFETCH_CLIENT_REFERRER_STR));
request->SetReferrerPolicy(ReferrerPolicy::_empty);
}
if (aInit.mReferrer.WasPassed()) {
const nsString& referrer = aInit.mReferrer.Value();
const nsCString& referrer = aInit.mReferrer.Value();
if (referrer.IsEmpty()) {
request->SetReferrer(u""_ns);
request->SetReferrer(""_ns);
} else {
nsAutoString referrerURL;
nsAutoCString referrerURL;
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> inner(do_QueryInterface(aGlobal));
Document* doc = inner ? inner->GetExtantDoc() : nullptr;
@ -390,13 +369,10 @@ SafeRefPtr<Request> Request::Constructor(
uri = ParseURLFromChrome(referrer, aRv);
}
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(
NS_ConvertUTF16toUTF8(referrer));
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(referrer);
return nullptr;
}
nsAutoCString spec;
uri->GetSpec(spec);
CopyUTF8toUTF16(spec, referrerURL);
uri->GetSpec(referrerURL);
if (!referrerURL.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) {
nsCOMPtr<nsIPrincipal> principal = aGlobal->PrincipalOrNull();
if (principal) {
@ -411,8 +387,7 @@ SafeRefPtr<Request> Request::Constructor(
} else {
RefPtr<URL> url = ParseURLFromWorker(aGlobal, referrer, aRv);
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(
NS_ConvertUTF16toUTF8(referrer));
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(referrer);
return nullptr;
}
url->GetHref(referrerURL);

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

@ -21,7 +21,7 @@ namespace mozilla::dom {
class Headers;
class InternalHeaders;
class RequestOrUSVString;
class RequestOrUTF8String;
class Request final : public FetchBody<Request>, public nsWrapperCache {
NS_DECL_ISUPPORTS_INHERITED
@ -37,12 +37,7 @@ class Request final : public FetchBody<Request>, public nsWrapperCache {
return Request_Binding::Wrap(aCx, this, aGivenProto);
}
void GetUrl(nsAString& aUrl) const {
nsAutoCString url;
mRequest->GetURL(url);
CopyUTF8toUTF16(url, aUrl);
}
void GetUrl(nsACString& aUrl) const { mRequest->GetURL(aUrl); }
void GetMethod(nsCString& aMethod) const { aMethod = mRequest->mMethod; }
RequestMode Mode() const { return mRequest->mMode; }
@ -74,7 +69,7 @@ class Request final : public FetchBody<Request>, public nsWrapperCache {
return mRequest->IsContentPolicyTypeOverridden();
}
void GetReferrer(nsAString& aReferrer) const {
void GetReferrer(nsACString& aReferrer) const {
mRequest->GetReferrer(aReferrer);
}
@ -105,13 +100,13 @@ class Request final : public FetchBody<Request>, public nsWrapperCache {
const nsAString& BodyLocalPath() const { return mRequest->BodyLocalPath(); }
static SafeRefPtr<Request> Constructor(const GlobalObject& aGlobal,
const RequestOrUSVString& aInput,
const RequestOrUTF8String& aInput,
const RequestInit& aInit,
ErrorResult& rv);
static SafeRefPtr<Request> Constructor(nsIGlobalObject* aGlobal,
JSContext* aCx,
const RequestOrUSVString& aInput,
const RequestOrUTF8String& aInput,
const RequestInit& aInit,
const CallerType aCallerType,
ErrorResult& rv);

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

@ -84,53 +84,42 @@ already_AddRefed<Response> Response::Error(const GlobalObject& aGlobal) {
/* static */
already_AddRefed<Response> Response::Redirect(const GlobalObject& aGlobal,
const nsAString& aUrl,
const nsACString& aUrl,
uint16_t aStatus,
ErrorResult& aRv) {
nsAutoString parsedURL;
nsAutoCString parsedURL;
if (NS_IsMainThread()) {
nsIURI* baseURI = nullptr;
nsCOMPtr<nsPIDOMWindowInner> inner(
do_QueryInterface(aGlobal.GetAsSupports()));
Document* doc = inner ? inner->GetExtantDoc() : nullptr;
if (doc) {
if (Document* doc = inner ? inner->GetExtantDoc() : nullptr) {
baseURI = doc->GetBaseURI();
}
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString url;
if (!AppendUTF16toUTF8(aUrl, url, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> resolvedURI;
nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), url, nullptr, baseURI);
nsresult rv =
NS_NewURI(getter_AddRefs(resolvedURI), aUrl, nullptr, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(url);
aRv.ThrowTypeError<MSG_INVALID_URL>(aUrl);
return nullptr;
}
nsAutoCString spec;
rv = resolvedURI->GetSpec(spec);
rv = resolvedURI->GetSpec(parsedURL);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(url);
aRv.ThrowTypeError<MSG_INVALID_URL>(aUrl);
return nullptr;
}
CopyUTF8toUTF16(spec, parsedURL);
} else {
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
worker->AssertIsOnWorkerThread();
NS_ConvertUTF8toUTF16 baseURL(worker->GetLocationInfo().mHref);
const auto& baseURL = worker->GetLocationInfo().mHref;
RefPtr<URL> url =
URL::Constructor(aGlobal.GetAsSupports(), aUrl, baseURL, aRv);
if (aRv.Failed()) {
return nullptr;
}
url->GetHref(parsedURL);
}
@ -152,8 +141,7 @@ already_AddRefed<Response> Response::Redirect(const GlobalObject& aGlobal,
return nullptr;
}
r->GetInternalHeaders()->Set("Location"_ns, NS_ConvertUTF16toUTF8(parsedURL),
aRv);
r->GetInternalHeaders()->Set("Location"_ns, parsedURL, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

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

@ -43,9 +43,7 @@ class Response final : public FetchBody<Response>, public nsWrapperCache {
}
ResponseType Type() const { return mInternalResponse->Type(); }
void GetUrl(nsAString& aUrl) const {
CopyUTF8toUTF16(mInternalResponse->GetURL(), aUrl);
}
void GetUrl(nsACString& aUrl) const { aUrl = mInternalResponse->GetURL(); }
bool Redirected() const { return mInternalResponse->IsRedirected(); }
uint16_t Status() const { return mInternalResponse->GetStatus(); }
@ -101,7 +99,7 @@ class Response final : public FetchBody<Response>, public nsWrapperCache {
static already_AddRefed<Response> Error(const GlobalObject& aGlobal);
static already_AddRefed<Response> Redirect(const GlobalObject& aGlobal,
const nsAString& aUrl,
const nsACString& aUrl,
uint16_t aStatus,
ErrorResult& aRv);

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

@ -68,11 +68,11 @@ class HTMLAnchorElement final : public nsGenericHTMLElement,
// WebIDL API
void GetHref(nsAString& aValue) const {
void GetHref(nsACString& aValue) const {
GetURIAttr(nsGkAtoms::href, nullptr, aValue);
}
void SetHref(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::href, aValue, rv);
void SetHref(const nsACString& aValue, ErrorResult& aRv) {
SetHTMLAttr(nsGkAtoms::href, NS_ConvertUTF8toUTF16(aValue), aRv);
}
void GetTarget(nsAString& aValue) const;
void SetTarget(const nsAString& aValue, mozilla::ErrorResult& rv) {
@ -180,8 +180,6 @@ class HTMLAnchorElement final : public nsGenericHTMLElement,
void SetShape(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::shape, aValue, rv);
}
void Stringify(nsAString& aResult) const { GetHref(aResult); }
void ToString(nsAString& aSource) const { GetHref(aSource); }
void NodeInfoChanged(Document* aOldDoc) final {
ClearHasPendingLinkUpdate();

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

@ -92,8 +92,6 @@ void HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
}
void HTMLAreaElement::ToString(nsAString& aSource) { GetHref(aSource); }
already_AddRefed<nsIURI> HTMLAreaElement::GetHrefURI() const {
if (nsCOMPtr<nsIURI> uri = GetCachedURI()) {
return uri.forget();

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

@ -64,12 +64,11 @@ class HTMLAreaElement final : public nsGenericHTMLElement, public Link {
SetHTMLAttr(nsGkAtoms::shape, aShape, aError);
}
// argument type nsAString for nsContextMenuInfo
void GetHref(nsAString& aValue) {
void GetHref(nsACString& aValue) {
GetURIAttr(nsGkAtoms::href, nullptr, aValue);
}
void SetHref(const nsAString& aHref, ErrorResult& aError) {
SetHTMLAttr(nsGkAtoms::href, aHref, aError);
void SetHref(const nsACString& aHref, ErrorResult& aError) {
SetHTMLAttr(nsGkAtoms::href, NS_ConvertUTF8toUTF16(aHref), aError);
}
void GetTarget(DOMString& aValue);
@ -85,13 +84,11 @@ class HTMLAreaElement final : public nsGenericHTMLElement, public Link {
}
void GetPing(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::ping, aValue); }
void SetPing(const nsAString& aPing, ErrorResult& aError) {
SetHTMLAttr(nsGkAtoms::ping, aPing, aError);
}
void GetRel(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::rel, aValue); }
void SetRel(const nsAString& aRel, ErrorResult& aError) {
SetHTMLAttr(nsGkAtoms::rel, aRel, aError);
}
@ -141,9 +138,6 @@ class HTMLAreaElement final : public nsGenericHTMLElement, public Link {
SetHTMLBoolAttr(nsGkAtoms::nohref, aValue, aError);
}
void ToString(nsAString& aSource);
void Stringify(nsAString& aResult) { GetHref(aResult); }
void NodeInfoChanged(Document* aOldDoc) final {
ClearHasPendingLinkUpdate();
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);

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

@ -646,7 +646,6 @@ already_AddRefed<nsIURI> nsGenericHTMLElement::GetHrefURIForAnchors() const {
// We use the nsAttrValue's copy of the URI string to avoid copying.
nsCOMPtr<nsIURI> uri;
GetURIAttr(nsGkAtoms::href, nullptr, getter_AddRefs(uri));
return uri.forget();
}
@ -1661,34 +1660,50 @@ uint32_t nsGenericHTMLElement::GetDimensionAttrAsUnsignedInt(
void nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
nsAString& aResult) const {
nsCOMPtr<nsIURI> uri;
bool hadAttr = GetURIAttr(aAttr, aBaseAttr, getter_AddRefs(uri));
if (!hadAttr) {
const nsAttrValue* attr = GetURIAttr(aAttr, aBaseAttr, getter_AddRefs(uri));
if (!attr) {
aResult.Truncate();
return;
}
if (!uri) {
// Just return the attr value
GetAttr(aAttr, aResult);
attr->ToString(aResult);
return;
}
nsAutoCString spec;
uri->GetSpec(spec);
CopyUTF8toUTF16(spec, aResult);
}
bool nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
nsIURI** aURI) const {
void nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
nsACString& aResult) const {
nsCOMPtr<nsIURI> uri;
const nsAttrValue* attr = GetURIAttr(aAttr, aBaseAttr, getter_AddRefs(uri));
if (!attr) {
aResult.Truncate();
return;
}
if (!uri) {
// Just return the attr value
nsAutoString value;
attr->ToString(value);
CopyUTF16toUTF8(value, aResult);
return;
}
uri->GetSpec(aResult);
}
const nsAttrValue* nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr,
nsAtom* aBaseAttr,
nsIURI** aURI) const {
*aURI = nullptr;
const nsAttrValue* attr = mAttrs.GetAttr(aAttr);
if (!attr) {
return false;
return nullptr;
}
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
if (aBaseAttr) {
nsAutoString baseAttrValue;
if (GetAttr(aBaseAttr, baseAttrValue)) {
@ -1696,7 +1711,7 @@ bool nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(
getter_AddRefs(baseAttrURI), baseAttrValue, OwnerDoc(), baseURI);
if (NS_FAILED(rv)) {
return true;
return attr;
}
baseURI.swap(baseAttrURI);
}
@ -1706,7 +1721,7 @@ bool nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
// return true, and *aURI will be null.
nsContentUtils::NewURIWithDocumentCharset(aURI, attr->GetStringValue(),
OwnerDoc(), baseURI);
return true;
return attr;
}
bool nsGenericHTMLElement::IsLabelable() const {

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

@ -640,6 +640,7 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
* @param aResult result value [out]
*/
void GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr, nsAString& aResult) const;
void GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr, nsACString& aResult) const;
/**
* Gets the absolute URI values of an attribute, by resolving any relative
@ -647,7 +648,8 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
* isn't a relative URI, the substring is returned as is. Only works for
* attributes in null namespace.
*/
bool GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr, nsIURI** aURI) const;
const nsAttrValue* GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
nsIURI** aURI) const;
bool IsHidden() const { return HasAttr(nsGkAtoms::hidden); }
@ -766,6 +768,9 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
void GetHTMLURIAttr(nsAtom* aName, nsAString& aResult) const {
GetURIAttr(aName, nullptr, aResult);
}
void GetHTMLURIAttr(nsAtom* aName, nsACString& aResult) const {
GetURIAttr(aName, nullptr, aResult);
}
void SetHTMLAttr(nsAtom* aName, const nsAString& aValue) {
SetAttr(kNameSpaceID_None, aName, aValue, true);

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

@ -391,7 +391,8 @@ JSObject* CommonStructuredCloneReadCallback(
!StructuredCloneHolder::ReadString(aReader, value)) {
return nullptr;
}
params->Append(key, value);
params->Append(NS_ConvertUTF16toUTF8(key),
NS_ConvertUTF16toUTF8(value));
}
if (!WrapAsJSObject(aCx, params, &result)) {

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

@ -241,7 +241,7 @@ interface nsIContentSecurityPolicy : nsISerializable
[must_use] void setRequestContextWithDocument(in Document aDocument);
[must_use] void setRequestContextWithPrincipal(in nsIPrincipal aRequestPrincipal,
in nsIURI aSelfURI,
in AString aReferrer,
in ACString aReferrer,
in unsigned long long aInnerWindowId);
/**
@ -249,7 +249,7 @@ interface nsIContentSecurityPolicy : nsISerializable
*/
[noscript, notxpcom, nostdcall] readonly attribute nsIPrincipal requestPrincipal;
[noscript, notxpcom, nostdcall] readonly attribute nsIURI selfURI;
[noscript] readonly attribute AString referrer;
[noscript] readonly attribute ACString referrer;
[noscript, notxpcom, nostdcall] readonly attribute unsigned long long innerWindowID;
/**

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

@ -108,7 +108,7 @@ interface nsIReferrerInfo : nsISerializable
/**
* Indicates if the referrer should not be sent or not even when it's available.
*/
readonly attribute AString computedReferrerSpec;
readonly attribute ACString computedReferrerSpec;
/**
* Get the computed referrer, if one has been set. The computed referrer is

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

@ -408,8 +408,8 @@ static already_AddRefed<BasePrincipal> GetAboutReaderURLPrincipal(
// Extract the "url" parameter from the `about:reader`'s query parameters,
// and recover a content principal from it.
nsAutoString readerSpec;
if (URLParams::Extract(query, u"url"_ns, readerSpec)) {
nsAutoCString readerSpec;
if (URLParams::Extract(query, "url"_ns, readerSpec)) {
nsCOMPtr<nsIURI> readerUri;
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(readerUri), readerSpec))) {
return BasePrincipal::CreateContentPrincipal(readerUri, aAttrs);

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

@ -7659,11 +7659,10 @@ Result<bool, nsresult> UpgradeStorageFrom1_0To2_0Helper::MaybeRemoveAppsData(
if (!URLParams::Parse(
Substring(originalSuffix, 1, originalSuffix.Length() - 1), true,
[](const nsAString& aName, const nsAString& aValue) {
[](const nsACString& aName, const nsACString& aValue) {
if (aName.EqualsLiteral("appId")) {
return false;
}
return true;
})) {
QM_TRY(MOZ_TO_RESULT(RemoveObsoleteOrigin(aOriginProps)));

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

@ -17,18 +17,17 @@ void StorageOriginAttributes::CreateSuffix(nsACString& aStr) const {
nsCString str1;
URLParams params;
nsAutoString value;
nsAutoCString value;
if (mInIsolatedMozBrowser) {
params.Set(u"inBrowser"_ns, u"1"_ns);
params.Set("inBrowser"_ns, "1"_ns);
}
str1.Truncate();
params.Serialize(value, true);
if (!value.IsEmpty()) {
str1.AppendLiteral("^");
str1.Append(NS_ConvertUTF16toUTF8(value));
str1.Append(value);
}
// Make sure that the string don't contain characters that would get replaced
@ -67,22 +66,22 @@ bool StorageOriginAttributes::PopulateFromSuffix(const nsACString& aStr) {
return false;
}
bool ok =
URLParams::Parse(Substring(aStr, 1, aStr.Length() - 1), true,
[this](const nsAString& aName, const nsAString& aValue) {
if (aName.EqualsLiteral("inBrowser")) {
if (!aValue.EqualsLiteral("1")) {
return false;
}
bool ok = URLParams::Parse(
Substring(aStr, 1, aStr.Length() - 1), true,
[this](const nsACString& aName, const nsACString& aValue) {
if (aName.EqualsLiteral("inBrowser")) {
if (!aValue.EqualsLiteral("1")) {
return false;
}
mInIsolatedMozBrowser = true;
return true;
}
mInIsolatedMozBrowser = true;
return true;
}
// Let OriginAttributes::PopulateFromSuffix parse other
// origin attributes.
return true;
});
// Let OriginAttributes::PopulateFromSuffix parse other
// origin attributes.
return true;
});
if (!ok) {
return false;
}

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

@ -213,7 +213,7 @@ void SendReports(nsTArray<ReportDeliver::ReportData>& aReports,
RefPtr<Request> request =
new Request(globalObject, std::move(internalRequest), nullptr);
RequestOrUSVString fetchInput;
RequestOrUTF8String fetchInput;
fetchInput.SetAsRequest() = request;
RootedDictionary<RequestInit> requestInit(RootingCx());

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

@ -1078,11 +1078,9 @@ ReferrerInfo::Equals(nsIReferrerInfo* aOther, bool* aResult) {
}
NS_IMETHODIMP
ReferrerInfo::GetComputedReferrerSpec(nsAString& aComputedReferrerSpec) {
ReferrerInfo::GetComputedReferrerSpec(nsACString& aComputedReferrerSpec) {
aComputedReferrerSpec.Assign(
mComputedReferrer.isSome()
? NS_ConvertUTF8toUTF16(mComputedReferrer.value())
: EmptyString());
mComputedReferrer.isSome() ? mComputedReferrer.value() : EmptyCString());
return NS_OK;
}

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

@ -450,15 +450,14 @@ nsCSPContext::AppendPolicy(const nsAString& aPolicyString, bool aReportOnly,
if (policy) {
if (policy->hasDirective(
nsIContentSecurityPolicy::UPGRADE_IF_INSECURE_DIRECTIVE)) {
nsAutoCString selfURIspec, referrer;
nsAutoCString selfURIspec;
if (mSelfURI) {
mSelfURI->GetAsciiSpec(selfURIspec);
}
CopyUTF16toUTF8(mReferrer, referrer);
CSPCONTEXTLOG(
("nsCSPContext::AppendPolicy added UPGRADE_IF_INSECURE_DIRECTIVE "
"self-uri=%s referrer=%s",
selfURIspec.get(), referrer.get()));
selfURIspec.get(), mReferrer.get()));
}
mPolicies.AppendElement(policy);
@ -787,7 +786,7 @@ nsCSPContext::SetRequestContextWithDocument(Document* aDocument) {
NS_IMETHODIMP
nsCSPContext::SetRequestContextWithPrincipal(nsIPrincipal* aRequestPrincipal,
nsIURI* aSelfURI,
const nsAString& aReferrer,
const nsACString& aReferrer,
uint64_t aInnerWindowId) {
NS_ENSURE_ARG(aRequestPrincipal);
@ -812,9 +811,8 @@ nsIPrincipal* nsCSPContext::GetRequestPrincipal() { return mLoadingPrincipal; }
nsIURI* nsCSPContext::GetSelfURI() { return mSelfURI; }
NS_IMETHODIMP
nsCSPContext::GetReferrer(nsAString& outReferrer) {
outReferrer.Truncate();
outReferrer.Append(mReferrer);
nsCSPContext::GetReferrer(nsACString& outReferrer) {
outReferrer.Assign(mReferrer);
return NS_OK;
}
@ -987,7 +985,7 @@ nsresult nsCSPContext::GatherSecurityPolicyViolationEventData(
CopyUTF8toUTF16(reportDocumentURI, aViolationEventInit.mDocumentURI);
// referrer
aViolationEventInit.mReferrer = mReferrer;
CopyUTF8toUTF16(mReferrer, aViolationEventInit.mReferrer);
// blocked-uri
if (aBlockedURI) {

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

@ -175,7 +175,7 @@ class nsCSPContext : public nsIContentSecurityPolicy {
uint32_t aViolatedPolicyIndex,
uint32_t aLineNumber, uint32_t aColumnNumber);
nsString mReferrer;
nsCString mReferrer;
uint64_t mInnerWindowID; // used for web console logging
bool mSkipAllowInlineStyleCheck; // used to allow Devtools to edit styles
// When deserializing an nsCSPContext instance, we initially just keep the

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

@ -1065,7 +1065,7 @@ nsresult CheckCSPFrameAncestorPolicy(nsIChannel* aChannel,
csp->SuppressParserLogMessages();
nsCOMPtr<nsIURI> selfURI;
nsAutoString referrerSpec;
nsAutoCString referrerSpec;
if (httpChannel) {
aChannel->GetURI(getter_AddRefs(selfURI));
nsCOMPtr<nsIReferrerInfo> referrerInfo = httpChannel->GetReferrerInfo();

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

@ -93,8 +93,7 @@ nsresult runTest(
// for testing the parser we only need to set a principal which is needed
// to translate the keyword 'self' into an actual URI.
rv =
csp->SetRequestContextWithPrincipal(selfURIPrincipal, selfURI, u""_ns, 0);
rv = csp->SetRequestContextWithPrincipal(selfURIPrincipal, selfURI, ""_ns, 0);
NS_ENSURE_SUCCESS(rv, rv);
// append a policy

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

@ -324,7 +324,7 @@ Result<IPCInternalRequest, nsresult> GetIPCInternalRequest(
RequestCredentials requestCredentials =
InternalRequest::MapChannelToRequestCredentials(underlyingChannel);
nsAutoString referrer;
nsAutoCString referrer;
ReferrerPolicy referrerPolicy = ReferrerPolicy::_empty;
ReferrerPolicy environmentReferrerPolicy = ReferrerPolicy::_empty;

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

@ -114,7 +114,7 @@ class CompareNetwork final : public nsIStreamLoaderObserver,
MOZ_ASSERT(NS_IsMainThread());
}
nsresult Initialize(nsIPrincipal* aPrincipal, const nsAString& aURL,
nsresult Initialize(nsIPrincipal* aPrincipal, const nsACString& aURL,
Cache* const aCache);
void Abort();
@ -123,7 +123,7 @@ class CompareNetwork final : public nsIStreamLoaderObserver,
void CacheFinish(nsresult aRv);
const nsString& URL() const {
const nsCString& URL() const {
MOZ_ASSERT(NS_IsMainThread());
return mURL;
}
@ -164,7 +164,7 @@ class CompareNetwork final : public nsIStreamLoaderObserver,
nsCOMPtr<nsIChannel> mChannel;
nsString mBuffer;
nsString mURL;
nsCString mURL;
ChannelInfo mChannelInfo;
RefPtr<InternalHeaders> mInternalHeaders;
UniquePtr<PrincipalInfo> mPrincipalInfo;
@ -204,7 +204,7 @@ class CompareCache final : public PromiseNativeHandler,
MOZ_ASSERT(NS_IsMainThread());
}
nsresult Initialize(Cache* const aCache, const nsAString& aURL);
nsresult Initialize(Cache* const aCache, const nsACString& aURL);
void Finish(nsresult aStatus, bool aInCache);
@ -231,7 +231,7 @@ class CompareCache final : public PromiseNativeHandler,
RefPtr<CompareNetwork> mCN;
nsCOMPtr<nsIInputStreamPump> mPump;
nsString mURL;
nsCString mURL;
nsString mBuffer;
enum {
@ -262,7 +262,7 @@ class CompareManager final : public PromiseNativeHandler {
MOZ_ASSERT(aRegistration);
}
nsresult Initialize(nsIPrincipal* aPrincipal, const nsAString& aURL,
nsresult Initialize(nsIPrincipal* aPrincipal, const nsACString& aURL,
const nsAString& aCacheName);
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
@ -326,7 +326,7 @@ class CompareManager final : public PromiseNativeHandler {
void Cleanup();
nsresult FetchScript(const nsAString& aURL, bool aIsMainScript,
nsresult FetchScript(const nsACString& aURL, bool aIsMainScript,
Cache* const aCache = nullptr) {
MOZ_ASSERT(NS_IsMainThread());
@ -364,7 +364,7 @@ class CompareManager final : public PromiseNativeHandler {
return;
}
Optional<RequestOrUSVString> request;
Optional<RequestOrUTF8String> request;
CacheQueryOptions options;
ErrorResult error;
RefPtr<Promise> promise = mOldCache->Keys(aCx, request, options, error);
@ -407,7 +407,7 @@ class CompareManager final : public PromiseNativeHandler {
mState = WaitingForScriptOrComparisonResult;
bool hasMainScript = false;
AutoTArray<nsString, 8> urlList;
AutoTArray<nsCString, 8> urlList;
// Extract the list of URLs in the old cache.
for (uint32_t i = 0; i < len; ++i) {
@ -423,14 +423,14 @@ class CompareManager final : public PromiseNativeHandler {
return;
};
nsString url;
nsCString url;
request->GetUrl(url);
if (!hasMainScript && url == mURL) {
hasMainScript = true;
}
urlList.AppendElement(url);
urlList.AppendElement(std::move(url));
}
// If the main script is missing, then something has gone wrong. We
@ -565,8 +565,8 @@ class CompareManager final : public PromiseNativeHandler {
RefPtr<Response> response =
new Response(aCache->GetGlobalObject(), std::move(ir), nullptr);
RequestOrUSVString request;
request.SetAsUSVString().ShareOrDependUpon(aCN->URL());
RequestOrUTF8String request;
request.SetAsUTF8String().ShareOrDependUpon(aCN->URL());
// For now we have to wait until the Put Promise is fulfilled before we can
// continue since Cache does not yet support starting a read that is being
@ -592,7 +592,7 @@ class CompareManager final : public PromiseNativeHandler {
nsTArray<RefPtr<CompareNetwork>> mCNList;
nsString mURL;
nsCString mURL;
RefPtr<nsIPrincipal> mPrincipal;
// Used for the old cache where saves the old source scripts.
@ -622,7 +622,7 @@ class CompareManager final : public PromiseNativeHandler {
NS_IMPL_ISUPPORTS0(CompareManager)
nsresult CompareNetwork::Initialize(nsIPrincipal* aPrincipal,
const nsAString& aURL,
const nsACString& aURL,
Cache* const aCache) {
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(NS_IsMainThread());
@ -634,7 +634,7 @@ nsresult CompareNetwork::Initialize(nsIPrincipal* aPrincipal,
}
mURL = aURL;
mURLList.AppendElement(NS_ConvertUTF16toUTF8(mURL));
mURLList.AppendElement(mURL);
nsCOMPtr<nsILoadGroup> loadGroup;
rv = NS_NewLoadGroup(getter_AddRefs(loadGroup), aPrincipal);
@ -1045,7 +1045,7 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader,
ServiceWorkerManager::LocalizeAndReportToAllClients(
mRegistration->Scope(), "ServiceWorkerRegisterNetworkError",
nsTArray<nsString>{NS_ConvertUTF8toUTF16(mRegistration->Scope()),
statusAsText, mURL});
statusAsText, NS_ConvertUTF8toUTF16(mURL)});
rv = NS_ERROR_FAILURE;
return NS_OK;
@ -1078,7 +1078,8 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader,
ServiceWorkerManager::LocalizeAndReportToAllClients(
mRegistration->Scope(), "ServiceWorkerRegisterMimeTypeError2",
nsTArray<nsString>{NS_ConvertUTF8toUTF16(mRegistration->Scope()),
NS_ConvertUTF8toUTF16(mimeType), mURL});
NS_ConvertUTF8toUTF16(mimeType),
NS_ConvertUTF8toUTF16(mURL)});
rv = NS_ERROR_DOM_SECURITY_ERR;
return rv;
}
@ -1115,7 +1116,7 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader,
return NS_OK;
}
nsresult CompareCache::Initialize(Cache* const aCache, const nsAString& aURL) {
nsresult CompareCache::Initialize(Cache* const aCache, const nsACString& aURL) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aCache);
MOZ_DIAGNOSTIC_ASSERT(mState == WaitingForInitialization);
@ -1125,8 +1126,8 @@ nsresult CompareCache::Initialize(Cache* const aCache, const nsAString& aURL) {
AutoJSAPI jsapi;
jsapi.Init();
RequestOrUSVString request;
request.SetAsUSVString().ShareOrDependUpon(aURL);
RequestOrUTF8String request;
request.SetAsUTF8String().ShareOrDependUpon(aURL);
ErrorResult error;
CacheQueryOptions params;
RefPtr<Promise> promise = aCache->Match(jsapi.cx(), request, params, error);
@ -1294,7 +1295,7 @@ void CompareCache::ManageValueResult(JSContext* aCx,
}
nsresult CompareManager::Initialize(nsIPrincipal* aPrincipal,
const nsAString& aURL,
const nsACString& aURL,
const nsAString& aCacheName) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPrincipal);
@ -1489,7 +1490,7 @@ nsresult GenerateCacheName(nsAString& aName) {
nsresult Compare(ServiceWorkerRegistrationInfo* aRegistration,
nsIPrincipal* aPrincipal, const nsAString& aCacheName,
const nsAString& aURL, CompareCallback* aCallback) {
const nsACString& aURL, CompareCallback* aCallback) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aRegistration);
MOZ_ASSERT(aPrincipal);

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

@ -45,7 +45,7 @@ class CompareCallback {
nsresult Compare(ServiceWorkerRegistrationInfo* aRegistration,
nsIPrincipal* aPrincipal, const nsAString& aCacheName,
const nsAString& aURL, CompareCallback* aCallback);
const nsACString& aURL, CompareCallback* aCallback);
} // namespace serviceWorkerScriptCache

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

@ -287,8 +287,7 @@ void ServiceWorkerUpdateJob::Update() {
RefPtr<CompareCallback> callback = new CompareCallback(this);
nsresult rv = serviceWorkerScriptCache::Compare(
mRegistration, mPrincipal, cacheName, NS_ConvertUTF8toUTF16(mScriptSpec),
callback);
mRegistration, mPrincipal, cacheName, mScriptSpec, callback);
if (NS_WARN_IF(NS_FAILED(rv))) {
FailUpdateJob(rv);
return;

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

@ -36,8 +36,8 @@ JSObject* URL::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
/* static */
already_AddRefed<URL> URL::Constructor(const GlobalObject& aGlobal,
const nsAString& aURL,
const Optional<nsAString>& aBase,
const nsACString& aURL,
const Optional<nsACString>& aBase,
ErrorResult& aRv) {
if (aBase.WasPassed()) {
return Constructor(aGlobal.GetAsSupports(), aURL, aBase.Value(), aRv);
@ -48,20 +48,13 @@ already_AddRefed<URL> URL::Constructor(const GlobalObject& aGlobal,
/* static */
already_AddRefed<URL> URL::Constructor(nsISupports* aParent,
const nsAString& aURL,
const nsAString& aBase,
const nsACString& aURL,
const nsACString& aBase,
ErrorResult& aRv) {
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString base;
if (!AppendUTF16toUTF8(aBase, base, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> baseUri;
nsresult rv = NS_NewURI(getter_AddRefs(baseUri), base);
nsresult rv = NS_NewURI(getter_AddRefs(baseUri), aBase);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(base);
aRv.ThrowTypeError<MSG_INVALID_URL>(aBase);
return nullptr;
}
@ -70,21 +63,14 @@ already_AddRefed<URL> URL::Constructor(nsISupports* aParent,
/* static */
already_AddRefed<URL> URL::Constructor(nsISupports* aParent,
const nsAString& aURL, nsIURI* aBase,
const nsACString& aURL, nsIURI* aBase,
ErrorResult& aRv) {
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString urlStr;
if (!AppendUTF16toUTF8(aURL, urlStr, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), urlStr, nullptr, aBase);
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, nullptr, aBase);
if (NS_FAILED(rv)) {
// No need to warn in this case. It's common to use the URL constructor
// to determine if a URL is valid and an exception will be propagated.
aRv.ThrowTypeError<MSG_INVALID_URL>(urlStr);
aRv.ThrowTypeError<MSG_INVALID_URL>(aURL);
return nullptr;
}
@ -96,7 +82,7 @@ already_AddRefed<URL> URL::FromURI(GlobalObject& aGlobal, nsIURI* aURI) {
}
void URL::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsAString& aResult, ErrorResult& aRv) {
nsACString& aResult, ErrorResult& aRv) {
if (NS_IsMainThread()) {
URLMainThread::CreateObjectURL(aGlobal, aBlob, aResult, aRv);
} else {
@ -105,12 +91,12 @@ void URL::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
}
void URL::CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
nsAString& aResult, ErrorResult& aRv) {
nsACString& aResult, ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
URLMainThread::CreateObjectURL(aGlobal, aSource, aResult, aRv);
}
void URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aURL,
void URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsACString& aURL,
ErrorResult& aRv) {
if (aURL.Contains('#')) {
// Don't revoke URLs that contain fragments.
@ -124,7 +110,7 @@ void URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aURL,
}
}
bool URL::IsValidObjectURL(const GlobalObject& aGlobal, const nsAString& aURL,
bool URL::IsValidObjectURL(const GlobalObject& aGlobal, const nsACString& aURL,
ErrorResult& aRv) {
if (NS_IsMainThread()) {
return URLMainThread::IsValidObjectURL(aGlobal, aURL, aRv);
@ -182,7 +168,7 @@ void URL::CreateSearchParamsIfNeeded() {
}
}
void URL::SetSearch(const nsAString& aSearch) {
void URL::SetSearch(const nsACString& aSearch) {
SetSearchInternal(aSearch);
UpdateURLSearchParams();
}
@ -191,35 +177,22 @@ void URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams) {
MOZ_ASSERT(mSearchParams);
MOZ_ASSERT(mSearchParams == aSearchParams);
nsAutoString search;
nsAutoCString search;
mSearchParams->Serialize(search);
SetSearchInternal(search);
}
#define URL_GETTER(value, func) \
MOZ_ASSERT(mURI); \
value.Truncate(); \
nsAutoCString tmp; \
nsresult rv = mURI->func(tmp); \
if (NS_SUCCEEDED(rv)) { \
CopyUTF8toUTF16(tmp, value); \
}
#define URL_GETTER(value, func) \
MOZ_ASSERT(mURI); \
mURI->func(value);
void URL::GetHref(nsAString& aHref) const { URL_GETTER(aHref, GetSpec); }
void URL::SetHref(const nsAString& aHref, ErrorResult& aRv) {
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString href;
if (!AppendUTF16toUTF8(aHref, href, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
void URL::GetHref(nsACString& aHref) const { URL_GETTER(aHref, GetSpec); }
void URL::SetHref(const nsACString& aHref, ErrorResult& aRv) {
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), href);
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(href);
aRv.ThrowTypeError<MSG_INVALID_URL>(aHref);
return;
}
@ -227,7 +200,7 @@ void URL::SetHref(const nsAString& aHref, ErrorResult& aRv) {
UpdateURLSearchParams();
}
void URL::GetOrigin(nsAString& aOrigin) const {
void URL::GetOrigin(nsACString& aOrigin) const {
nsresult rv =
nsContentUtils::GetWebExposedOriginSerialization(URI(), aOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -235,12 +208,12 @@ void URL::GetOrigin(nsAString& aOrigin) const {
}
}
void URL::GetProtocol(nsAString& aProtocol) const {
void URL::GetProtocol(nsACString& aProtocol) const {
URL_GETTER(aProtocol, GetScheme);
aProtocol.Append(char16_t(':'));
}
void URL::SetProtocol(const nsAString& aProtocol) {
void URL::SetProtocol(const nsACString& aProtocol) {
nsCOMPtr<nsIURI> uri(URI());
if (!uri) {
return;
@ -252,81 +225,67 @@ void URL::SetProtocol(const nsAString& aProtocol) {
mURI = std::move(uri);
}
void URL::GetUsername(nsAString& aUsername) const {
void URL::GetUsername(nsACString& aUsername) const {
URL_GETTER(aUsername, GetUsername);
}
void URL::SetUsername(const nsAString& aUsername) {
void URL::SetUsername(const nsACString& aUsername) {
MOZ_ASSERT(mURI);
Unused << NS_MutateURI(mURI)
.SetUsername(NS_ConvertUTF16toUTF8(aUsername))
.Finalize(mURI);
Unused << NS_MutateURI(mURI).SetUsername(aUsername).Finalize(mURI);
}
void URL::GetPassword(nsAString& aPassword) const {
void URL::GetPassword(nsACString& aPassword) const {
URL_GETTER(aPassword, GetPassword);
}
void URL::SetPassword(const nsAString& aPassword) {
void URL::SetPassword(const nsACString& aPassword) {
MOZ_ASSERT(mURI);
Unused << NS_MutateURI(mURI)
.SetPassword(NS_ConvertUTF16toUTF8(aPassword))
.Finalize(mURI);
Unused << NS_MutateURI(mURI).SetPassword(aPassword).Finalize(mURI);
}
void URL::GetHost(nsAString& aHost) const { URL_GETTER(aHost, GetHostPort); }
void URL::GetHost(nsACString& aHost) const { URL_GETTER(aHost, GetHostPort); }
void URL::SetHost(const nsAString& aHost) {
void URL::SetHost(const nsACString& aHost) {
MOZ_ASSERT(mURI);
Unused << NS_MutateURI(mURI)
.SetHostPort(NS_ConvertUTF16toUTF8(aHost))
.Finalize(mURI);
Unused << NS_MutateURI(mURI).SetHostPort(aHost).Finalize(mURI);
}
void URL::GetHostname(nsAString& aHostname) const {
void URL::GetHostname(nsACString& aHostname) const {
MOZ_ASSERT(mURI);
aHostname.Truncate();
nsContentUtils::GetHostOrIPv6WithBrackets(mURI, aHostname);
}
void URL::SetHostname(const nsAString& aHostname) {
void URL::SetHostname(const nsACString& aHostname) {
MOZ_ASSERT(mURI);
// nsStandardURL returns NS_ERROR_UNEXPECTED for an empty hostname
// The return code is silently ignored
mozilla::Unused << NS_MutateURI(mURI)
.SetHost(NS_ConvertUTF16toUTF8(aHostname))
.Finalize(mURI);
Unused << NS_MutateURI(mURI).SetHost(aHostname).Finalize(mURI);
}
void URL::GetPort(nsAString& aPort) const {
void URL::GetPort(nsACString& aPort) const {
MOZ_ASSERT(mURI);
aPort.Truncate();
int32_t port;
nsresult rv = mURI->GetPort(&port);
if (NS_SUCCEEDED(rv) && port != -1) {
nsAutoString portStr;
portStr.AppendInt(port, 10);
aPort.Assign(portStr);
aPort.AppendInt(port, 10);
}
}
void URL::SetPort(const nsAString& aPort) {
void URL::SetPort(const nsACString& aPort) {
nsresult rv;
nsAutoString portStr(aPort);
nsAutoCString portStr(aPort);
int32_t port = -1;
// nsIURI uses -1 as default value.
portStr.StripTaggedASCII(ASCIIMask::MaskCRLFTab());
if (!portStr.IsEmpty()) {
// To be valid, the port must start with an ASCII digit.
// (nsAString::ToInteger ignores leading junk, so check before calling.)
// (nsACString::ToInteger ignores leading junk, so check before calling.)
if (!IsAsciiDigit(portStr[0])) {
return;
}
@ -339,32 +298,21 @@ void URL::SetPort(const nsAString& aPort) {
Unused << NS_MutateURI(mURI).SetPort(port).Finalize(mURI);
}
void URL::GetPathname(nsAString& aPathname) const {
void URL::GetPathname(nsACString& aPathname) const {
MOZ_ASSERT(mURI);
aPathname.Truncate();
// Do not throw! Not having a valid URI or URL should result in an empty
// string.
nsAutoCString file;
nsresult rv = mURI->GetFilePath(file);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(file, aPathname);
}
mURI->GetFilePath(aPathname);
}
void URL::SetPathname(const nsAString& aPathname) {
void URL::SetPathname(const nsACString& aPathname) {
MOZ_ASSERT(mURI);
// Do not throw!
Unused << NS_MutateURI(mURI)
.SetFilePath(NS_ConvertUTF16toUTF8(aPathname))
.Finalize(mURI);
Unused << NS_MutateURI(mURI).SetFilePath(aPathname).Finalize(mURI);
}
void URL::GetSearch(nsAString& aSearch) const {
void URL::GetSearch(nsACString& aSearch) const {
MOZ_ASSERT(mURI);
aSearch.Truncate();
@ -372,44 +320,33 @@ void URL::GetSearch(nsAString& aSearch) const {
// Do not throw! Not having a valid URI or URL should result in an empty
// string.
nsAutoCString search;
nsresult rv;
rv = mURI->GetQuery(search);
if (NS_SUCCEEDED(rv) && !search.IsEmpty()) {
aSearch.Assign(u'?');
AppendUTF8toUTF16(search, aSearch);
rv = mURI->GetQuery(aSearch);
if (NS_SUCCEEDED(rv) && !aSearch.IsEmpty()) {
aSearch.Insert('?', 0);
}
}
void URL::GetHash(nsAString& aHash) const {
void URL::GetHash(nsACString& aHash) const {
MOZ_ASSERT(mURI);
aHash.Truncate();
nsAutoCString ref;
nsresult rv = mURI->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, aHash);
nsresult rv = mURI->GetRef(aHash);
if (NS_SUCCEEDED(rv) && !aHash.IsEmpty()) {
aHash.Insert('#', 0);
}
}
void URL::SetHash(const nsAString& aHash) {
void URL::SetHash(const nsACString& aHash) {
MOZ_ASSERT(mURI);
Unused
<< NS_MutateURI(mURI).SetRef(NS_ConvertUTF16toUTF8(aHash)).Finalize(mURI);
Unused << NS_MutateURI(mURI).SetRef(aHash).Finalize(mURI);
}
void URL::SetSearchInternal(const nsAString& aSearch) {
void URL::SetSearchInternal(const nsACString& aSearch) {
MOZ_ASSERT(mURI);
// Ignore failures to be compatible with NS4.
Unused << NS_MutateURI(mURI)
.SetQuery(NS_ConvertUTF16toUTF8(aSearch))
.Finalize(mURI);
Unused << NS_MutateURI(mURI).SetQuery(aSearch).Finalize(mURI);
}
void URL::UpdateURLSearchParams() {

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

@ -44,30 +44,30 @@ class URL final : public URLSearchParamsObserver, public nsWrapperCache {
JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<URL> Constructor(const GlobalObject& aGlobal,
const nsAString& aURL,
const Optional<nsAString>& aBase,
const nsACString& aURL,
const Optional<nsACString>& aBase,
ErrorResult& aRv);
static already_AddRefed<URL> Constructor(nsISupports* aParent,
const nsAString& aURL,
const nsAString& aBase,
const nsACString& aURL,
const nsACString& aBase,
ErrorResult& aRv);
static already_AddRefed<URL> Constructor(nsISupports* aParent,
const nsAString& aURL, nsIURI* aBase,
ErrorResult& aRv);
const nsACString& aURL,
nsIURI* aBase, ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsAString& aResult, ErrorResult& aRv);
nsACString& aResult, ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
nsAString& aResult, ErrorResult& aRv);
nsACString& aResult, ErrorResult& aRv);
static void RevokeObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL, ErrorResult& aRv);
const nsACString& aURL, ErrorResult& aRv);
static bool IsValidObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL, ErrorResult& aRv);
const nsACString& aURL, ErrorResult& aRv);
static already_AddRefed<URL> Parse(const GlobalObject& aGlobal,
const nsACString& aURL,
@ -76,51 +76,41 @@ class URL final : public URLSearchParamsObserver, public nsWrapperCache {
static bool CanParse(const GlobalObject& aGlobal, const nsACString& aURL,
const Optional<nsACString>& aBase);
void GetHref(nsAString& aHref) const;
void GetHref(nsACString& aHref) const;
void SetHref(const nsACString& aHref, ErrorResult& aRv);
void SetHref(const nsAString& aHref, ErrorResult& aRv);
void GetOrigin(nsACString& aOrigin) const;
void GetOrigin(nsAString& aOrigin) const;
void GetProtocol(nsACString& aProtocol) const;
void SetProtocol(const nsACString& aProtocol);
void GetProtocol(nsAString& aProtocol) const;
void GetUsername(nsACString& aUsername) const;
void SetUsername(const nsACString& aUsername);
void SetProtocol(const nsAString& aProtocol);
void GetPassword(nsACString& aPassword) const;
void SetPassword(const nsACString& aPassword);
void GetUsername(nsAString& aUsername) const;
void GetHost(nsACString& aHost) const;
void SetHost(const nsACString& aHost);
void SetUsername(const nsAString& aUsername);
void GetHostname(nsACString& aHostname) const;
void SetHostname(const nsACString& aHostname);
void GetPassword(nsAString& aPassword) const;
void GetPort(nsACString& aPort) const;
void SetPort(const nsACString& aPort);
void SetPassword(const nsAString& aPassword);
void GetPathname(nsACString& aPathname) const;
void SetPathname(const nsACString& aPathname);
void GetHost(nsAString& aHost) const;
void SetHost(const nsAString& aHost);
void GetHostname(nsAString& aHostname) const;
void SetHostname(const nsAString& aHostname);
void GetPort(nsAString& aPort) const;
void SetPort(const nsAString& aPort);
void GetPathname(nsAString& aPathname) const;
void SetPathname(const nsAString& aPathname);
void GetSearch(nsAString& aSearch) const;
void SetSearch(const nsAString& aSearch);
void GetSearch(nsACString& aSearch) const;
void SetSearch(const nsACString& aSearch);
URLSearchParams* SearchParams();
void GetHash(nsAString& aHost) const;
void GetHash(nsACString& aHash) const;
void SetHash(const nsACString& aHash);
void SetHash(const nsAString& aHash);
void ToJSON(nsAString& aResult) const { GetHref(aResult); }
void ToJSON(nsACString& aResult) const { GetHref(aResult); }
// URLSearchParamsObserver
void URLSearchParamsUpdated(URLSearchParams* aSearchParams) override;
@ -137,7 +127,7 @@ class URL final : public URLSearchParamsObserver, public nsWrapperCache {
void UpdateURLSearchParams();
private:
void SetSearchInternal(const nsAString& aSearch);
void SetSearchInternal(const nsACString& aSearch);
void CreateSearchParamsIfNeeded();

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

@ -19,7 +19,7 @@ namespace mozilla::dom {
/* static */
void URLMainThread::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsAString& aResult, ErrorResult& aRv) {
nsACString& aResult, ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
@ -41,20 +41,18 @@ void URLMainThread::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsCOMPtr<nsIPrincipal> principal =
nsContentUtils::ObjectPrincipal(aGlobal.Get());
nsAutoCString url;
aRv = BlobURLProtocolHandler::AddDataEntry(
aBlob.Impl(), principal, NS_ConvertUTF16toUTF8(partKey), url);
aBlob.Impl(), principal, NS_ConvertUTF16toUTF8(partKey), aResult);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
global->RegisterHostObjectURI(url);
CopyASCIItoUTF16(url, aResult);
global->RegisterHostObjectURI(aResult);
}
/* static */
void URLMainThread::CreateObjectURL(const GlobalObject& aGlobal,
MediaSource& aSource, nsAString& aResult,
MediaSource& aSource, nsACString& aResult,
ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
@ -77,25 +75,23 @@ void URLMainThread::CreateObjectURL(const GlobalObject& aGlobal,
nsCOMPtr<nsIPrincipal> principal =
nsContentUtils::ObjectPrincipal(aGlobal.Get());
nsAutoCString url;
aRv = BlobURLProtocolHandler::AddDataEntry(
&aSource, principal, NS_ConvertUTF16toUTF8(partKey), url);
&aSource, principal, NS_ConvertUTF16toUTF8(partKey), aResult);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
nsCOMPtr<nsIRunnable> revocation = NS_NewRunnableFunction(
"dom::URLMainThread::CreateObjectURL",
[url] { BlobURLProtocolHandler::RemoveDataEntry(url); });
"dom::URLMainThread::CreateObjectURL", [result = nsCString(aResult)] {
BlobURLProtocolHandler::RemoveDataEntry(result);
});
nsContentUtils::RunInStableState(revocation.forget());
CopyASCIItoUTF16(url, aResult);
}
/* static */
void URLMainThread::RevokeObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL, ErrorResult& aRv) {
const nsACString& aURL, ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
if (!global) {
@ -113,21 +109,18 @@ void URLMainThread::RevokeObjectURL(const GlobalObject& aGlobal,
}
}
NS_LossyConvertUTF16toASCII asciiurl(aURL);
if (BlobURLProtocolHandler::RemoveDataEntry(
asciiurl, nsContentUtils::ObjectPrincipal(aGlobal.Get()),
aURL, nsContentUtils::ObjectPrincipal(aGlobal.Get()),
NS_ConvertUTF16toUTF8(partKey))) {
global->UnregisterHostObjectURI(asciiurl);
global->UnregisterHostObjectURI(aURL);
}
}
/* static */
bool URLMainThread::IsValidObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL, ErrorResult& aRv) {
const nsACString& aURL, ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
NS_LossyConvertUTF16toASCII asciiurl(aURL);
return BlobURLProtocolHandler::HasDataEntry(asciiurl);
return BlobURLProtocolHandler::HasDataEntry(aURL);
}
} // namespace mozilla::dom

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

@ -14,16 +14,13 @@ namespace mozilla::dom {
class URLMainThread final {
public:
static void CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsAString& aResult, ErrorResult& aRv);
nsACString& aResult, ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
nsAString& aResult, ErrorResult& aRv);
nsACString& aResult, ErrorResult& aRv);
static void RevokeObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL, ErrorResult& aRv);
const nsACString& aURL, ErrorResult& aRv);
static bool IsValidObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL, ErrorResult& aRv);
const nsACString& aURL, ErrorResult& aRv);
};
} // namespace mozilla::dom

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

@ -60,23 +60,24 @@ JSObject* URLSearchParams::WrapObject(JSContext* aCx,
/* static */
already_AddRefed<URLSearchParams> URLSearchParams::Constructor(
const GlobalObject& aGlobal,
const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString& aInit,
const UTF8StringSequenceSequenceOrUTF8StringUTF8StringRecordOrUTF8String&
aInit,
ErrorResult& aRv) {
RefPtr<URLSearchParams> sp =
new URLSearchParams(aGlobal.GetAsSupports(), nullptr);
if (aInit.IsUSVString()) {
NS_ConvertUTF16toUTF8 input(aInit.GetAsUSVString());
if (aInit.IsUTF8String()) {
const auto& input = aInit.GetAsUTF8String();
if (StringBeginsWith(input, "?"_ns)) {
sp->ParseInput(Substring(input, 1, input.Length() - 1));
} else {
sp->ParseInput(input);
}
} else if (aInit.IsUSVStringSequenceSequence()) {
const Sequence<Sequence<nsString>>& list =
aInit.GetAsUSVStringSequenceSequence();
} else if (aInit.IsUTF8StringSequenceSequence()) {
const Sequence<Sequence<nsCString>>& list =
aInit.GetAsUTF8StringSequenceSequence();
for (uint32_t i = 0; i < list.Length(); ++i) {
const Sequence<nsString>& item = list[i];
const Sequence<nsCString>& item = list[i];
if (item.Length() != 2) {
nsPrintfCString err("Expected 2 items in pair but got %zu",
item.Length());
@ -85,9 +86,9 @@ already_AddRefed<URLSearchParams> URLSearchParams::Constructor(
}
sp->Append(item[0], item[1]);
}
} else if (aInit.IsUSVStringUSVStringRecord()) {
const Record<nsString, nsString>& record =
aInit.GetAsUSVStringUSVStringRecord();
} else if (aInit.IsUTF8StringUTF8StringRecord()) {
const Record<nsCString, nsCString>& record =
aInit.GetAsUTF8StringUTF8StringRecord();
for (auto& entry : record.Entries()) {
sp->Append(entry.mKey, entry.mValue);
}
@ -104,35 +105,36 @@ void URLSearchParams::ParseInput(const nsACString& aInput) {
uint32_t URLSearchParams::Size() const { return mParams->Length(); }
void URLSearchParams::Get(const nsAString& aName, nsString& aRetval) {
void URLSearchParams::Get(const nsACString& aName, nsACString& aRetval) {
return mParams->Get(aName, aRetval);
}
void URLSearchParams::GetAll(const nsAString& aName,
nsTArray<nsString>& aRetval) {
void URLSearchParams::GetAll(const nsACString& aName,
nsTArray<nsCString>& aRetval) {
return mParams->GetAll(aName, aRetval);
}
void URLSearchParams::Set(const nsAString& aName, const nsAString& aValue) {
void URLSearchParams::Set(const nsACString& aName, const nsACString& aValue) {
mParams->Set(aName, aValue);
NotifyObserver();
}
void URLSearchParams::Append(const nsAString& aName, const nsAString& aValue) {
void URLSearchParams::Append(const nsACString& aName,
const nsACString& aValue) {
mParams->Append(aName, aValue);
NotifyObserver();
}
bool URLSearchParams::Has(const nsAString& aName,
const Optional<nsAString>& aValue) {
bool URLSearchParams::Has(const nsACString& aName,
const Optional<nsACString>& aValue) {
if (!aValue.WasPassed()) {
return mParams->Has(aName);
}
return mParams->Has(aName, aValue.Value());
}
void URLSearchParams::Delete(const nsAString& aName,
const Optional<nsAString>& aValue) {
void URLSearchParams::Delete(const nsACString& aName,
const Optional<nsACString>& aValue) {
if (!aValue.WasPassed()) {
mParams->Delete(aName);
NotifyObserver();
@ -144,10 +146,17 @@ void URLSearchParams::Delete(const nsAString& aName,
void URLSearchParams::DeleteAll() { mParams->DeleteAll(); }
void URLSearchParams::Serialize(nsAString& aValue) const {
void URLSearchParams::Serialize(nsACString& aValue) const {
mParams->Serialize(aValue, true);
}
// TODO(emilio): Allow stringifier attributes with CString return values.
void URLSearchParams::Stringify(nsAString& aValue) const {
nsAutoCString serialized;
mParams->Serialize(serialized, true);
CopyUTF8toUTF16(serialized, aValue);
}
void URLSearchParams::NotifyObserver() {
if (mObserver) {
mObserver->URLSearchParamsUpdated(this);
@ -158,11 +167,11 @@ uint32_t URLSearchParams::GetIterableLength() const {
return mParams->Length();
}
const nsAString& URLSearchParams::GetKeyAtIndex(uint32_t aIndex) const {
const nsACString& URLSearchParams::GetKeyAtIndex(uint32_t aIndex) const {
return mParams->GetKeyAtIndex(aIndex);
}
const nsAString& URLSearchParams::GetValueAtIndex(uint32_t aIndex) const {
const nsACString& URLSearchParams::GetValueAtIndex(uint32_t aIndex) const {
return mParams->GetValueAtIndex(aIndex);
}
@ -182,11 +191,10 @@ nsresult URLSearchParams::GetSendInfo(nsIInputStream** aBody,
"application/x-www-form-urlencoded;charset=UTF-8");
aCharset.AssignLiteral("UTF-8");
nsAutoString serialized;
nsAutoCString serialized;
Serialize(serialized);
NS_ConvertUTF16toUTF8 converted(serialized);
*aContentLength = converted.Length();
return NS_NewCStringInputStream(aBody, std::move(converted));
*aContentLength = serialized.Length();
return NS_NewCStringInputStream(aBody, std::move(serialized));
}
} // namespace mozilla::dom

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

@ -37,7 +37,7 @@ namespace dom {
class GlobalObject;
class URLSearchParams;
class USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString;
class UTF8StringSequenceSequenceOrUTF8StringUTF8StringRecordOrUTF8String;
template <typename T>
class Optional;
@ -66,42 +66,42 @@ class URLSearchParams final : public nsISupports, public nsWrapperCache {
static already_AddRefed<URLSearchParams> Constructor(
const GlobalObject& aGlobal,
const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString&
const UTF8StringSequenceSequenceOrUTF8StringUTF8StringRecordOrUTF8String&
aInit,
ErrorResult& aRv);
void ParseInput(const nsACString& aInput);
void Serialize(nsAString& aValue) const;
void Serialize(nsACString& aValue) const;
uint32_t Size() const;
void Get(const nsAString& aName, nsString& aRetval);
void Get(const nsACString& aName, nsACString& aRetval);
void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval);
void GetAll(const nsACString& aName, nsTArray<nsCString>& aRetval);
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, const Optional<nsAString>& aValue);
bool Has(const nsACString& aName, const Optional<nsACString>& aValue);
void Delete(const nsAString& aName, const Optional<nsAString>& aValue);
void Delete(const nsACString& aName, const Optional<nsACString>& aValue);
uint32_t GetIterableLength() const;
const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
const nsAString& GetValueAtIndex(uint32_t aIndex) const;
const nsACString& GetKeyAtIndex(uint32_t aIndex) const;
const nsACString& GetValueAtIndex(uint32_t aIndex) const;
void Sort(ErrorResult& aRv);
void Stringify(nsString& aRetval) const { Serialize(aRetval); }
void Stringify(nsAString&) const;
nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
nsACString& aContentTypeWithCharset,
nsACString& aCharset) const;
private:
void AppendInternal(const nsAString& aName, const nsAString& aValue);
void AppendInternal(const nsACString& aName, const nsACString& aValue);
void DeleteAll();

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

@ -18,11 +18,11 @@ namespace mozilla::dom {
class CreateURLRunnable : public WorkerMainThreadRunnable {
private:
BlobImpl* mBlobImpl;
nsAString& mURL;
nsACString& mURL;
public:
CreateURLRunnable(WorkerPrivate* aWorkerPrivate, BlobImpl* aBlobImpl,
nsAString& aURL)
nsACString& aURL)
: WorkerMainThreadRunnable(aWorkerPrivate, "URL :: CreateURL"_ns),
mBlobImpl(aBlobImpl),
mURL(aURL) {
@ -42,17 +42,13 @@ class CreateURLRunnable : public WorkerMainThreadRunnable {
nsAutoString partKey;
cookieJarSettings->GetPartitionKey(partKey);
nsAutoCString url;
nsresult rv = BlobURLProtocolHandler::AddDataEntry(
mBlobImpl, principal, NS_ConvertUTF16toUTF8(partKey), url);
mBlobImpl, principal, NS_ConvertUTF16toUTF8(partKey), mURL);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to add data entry for the blob!");
SetDOMStringToNull(mURL);
mURL.SetIsVoid(true);
return false;
}
CopyUTF8toUTF16(url, mURL);
return true;
}
};
@ -60,26 +56,24 @@ class CreateURLRunnable : public WorkerMainThreadRunnable {
// This class revokes an URL on the main thread.
class RevokeURLRunnable : public WorkerMainThreadRunnable {
private:
const nsString mURL;
const nsCString mURL;
public:
RevokeURLRunnable(WorkerPrivate* aWorkerPrivate, const nsAString& aURL)
RevokeURLRunnable(WorkerPrivate* aWorkerPrivate, const nsACString& aURL)
: WorkerMainThreadRunnable(aWorkerPrivate, "URL :: RevokeURL"_ns),
mURL(aURL) {}
bool MainThreadRun() override {
AssertIsOnMainThread();
NS_ConvertUTF16toUTF8 url(mURL);
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
mWorkerPrivate->CookieJarSettings();
nsAutoString partKey;
cookieJarSettings->GetPartitionKey(partKey);
BlobURLProtocolHandler::RemoveDataEntry(url, mWorkerPrivate->GetPrincipal(),
NS_ConvertUTF16toUTF8(partKey));
BlobURLProtocolHandler::RemoveDataEntry(
mURL, mWorkerPrivate->GetPrincipal(), NS_ConvertUTF16toUTF8(partKey));
return true;
}
};
@ -87,11 +81,11 @@ class RevokeURLRunnable : public WorkerMainThreadRunnable {
// This class checks if an URL is valid on the main thread.
class IsValidURLRunnable : public WorkerMainThreadRunnable {
private:
const nsString mURL;
const nsCString mURL;
bool mValid;
public:
IsValidURLRunnable(WorkerPrivate* aWorkerPrivate, const nsAString& aURL)
IsValidURLRunnable(WorkerPrivate* aWorkerPrivate, const nsACString& aURL)
: WorkerMainThreadRunnable(aWorkerPrivate, "URL :: IsValidURL"_ns),
mURL(aURL),
mValid(false) {}
@ -99,8 +93,7 @@ class IsValidURLRunnable : public WorkerMainThreadRunnable {
bool MainThreadRun() override {
AssertIsOnMainThread();
NS_ConvertUTF16toUTF8 url(mURL);
mValid = BlobURLProtocolHandler::HasDataEntry(url);
mValid = BlobURLProtocolHandler::HasDataEntry(mURL);
return true;
}
@ -110,7 +103,8 @@ class IsValidURLRunnable : public WorkerMainThreadRunnable {
/* static */
void URLWorker::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsAString& aResult, mozilla::ErrorResult& aRv) {
nsACString& aResult,
mozilla::ErrorResult& aRv) {
JSContext* cx = aGlobal.Context();
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
@ -128,12 +122,12 @@ void URLWorker::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
MOZ_ASSERT(scope);
scope->RegisterHostObjectURI(NS_ConvertUTF16toUTF8(aResult));
scope->RegisterHostObjectURI(aResult);
}
/* static */
void URLWorker::RevokeObjectURL(const GlobalObject& aGlobal,
const nsAString& aUrl, ErrorResult& aRv) {
const nsACString& aUrl, ErrorResult& aRv) {
JSContext* cx = aGlobal.Context();
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
@ -148,12 +142,12 @@ void URLWorker::RevokeObjectURL(const GlobalObject& aGlobal,
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
MOZ_ASSERT(scope);
scope->UnregisterHostObjectURI(NS_ConvertUTF16toUTF8(aUrl));
scope->UnregisterHostObjectURI(aUrl);
}
/* static */
bool URLWorker::IsValidObjectURL(const GlobalObject& aGlobal,
const nsAString& aUrl, ErrorResult& aRv) {
const nsACString& aUrl, ErrorResult& aRv) {
JSContext* cx = aGlobal.Context();
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);

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

@ -21,22 +21,20 @@ namespace dom {
class URLWorker final {
public:
static already_AddRefed<URLWorker> Constructor(
const GlobalObject& aGlobal, const nsAString& aURL,
const Optional<nsAString>& aBase, ErrorResult& aRv);
const GlobalObject& aGlobal, const nsACString& aURL,
const Optional<nsACString>& aBase, ErrorResult& aRv);
static already_AddRefed<URLWorker> Constructor(const GlobalObject& aGlobal,
const nsAString& aURL,
const nsAString& aBase,
const nsACString& aURL,
const nsACString& aBase,
ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
nsAString& aResult, mozilla::ErrorResult& aRv);
nsACString& aResult, mozilla::ErrorResult& aRv);
static void RevokeObjectURL(const GlobalObject& aGlobal,
const nsAString& aUrl, ErrorResult& aRv);
const nsACString& aUrl, ErrorResult& aRv);
static bool IsValidObjectURL(const GlobalObject& aGlobal,
const nsAString& aUrl, ErrorResult& aRv);
const nsACString& aUrl, ErrorResult& aRv);
};
} // namespace dom

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

@ -154,7 +154,7 @@ partial interface Document {
[PutForwards=href, LegacyUnforgeable] readonly attribute Location? location;
[SetterThrows] attribute DOMString domain;
readonly attribute DOMString referrer;
readonly attribute UTF8String referrer;
[Throws] attribute DOMString cookie;
readonly attribute DOMString lastModified;
readonly attribute DOMString readyState;

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

@ -12,25 +12,25 @@
interface mixin HTMLHyperlinkElementUtils {
[CEReactions, SetterThrows]
stringifier attribute USVString href;
stringifier attribute UTF8String href;
readonly attribute USVString origin;
readonly attribute UTF8String origin;
[CEReactions]
attribute USVString protocol;
attribute UTF8String protocol;
[CEReactions]
attribute USVString username;
attribute UTF8String username;
[CEReactions]
attribute USVString password;
attribute UTF8String password;
[CEReactions]
attribute USVString host;
attribute UTF8String host;
[CEReactions]
attribute USVString hostname;
attribute UTF8String hostname;
[CEReactions]
attribute USVString port;
attribute UTF8String port;
[CEReactions]
attribute USVString pathname;
attribute UTF8String pathname;
[CEReactions]
attribute USVString search;
attribute UTF8String search;
[CEReactions]
attribute USVString hash;
attribute UTF8String hash;
};

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

@ -23,8 +23,8 @@ dictionary IdentityCredentialRequestOptions {
[GenerateConversionToJS]
dictionary IdentityProviderConfig {
required UTF8String configURL;
required USVString clientId;
USVString nonce;
required UTF8String clientId;
UTF8String nonce;
};
// https://fedidcg.github.io/FedCM/#dictdef-identityproviderwellknown
@ -35,7 +35,7 @@ dictionary IdentityProviderWellKnown {
// https://fedidcg.github.io/FedCM/#dictdef-identityprovidericon
dictionary IdentityProviderIcon {
required USVString url;
required UTF8String url;
unsigned long size;
};

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

@ -7,7 +7,7 @@
* https://fetch.spec.whatwg.org/#request-class
*/
typedef (Request or USVString) RequestInfo;
typedef (Request or UTF8String) RequestInfo;
typedef unsigned long nsContentPolicyType;
[Exposed=(Window,Worker)]
@ -21,11 +21,11 @@ interface Request {
constructor(RequestInfo input, optional RequestInit init = {});
readonly attribute ByteString method;
readonly attribute USVString url;
readonly attribute UTF8String url;
[SameObject, BinaryName="headers_"] readonly attribute Headers headers;
readonly attribute RequestDestination destination;
readonly attribute USVString referrer;
readonly attribute UTF8String referrer;
[BinaryName="referrerPolicy_"]
readonly attribute ReferrerPolicy referrerPolicy;
readonly attribute RequestMode mode;
@ -59,7 +59,7 @@ dictionary RequestInit {
ByteString method;
HeadersInit headers;
BodyInit? body;
USVString referrer;
UTF8String referrer;
ReferrerPolicy referrerPolicy;
RequestMode mode;
/**

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

@ -18,13 +18,13 @@ interface Response {
[NewObject] static Response error();
[Throws,
NewObject] static Response redirect(USVString url, optional unsigned short status = 302);
NewObject] static Response redirect(UTF8String url, optional unsigned short status = 302);
[BinaryName=CreateFromJson, Throws,
NewObject] static Response json(any data, optional ResponseInit init = {});
readonly attribute ResponseType type;
readonly attribute USVString url;
readonly attribute UTF8String url;
readonly attribute boolean redirected;
readonly attribute unsigned short status;
readonly attribute boolean ok;

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

@ -17,44 +17,44 @@ interface URI;
LegacyWindowAlias=webkitURL]
interface URL {
[Throws]
constructor(USVString url, optional USVString base);
constructor(UTF8String url, optional UTF8String base);
static URL? parse(UTF8String url, optional UTF8String base);
static boolean canParse(UTF8String url, optional UTF8String base);
[SetterThrows]
stringifier attribute USVString href;
readonly attribute USVString origin;
attribute USVString protocol;
attribute USVString username;
attribute USVString password;
attribute USVString host;
attribute USVString hostname;
attribute USVString port;
attribute USVString pathname;
attribute USVString search;
stringifier attribute UTF8String href;
readonly attribute UTF8String origin;
attribute UTF8String protocol;
attribute UTF8String username;
attribute UTF8String password;
attribute UTF8String host;
attribute UTF8String hostname;
attribute UTF8String port;
attribute UTF8String pathname;
attribute UTF8String search;
[SameObject]
readonly attribute URLSearchParams searchParams;
attribute USVString hash;
attribute UTF8String hash;
[ChromeOnly]
readonly attribute URI URI;
[ChromeOnly]
static URL fromURI(URI uri);
USVString toJSON();
UTF8String toJSON();
};
[Exposed=(Window,DedicatedWorker,SharedWorker)]
partial interface URL {
[Throws]
static DOMString createObjectURL(Blob blob);
static UTF8String createObjectURL(Blob blob);
[Throws]
static undefined revokeObjectURL(DOMString url);
static undefined revokeObjectURL(UTF8String url);
[ChromeOnly, Throws]
static boolean isValidObjectURL(DOMString url);
static boolean isValidObjectURL(UTF8String url);
// https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html
[Throws]
static DOMString createObjectURL(MediaSource source);
static UTF8String createObjectURL(MediaSource source);
};

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

@ -16,21 +16,21 @@
[Exposed=(Window,Worker,WorkerDebugger)]
interface URLSearchParams {
[Throws]
constructor(optional (sequence<sequence<USVString>> or
record<USVString, USVString> or USVString) init = "");
constructor(optional (sequence<sequence<UTF8String>> or
record<UTF8String, UTF8String> or UTF8String) init = "");
readonly attribute unsigned long size;
undefined append(USVString name, USVString value);
undefined delete(USVString name, optional USVString value);
USVString? get(USVString name);
sequence<USVString> getAll(USVString name);
boolean has(USVString name, optional USVString value);
undefined set(USVString name, USVString value);
undefined append(UTF8String name, UTF8String value);
undefined delete(UTF8String name, optional UTF8String value);
UTF8String? get(UTF8String name);
sequence<UTF8String> getAll(UTF8String name);
boolean has(UTF8String name, optional UTF8String value);
undefined set(UTF8String name, UTF8String value);
[Throws]
undefined sort();
iterable<USVString, USVString>;
iterable<UTF8String, UTF8String>;
stringifier;
};

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

@ -1443,8 +1443,8 @@ nsresult WorkerPrivate::SetCSPFromHeaderValues(
}
MOZ_ASSERT(selfURI, "need a self URI for CSP");
rv = csp->SetRequestContextWithPrincipal(mLoadInfo.mPrincipal, selfURI,
u""_ns, 0);
rv = csp->SetRequestContextWithPrincipal(mLoadInfo.mPrincipal, selfURI, ""_ns,
0);
NS_ENSURE_SUCCESS(rv, rv);
csp->EnsureEventTarget(mMainThreadEventTarget);

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

@ -721,7 +721,7 @@ void WorkerGlobalScope::GetJSTestingFunctions(
}
already_AddRefed<Promise> WorkerGlobalScope::Fetch(
const RequestOrUSVString& aInput, const RequestInit& aInit,
const RequestOrUTF8String& aInput, const RequestInit& aInit,
CallerType aCallerType, ErrorResult& aRv) {
return FetchRequest(this, aInput, aInit, aCallerType, aRv);
}

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

@ -68,7 +68,7 @@ template <typename T>
class Optional;
class Performance;
class Promise;
class RequestOrUSVString;
class RequestOrUTF8String;
template <typename T>
class Sequence;
class ServiceWorkerDescriptor;
@ -326,7 +326,7 @@ class WorkerGlobalScope : public WorkerGlobalScopeBase {
JS::MutableHandle<JS::Value> aRetval,
ErrorResult& aError);
already_AddRefed<Promise> Fetch(const RequestOrUSVString& aInput,
already_AddRefed<Promise> Fetch(const RequestOrUTF8String& aInput,
const RequestInit& aInit,
CallerType aCallerType, ErrorResult& aRv);

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

@ -305,18 +305,15 @@ void CacheLoadHandler::Load(Cache* aCache) {
return;
}
nsAutoCString spec;
rv = uri->GetSpec(spec);
MOZ_ASSERT(loadContext->mFullURL.IsEmpty());
rv = uri->GetSpec(loadContext->mFullURL);
if (NS_WARN_IF(NS_FAILED(rv))) {
Fail(rv);
return;
}
MOZ_ASSERT(loadContext->mFullURL.IsEmpty());
CopyUTF8toUTF16(spec, loadContext->mFullURL);
mozilla::dom::RequestOrUSVString request;
request.SetAsUSVString().ShareOrDependUpon(loadContext->mFullURL);
mozilla::dom::RequestOrUTF8String request;
request.SetAsUTF8String().ShareOrDependUpon(loadContext->mFullURL);
mozilla::dom::CacheQueryOptions params;

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

@ -358,10 +358,10 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) {
RefPtr<mozilla::dom::Response> response = new mozilla::dom::Response(
mRequestHandle->GetCacheCreator()->Global(), std::move(ir), nullptr);
mozilla::dom::RequestOrUSVString request;
mozilla::dom::RequestOrUTF8String request;
MOZ_ASSERT(!loadContext->mFullURL.IsEmpty());
request.SetAsUSVString().ShareOrDependUpon(loadContext->mFullURL);
request.SetAsUTF8String().ShareOrDependUpon(loadContext->mFullURL);
// This JSContext will not end up executing JS code because here there are
// no ReadableStreams involved.

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

@ -130,7 +130,7 @@ class WorkerLoadContext : public JS::loader::LoadContextBase {
/* TODO: Split out a ServiceWorkerLoadContext */
// This full URL string is populated only if this object is used in a
// ServiceWorker.
nsString mFullURL;
nsCString mFullURL;
// This promise is set only when the script is for a ServiceWorker but
// it's not in the cache yet. The promise is resolved when the full body is

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

@ -458,11 +458,8 @@ nsresult WorkletFetchHandler::StartFetch(JSContext* aCx, nsIURI* aURI,
return NS_ERROR_FAILURE;
}
RequestOrUSVString requestInput;
nsAutoString url;
CopyUTF8toUTF16(spec, url);
requestInput.SetAsUSVString().ShareOrDependUpon(url);
RequestOrUTF8String requestInput;
requestInput.SetAsUTF8String().ShareOrDependUpon(spec);
RootedDictionary<RequestInit> requestInit(aCx);
requestInit.mCredentials.Construct(mCredentials);
@ -472,14 +469,10 @@ nsresult WorkletFetchHandler::StartFetch(JSContext* aCx, nsIURI* aURI,
requestInit.mMode.Construct(RequestMode::Cors);
if (aReferrer) {
nsAutoString referrer;
res = aReferrer->GetSpec(spec);
res = aReferrer->GetSpec(requestInit.mReferrer.Construct());
if (NS_WARN_IF(NS_FAILED(res))) {
return NS_ERROR_FAILURE;
}
CopyUTF8toUTF16(spec, referrer);
requestInit.mReferrer.Construct(referrer);
}
nsCOMPtr<nsIGlobalObject> global =
@ -502,7 +495,7 @@ nsresult WorkletFetchHandler::StartFetch(JSContext* aCx, nsIURI* aURI,
request->OverrideContentPolicyType(mWorklet->Impl()->ContentPolicyType());
RequestOrUSVString finalRequestInput;
RequestOrUTF8String finalRequestInput;
finalRequestInput.SetAsRequest() = request.unsafeGetRawPtr();
RefPtr<Promise> fetchPromise = FetchRequest(

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

@ -538,7 +538,7 @@ bool HTMLEditUtils::IsLink(const nsINode* aNode) {
return false;
}
nsAutoString tmpText;
nsAutoCString tmpText;
anchor->GetHref(tmpText);
return !tmpText.IsEmpty();
}

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

@ -3773,10 +3773,14 @@ nsresult HTMLEditor::InsertLinkAroundSelectionAsAction(
return EditorBase::ToGenericNSResult(rv);
}
nsAutoString href;
anchor->GetHref(href);
if (href.IsEmpty()) {
return NS_OK;
// XXX Is this ok? Does this just want to check that we're a link? If so
// there are faster ways to do this.
{
nsAutoCString href;
anchor->GetHref(href);
if (href.IsEmpty()) {
return NS_OK;
}
}
AutoPlaceholderBatch treatAsOneTransaction(

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

@ -249,7 +249,7 @@ nsresult CSPToCSPInfo(nsIContentSecurityPolicy* aCSP, CSPInfo* aCSPInfo) {
selfURI->GetSpec(selfURISpec);
}
nsAutoString referrer;
nsAutoCString referrer;
aCSP->GetReferrer(referrer);
uint64_t windowID = aCSP->GetInnerWindowID();

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

@ -64,7 +64,7 @@ namespace ipc {
ContentSecurityPolicy[] policyInfos;
PrincipalInfo requestPrincipalInfo;
nsCString selfURISpec;
nsString referrer;
nsCString referrer;
uint64_t innerWindowID;
bool skipAllowInlineStyleCheck;
};

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

@ -311,7 +311,7 @@ static bool SandboxFetch(JSContext* cx, JS::HandleObject scope,
}
BindingCallContext callCx(cx, "fetch");
RequestOrUSVString request;
RequestOrUTF8String request;
if (!request.Init(callCx, args[0], "Argument 1")) {
return false;
}
@ -1274,7 +1274,7 @@ nsresult ApplyAddonContentScriptCSP(nsISupports* prinOrSop) {
csp = new nsCSPContext();
MOZ_TRY(
csp->SetRequestContextWithPrincipal(clonedPrincipal, selfURI, u""_ns, 0));
csp->SetRequestContextWithPrincipal(clonedPrincipal, selfURI, ""_ns, 0));
MOZ_TRY(csp->AppendPolicy(baseCSP, false, false));

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

@ -3412,25 +3412,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;
}

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

@ -1038,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;

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

@ -1097,24 +1097,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 +1131,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 +1141,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 +1172,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 +1212,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 +1267,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,14 +1291,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;
});
}
void URLParams::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) {
@ -1323,7 +1318,7 @@ void URLParams::SerializeString(const nsCString& aInput, nsAString& aValue) {
}
}
void URLParams::Serialize(nsAString& aValue, bool aEncode) const {
void URLParams::Serialize(nsACString& aValue, bool aEncode) const {
aValue.Truncate();
bool first = true;
@ -1337,9 +1332,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('=');
@ -1350,7 +1345,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));
});
}

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

@ -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,13 +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;
static void SerializeString(const nsCString& aInput, nsAString& aValue);
static void SerializeString(const nsACString& aInput, nsACString& aValue);
void Get(const nsACString& aName, nsACString& aRetval);
void Get(const nsAString& aName, nsString& 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.
@ -321,33 +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(); }
static void DecodeString(const nsACString& aInput, nsAString& aOutput);
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;
}
@ -359,14 +357,13 @@ class URLParams final {
void Sort();
private:
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;

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

@ -330,7 +330,7 @@ void EarlyHintPreloader::MaybeCreateAndInsertPreload(
// directives to it
nsCOMPtr<nsIContentSecurityPolicy> csp = new nsCSPContext();
nsresult rv = csp->SetRequestContextWithPrincipal(
aPrincipal, aBaseURI, u""_ns, 0 /* aInnerWindowId */);
aPrincipal, aBaseURI, ""_ns, 0 /* aInnerWindowId */);
NS_ENSURE_SUCCESS_VOID(rv);
rv = CSP_AppendCSPFromHeader(csp, NS_ConvertUTF8toUTF16(aCSPHeader),
false /* report only */);

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

@ -304,9 +304,9 @@ nsresult PageThumbProtocolHandler::GetThumbnailPath(const nsACString& aPath,
}
// Extract URL from query string.
nsAutoString url;
nsAutoCString url;
bool found =
URLParams::Extract(Substring(aPath, queryIndex + 1), u"url"_ns, url);
URLParams::Extract(Substring(aPath, queryIndex + 1), "url"_ns, url);
if (!found || url.IsVoid()) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -320,7 +320,8 @@ nsresult PageThumbProtocolHandler::GetThumbnailPath(const nsACString& aPath,
}
// Use PageThumbsStorageService to get the local file path of the screenshot
// for the given URL.
rv = pageThumbsStorage->GetFilePathForURL(url, aThumbnailPath);
rv = pageThumbsStorage->GetFilePathForURL(NS_ConvertUTF8toUTF16(url),
aThumbnailPath);
#ifdef MOZ_PLACES
} else if (aHost.EqualsLiteral(PLACES_PREVIEWS_HOST)) {
nsCOMPtr<nsIPlacesPreviewsHelperService> helper =
@ -328,7 +329,7 @@ nsresult PageThumbProtocolHandler::GetThumbnailPath(const nsACString& aPath,
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = helper->GetFilePathForURL(url, aThumbnailPath);
rv = helper->GetFilePathForURL(NS_ConvertUTF8toUTF16(url), aThumbnailPath);
#endif
} else {
MOZ_ASSERT_UNREACHABLE("Unknown thumbnail host");

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

@ -1157,8 +1157,8 @@ nsresult Connection::initialize(nsIFileURL* aFileURL) {
MOZ_ALWAYS_TRUE(
URLParams::Parse(query, true,
[&hasKey, &hasDirectoryLockId](const nsAString& aName,
const nsAString& aValue) {
[&hasKey, &hasDirectoryLockId](
const nsACString& aName, const nsACString& aValue) {
if (aName.EqualsLiteral("key")) {
hasKey = true;
return true;

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

@ -22,8 +22,8 @@ namespace mozilla {
nsresult URLDecorationStripper::StripTrackingIdentifiers(nsIURI* aURI,
nsACString& aOutSpec) {
nsAutoString tokenList;
nsresult rv = Preferences::GetString(kPrefName, tokenList);
nsAutoCString tokenList;
nsresult rv = Preferences::GetCString(kPrefName, tokenList);
ToLowerCase(tokenList);
nsAutoCString path;
@ -34,12 +34,12 @@ nsresult URLDecorationStripper::StripTrackingIdentifiers(nsIURI* aURI,
int32_t queryBegins = path.FindChar('?');
// Only positive values are valid since the path must begin with a '/'.
if (queryBegins > 0) {
for (const nsAString& token : tokenList.Split(' ')) {
for (const nsACString& token : tokenList.Split(' ')) {
if (token.IsEmpty()) {
continue;
}
nsAutoString value;
nsAutoCString value;
if (URLParams::Extract(Substring(path, queryBegins + 1), token, value) &&
!value.IsVoid()) {
// Tracking identifier found in the URL!

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

@ -261,9 +261,8 @@ nsresult URLQueryStringStripper::StripQueryString(nsIURI* aURI,
URLParams params;
URLParams::Parse(query, false, [&](nsString&& name, nsString&& value) {
nsAutoString lowerCaseName;
URLParams::Parse(query, false, [&](nsCString&& name, nsCString&& value) {
nsAutoCString lowerCaseName;
ToLowerCase(name, lowerCaseName);
if (mList.Contains(lowerCaseName)) {
@ -273,7 +272,7 @@ nsresult URLQueryStringStripper::StripQueryString(nsIURI* aURI,
// this will only count query params listed in the Histogram definition.
// Calls for any other query params will be discarded.
nsAutoCString telemetryLabel("param_");
AppendUTF16toUTF8(lowerCaseName, telemetryLabel);
telemetryLabel.Append(lowerCaseName);
Telemetry::AccumulateCategorical(
Telemetry::QUERY_STRIPPING_COUNT_BY_PARAM, telemetryLabel);
@ -289,13 +288,10 @@ nsresult URLQueryStringStripper::StripQueryString(nsIURI* aURI,
return NS_OK;
}
nsAutoString newQuery;
nsAutoCString newQuery;
params.Serialize(newQuery, false);
Unused << NS_MutateURI(uri)
.SetQuery(NS_ConvertUTF16toUTF8(newQuery))
.Finalize(aOutput);
Unused << NS_MutateURI(uri).SetQuery(newQuery).Finalize(aOutput);
return NS_OK;
}
@ -315,10 +311,10 @@ bool URLQueryStringStripper::CheckAllowList(nsIURI* aURI) {
return mAllowList.Contains(baseDomain);
}
void URLQueryStringStripper::PopulateStripList(const nsAString& aList) {
void URLQueryStringStripper::PopulateStripList(const nsACString& aList) {
mList.Clear();
for (const nsAString& item : aList.Split(' ')) {
for (const nsACString& item : aList.Split(' ')) {
mList.Insert(item);
}
}
@ -333,7 +329,7 @@ void URLQueryStringStripper::PopulateAllowList(const nsACString& aList) {
NS_IMETHODIMP
URLQueryStringStripper::OnQueryStrippingListUpdate(
const nsAString& aStripList, const nsACString& aAllowList) {
const nsACString& aStripList, const nsACString& aAllowList) {
PopulateStripList(aStripList);
PopulateAllowList(aAllowList);
return NS_OK;
@ -349,8 +345,7 @@ URLQueryStringStripper::OnStripOnShareUpdate(const nsTArray<nsString>& aArgs,
continue;
}
for (const auto& topLevelSite : rule.mTopLevelSites) {
mStripOnShareMap.InsertOrUpdate(NS_ConvertUTF16toUTF8(topLevelSite),
rule);
mStripOnShareMap.InsertOrUpdate(topLevelSite, rule);
}
}
return NS_OK;
@ -360,10 +355,9 @@ NS_IMETHODIMP
URLQueryStringStripper::TestGetStripList(nsACString& aStripList) {
aStripList.Truncate();
StringJoinAppend(aStripList, " "_ns, mList,
[](auto& aResult, const auto& aValue) {
aResult.Append(NS_ConvertUTF16toUTF8(aValue));
});
StringJoinAppend(
aStripList, " "_ns, mList,
[](auto& aResult, const auto& aValue) { aResult.Append(aValue); });
return NS_OK;
}
@ -398,8 +392,8 @@ nsresult URLQueryStringStripper::StripForCopyOrShareInternal(
URLParams params;
URLParams::Parse(query, false, [&](nsString&& name, nsString&& value) {
nsAutoString lowerCaseName;
URLParams::Parse(query, false, [&](nsCString&& name, nsCString&& value) {
nsAutoCString lowerCaseName;
ToLowerCase(name, lowerCaseName);
// Look through the global rules.
@ -434,8 +428,8 @@ nsresult URLQueryStringStripper::StripForCopyOrShareInternal(
// it gets passed back into this method but with the recursive
// stripping flag set to true
if (!aStripNestedURIs) {
nsAutoString decodeValue;
URLParams::DecodeString(NS_ConvertUTF16toUTF8(value), decodeValue);
nsAutoCString decodeValue;
URLParams::DecodeString(value, decodeValue);
nsCOMPtr<nsIURI> nestedURI;
rv = NS_NewURI(getter_AddRefs(nestedURI), decodeValue);
@ -459,7 +453,7 @@ nsresult URLQueryStringStripper::StripForCopyOrShareInternal(
}
// Encodes URI
nsAutoString encodedURI;
nsAutoCString encodedURI;
URLParams::SerializeString(nestedURIString, encodedURI);
params.Append(name, encodedURI);
@ -470,12 +464,9 @@ nsresult URLQueryStringStripper::StripForCopyOrShareInternal(
return true;
});
nsAutoString newQuery;
nsAutoCString newQuery;
params.Serialize(newQuery, false);
return NS_MutateURI(aURI)
.SetQuery(NS_ConvertUTF16toUTF8(newQuery))
.Finalize(strippedURI);
return NS_MutateURI(aURI).SetQuery(newQuery).Finalize(strippedURI);
}
} // namespace mozilla

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

@ -46,7 +46,7 @@ class URLQueryStringStripper final : public nsIObserver,
bool CheckAllowList(nsIURI* aURI);
void PopulateStripList(const nsAString& aList);
void PopulateStripList(const nsACString& aList);
void PopulateAllowList(const nsACString& aList);
// Recursive helper function that helps strip URIs of tracking parameters
@ -55,7 +55,7 @@ class URLQueryStringStripper final : public nsIObserver,
nsresult StripForCopyOrShareInternal(nsIURI* aURI, nsIURI** strippedURI,
int& aStripCount, bool aStripNestedURIs);
nsTHashSet<nsString> mList;
nsTHashSet<nsCString> mList;
nsTHashSet<nsCString> mAllowList;
nsCOMPtr<nsIURLQueryStrippingListService> mListService;
nsTHashMap<nsCString, dom::StripRule> mStripOnShareMap;

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

@ -22,7 +22,7 @@ interface nsIURLQueryStrippingListObserver : nsISupports
* A comma-separated list of hosts (eTLD+1) that are exempt from query
* stripping.
*/
void onQueryStrippingListUpdate(in AString aStripList, in ACString aAllowList);
void onQueryStrippingListUpdate(in ACString aStripList, in ACString aAllowList);
/**
* Called by nsIQueryStrippingListService when the list of query stripping

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

@ -1134,16 +1134,15 @@ GetQueryParamFunction::OnFunctionCall(mozIStorageValueArray* aArguments,
RefPtr<nsVariant> result = new nsVariant();
if (!queryString.IsEmpty() && !paramName.IsEmpty()) {
URLParams::Parse(
queryString, true,
[&paramName, &result](const nsAString& aName, const nsAString& aValue) {
NS_ConvertUTF16toUTF8 name(aName);
if (!paramName.Equals(name)) {
return true;
}
result->SetAsAString(aValue);
return false;
});
URLParams::Parse(queryString, true,
[&paramName, &result](const nsACString& aName,
const nsACString& aValue) {
if (!paramName.Equals(aName)) {
return true;
}
result->SetAsACString(aValue);
return false;
});
}
result.forget(_result);

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

@ -319,7 +319,7 @@ AddonContentPolicy::ValidateAddonCSP(const nsAString& aPolicyString,
nsCOMPtr<nsIURI> selfURI;
principal->GetURI(getter_AddRefs(selfURI));
RefPtr<nsCSPContext> csp = new nsCSPContext();
rv = csp->SetRequestContextWithPrincipal(principal, selfURI, u""_ns, 0);
rv = csp->SetRequestContextWithPrincipal(principal, selfURI, ""_ns, 0);
NS_ENSURE_SUCCESS(rv, rv);
csp->AppendPolicy(aPolicyString, false, false);