Bug 672814 - Part c: Remove the typeID variable in nsScriptLoader::ProcessScriptElement; r=bz
authorMs2ger <ms2ger@gmail.com>
Sat, 04 Aug 2012 09:43:59 +0200
changeset 101334 ad10220d809325ddaeff4a6905d923c6359f2a51
parent 101333 a246a4b88efb3806a61615c2363877de0ce6f7f2
child 101335 7bdb887fadcf7705b86cf172f90dd5649ee79432
push id23230
push userMs2ger@gmail.com
push dateSat, 04 Aug 2012 07:45:45 +0000
treeherdermozilla-central@20fc34efd733 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs672814
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 672814 - Part c: Remove the typeID variable in nsScriptLoader::ProcessScriptElement; r=bz
content/base/src/nsScriptLoader.cpp
--- a/content/base/src/nsScriptLoader.cpp
+++ b/content/base/src/nsScriptLoader.cpp
@@ -388,99 +388,79 @@ nsScriptLoader::ProcessScriptElement(nsI
   nsIScriptContext *context = globalObject->GetScriptContext();
 
   // If scripts aren't enabled in the current context, there's no
   // point in going on.
   if (!context || !context->GetScriptsEnabled()) {
     return false;
   }
 
-  PRUint32 typeID = nsIProgrammingLanguage::JAVASCRIPT;
   JSVersion version = JSVERSION_DEFAULT;
-  nsAutoString language, type, src;
   nsresult rv = NS_OK;
 
   // Check the type attribute to determine language and version.
   // If type exists, it trumps the deprecated 'language='
+  nsAutoString type;
   aElement->GetScriptType(type);
   if (!type.IsEmpty()) {
     nsContentTypeParser parser(type);
 
     nsAutoString mimeType;
     rv = parser.GetType(mimeType);
     NS_ENSURE_SUCCESS(rv, false);
 
     if (!nsContentUtils::IsJavascriptMIMEType(mimeType)) {
       return false;
     }
 
-    if (typeID != nsIProgrammingLanguage::UNKNOWN) {
-      // Get the version string, and ensure the language supports it.
-      nsAutoString versionName;
-      rv = parser.GetParameter("version", versionName);
+    // Get the version string, and ensure the language supports it.
+    nsAutoString versionName;
+    rv = parser.GetParameter("version", versionName);
 
-      if (NS_SUCCEEDED(rv)) {
-        version = nsContentUtils::ParseJavascriptVersion(versionName);
-      } else if (rv != NS_ERROR_INVALID_ARG) {
-        return false;
-      }
+    if (NS_SUCCEEDED(rv)) {
+      version = nsContentUtils::ParseJavascriptVersion(versionName);
+    } else if (rv != NS_ERROR_INVALID_ARG) {
+      return false;
     }
 
-    // Some js specifics yet to be abstracted.
-    if (typeID == nsIProgrammingLanguage::JAVASCRIPT) {
-      nsAutoString value;
-      rv = parser.GetParameter("e4x", value);
-      if (NS_FAILED(rv)) {
-        if (rv != NS_ERROR_INVALID_ARG)
-          return false;
-      } else {
-        if (value.Length() == 1 && value[0] == '1')
-          // This happens in about 2 web pages. Enable E4X no matter what JS
-          // version number was selected.  We do this by turning on the "moar
-          // XML" version bit.  This is OK even if version has
-          // JSVERSION_UNKNOWN (-1).
-          version = js::VersionSetMoarXML(version, true);
+    nsAutoString value;
+    rv = parser.GetParameter("e4x", value);
+    if (NS_SUCCEEDED(rv)) {
+      if (value.Length() == 1 && value[0] == '1') {
+        // This happens in about 2 web pages. Enable E4X no matter what JS
+        // version number was selected.  We do this by turning on the "moar
+        // XML" version bit.  This is OK even if version has
+        // JSVERSION_UNKNOWN (-1).
+        version = js::VersionSetMoarXML(version, true);
       }
+    } else if (rv != NS_ERROR_INVALID_ARG) {
+      return false;
     }
   } else {
     // no 'type=' element
     // "language" is a deprecated attribute of HTML, so we check it only for
     // HTML script elements.
     if (scriptContent->IsHTML()) {
+      nsAutoString language;
       scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language);
       if (!language.IsEmpty()) {
         // IE, Opera, etc. do not respect language version, so neither should
         // we at this late date in the browser wars saga.  Note that this change
         // affects HTML but not XUL or SVG (but note also that XUL has its own
         // code to check nsContentUtils::IsJavaScriptLanguage -- that's probably
         // a separate bug, one we may not be able to fix short of XUL2).  See
         // bug 255895 (https://bugzilla.mozilla.org/show_bug.cgi?id=255895).
         PRUint32 dummy;
         if (!nsContentUtils::IsJavaScriptLanguage(language, &dummy)) {
           return false;
         }
       }
     }
   }
 
-  // If we don't know the language, we don't know how to evaluate
-  if (typeID == nsIProgrammingLanguage::UNKNOWN) {
-    return false;
-  }
-  // If not from a chrome document (which is always trusted), we need some way 
-  // of checking the language is "safe".  Currently the only other language 
-  // impl is Python, and that is *not* safe in untrusted code - so fixing 
-  // this isn't a priority.!
-  // See also similar code in nsXULContentSink.cpp
-  if (typeID != nsIProgrammingLanguage::JAVASCRIPT &&
-      !nsContentUtils::IsChromeDoc(mDocument)) {
-    NS_WARNING("Untrusted language called from non-chrome - ignored");
-    return false;
-  }
-
   // Step 14. in the HTML5 spec
 
   nsRefPtr<nsScriptLoadRequest> request;
   if (aElement->GetScriptExternal()) {
     // external script
     nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI();
     if (!scriptURI) {
       return false;