Bug 1481176 - P1. Export GetParameterHTTP as static method. r=valentin,r=bzbarsky

nsContentTypeParser used internally a nsIMIMEHeaderParam reference, effectively limiting its use on the main thread, and as such restricting any methods handling mime type there too.

nsContentTypeParser only made use of a single method nsMIMEHeaderParamImpl::GetParameterHTTP, so we make that method static and export it via nsNetUtil.

Differential Revision: https://phabricator.services.mozilla.com/D2788
This commit is contained in:
Jean-Yves Avenard 2018-08-06 21:31:22 +02:00
parent 7845f72f27
commit 35a7076534
4 changed files with 68 additions and 14 deletions

View File

@ -80,6 +80,7 @@
#include "nsICertOverrideService.h"
#include "nsQueryObject.h"
#include "mozIThirdPartyUtil.h"
#include "../mime/nsMIMEHeaderParamImpl.h"
#include <limits>
@ -3259,5 +3260,14 @@ InScriptableRange(uint64_t val)
return val <= kJS_MAX_SAFE_UINTEGER;
}
nsresult
GetParameterHTTP(const nsACString& aHeaderVal,
const char* aParamName,
nsAString& aResult)
{
return nsMIMEHeaderParamImpl::GetParameterHTTP(
aHeaderVal, aParamName, aResult);
}
} // namespace net
} // namespace mozilla

View File

@ -991,6 +991,24 @@ bool InScriptableRange(int64_t val);
// Make sure a 64bit value can be captured by JS MAX_SAFE_INTEGER
bool InScriptableRange(uint64_t val);
/**
* Given the value of a single header field (such as
* Content-Disposition and Content-Type) and the name of a parameter
* (e.g. filename, name, charset), returns the value of the parameter.
* See nsIMIMEHeaderParam.idl for more information.
*
* @param aHeaderVal a header string to get the value of a parameter
* from.
* @param aParamName the name of a MIME header parameter (e.g.
* filename, name, charset). If empty or nullptr,
* returns the first (possibly) _unnamed_ 'parameter'.
* @return the value of <code>aParamName</code> in Unichar(UTF-16).
*/
nsresult
GetParameterHTTP(const nsACString& aHeaderVal,
const char* aParamName,
nsAString& aResult);
} // namespace net
} // namespace mozilla

View File

@ -64,7 +64,23 @@ nsMIMEHeaderParamImpl::GetParameterHTTP(const nsACString& aHeaderVal,
aFallbackCharset, aTryLocaleCharset, aLang, aResult);
}
/* static */
nsresult
nsMIMEHeaderParamImpl::GetParameterHTTP(const nsACString& aHeaderVal,
const char *aParamName,
nsAString& aResult)
{
return DoGetParameter(aHeaderVal,
aParamName,
HTTP_FIELD_ENCODING,
EmptyCString(),
false,
nullptr,
aResult);
}
// XXX : aTryLocaleCharset is not yet effective.
/* static */
nsresult
nsMIMEHeaderParamImpl::DoGetParameter(const nsACString& aHeaderVal,
const char *aParamName,
@ -355,6 +371,7 @@ nsMIMEHeaderParamImpl::GetParameterInternal(const char *aHeaderValue,
}
/* static */
nsresult
nsMIMEHeaderParamImpl::DoParameterInternal(const char *aHeaderValue,
const char *aParamName,

View File

@ -14,6 +14,16 @@ public:
NS_DECL_NSIMIMEHEADERPARAM
nsMIMEHeaderParamImpl() = default;
/**
* Identical to calling
* GetParameterHTTP(aHeaderVal, aParameterName, EmptyCString(), false, nullptr, aResult)
* See nsIMIMEHeaderParam.idl for more information.
*/
static nsresult GetParameterHTTP(const nsACString& aHeaderVal,
const char *aParamName,
nsAString &aResult);
private:
virtual ~nsMIMEHeaderParamImpl() = default;
enum ParamDecoding {
@ -21,7 +31,7 @@ private:
HTTP_FIELD_ENCODING
};
nsresult DoGetParameter(const nsACString& aHeaderVal,
static nsresult DoGetParameter(const nsACString& aHeaderVal,
const char *aParamName,
ParamDecoding aDecoding,
const nsACString& aFallbackCharset,
@ -29,13 +39,12 @@ private:
char **aLang,
nsAString& aResult);
nsresult DoParameterInternal(const char *aHeaderValue,
static nsresult DoParameterInternal(const char *aHeaderValue,
const char *aParamName,
ParamDecoding aDecoding,
char **aCharset,
char **aLang,
char **aResult);
};
#endif