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 | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights |
6 * reserved. | 6 * reserved. |
7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 m_nonBlocking = false; | 140 m_nonBlocking = false; |
141 } | 141 } |
142 | 142 |
143 void ScriptLoader::detachPendingScript() { | 143 void ScriptLoader::detachPendingScript() { |
144 if (!m_pendingScript) | 144 if (!m_pendingScript) |
145 return; | 145 return; |
146 m_pendingScript->dispose(); | 146 m_pendingScript->dispose(); |
147 m_pendingScript = nullptr; | 147 m_pendingScript = nullptr; |
148 } | 148 } |
149 | 149 |
150 static bool isLegacySupportedJavaScriptLanguage(const String& language) { | |
151 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only | |
152 // javascript1.1 - javascript1.3. | |
153 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. | |
154 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. | |
155 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. | |
156 // We want to accept all the values that either of these browsers accept, but | |
157 // not other values. | |
158 | |
159 // FIXME: This function is not HTML5 compliant. These belong in the MIME | |
160 // registry as "text/javascript<version>" entries. | |
161 return equalIgnoringASCIICase(language, "javascript") || | |
162 equalIgnoringASCIICase(language, "javascript1.0") || | |
163 equalIgnoringASCIICase(language, "javascript1.1") || | |
164 equalIgnoringASCIICase(language, "javascript1.2") || | |
165 equalIgnoringASCIICase(language, "javascript1.3") || | |
166 equalIgnoringASCIICase(language, "javascript1.4") || | |
167 equalIgnoringASCIICase(language, "javascript1.5") || | |
168 equalIgnoringASCIICase(language, "javascript1.6") || | |
169 equalIgnoringASCIICase(language, "javascript1.7") || | |
170 equalIgnoringASCIICase(language, "livescript") || | |
171 equalIgnoringASCIICase(language, "ecmascript") || | |
172 equalIgnoringASCIICase(language, "jscript"); | |
173 } | |
174 | |
175 void ScriptLoader::dispatchErrorEvent() { | 150 void ScriptLoader::dispatchErrorEvent() { |
176 m_element->dispatchErrorEvent(); | 151 m_element->dispatchErrorEvent(); |
177 } | 152 } |
178 | 153 |
179 void ScriptLoader::dispatchLoadEvent() { | 154 void ScriptLoader::dispatchLoadEvent() { |
180 m_element->dispatchLoadEvent(); | 155 m_element->dispatchLoadEvent(); |
181 setHaveFiredLoadEvent(true); | 156 setHaveFiredLoadEvent(true); |
182 } | 157 } |
183 | 158 |
184 bool ScriptLoader::isValidScriptTypeAndLanguage( | 159 bool ScriptLoader::isValidScriptTypeAndLanguage( |
185 const String& type, | 160 const String& type, |
186 const String& language, | 161 const String& language, |
187 LegacyTypeSupport supportLegacyTypes) { | 162 LegacyTypeSupport supportLegacyTypes) { |
188 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used | 163 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used |
189 // here to maintain backwards compatibility with existing layout tests. The | 164 // here to maintain backwards compatibility with existing layout tests. The |
190 // specific violations are: | 165 // specific violations are: |
191 // - Allowing type=javascript. type= should only support MIME types, such as | 166 // - Allowing type=javascript. type= should only support MIME types, such as |
192 // text/javascript. | 167 // text/javascript. |
193 // - Allowing a different set of languages for language= and type=. language= | 168 // - Allowing a different set of languages for language= and type=. language= |
194 // supports Javascript 1.1 and 1.4-1.6, but type= does not. | 169 // supports Javascript 1.1 and 1.4-1.6, but type= does not. |
195 if (type.isEmpty()) { | 170 if (type.isEmpty()) { |
196 return language.isEmpty() || // assume text/javascript. | 171 return language.isEmpty() || // assume text/javascript. |
197 MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + | 172 MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + |
198 language) || | 173 language) || |
199 isLegacySupportedJavaScriptLanguage(language); | 174 MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(language); |
200 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && | 175 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && |
201 type == "module") { | 176 type == "module") { |
202 return true; | 177 return true; |
203 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType( | 178 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType( |
204 type.stripWhiteSpace()) || | 179 type.stripWhiteSpace()) || |
205 (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && | 180 (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && |
206 isLegacySupportedJavaScriptLanguage(type))) { | 181 MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(type))) { |
207 return true; | 182 return true; |
208 } | 183 } |
209 | 184 |
210 return false; | 185 return false; |
211 } | 186 } |
212 | 187 |
213 bool ScriptLoader::isScriptTypeSupported( | 188 bool ScriptLoader::isScriptTypeSupported( |
214 LegacyTypeSupport supportLegacyTypes) const { | 189 LegacyTypeSupport supportLegacyTypes) const { |
215 return isValidScriptTypeAndLanguage(m_element->typeAttributeValue(), | 190 return isValidScriptTypeAndLanguage(m_element->typeAttributeValue(), |
216 m_element->languageAttributeValue(), | 191 m_element->languageAttributeValue(), |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 | 587 |
613 return true; | 588 return true; |
614 } | 589 } |
615 | 590 |
616 void ScriptLoader::logScriptMIMEType(LocalFrame* frame, | 591 void ScriptLoader::logScriptMIMEType(LocalFrame* frame, |
617 ScriptResource* resource, | 592 ScriptResource* resource, |
618 const String& mimeType) { | 593 const String& mimeType) { |
619 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)) | 594 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)) |
620 return; | 595 return; |
621 bool isText = mimeType.startsWith("text/", TextCaseASCIIInsensitive); | 596 bool isText = mimeType.startsWith("text/", TextCaseASCIIInsensitive); |
622 if (isText && isLegacySupportedJavaScriptLanguage(mimeType.substring(5))) | 597 if (isText && MIMETypeRegistry::isLegacySupportedJavaScriptLanguage( |
| 598 mimeType.substring(5))) |
623 return; | 599 return; |
624 bool isSameOrigin = | 600 bool isSameOrigin = |
625 m_element->document().getSecurityOrigin()->canRequest(resource->url()); | 601 m_element->document().getSecurityOrigin()->canRequest(resource->url()); |
626 bool isApplication = | 602 bool isApplication = |
627 !isText && mimeType.startsWith("application/", TextCaseASCIIInsensitive); | 603 !isText && mimeType.startsWith("application/", TextCaseASCIIInsensitive); |
628 | 604 |
629 UseCounter::Feature feature = | 605 UseCounter::Feature feature = |
630 isSameOrigin | 606 isSameOrigin |
631 ? (isText ? UseCounter::SameOriginTextScript | 607 ? (isText ? UseCounter::SameOriginTextScript |
632 : isApplication ? UseCounter::SameOriginApplicationScript | 608 : isApplication ? UseCounter::SameOriginApplicationScript |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 // then abort these steps at this point. The script is not executed. | 834 // then abort these steps at this point. The script is not executed. |
859 return equalIgnoringCase(eventAttribute, "onload") || | 835 return equalIgnoringCase(eventAttribute, "onload") || |
860 equalIgnoringCase(eventAttribute, "onload()"); | 836 equalIgnoringCase(eventAttribute, "onload()"); |
861 } | 837 } |
862 | 838 |
863 String ScriptLoader::scriptContent() const { | 839 String ScriptLoader::scriptContent() const { |
864 return m_element->textFromChildren(); | 840 return m_element->textFromChildren(); |
865 } | 841 } |
866 | 842 |
867 } // namespace blink | 843 } // namespace blink |
OLD | NEW |