Bug 672814 - Part b: Introduce nsContentUtils::IsJavascriptMIMEType; r=bz

This commit is contained in:
Ms2ger 2012-08-04 09:43:59 +02:00
Родитель 78e3c35a3c
Коммит f37eda9fb5
3 изменённых файлов: 24 добавлений и 46 удалений

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

@ -2025,6 +2025,27 @@ public:
*/
static JSVersion ParseJavascriptVersion(const nsAString& aVersionStr);
static bool IsJavascriptMIMEType(const nsAString& aMIMEType)
{
// Table ordered from most to least likely JS MIME types.
static const char* jsTypes[] = {
"text/javascript",
"text/ecmascript",
"application/javascript",
"application/ecmascript",
"application/x-javascript",
nullptr
};
for (PRUint32 i = 0; jsTypes[i]; ++i) {
if (aMIMEType.LowerCaseEqualsASCII(jsTypes[i])) {
return true;
}
}
return false;
}
static void SplitMimeType(const nsAString& aValue, nsString& aType,
nsString& aParams);

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

@ -408,29 +408,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
rv = parser.GetType(mimeType);
NS_ENSURE_SUCCESS(rv, false);
// Javascript keeps the fast path, optimized for most-likely type
// Table ordered from most to least likely JS MIME types.
// See bug 62485, feel free to add <script type="..."> survey data to it,
// or to a new bug once 62485 is closed.
static const char *jsTypes[] = {
"text/javascript",
"text/ecmascript",
"application/javascript",
"application/ecmascript",
"application/x-javascript",
nullptr
};
bool isJavaScript = false;
for (PRInt32 i = 0; jsTypes[i]; i++) {
if (mimeType.LowerCaseEqualsASCII(jsTypes[i])) {
isJavaScript = true;
break;
}
}
if (!isJavaScript) {
typeID = nsIProgrammingLanguage::UNKNOWN;
if (!nsContentUtils::IsJavascriptMIMEType(mimeType)) {
return false;
}
if (typeID != nsIProgrammingLanguage::UNKNOWN) {

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

@ -865,29 +865,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
NS_ENSURE_SUCCESS(rv, rv);
}
// Javascript keeps the fast path, optimized for most-likely type
// Table ordered from most to least likely JS MIME types. For .xul
// files that we host, the likeliest type is application/x-javascript.
// See bug 62485, feel free to add <script type="..."> survey data to it,
// or to a new bug once 62485 is closed.
static const char *jsTypes[] = {
"application/x-javascript",
"text/javascript",
"text/ecmascript",
"application/javascript",
"application/ecmascript",
nullptr
};
bool isJavaScript = false;
for (PRInt32 i = 0; jsTypes[i]; i++) {
if (mimeType.LowerCaseEqualsASCII(jsTypes[i])) {
isJavaScript = true;
break;
}
}
if (isJavaScript) {
if (nsContentUtils::IsJavascriptMIMEType(mimeType)) {
langID = nsIProgrammingLanguage::JAVASCRIPT;
version = JSVERSION_LATEST;
} else {