Bug 1322874 - Get rid of nsIURI.originCharset. r=valentin.gosu

nsIURI.originCharset had two use cases:
 1) Dealing with the spec-incompliant feature of escapes in the hash
    (reference) part of the URL.
 2) For UI display of non-UTF-8 URLs.

For hash part handling, we use the document charset instead. For pretty
display of query strings on legacy-encoded pages, we no longer care to them
(see bug 817374 comment 18).

Also, the URL Standard has no concept of "origin charset". This patch
removes nsIURI.originCharset for reducing complexity and spec compliance.

MozReview-Commit-ID: 3tHd0VCWSqF

--HG--
extra : rebase_source : b2caa01f75e5dd26078a7679fd7caa319a65af14
This commit is contained in:
Masatoshi Kimura 2017-08-02 20:43:30 +09:00
Родитель 80a38fa00e
Коммит 8ed4a80a4e
32 изменённых файлов: 154 добавлений и 255 удалений

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

@ -1210,7 +1210,6 @@ var PageInfoListener = {
let documentURIObject = {};
documentURIObject.spec = document.documentURIObject.spec;
documentURIObject.originCharset = document.documentURIObject.originCharset;
docInfo.documentURIObject = documentURIObject;
docInfo.isContentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate(content);

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

@ -362,8 +362,7 @@ function loadPageInfo(frameOuterWindowID, imageElement, browser) {
pageInfoData = message.data;
let docInfo = pageInfoData.docInfo;
let windowInfo = pageInfoData.windowInfo;
let uri = makeURI(docInfo.documentURIObject.spec,
docInfo.documentURIObject.originCharset);
let uri = makeURI(docInfo.documentURIObject.spec);
let principal = docInfo.principal;
gDocInfo = docInfo;

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

@ -979,7 +979,6 @@ var RefreshBlocker = {
let data = {
URI: aURI.spec,
originCharset: aURI.originCharset,
delay: aDelay,
sameURI: aSameURI,
outerWindowID,
@ -1007,7 +1006,7 @@ var RefreshBlocker = {
.getInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIRefreshURI);
let URI = Services.io.newURI(data.URI, data.originCharset);
let URI = Services.io.newURI(data.URI);
refreshURI.forceRefreshURI(URI, data.delay, true);
}

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

@ -135,13 +135,6 @@ NullPrincipalURI::SetHostAndPort(const nsACString& aHost)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NullPrincipalURI::GetOriginCharset(nsACString& _charset)
{
_charset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
NullPrincipalURI::GetPassword(nsACString& _password)
{
@ -193,6 +186,13 @@ NullPrincipalURI::SetQuery(const nsACString& aQuery)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NullPrincipalURI::SetQueryWithEncoding(const nsACString& aQuery,
const Encoding* aEncoding)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NullPrincipalURI::GetRef(nsACString& _ref)
{

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

@ -12,12 +12,10 @@
struct SerializedURI
{
nsCString spec;
nsCString charset;
bool operator ==(const SerializedURI& rhs) const
{
return spec.Equals(rhs.spec) &&
charset.Equals(rhs.charset);
return spec.Equals(rhs.spec);
}
};
@ -75,16 +73,13 @@ struct ParamTraits<SerializedURI>
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.spec);
WriteParam(aMsg, aParam.charset);
}
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
{
nsCString spec, charset;
if (ReadParam(aMsg, aIter, &spec) &&
ReadParam(aMsg, aIter, &charset)) {
nsCString spec;
if (ReadParam(aMsg, aIter, &spec)) {
aResult->spec = spec;
aResult->charset = charset;
return true;
}
return false;

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

@ -329,7 +329,6 @@ SerializeURI(nsIURI* aURI,
return;
aURI->GetSpec(aSerializedURI.spec);
aURI->GetOriginCharset(aSerializedURI.charset);
}
void

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

@ -61,24 +61,21 @@ nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
if (aPackage.contentBaseURI.spec.Length()) {
nsresult rv = NS_NewURI(getter_AddRefs(content),
aPackage.contentBaseURI.spec,
aPackage.contentBaseURI.charset.get(),
nullptr, io);
nullptr, nullptr, io);
if (NS_FAILED(rv))
return;
}
if (aPackage.localeBaseURI.spec.Length()) {
nsresult rv = NS_NewURI(getter_AddRefs(locale),
aPackage.localeBaseURI.spec,
aPackage.localeBaseURI.charset.get(),
nullptr, io);
nullptr, nullptr, io);
if (NS_FAILED(rv))
return;
}
if (aPackage.skinBaseURI.spec.Length()) {
nsresult rv = NS_NewURI(getter_AddRefs(skin),
aPackage.skinBaseURI.spec,
aPackage.skinBaseURI.charset.get(),
nullptr, io);
nullptr, nullptr, io);
if (NS_FAILED(rv))
return;
}
@ -112,8 +109,7 @@ nsChromeRegistryContent::RegisterSubstitution(const SubstitutionMapping& aSubsti
if (aSubstitution.resolvedURI.spec.Length()) {
rv = NS_NewURI(getter_AddRefs(resolvedURI),
aSubstitution.resolvedURI.spec,
aSubstitution.resolvedURI.charset.get(),
nullptr, io);
nullptr, nullptr, io);
if (NS_FAILED(rv))
return;
}
@ -133,13 +129,12 @@ nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
nsCOMPtr<nsIURI> chromeURI, overrideURI;
nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
aOverride.originalURI.spec,
aOverride.originalURI.charset.get(),
nullptr, io);
nullptr, nullptr, io);
if (NS_FAILED(rv))
return;
rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
aOverride.overrideURI.charset.get(), nullptr, io);
nullptr, nullptr, io);
if (NS_FAILED(rv))
return;

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

@ -87,14 +87,8 @@ nsDefaultURIFixup::CreateExposableURI(nsIURI* aURI, nsIURI** aReturn)
return NS_ERROR_FAILURE;
}
// Get the charset of the original URI so we can pass it to our fixed up
// URI.
nsAutoCString charset;
aURI->GetOriginCharset(charset);
rv = NS_NewURI(getter_AddRefs(uri),
Substring(path, slashIndex + 1, pathLength - slashIndex - 1),
charset.get());
Substring(path, slashIndex + 1, pathLength - slashIndex - 1));
NS_ENSURE_SUCCESS(rv, rv);
} else {
// clone the URI so zapping user:pass doesn't change the original

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

@ -5287,13 +5287,10 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
aURI->GetSpec(spec);
}
nsAutoCString charset;
// unescape and convert from origin charset
aURI->GetOriginCharset(charset);
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
rv = textToSubURI->UnEscapeURIForUI(charset, spec,
rv = textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"), spec,
formatStrs[formatStrCount]);
}
} else {
@ -5387,12 +5384,9 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
}
nsAutoCString url;
nsAutoCString charset;
if (aURI) {
nsresult rv = aURI->GetSpec(url);
NS_ENSURE_SUCCESS(rv, rv);
rv = aURI->GetOriginCharset(charset);
NS_ENSURE_SUCCESS(rv, rv);
} else if (aURL) {
CopyUTF16toUTF8(aURL, url);
} else {
@ -5407,10 +5401,9 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
return NS_ERROR_OUT_OF_MEMORY; \
}
nsCString escapedUrl, escapedCharset, escapedError, escapedDescription,
nsCString escapedUrl, escapedError, escapedDescription,
escapedCSSClass;
SAFE_ESCAPE(escapedUrl, url, url_Path);
SAFE_ESCAPE(escapedCharset, charset, url_Path);
SAFE_ESCAPE(escapedError, nsDependentCString(aErrorType), url_Path);
SAFE_ESCAPE(escapedDescription,
NS_ConvertUTF16toUTF8(aDescription), url_Path);
@ -5433,8 +5426,7 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
errorPageUrl.AppendLiteral("&s=");
errorPageUrl.AppendASCII(escapedCSSClass.get());
}
errorPageUrl.AppendLiteral("&c=");
errorPageUrl.AppendASCII(escapedCharset.get());
errorPageUrl.AppendLiteral("&c=UTF-8");
nsAutoCString frameType(FrameTypeToString(mFrameType));
errorPageUrl.AppendLiteral("&f=");
@ -12141,11 +12133,8 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
nsAutoCString spec;
docBaseURI->GetSpec(spec);
nsAutoCString charset;
rv = docBaseURI->GetOriginCharset(charset);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
rv = NS_NewURI(getter_AddRefs(newURI), aURL, charset.get(), docBaseURI);
rv = NS_NewURI(getter_AddRefs(newURI), aURL,
document->GetDocumentCharacterSet(), docBaseURI);
// 2b: If 2a fails, raise a SECURITY_ERR
if (NS_FAILED(rv)) {

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

@ -513,7 +513,8 @@ Link::SetSearch(const nsAString& aSearch)
return;
}
(void)url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
auto encoding = mElement->OwnerDoc()->GetDocumentCharacterSet();
(void)url->SetQueryWithEncoding(NS_ConvertUTF16toUTF8(aSearch), encoding);
SetHrefAttribute(uri);
}

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

@ -821,7 +821,12 @@ Location::SetSearch(const nsAString& aSearch,
return;
}
aRv = url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
if (nsIDocument* doc = GetEntryDocument()) {
aRv = url->SetQueryWithEncoding(NS_ConvertUTF16toUTF8(aSearch),
doc->GetDocumentCharacterSet());
} else {
aRv = url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
}
if (NS_WARN_IF(aRv.Failed())) {
return;
}

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

@ -28,15 +28,16 @@ nsReferencedElement::Reset(nsIContent* aFromContent, nsIURI* aURI,
nsAutoCString refPart;
aURI->GetRef(refPart);
// Unescape %-escapes in the reference. The result will be in the
// origin charset of the URL, hopefully...
// document charset, hopefully...
NS_UnescapeURL(refPart);
nsAutoCString charset;
aURI->GetOriginCharset(charset);
auto encoding = Encoding::ForLabelNoReplacement(charset);
if (!encoding) {
encoding = UTF_8_ENCODING;
// Get the current document
nsIDocument *doc = aFromContent->OwnerDoc();
if (!doc) {
return;
}
auto encoding = doc->GetDocumentCharacterSet();
nsAutoString ref;
nsresult rv = encoding->DecodeWithoutBOMHandling(refPart, ref);
if (NS_FAILED(rv) || ref.IsEmpty()) {
@ -44,11 +45,6 @@ nsReferencedElement::Reset(nsIContent* aFromContent, nsIURI* aURI,
}
rv = NS_OK;
// Get the current document
nsIDocument *doc = aFromContent->OwnerDoc();
if (!doc)
return;
nsIContent* bindingParent = aFromContent->GetBindingParent();
if (bindingParent) {
nsXBLBinding* binding = bindingParent->GetXBLBinding();

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

@ -295,17 +295,12 @@ MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel)
// the document viewer instead of a bogus value ("windows-1252" set in
// |nsDocument|'s ctor), the priority is given to the current charset.
// This is necessary to deal with a media document being opened in a new
// window or a new tab, in which case |originCharset| of |nsIURI| is not
// reliable.
// window or a new tab.
if (mCharacterSetSource != kCharsetUninitialized) {
mCharacterSet->Name(docCharset);
} else {
// resort to |originCharset|
url->GetOriginCharset(docCharset);
auto encoding = Encoding::ForLabelNoReplacement(docCharset);
if (encoding) {
SetDocumentCharacterSet(WrapNotNull(encoding));
}
// resort to UTF-8
SetDocumentCharacterSet(UTF_8_ENCODING);
}
nsresult rv;

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

@ -415,6 +415,13 @@ nsMozIconURI::SetQuery(const nsACString& aQuery)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMozIconURI::SetQueryWithEncoding(const nsACString& aQuery,
const Encoding* aEncoding)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMozIconURI::GetRef(nsACString& aRef)
{
@ -541,13 +548,6 @@ nsMozIconURI::GetAsciiHost(nsACString& aHostA)
return GetHost(aHostA);
}
NS_IMETHODIMP
nsMozIconURI::GetOriginCharset(nsACString& result)
{
result.Truncate();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIIconUri methods:

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

@ -43,7 +43,6 @@ struct StandardURLParams
StandardURLSegment extension;
StandardURLSegment query;
StandardURLSegment ref;
nsCString originCharset;
bool isMutable;
bool supportsFileURL;
};

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

@ -475,13 +475,6 @@ nsJARURI::GetAsciiHost(nsACString &aHost)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJARURI::GetOriginCharset(nsACString &aOriginCharset)
{
aOriginCharset = mCharsetHint;
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::Equals(nsIURI *other, bool *result)
{
@ -625,6 +618,13 @@ nsJARURI::SetQuery(const nsACString& query)
return mJAREntry->SetQuery(query);
}
NS_IMETHODIMP
nsJARURI::SetQueryWithEncoding(const nsACString& query,
const Encoding* encoding)
{
return mJAREntry->SetQueryWithEncoding(query, encoding);
}
NS_IMETHODIMP
nsJARURI::GetRef(nsACString& ref)
{
@ -728,12 +728,8 @@ nsJARURI::GetCommonBaseSpec(nsIURI* uriToCompare, nsACString& commonSpec)
rv = otherJARURI->GetJAREntry(otherEntry);
if (NS_FAILED(rv)) return rv;
nsAutoCString otherCharset;
rv = uriToCompare->GetOriginCharset(otherCharset);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> url;
rv = CreateEntryURL(otherEntry, otherCharset.get(), getter_AddRefs(url));
rv = CreateEntryURL(otherEntry, nullptr, getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
nsAutoCString common;
@ -775,12 +771,8 @@ nsJARURI::GetRelativeSpec(nsIURI* uriToCompare, nsACString& relativeSpec)
rv = otherJARURI->GetJAREntry(otherEntry);
if (NS_FAILED(rv)) return rv;
nsAutoCString otherCharset;
rv = uriToCompare->GetOriginCharset(otherCharset);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> url;
rv = CreateEntryURL(otherEntry, otherCharset.get(), getter_AddRefs(url));
rv = CreateEntryURL(otherEntry, nullptr, getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
nsAutoCString relativeEntrySpec;

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

@ -364,13 +364,6 @@ RustURL::GetAsciiHost(nsACString & aAsciiHost)
return GetHost(aAsciiHost);
}
NS_IMETHODIMP
RustURL::GetOriginCharset(nsACString & aOriginCharset)
{
aOriginCharset.AssignLiteral("UTF-8");
return NS_OK;
}
NS_IMETHODIMP
RustURL::GetRef(nsACString & aRef)
{
@ -495,6 +488,15 @@ RustURL::SetQuery(const nsACString & aQuery)
return rusturl_set_query(mURL.get(), &aQuery);
}
NS_IMETHODIMP
RustURL::SetQueryWithEncoding(const nsACString& aQuery,
const Encoding* aEncoding)
{
ENSURE_MUTABLE();
//XXX rust-url-capi should support the concept of "encoding override"
return rusturl_set_query(mURL.get(), &aQuery);
}
NS_IMETHODIMP
RustURL::GetDirectory(nsACString & aDirectory)
{

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

@ -20,7 +20,7 @@
namespace mozilla {
namespace net {
class RustURL
class RustURL final
: public nsIFileURL
, public nsIStandardURL
, public nsISerializable

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

@ -40,8 +40,14 @@
#undef GetPort // XXX Windows!
#undef SetPort // XXX Windows!
namespace mozilla {
class Encoding;
}
%}
[ptr] native Encoding(const mozilla::Encoding);
/**
* nsIURI - interface for an uniform resource identifier w/ i18n support.
*
@ -230,17 +236,6 @@ interface nsIURI : nsISupports
*/
readonly attribute ACString asciiHost;
/**
* The charset of the document from which this URI originated. An empty
* value implies UTF-8.
*
* If this value is something other than UTF-8 then the URI components
* (e.g., spec, prePath, username, etc.) will all be fully URL-escaped.
* Otherwise, the URI components may contain unescaped multibyte UTF-8
* characters.
*/
readonly attribute ACString originCharset;
/************************************************************************
* Additional attribute & methods added for .ref support:
*/
@ -303,6 +298,8 @@ interface nsIURI : nsISupports
* Some characters may be escaped.
*/
attribute AUTF8String query;
[noscript]
void setQueryWithEncoding(in AUTF8String query, in Encoding encoding);
/**
* If the URI has a punycode encoded hostname, this will hold the UTF8

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

@ -2396,16 +2396,8 @@ NS_GetContentDispositionFromHeader(const nsACString &aHeader,
if (NS_FAILED(rv))
return nsIChannel::DISPOSITION_ATTACHMENT;
nsAutoCString fallbackCharset;
if (aChan) {
nsCOMPtr<nsIURI> uri;
aChan->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetOriginCharset(fallbackCharset);
}
nsAutoString dispToken;
rv = mimehdrpar->GetParameterHTTP(aHeader, "", fallbackCharset, true, nullptr,
rv = mimehdrpar->GetParameterHTTP(aHeader, "", EmptyCString(), true, nullptr,
dispToken);
if (NS_FAILED(rv)) {
@ -2431,14 +2423,9 @@ NS_GetFilenameFromDisposition(nsAString &aFilename,
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
nsAutoCString fallbackCharset;
if (url)
url->GetOriginCharset(fallbackCharset);
// Get the value of 'filename' parameter
rv = mimehdrpar->GetParameterHTTP(aDisposition, "filename",
fallbackCharset, true, nullptr,
EmptyCString(), true, nullptr,
aFilename);
if (NS_FAILED(rv)) {

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

@ -711,13 +711,6 @@ nsSimpleURI::GetAsciiHost(nsACString &result)
return NS_OK;
}
NS_IMETHODIMP
nsSimpleURI::GetOriginCharset(nsACString &result)
{
result.Truncate();
return NS_OK;
}
//----------------------------------------------------------------------------
// nsSimpleURI::nsIClassInfo
//----------------------------------------------------------------------------
@ -870,5 +863,12 @@ nsSimpleURI::SetQuery(const nsACString& aQuery)
return NS_OK;
}
NS_IMETHODIMP
nsSimpleURI::SetQueryWithEncoding(const nsACString& aQuery,
const Encoding* aEncoding)
{
return SetQuery(aQuery);
}
} // namespace net
} // namespace mozilla

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

@ -209,9 +209,8 @@ nsPrefObserver::Observe(nsISupports *subject,
// nsStandardURL::nsSegmentEncoder
//----------------------------------------------------------------------------
nsStandardURL::nsSegmentEncoder::nsSegmentEncoder(const char* charset)
: mEncoding(charset ? Encoding::ForLabelNoReplacement(MakeStringSpan(charset))
: nullptr)
nsStandardURL::nsSegmentEncoder::nsSegmentEncoder(const Encoding* encoding)
: mEncoding(encoding)
{
if (mEncoding == UTF_8_ENCODING) {
mEncoding = nullptr;
@ -285,15 +284,6 @@ nsSegmentEncoder::EncodeSegment(const nsACString& str,
return str;
}
#define GET_SEGMENT_ENCODER_INTERNAL(name, useUTF8) \
nsSegmentEncoder name(useUTF8 ? nullptr : mOriginCharset.get())
#define GET_SEGMENT_ENCODER(name) \
GET_SEGMENT_ENCODER_INTERNAL(name, true)
#define GET_QUERY_ENCODER(name) \
GET_SEGMENT_ENCODER_INTERNAL(name, false)
//----------------------------------------------------------------------------
// nsStandardURL <public>
//----------------------------------------------------------------------------
@ -794,7 +784,8 @@ nsStandardURL::AppendToBuf(char *buf, uint32_t i, const char *str, uint32_t len)
// 3- write url segments
// 4- update url segment positions and lengths
nsresult
nsStandardURL::BuildNormalizedSpec(const char *spec)
nsStandardURL::BuildNormalizedSpec(const char *spec,
const Encoding* encoding)
{
// Assumptions: all member URLSegments must be relative the |spec| argument
// passed to this function.
@ -823,8 +814,8 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
// results written to encXXX variables only if |spec| is not already in the
// appropriate encoding.
{
GET_SEGMENT_ENCODER(encoder);
GET_QUERY_ENCODER(queryEncoder);
nsSegmentEncoder encoder;
nsSegmentEncoder queryEncoder(encoding);
// Items using an extraLen of 1 don't add anything unless mLen > 0
// Username@
approxLen += encoder.EncodeSegmentCount(spec, mUsername, esc_Username, encUsername, useEncUsername, 1);
@ -1654,17 +1645,6 @@ nsStandardURL::GetAsciiHost(nsACString &result)
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::GetOriginCharset(nsACString &result)
{
if (mOriginCharset.IsEmpty())
result.AssignLiteral("UTF-8");
else
result = mOriginCharset;
CALL_RUST_GETTER_STR(result, GetOriginCharset, result);
return NS_OK;
}
static bool
IsSpecialProtocol(const nsACString &input)
{
@ -1690,6 +1670,13 @@ IsSpecialProtocol(const nsACString &input)
NS_IMETHODIMP
nsStandardURL::SetSpec(const nsACString &input)
{
return SetSpecWithEncoding(input, nullptr);
}
nsresult
nsStandardURL::SetSpecWithEncoding(const nsACString &input,
const Encoding* encoding)
{
ENSURE_MUTABLE();
@ -1739,7 +1726,7 @@ nsStandardURL::SetSpec(const nsACString &input)
if (NS_SUCCEEDED(rv)) {
// finally, use the URLSegment member variables to build a normalized
// copy of |spec|
rv = BuildNormalizedSpec(spec);
rv = BuildNormalizedSpec(spec, encoding);
}
// Make sure that a URLTYPE_AUTHORITY has a non-empty hostname.
@ -1878,7 +1865,7 @@ nsStandardURL::SetUserPass(const nsACString &input)
// build new user:pass in |buf|
nsAutoCString buf;
if (usernameLen > 0) {
GET_SEGMENT_ENCODER(encoder);
nsSegmentEncoder encoder;
bool ignoredOut;
usernameLen = encoder.EncodeSegmentCount(userpass.get(),
URLSegment(usernamePos,
@ -1960,7 +1947,7 @@ nsStandardURL::SetUsername(const nsACString &input)
// escape username if necessary
nsAutoCString buf;
GET_SEGMENT_ENCODER(encoder);
nsSegmentEncoder encoder;
const nsACString &escUsername =
encoder.EncodeSegment(username, esc_Username, buf);
@ -2024,7 +2011,7 @@ nsStandardURL::SetPassword(const nsACString &input)
// escape password if necessary
nsAutoCString buf;
GET_SEGMENT_ENCODER(encoder);
nsSegmentEncoder encoder;
const nsACString &escPassword =
encoder.EncodeSegment(password, esc_Password, buf);
@ -2540,7 +2527,6 @@ nsresult nsStandardURL::CopyMembers(nsStandardURL * source,
mExtension = source->mExtension;
mQuery = source->mQuery;
mRef = source->mRef;
mOriginCharset = source->mOriginCharset;
mURLType = source->mURLType;
mParser = source->mParser;
mMutable = true;
@ -2994,7 +2980,7 @@ nsStandardURL::SetFilePath(const nsACString &input)
if (filepath[dirPos] != '/')
spec.Append('/');
GET_SEGMENT_ENCODER(encoder);
nsSegmentEncoder encoder;
// append encoded filepath components
if (dirLen > 0)
@ -3038,8 +3024,23 @@ nsStandardURL::SetFilePath(const nsACString &input)
return NS_OK;
}
inline bool
IsUTFEncoding(const Encoding* aEncoding)
{
return aEncoding == UTF_8_ENCODING ||
aEncoding == UTF_16BE_ENCODING ||
aEncoding == UTF_16LE_ENCODING;
}
NS_IMETHODIMP
nsStandardURL::SetQuery(const nsACString &input)
{
return SetQueryWithEncoding(input, nullptr);
}
NS_IMETHODIMP
nsStandardURL::SetQueryWithEncoding(const nsACString &input,
const Encoding* encoding)
{
ENSURE_MUTABLE();
@ -3048,6 +3049,10 @@ nsStandardURL::SetQuery(const nsACString &input)
LOG(("nsStandardURL::SetQuery [query=%s]\n", query));
if (IsUTFEncoding(encoding)) {
encoding = nullptr;
}
if (mPath.mLen < 0)
return SetPathQueryRef(flat);
@ -3093,7 +3098,7 @@ nsStandardURL::SetQuery(const nsACString &input)
// encode query if necessary
nsAutoCString buf;
bool encoded;
GET_QUERY_ENCODER(encoder);
nsSegmentEncoder encoder(encoding);
encoder.EncodeSegmentCount(query, URLSegment(0, queryLen), esc_Query,
buf, encoded);
if (encoded) {
@ -3162,7 +3167,7 @@ nsStandardURL::SetRef(const nsACString &input)
nsAutoCString buf;
// encode ref if necessary
bool encoded;
GET_SEGMENT_ENCODER(encoder);
nsSegmentEncoder encoder;
encoder.EncodeSegmentCount(ref, URLSegment(0, refLen), esc_Ref,
buf, encoded);
if (encoded) {
@ -3239,7 +3244,7 @@ nsStandardURL::SetFileName(const nsACString &input)
else {
nsAutoCString newFilename;
bool ignoredOut;
GET_SEGMENT_ENCODER(encoder);
nsSegmentEncoder encoder;
basename.mLen = encoder.EncodeSegmentCount(filename, basename,
esc_FileBaseName |
esc_AlwaysCopy,
@ -3407,14 +3412,6 @@ nsStandardURL::SetFile(nsIFile *file)
// nsStandardURL::nsIStandardURL
//----------------------------------------------------------------------------
inline bool
IsUTFCharset(const char *aCharset)
{
return ((aCharset[0] == 'U' || aCharset[0] == 'u') &&
(aCharset[1] == 'T' || aCharset[1] == 't') &&
(aCharset[2] == 'F' || aCharset[2] == 'f'));
}
NS_IMETHODIMP
nsStandardURL::Init(uint32_t urlType,
int32_t defaultPort,
@ -3448,25 +3445,14 @@ nsStandardURL::Init(uint32_t urlType,
mDefaultPort = defaultPort;
mURLType = urlType;
mOriginCharset.Truncate();
if (charset == nullptr || *charset == '\0') {
// check if baseURI provides an origin charset and use that.
if (baseURI)
baseURI->GetOriginCharset(mOriginCharset);
// URI can't be encoded in UTF-16, UTF-16BE, UTF-16LE, UTF-32,
// UTF-32-LE, UTF-32LE, UTF-32BE (yet?). Truncate mOriginCharset if
// it starts with "utf" (since an empty mOriginCharset implies
// UTF-8, this is safe even if mOriginCharset is UTF-8).
if (mOriginCharset.Length() > 3 &&
IsUTFCharset(mOriginCharset.get())) {
mOriginCharset.Truncate();
}
}
else if (!IsUTFCharset(charset)) {
mOriginCharset = charset;
auto encoding =
charset ? Encoding::ForLabelNoReplacement(MakeStringSpan(charset))
: nullptr;
// URI can't be encoded in UTF-16BE or UTF-16LE. Truncate encoding
// if it is one of utf encodings (since a null encoding implies
// UTF-8, this is safe even if encoding is UTF-8).
if (IsUTFEncoding(encoding)) {
encoding = nullptr;
}
if (baseURI && net_IsAbsoluteURL(spec)) {
@ -3476,13 +3462,13 @@ nsStandardURL::Init(uint32_t urlType,
CALL_RUST_INIT;
if (!baseURI)
return SetSpec(spec);
return SetSpecWithEncoding(spec, encoding);
nsAutoCString buf;
nsresult rv = baseURI->Resolve(spec, buf);
if (NS_FAILED(rv)) return rv;
return SetSpec(buf);
return SetSpecWithEncoding(buf, encoding);
}
NS_IMETHODIMP
@ -3608,7 +3594,8 @@ nsStandardURL::Read(nsIObjectInputStream *stream)
rv = ReadSegment(stream, mRef);
if (NS_FAILED(rv)) return rv;
rv = NS_ReadOptionalCString(stream, mOriginCharset);
nsAutoCString oldOriginCharset;
rv = NS_ReadOptionalCString(stream, oldOriginCharset);
if (NS_FAILED(rv)) return rv;
bool isMutable;
@ -3700,7 +3687,8 @@ nsStandardURL::Write(nsIObjectOutputStream *stream)
rv = WriteSegment(stream, mRef);
if (NS_FAILED(rv)) return rv;
rv = NS_WriteOptionalStringZ(stream, mOriginCharset.get());
// former origin charset
rv = NS_WriteOptionalStringZ(stream, EmptyCString().get());
if (NS_FAILED(rv)) return rv;
rv = stream->WriteBoolean(mMutable);
@ -3755,7 +3743,6 @@ nsStandardURL::Serialize(URIParams& aParams)
params.extension() = ToIPCSegment(mExtension);
params.query() = ToIPCSegment(mQuery);
params.ref() = ToIPCSegment(mRef);
params.originCharset() = mOriginCharset;
params.isMutable() = !!mMutable;
params.supportsFileURL() = !!mSupportsFileURL;
// mSpecEncoding and mDisplayHost are just caches that can be recovered as needed.
@ -3809,7 +3796,6 @@ nsStandardURL::Deserialize(const URIParams& aParams)
mExtension = FromIPCSegment(params.extension());
mQuery = FromIPCSegment(params.query());
mRef = FromIPCSegment(params.ref());
mOriginCharset = params.originCharset();
mMutable = params.isMutable();
mSupportsFileURL = params.supportsFileURL();
@ -3883,7 +3869,6 @@ size_t
nsStandardURL::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
return mSpec.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
mOriginCharset.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
mDisplayHost.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
// Measurement of the following members may be added later if DMD finds it is

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

@ -35,6 +35,7 @@ class nsIFile;
class nsIURLParser;
namespace mozilla {
class Encoding;
namespace net {
//-----------------------------------------------------------------------------
@ -122,7 +123,7 @@ public: /* internal -- HPUX compiler can't handle this being private */
class nsSegmentEncoder
{
public:
explicit nsSegmentEncoder(const char *charset);
explicit nsSegmentEncoder(const Encoding* encoding = nullptr);
// Encode the given segment if necessary, and return the length of
// the encoded segment. The encoded segment is appended to |buf|
@ -198,7 +199,8 @@ private:
bool useEsc = false, int32_t* diff = nullptr);
uint32_t AppendToBuf(char *, uint32_t, const char *, uint32_t);
nsresult BuildNormalizedSpec(const char *spec);
nsresult BuildNormalizedSpec(const char* spec, const Encoding* encoding);
nsresult SetSpecWithEncoding(const nsACString &input, const Encoding* encoding);
bool SegmentIs(const URLSegment &s1, const char *val, bool ignoreCase = false);
bool SegmentIs(const char* spec, const URLSegment &s1, const char *val, bool ignoreCase = false);
@ -274,7 +276,6 @@ private:
URLSegment mQuery;
URLSegment mRef;
nsCString mOriginCharset;
nsCOMPtr<nsIURLParser> mParser;
// mFile is protected so subclasses can access it directly

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

@ -1594,14 +1594,9 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer,
int32_t slashIndex = path.FindChar('/', 2);
if (slashIndex == kNotFound) return NS_ERROR_FAILURE;
// Get charset of the original URI so we can pass it to our fixed up URI.
nsAutoCString charset;
referrer->GetOriginCharset(charset);
// Replace |referrer| with a URI without wyciwyg://123/.
rv = NS_NewURI(getter_AddRefs(referrerGrip),
Substring(path, slashIndex + 1, pathLength - slashIndex - 1),
charset.get());
Substring(path, slashIndex + 1, pathLength - slashIndex - 1));
if (NS_FAILED(rv)) return rv;
referrer = referrerGrip.get();

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

@ -8385,14 +8385,8 @@ nsHttpChannel::CreateNewURI(const char *loc, nsIURI **newURI)
nsresult rv = gHttpHandler->GetIOService(getter_AddRefs(ioService));
if (NS_FAILED(rv)) return rv;
// the new uri should inherit the origin charset of the current uri
nsAutoCString originCharset;
rv = mURI->GetOriginCharset(originCharset);
if (NS_FAILED(rv))
originCharset.Truncate();
return ioService->NewURI(nsDependentCString(loc),
originCharset.get(),
nullptr,
mURI,
newURI);
}

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

@ -122,7 +122,6 @@ SubstitutingProtocolHandler::CollectSubstitutions(InfallibleTArray<SubstitutionM
if (uri) {
nsresult rv = uri->GetSpec(serialized.spec);
NS_ENSURE_SUCCESS(rv, rv);
uri->GetOriginCharset(serialized.charset);
}
SubstitutionMapping substitution = { mScheme, nsCString(iter.Key()), serialized };
aMappings.AppendElement(substitution);
@ -150,7 +149,6 @@ SubstitutingProtocolHandler::SendSubstitution(const nsACString& aRoot, nsIURI* a
if (aBaseURI) {
nsresult rv = aBaseURI->GetSpec(mapping.resolvedURI.spec);
NS_ENSURE_SUCCESS(rv, rv);
aBaseURI->GetOriginCharset(mapping.resolvedURI.charset);
}
for (uint32_t i = 0; i < parents.Length(); i++) {

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

@ -494,15 +494,8 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext,
if (NS_FAILED(rv)) return rv;
}
nsXPIDLCString encoding;
rv = uri->GetOriginCharset(encoding);
if (NS_FAILED(rv)) return rv;
if (encoding.IsEmpty()) {
encoding.AssignLiteral("UTF-8");
}
nsAutoString unEscapeSpec;
rv = mTextToSubURI->UnEscapeAndConvert(encoding, titleUri, unEscapeSpec);
rv = mTextToSubURI->UnEscapeAndConvert(NS_LITERAL_CSTRING("UTF-8"), titleUri, unEscapeSpec);
// unescape may fail because
// 1. file URL may be encoded in platform charset for backward compatibility
// 2. query part may not be encoded in UTF-8 (see bug 261929)

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

@ -403,8 +403,6 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
var charset = null;
if (aDocument)
charset = aDocument.characterSet;
else if (aReferrer)
charset = aReferrer.originCharset;
var fileInfo = new FileInfo(aDefaultFileName);
initFileInfo(fileInfo, aURL, charset, aDocument,
aContentType, aContentDisposition);
@ -1034,7 +1032,7 @@ function getDefaultFileName(aDefaultFileName, aURI, aDocument,
// 3) Use the actual file name, if present
var textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
.getService(Components.interfaces.nsITextToSubURI);
return validateFileName(textToSubURI.unEscapeURIForUI(url.originCharset || "UTF-8", url.fileName));
return validateFileName(textToSubURI.unEscapeURIForUI("UTF-8", url.fileName));
}
} catch (e) {
// This is something like a data: and so forth URI... no filename here.

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

@ -184,7 +184,7 @@ this.BrowserUtils = {
},
makeURIFromCPOW(aCPOWURI) {
return Services.io.newURI(aCPOWURI.spec, aCPOWURI.originCharset);
return Services.io.newURI(aCPOWURI.spec);
},
/**

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

@ -152,8 +152,6 @@ var SessionHistoryInternal = {
entry.subframe = true;
}
entry.charset = shEntry.URI.originCharset;
let cacheKey = shEntry.cacheKey;
if (cacheKey && cacheKey instanceof Ci.nsISupportsPRUint32 &&
cacheKey.data != 0) {
@ -375,7 +373,7 @@ var SessionHistoryInternal = {
var shEntry = Cc["@mozilla.org/browser/session-history-entry;1"].
createInstance(Ci.nsISHEntry);
shEntry.setURI(Utils.makeURI(entry.url, entry.charset));
shEntry.setURI(Utils.makeURI(entry.url));
shEntry.setTitle(entry.title || entry.url);
if (entry.subframe)
shEntry.setIsSubFrame(entry.subframe || false);

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

@ -145,16 +145,12 @@ static const char NEVER_ASK_FOR_OPEN_FILE_PREF[] =
static nsresult UnescapeFragment(const nsACString& aFragment, nsIURI* aURI,
nsAString& aResult)
{
// First, we need a charset
nsAutoCString originCharset;
nsresult rv = aURI->GetOriginCharset(originCharset);
NS_ENSURE_SUCCESS(rv, rv);
// Now, we need the unescaper
// We need the unescaper
nsresult rv;
nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return textToSubURI->UnEscapeURIForUI(originCharset, aFragment, aResult);
return textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"), aFragment, aResult);
}
/**

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

@ -227,15 +227,13 @@ nsMIMEInfoWin::LoadUriInternal(nsIURI * aURL)
aURL->GetAsciiSpec(urlSpec);
// Unescape non-ASCII characters in the URL
nsAutoCString urlCharset;
nsAutoString utf16Spec;
rv = aURL->GetOriginCharset(urlCharset);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(textToSubURI->UnEscapeNonAsciiURI(urlCharset, urlSpec, utf16Spec))) {
if (NS_FAILED(textToSubURI->UnEscapeNonAsciiURI(NS_LITERAL_CSTRING("UTF-8"),
urlSpec, utf16Spec))) {
CopyASCIItoUTF16(urlSpec, utf16Spec);
}