Bug 1210302 - Part 1: Rename nsINetUtil.parseContentType() to parseResponseContentType(); r=mcmanus

This commit is contained in:
Ehsan Akhgari 2015-10-01 12:50:13 -04:00
parent 02aed11362
commit 59d8bdd7e5
5 changed files with 38 additions and 38 deletions

View File

@ -507,7 +507,7 @@ this.AppsUtils = {
let hadCharset = { };
let charset = { };
let netutil = Cc["@mozilla.org/network/util;1"].getService(Ci.nsINetUtil);
let contentType = netutil.parseContentType(aContentType, charset, hadCharset);
let contentType = netutil.parseResponseContentType(aContentType, charset, hadCharset);
if (aInstallOrigin != aWebappOrigin &&
!(contentType == "application/x-web-app-manifest+json" ||
contentType == "application/manifest+json")) {

View File

@ -11,7 +11,7 @@ interface nsIPrefBranch;
/**
* nsINetUtil provides various network-related utility methods.
*/
[scriptable, uuid(885d6940-1001-46e7-92ec-d494a78d7784)]
[scriptable, uuid(ff0b3233-7ec5-4bf4-830f-6b2edaa53661)]
interface nsINetUtil : nsISupports
{
/**
@ -24,9 +24,9 @@ interface nsINetUtil : nsISupports
* @param [out] aHadCharset whether a charset was explicitly specified.
* @return the MIME type specified in the header, in lower-case.
*/
AUTF8String parseContentType(in AUTF8String aTypeHeader,
out AUTF8String aCharset,
out boolean aHadCharset);
AUTF8String parseResponseContentType(in AUTF8String aTypeHeader,
out AUTF8String aCharset,
out boolean aHadCharset);
/**
* Test whether the given URI's handler has the given protocol flags.

View File

@ -1507,10 +1507,10 @@ nsIOService::Observe(nsISupports *subject,
// nsINetUtil interface
NS_IMETHODIMP
nsIOService::ParseContentType(const nsACString &aTypeHeader,
nsACString &aCharset,
bool *aHadCharset,
nsACString &aContentType)
nsIOService::ParseResponseContentType(const nsACString &aTypeHeader,
nsACString &aCharset,
bool *aHadCharset,
nsACString &aContentType)
{
net_ParseContentType(aTypeHeader, aContentType, aCharset, aHadCharset);
return NS_OK;

View File

@ -919,8 +919,8 @@ NS_ParseContentType(const nsACString &rawContentType,
NS_ENSURE_SUCCESS(rv, rv);
nsCString charset;
bool hadCharset;
rv = util->ParseContentType(rawContentType, charset, &hadCharset,
contentType);
rv = util->ParseResponseContentType(rawContentType, charset, &hadCharset,
contentType);
if (NS_SUCCEEDED(rv) && hadCharset)
contentCharset = charset;
return rv;

View File

@ -25,95 +25,95 @@ function run_test() {
var netutil = Components.classes["@mozilla.org/network/util;1"]
.getService(Components.interfaces.nsINetUtil);
type = netutil.parseContentType("text/html", charset, hadCharset);
type = netutil.parseResponseContentType("text/html", charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType("TEXT/HTML", charset, hadCharset);
type = netutil.parseResponseContentType("TEXT/HTML", charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType("text/html, text/html", charset, hadCharset);
type = netutil.parseResponseContentType("text/html, text/html", charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType("text/html, text/plain",
type = netutil.parseResponseContentType("text/html, text/plain",
charset, hadCharset);
check("text/plain", "", false);
type = netutil.parseContentType('text/html, ', charset, hadCharset);
type = netutil.parseResponseContentType('text/html, ', charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType('text/html, */*', charset, hadCharset);
type = netutil.parseResponseContentType('text/html, */*', charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType('text/html, foo', charset, hadCharset);
type = netutil.parseResponseContentType('text/html, foo', charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType("text/html; charset=ISO-8859-1",
type = netutil.parseResponseContentType("text/html; charset=ISO-8859-1",
charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType('text/html; charset="ISO-8859-1"',
type = netutil.parseResponseContentType('text/html; charset="ISO-8859-1"',
charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType("text/html; charset='ISO-8859-1'",
type = netutil.parseResponseContentType("text/html; charset='ISO-8859-1'",
charset, hadCharset);
check("text/html", "'ISO-8859-1'", true);
type = netutil.parseContentType("text/html; charset=\"ISO-8859-1\", text/html",
type = netutil.parseResponseContentType("text/html; charset=\"ISO-8859-1\", text/html",
charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType("text/html; charset=\"ISO-8859-1\", text/html; charset=UTF8",
type = netutil.parseResponseContentType("text/html; charset=\"ISO-8859-1\", text/html; charset=UTF8",
charset, hadCharset);
check("text/html", "UTF8", true);
type = netutil.parseContentType("text/html; charset=ISO-8859-1, TEXT/HTML", charset, hadCharset);
type = netutil.parseResponseContentType("text/html; charset=ISO-8859-1, TEXT/HTML", charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType("text/html; charset=ISO-8859-1, TEXT/plain", charset, hadCharset);
type = netutil.parseResponseContentType("text/html; charset=ISO-8859-1, TEXT/plain", charset, hadCharset);
check("text/plain", "", true);
type = netutil.parseContentType("text/plain, TEXT/HTML; charset=ISO-8859-1, text/html, TEXT/HTML", charset, hadCharset);
type = netutil.parseResponseContentType("text/plain, TEXT/HTML; charset=ISO-8859-1, text/html, TEXT/HTML", charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset="ISO-8859-1"; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset="ISO-8859-1"; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset);
check("text/html", "ISO-8859-1", true);
type = netutil.parseContentType("text/plain; param= , text/html", charset, hadCharset);
type = netutil.parseResponseContentType("text/plain; param= , text/html", charset, hadCharset);
check("text/html", "", false);
type = netutil.parseContentType('text/plain; param=", text/html"', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain; param=", text/html"', charset, hadCharset);
check("text/plain", "", false);
type = netutil.parseContentType('text/plain; param=", \\" , text/html"', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain; param=", \\" , text/html"', charset, hadCharset);
check("text/plain", "", false);
type = netutil.parseContentType('text/plain; param=", \\" , text/html , "', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain; param=", \\" , text/html , "', charset, hadCharset);
check("text/plain", "", false);
type = netutil.parseContentType('text/plain param=", \\" , text/html , "', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain param=", \\" , text/html , "', charset, hadCharset);
check("text/plain", "", false);
type = netutil.parseContentType('text/plain charset=UTF8', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain charset=UTF8', charset, hadCharset);
check("text/plain", "", false);
type = netutil.parseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; ; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; ; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset);
check("text/html", "", false);
// Bug 562915 - correctness: "\x" is "x"
type = netutil.parseContentType('text/plain; charset="UTF\\-8"', charset, hadCharset);
type = netutil.parseResponseContentType('text/plain; charset="UTF\\-8"', charset, hadCharset);
check("text/plain", "UTF-8", true);
// Bug 700589
// check that single quote doesn't confuse parsing of subsequent parameters
type = netutil.parseContentType("text/plain; x='; charset=\"UTF-8\"", charset, hadCharset);
type = netutil.parseResponseContentType("text/plain; x='; charset=\"UTF-8\"", charset, hadCharset);
check("text/plain", "UTF-8", true);
// check that single quotes do not get removed from extracted charset
type = netutil.parseContentType("text/plain; charset='UTF-8'", charset, hadCharset);
type = netutil.parseResponseContentType("text/plain; charset='UTF-8'", charset, hadCharset);
check("text/plain", "'UTF-8'", true);
}