Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. |
| 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 } | 114 } |
| 115 | 115 |
| 116 void ScriptLoader::detach() | 116 void ScriptLoader::detach() |
| 117 { | 117 { |
| 118 if (!m_pendingScript) | 118 if (!m_pendingScript) |
| 119 return; | 119 return; |
| 120 m_pendingScript->dispose(); | 120 m_pendingScript->dispose(); |
| 121 m_pendingScript = nullptr; | 121 m_pendingScript = nullptr; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Helper function | 124 // Helper function. Must take a lowercase language as input. |
| 125 static bool isLegacySupportedJavaScriptLanguage(const String& language) | 125 static bool isLegacySupportedJavaScriptLanguage(const String& language) |
| 126 { | 126 { |
| 127 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3. | 127 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3. |
| 128 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. | 128 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. |
| 129 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. | 129 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. |
| 130 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. | 130 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. |
| 131 // We want to accept all the values that either of these browsers accept, bu t not other values. | 131 // We want to accept all the values that either of these browsers accept, bu t not other values. |
| 132 | 132 |
| 133 // FIXME: This function is not HTML5 compliant. These belong in the MIME reg istry as "text/javascript<version>" entries. | 133 // FIXME: This function is not HTML5 compliant. These belong in the MIME reg istry as "text/javascript<version>" entries. |
| 134 typedef HashSet<String, CaseFoldingHash> LanguageSet; | 134 DCHECK_EQ(language, language.lower()); |
|
Yoav Weiss
2016/09/05 15:06:25
Why the change here? I don't expect this function
Charlie Harrison
2016/09/05 17:15:06
I changed this so that the function could be calle
| |
| 135 DEFINE_STATIC_LOCAL(LanguageSet, languages, ({ | 135 return language == "javascript" |
| 136 "javascript", | 136 || language == "javascript1.0" |
| 137 "javascript1.0", | 137 || language == "javascript1.1" |
| 138 "javascript1.1", | 138 || language == "javascript1.2" |
| 139 "javascript1.2", | 139 || language == "javascript1.3" |
| 140 "javascript1.3", | 140 || language == "javascript1.4" |
| 141 "javascript1.4", | 141 || language == "javascript1.5" |
| 142 "javascript1.5", | 142 || language == "javascript1.6" |
| 143 "javascript1.6", | 143 || language == "javascript1.7" |
| 144 "javascript1.7", | 144 || language == "livescript" |
| 145 "livescript", | 145 || language == "ecmascript" |
| 146 "ecmascript", | 146 || language == "jscript"; |
| 147 "jscript", | |
| 148 })); | |
| 149 | |
| 150 return languages.contains(language); | |
| 151 } | 147 } |
| 152 | 148 |
| 153 void ScriptLoader::dispatchErrorEvent() | 149 void ScriptLoader::dispatchErrorEvent() |
| 154 { | 150 { |
| 155 m_element->dispatchEvent(Event::create(EventTypeNames::error)); | 151 m_element->dispatchEvent(Event::create(EventTypeNames::error)); |
| 156 } | 152 } |
| 157 | 153 |
| 158 void ScriptLoader::dispatchLoadEvent() | 154 void ScriptLoader::dispatchLoadEvent() |
| 159 { | 155 { |
| 160 if (ScriptLoaderClient* client = this->client()) | 156 if (ScriptLoaderClient* client = this->client()) |
| 161 client->dispatchLoadEvent(); | 157 client->dispatchLoadEvent(); |
| 162 setHaveFiredLoadEvent(true); | 158 setHaveFiredLoadEvent(true); |
| 163 } | 159 } |
| 164 | 160 |
| 165 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst | 161 bool ScriptLoader::isValidScriptTypeAndLanguage(const String& type, const String & language, LegacyTypeSupport supportLegacyTypes) |
| 166 { | 162 { |
| 167 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us ed here to maintain backwards compatibility with existing layout tests. The spec ific violations are: | 163 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us ed here to maintain backwards compatibility with existing layout tests. The spec ific violations are: |
| 168 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript. | 164 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript. |
| 169 // - Allowing a different set of languages for language= and type=. language = supports Javascript 1.1 and 1.4-1.6, but type= does not. | 165 // - Allowing a different set of languages for language= and type=. language = supports Javascript 1.1 and 1.4-1.6, but type= does not. |
| 170 | |
| 171 String type = client()->typeAttributeValue(); | |
| 172 String language = client()->languageAttributeValue(); | |
| 173 if (type.isEmpty() && language.isEmpty()) | |
| 174 return true; // Assume text/javascript. | |
| 175 if (type.isEmpty()) { | 166 if (type.isEmpty()) { |
| 176 type = "text/" + language.lower(); | 167 String lowerLanguage = language.lower(); |
| 177 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySup portedJavaScriptLanguage(language)) | 168 return language.isEmpty() // assume text/javascript. |
| 178 return true; | 169 || MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + lowerLa nguage) |
| 170 || isLegacySupportedJavaScriptLanguage(lowerLanguage); | |
| 179 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module ") { | 171 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module ") { |
| 180 return true; | 172 return true; |
| 181 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type))) { | 173 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type.lower()))) { |
| 182 return true; | 174 return true; |
| 183 } | 175 } |
| 184 | 176 |
| 185 return false; | 177 return false; |
| 186 } | 178 } |
| 187 | 179 |
| 180 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst | |
| 181 { | |
| 182 return isValidScriptTypeAndLanguage(client()->typeAttributeValue(), client() ->languageAttributeValue(), supportLegacyTypes); | |
| 183 } | |
| 184 | |
| 188 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script | 185 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script |
| 189 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes) | 186 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes) |
| 190 { | 187 { |
| 191 if (m_alreadyStarted) | 188 if (m_alreadyStarted) |
| 192 return false; | 189 return false; |
| 193 | 190 |
| 194 ScriptLoaderClient* client = this->client(); | 191 ScriptLoaderClient* client = this->client(); |
| 195 | 192 |
| 196 bool wasParserInserted; | 193 bool wasParserInserted; |
| 197 if (m_parserInserted) { | 194 if (m_parserInserted) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 } | 334 } |
| 338 | 335 |
| 339 bool isSVGScriptLoader(Element* element) | 336 bool isSVGScriptLoader(Element* element) |
| 340 { | 337 { |
| 341 DCHECK(element); | 338 DCHECK(element); |
| 342 return isSVGScriptElement(*element); | 339 return isSVGScriptElement(*element); |
| 343 } | 340 } |
| 344 | 341 |
| 345 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype) | 342 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype) |
| 346 { | 343 { |
| 347 bool text = mimetype.lower().startsWith("text/"); | 344 String lowerMimetype = mimetype.lower(); |
| 348 bool application = mimetype.lower().startsWith("application/"); | 345 bool text = lowerMimetype.startsWith("text/"); |
| 349 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype) || (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5))); | 346 bool application = lowerMimetype.startsWith("application/"); |
| 347 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(lowerMimet ype) || (text && isLegacySupportedJavaScriptLanguage(lowerMimetype.substring(5)) ); | |
| 350 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re source->url()); | 348 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re source->url()); |
| 351 if (expectedJs) { | 349 if (expectedJs) { |
| 352 return; | 350 return; |
| 353 } | 351 } |
| 354 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript); | 352 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript); |
| 355 UseCounter::count(frame, feature); | 353 UseCounter::count(frame, feature); |
| 356 } | 354 } |
| 357 | 355 |
| 358 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) | 356 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) |
| 359 { | 357 { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 if (isHTMLScriptLoader(element)) | 526 if (isHTMLScriptLoader(element)) |
| 529 return toHTMLScriptElement(element)->loader(); | 527 return toHTMLScriptElement(element)->loader(); |
| 530 | 528 |
| 531 if (isSVGScriptLoader(element)) | 529 if (isSVGScriptLoader(element)) |
| 532 return toSVGScriptElement(element)->loader(); | 530 return toSVGScriptElement(element)->loader(); |
| 533 | 531 |
| 534 return 0; | 532 return 0; |
| 535 } | 533 } |
| 536 | 534 |
| 537 } // namespace blink | 535 } // namespace blink |
| OLD | NEW |