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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 void ScriptLoader::detach() | 117 void ScriptLoader::detach() |
118 { | 118 { |
119 if (!m_pendingScript) | 119 if (!m_pendingScript) |
120 return; | 120 return; |
121 m_pendingScript->dispose(); | 121 m_pendingScript->dispose(); |
122 m_pendingScript = nullptr; | 122 m_pendingScript = nullptr; |
123 } | 123 } |
124 | 124 |
125 // Helper function | 125 // Helper function. Must take a lowercase language as input. |
126 static bool isLegacySupportedJavaScriptLanguage(const String& language) | 126 static bool isLegacySupportedJavaScriptLanguage(const String& language) |
127 { | 127 { |
128 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on
ly javascript1.1 - javascript1.3. | 128 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on
ly javascript1.1 - javascript1.3. |
129 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. | 129 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. |
130 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. | 130 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. |
131 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. | 131 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. |
132 // We want to accept all the values that either of these browsers accept, bu
t not other values. | 132 // We want to accept all the values that either of these browsers accept, bu
t not other values. |
133 | 133 |
134 // FIXME: This function is not HTML5 compliant. These belong in the MIME reg
istry as "text/javascript<version>" entries. | 134 // FIXME: This function is not HTML5 compliant. These belong in the MIME reg
istry as "text/javascript<version>" entries. |
135 typedef HashSet<String, CaseFoldingHash> LanguageSet; | 135 DCHECK_EQ(language, language.lower()); |
136 DEFINE_STATIC_LOCAL(LanguageSet, languages, ({ | 136 return language == "javascript" |
137 "javascript", | 137 || language == "javascript1.0" |
138 "javascript1.0", | 138 || language == "javascript1.1" |
139 "javascript1.1", | 139 || language == "javascript1.2" |
140 "javascript1.2", | 140 || language == "javascript1.3" |
141 "javascript1.3", | 141 || language == "javascript1.4" |
142 "javascript1.4", | 142 || language == "javascript1.5" |
143 "javascript1.5", | 143 || language == "javascript1.6" |
144 "javascript1.6", | 144 || language == "javascript1.7" |
145 "javascript1.7", | 145 || language == "livescript" |
146 "livescript", | 146 || language == "ecmascript" |
147 "ecmascript", | 147 || language == "jscript"; |
148 "jscript", | |
149 })); | |
150 | |
151 return languages.contains(language); | |
152 } | 148 } |
153 | 149 |
154 void ScriptLoader::dispatchErrorEvent() | 150 void ScriptLoader::dispatchErrorEvent() |
155 { | 151 { |
156 m_element->dispatchEvent(Event::create(EventTypeNames::error)); | 152 m_element->dispatchEvent(Event::create(EventTypeNames::error)); |
157 } | 153 } |
158 | 154 |
159 void ScriptLoader::dispatchLoadEvent() | 155 void ScriptLoader::dispatchLoadEvent() |
160 { | 156 { |
161 if (ScriptLoaderClient* client = this->client()) | 157 if (ScriptLoaderClient* client = this->client()) |
162 client->dispatchLoadEvent(); | 158 client->dispatchLoadEvent(); |
163 setHaveFiredLoadEvent(true); | 159 setHaveFiredLoadEvent(true); |
164 } | 160 } |
165 | 161 |
166 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c
onst | 162 bool ScriptLoader::isValidScriptTypeAndLanguage(const String& type, const String
& language, LegacyTypeSupport supportLegacyTypes) |
167 { | 163 { |
168 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us
ed here to maintain backwards compatibility with existing layout tests. The spec
ific violations are: | 164 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is us
ed here to maintain backwards compatibility with existing layout tests. The spec
ific violations are: |
169 // - Allowing type=javascript. type= should only support MIME types, such as
text/javascript. | 165 // - Allowing type=javascript. type= should only support MIME types, such as
text/javascript. |
170 // - Allowing a different set of languages for language= and type=. language
= supports Javascript 1.1 and 1.4-1.6, but type= does not. | 166 // - Allowing a different set of languages for language= and type=. language
= supports Javascript 1.1 and 1.4-1.6, but type= does not. |
171 | |
172 String type = client()->typeAttributeValue(); | |
173 String language = client()->languageAttributeValue(); | |
174 if (type.isEmpty() && language.isEmpty()) | |
175 return true; // Assume text/javascript. | |
176 if (type.isEmpty()) { | 167 if (type.isEmpty()) { |
177 type = "text/" + language.lower(); | 168 String lowerLanguage = language.lower(); |
178 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySup
portedJavaScriptLanguage(language)) | 169 return language.isEmpty() // assume text/javascript. |
179 return true; | 170 || MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + lowerLa
nguage) |
| 171 || isLegacySupportedJavaScriptLanguage(lowerLanguage); |
180 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module
") { | 172 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && type == "module
") { |
181 return true; | 173 return true; |
182 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp
ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo
rtedJavaScriptLanguage(type))) { | 174 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp
ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo
rtedJavaScriptLanguage(type.lower()))) { |
183 return true; | 175 return true; |
184 } | 176 } |
185 | 177 |
186 return false; | 178 return false; |
187 } | 179 } |
188 | 180 |
| 181 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c
onst |
| 182 { |
| 183 return isValidScriptTypeAndLanguage(client()->typeAttributeValue(), client()
->languageAttributeValue(), supportLegacyTypes); |
| 184 } |
| 185 |
189 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script | 186 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script |
190 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy
TypeSupport supportLegacyTypes) | 187 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy
TypeSupport supportLegacyTypes) |
191 { | 188 { |
192 if (m_alreadyStarted) | 189 if (m_alreadyStarted) |
193 return false; | 190 return false; |
194 | 191 |
195 ScriptLoaderClient* client = this->client(); | 192 ScriptLoaderClient* client = this->client(); |
196 | 193 |
197 bool wasParserInserted; | 194 bool wasParserInserted; |
198 if (m_parserInserted) { | 195 if (m_parserInserted) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 336 } |
340 | 337 |
341 bool isSVGScriptLoader(Element* element) | 338 bool isSVGScriptLoader(Element* element) |
342 { | 339 { |
343 DCHECK(element); | 340 DCHECK(element); |
344 return isSVGScriptElement(*element); | 341 return isSVGScriptElement(*element); |
345 } | 342 } |
346 | 343 |
347 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame
, String mimetype) | 344 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame
, String mimetype) |
348 { | 345 { |
349 bool text = mimetype.lower().startsWith("text/"); | 346 String lowerMimetype = mimetype.lower(); |
350 bool application = mimetype.lower().startsWith("application/"); | 347 bool text = lowerMimetype.startsWith("text/"); |
351 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype)
|| (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5))); | 348 bool application = lowerMimetype.startsWith("application/"); |
| 349 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(lowerMimet
ype) || (text && isLegacySupportedJavaScriptLanguage(lowerMimetype.substring(5))
); |
352 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re
source->url()); | 350 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re
source->url()); |
353 if (expectedJs) { | 351 if (expectedJs) { |
354 return; | 352 return; |
355 } | 353 } |
356 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex
tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa
meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ?
UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript); | 354 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex
tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa
meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ?
UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript); |
357 UseCounter::count(frame, feature); | 355 UseCounter::count(frame, feature); |
358 } | 356 } |
359 | 357 |
360 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) | 358 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) |
361 { | 359 { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 if (isHTMLScriptLoader(element)) | 543 if (isHTMLScriptLoader(element)) |
546 return toHTMLScriptElement(element)->loader(); | 544 return toHTMLScriptElement(element)->loader(); |
547 | 545 |
548 if (isSVGScriptLoader(element)) | 546 if (isSVGScriptLoader(element)) |
549 return toSVGScriptElement(element)->loader(); | 547 return toSVGScriptElement(element)->loader(); |
550 | 548 |
551 return 0; | 549 return 0; |
552 } | 550 } |
553 | 551 |
554 } // namespace blink | 552 } // namespace blink |
OLD | NEW |