Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: Source/core/dom/ScriptLoader.cpp

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/dom/ScriptLoader.h ('k') | Source/core/frame/LocalFrame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 */ 22 */
23 23
24 #include "config.h" 24 #include "config.h"
25 #include "core/dom/ScriptLoader.h" 25 #include "core/dom/ScriptLoader.h"
26 26
27 // FIXMEDART: This should move to bindings/core/dart.
28 #include "bindings/core/dart/DartController.h"
27 #include "bindings/core/v8/ScriptController.h" 29 #include "bindings/core/v8/ScriptController.h"
28 #include "bindings/core/v8/ScriptSourceCode.h" 30 #include "bindings/core/v8/ScriptSourceCode.h"
29 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
30 #include "core/SVGNames.h" 32 #include "core/SVGNames.h"
31 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
32 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" 34 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
33 #include "core/dom/ScriptLoaderClient.h" 35 #include "core/dom/ScriptLoaderClient.h"
34 #include "core/dom/ScriptRunner.h" 36 #include "core/dom/ScriptRunner.h"
35 #include "core/dom/ScriptableDocumentParser.h" 37 #include "core/dom/ScriptableDocumentParser.h"
36 #include "core/dom/Text.h" 38 #include "core/dom/Text.h"
(...skipping 25 matching lines...) Expand all
62 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) 64 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst())
63 , m_parserInserted(parserInserted) 65 , m_parserInserted(parserInserted)
64 , m_isExternalScript(false) 66 , m_isExternalScript(false)
65 , m_alreadyStarted(alreadyStarted) 67 , m_alreadyStarted(alreadyStarted)
66 , m_haveFiredLoad(false) 68 , m_haveFiredLoad(false)
67 , m_willBeParserExecuted(false) 69 , m_willBeParserExecuted(false)
68 , m_readyToBeParserExecuted(false) 70 , m_readyToBeParserExecuted(false)
69 , m_willExecuteWhenDocumentFinishedParsing(false) 71 , m_willExecuteWhenDocumentFinishedParsing(false)
70 , m_forceAsync(!parserInserted) 72 , m_forceAsync(!parserInserted)
71 , m_willExecuteInOrder(false) 73 , m_willExecuteInOrder(false)
74 , m_scriptType(ScriptJavaScript)
72 { 75 {
73 ASSERT(m_element); 76 ASSERT(m_element);
74 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite()) 77 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite())
75 m_startLineNumber = element->document().scriptableDocumentParser()->line Number(); 78 m_startLineNumber = element->document().scriptableDocumentParser()->line Number();
76 } 79 }
77 80
78 ScriptLoader::~ScriptLoader() 81 ScriptLoader::~ScriptLoader()
79 { 82 {
80 m_pendingScript.stopWatchingForLoad(this); 83 m_pendingScript.stopWatchingForLoad(this);
81 } 84 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 m_element->dispatchEvent(Event::create(EventTypeNames::error)); 155 m_element->dispatchEvent(Event::create(EventTypeNames::error));
153 } 156 }
154 157
155 void ScriptLoader::dispatchLoadEvent() 158 void ScriptLoader::dispatchLoadEvent()
156 { 159 {
157 if (ScriptLoaderClient* client = this->client()) 160 if (ScriptLoaderClient* client = this->client())
158 client->dispatchLoadEvent(); 161 client->dispatchLoadEvent();
159 setHaveFiredLoadEvent(true); 162 setHaveFiredLoadEvent(true);
160 } 163 }
161 164
162 bool ScriptLoader::isScriptTypeSupported(LegacyTypeSupport supportLegacyTypes) c onst 165 ScriptLoader::ScriptType ScriptLoader::isScriptTypeSupported(LegacyTypeSupport s upportLegacyTypes) const
163 { 166 {
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: 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:
165 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript. 168 // - Allowing type=javascript. type= should only support MIME types, such as text/javascript.
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. 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.
167 170
168 String type = client()->typeAttributeValue(); 171 String type = client()->typeAttributeValue();
169 String language = client()->languageAttributeValue(); 172 String language = client()->languageAttributeValue();
170 if (type.isEmpty() && language.isEmpty()) 173 if (type.isEmpty() && language.isEmpty())
171 return true; // Assume text/javascript. 174 return ScriptJavaScript; // Assume text/javascript.
172 if (type.isEmpty()) { 175 if (type.isEmpty()) {
173 type = "text/" + language.lower(); 176 type = "text/" + language.lower();
174 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySup portedJavaScriptLanguage(language)) 177 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type) || isLegacySup portedJavaScriptLanguage(language))
175 return true; 178 return ScriptJavaScript;
176 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type))) { 179 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSp ace()) || (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySuppo rtedJavaScriptLanguage(type))) {
177 return true; 180 return ScriptJavaScript;
181 } else if (MIMETypeRegistry::isSupportedDartMIMEType(type.stripWhiteSpace()) ) {
182 return ScriptDart;
178 } 183 }
179 184
180 return false; 185 return ScriptNone;
181 } 186 }
182 187
183 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script 188 // http://dev.w3.org/html5/spec/Overview.html#prepare-a-script
184 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes) 189 bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy TypeSupport supportLegacyTypes)
185 { 190 {
186 if (m_alreadyStarted) 191 if (m_alreadyStarted)
187 return false; 192 return false;
188 193
189 ScriptLoaderClient* client = this->client(); 194 ScriptLoaderClient* client = this->client();
190 195
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // http://www.whatwg.org/specs/web-apps/current-work/#execute-the-script-blo ck step 2.3 394 // http://www.whatwg.org/specs/web-apps/current-work/#execute-the-script-blo ck step 2.3
390 // with additional support for HTML imports. 395 // with additional support for HTML imports.
391 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncremente r(m_isExternalScript || isImportedScript ? contextDocument.get() : 0); 396 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncremente r(m_isExternalScript || isImportedScript ? contextDocument.get() : 0);
392 397
393 if (isHTMLScriptLoader(m_element)) 398 if (isHTMLScriptLoader(m_element))
394 contextDocument->pushCurrentScript(toHTMLScriptElement(m_element)); 399 contextDocument->pushCurrentScript(toHTMLScriptElement(m_element));
395 400
396 // Create a script from the script element node, using the script 401 // Create a script from the script element node, using the script
397 // block's source and the script block's type. 402 // block's source and the script block's type.
398 // Note: This is where the script is compiled and actually executed. 403 // Note: This is where the script is compiled and actually executed.
399 frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus, co mpilationFinishTime); 404 if (m_scriptType == ScriptJavaScript) {
405 frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus , compilationFinishTime);
406 } else if (m_scriptType == ScriptDart) {
407 frame->dart().evaluate(sourceCode, this);
408 } else {
409 ASSERT_NOT_REACHED();
410 }
400 411
401 if (isHTMLScriptLoader(m_element)) { 412 if (isHTMLScriptLoader(m_element)) {
402 ASSERT(contextDocument->currentScript() == m_element); 413 ASSERT(contextDocument->currentScript() == m_element);
403 contextDocument->popCurrentScript(); 414 contextDocument->popCurrentScript();
404 } 415 }
405 416
406 return true; 417 return true;
407 } 418 }
408 419
409 void ScriptLoader::execute() 420 void ScriptLoader::execute()
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 if (isHTMLScriptLoader(element)) 509 if (isHTMLScriptLoader(element))
499 return toHTMLScriptElement(element)->loader(); 510 return toHTMLScriptElement(element)->loader();
500 511
501 if (isSVGScriptLoader(element)) 512 if (isSVGScriptLoader(element))
502 return toSVGScriptElement(element)->loader(); 513 return toSVGScriptElement(element)->loader();
503 514
504 return 0; 515 return 0;
505 } 516 }
506 517
507 } // namespace blink 518 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/ScriptLoader.h ('k') | Source/core/frame/LocalFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698