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

Side by Side Diff: Source/core/xml/parser/XMLDocumentParser.cpp

Issue 18261015: Rename ScriptElement to ScriptLoader (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGScriptElement.cpp ('k') | no next file » | 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) 2000 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2000 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2008 Holger Hans Peter Freyther 7 * Copyright (C) 2008 Holger Hans Peter Freyther
8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 27 matching lines...) Expand all
38 #include "HTMLNames.h" 38 #include "HTMLNames.h"
39 #include "XMLNSNames.h" 39 #include "XMLNSNames.h"
40 #include "bindings/v8/ScriptSourceCode.h" 40 #include "bindings/v8/ScriptSourceCode.h"
41 #include "core/dom/CDATASection.h" 41 #include "core/dom/CDATASection.h"
42 #include "core/dom/Comment.h" 42 #include "core/dom/Comment.h"
43 #include "core/dom/Document.h" 43 #include "core/dom/Document.h"
44 #include "core/dom/DocumentFragment.h" 44 #include "core/dom/DocumentFragment.h"
45 #include "core/dom/DocumentType.h" 45 #include "core/dom/DocumentType.h"
46 #include "core/dom/ExceptionCodePlaceholder.h" 46 #include "core/dom/ExceptionCodePlaceholder.h"
47 #include "core/dom/ProcessingInstruction.h" 47 #include "core/dom/ProcessingInstruction.h"
48 #include "core/dom/ScriptElement.h" 48 #include "core/dom/ScriptLoader.h"
49 #include "core/dom/TransformSource.h" 49 #include "core/dom/TransformSource.h"
50 #include "core/html/HTMLHtmlElement.h" 50 #include "core/html/HTMLHtmlElement.h"
51 #include "core/html/HTMLTemplateElement.h" 51 #include "core/html/HTMLTemplateElement.h"
52 #include "core/html/parser/HTMLEntityParser.h" 52 #include "core/html/parser/HTMLEntityParser.h"
53 #include "core/loader/FrameLoader.h" 53 #include "core/loader/FrameLoader.h"
54 #include "core/loader/ImageLoader.h" 54 #include "core/loader/ImageLoader.h"
55 #include "core/loader/TextResourceDecoder.h" 55 #include "core/loader/TextResourceDecoder.h"
56 #include "core/loader/cache/CachedResourceLoader.h" 56 #include "core/loader/cache/CachedResourceLoader.h"
57 #include "core/loader/cache/CachedScript.h" 57 #include "core/loader/cache/CachedScript.h"
58 #include "core/page/Frame.h" 58 #include "core/page/Frame.h"
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 ScriptSourceCode sourceCode(m_pendingScript.get()); 437 ScriptSourceCode sourceCode(m_pendingScript.get());
438 bool errorOccurred = m_pendingScript->errorOccurred(); 438 bool errorOccurred = m_pendingScript->errorOccurred();
439 bool wasCanceled = m_pendingScript->wasCanceled(); 439 bool wasCanceled = m_pendingScript->wasCanceled();
440 440
441 m_pendingScript->removeClient(this); 441 m_pendingScript->removeClient(this);
442 m_pendingScript = 0; 442 m_pendingScript = 0;
443 443
444 RefPtr<Element> e = m_scriptElement; 444 RefPtr<Element> e = m_scriptElement;
445 m_scriptElement = 0; 445 m_scriptElement = 0;
446 446
447 ScriptElement* scriptElement = toScriptElementIfPossible(e.get()); 447 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e.get());
448 ASSERT(scriptElement); 448 ASSERT(scriptLoader);
449 449
450 // JavaScript can detach this parser, make sure it's kept alive even if deta ched. 450 // JavaScript can detach this parser, make sure it's kept alive even if deta ched.
451 RefPtr<XMLDocumentParser> protect(this); 451 RefPtr<XMLDocumentParser> protect(this);
452 452
453 if (errorOccurred) 453 if (errorOccurred)
454 scriptElement->dispatchErrorEvent(); 454 scriptLoader->dispatchErrorEvent();
455 else if (!wasCanceled) { 455 else if (!wasCanceled) {
456 scriptElement->executeScript(sourceCode); 456 scriptLoader->executeScript(sourceCode);
457 scriptElement->dispatchLoadEvent(); 457 scriptLoader->dispatchLoadEvent();
458 } 458 }
459 459
460 m_scriptElement = 0; 460 m_scriptElement = 0;
461 461
462 if (!isDetached() && !m_requestingScript) 462 if (!isDetached() && !m_requestingScript)
463 resumeParsing(); 463 resumeParsing();
464 } 464 }
465 465
466 bool XMLDocumentParser::isWaitingForScripts() const 466 bool XMLDocumentParser::isWaitingForScripts() const
467 { 467 {
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 948
949 handleElementAttributes(prefixedAttributes, libxmlAttributes, nb_attributes, ec); 949 handleElementAttributes(prefixedAttributes, libxmlAttributes, nb_attributes, ec);
950 setAttributes(newElement.get(), prefixedAttributes, parserContentPolicy()); 950 setAttributes(newElement.get(), prefixedAttributes, parserContentPolicy());
951 if (ec) { 951 if (ec) {
952 stopParsing(); 952 stopParsing();
953 return; 953 return;
954 } 954 }
955 955
956 newElement->beginParsingChildren(); 956 newElement->beginParsingChildren();
957 957
958 ScriptElement* scriptElement = toScriptElementIfPossible(newElement.get()); 958 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(newElement.get());
959 if (scriptElement) 959 if (scriptLoader)
960 m_scriptStartPosition = textPosition(); 960 m_scriptStartPosition = textPosition();
961 961
962 m_currentNode->parserAppendChild(newElement.get()); 962 m_currentNode->parserAppendChild(newElement.get());
963 963
964 const ContainerNode* currentNode = m_currentNode; 964 const ContainerNode* currentNode = m_currentNode;
965 if (newElement->hasTagName(HTMLNames::templateTag)) 965 if (newElement->hasTagName(HTMLNames::templateTag))
966 pushCurrentNode(toHTMLTemplateElement(newElement.get())->content()); 966 pushCurrentNode(toHTMLTemplateElement(newElement.get())->content());
967 else 967 else
968 pushCurrentNode(newElement.get()); 968 pushCurrentNode(newElement.get());
969 969
(...skipping 19 matching lines...) Expand all
989 989
990 // JavaScript can detach the parser. Make sure this is not released 990 // JavaScript can detach the parser. Make sure this is not released
991 // before the end of this method. 991 // before the end of this method.
992 RefPtr<XMLDocumentParser> protect(this); 992 RefPtr<XMLDocumentParser> protect(this);
993 993
994 exitText(); 994 exitText();
995 995
996 RefPtr<ContainerNode> n = m_currentNode; 996 RefPtr<ContainerNode> n = m_currentNode;
997 n->finishParsingChildren(); 997 n->finishParsingChildren();
998 998
999 if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptElementIfPossible(toElement(n.get()))) { 999 if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptLoaderIfPossible(toElement(n.get()))) {
1000 popCurrentNode(); 1000 popCurrentNode();
1001 n->remove(IGNORE_EXCEPTION); 1001 n->remove(IGNORE_EXCEPTION);
1002 return; 1002 return;
1003 } 1003 }
1004 1004
1005 if (!n->isElementNode() || !m_view) { 1005 if (!n->isElementNode() || !m_view) {
1006 popCurrentNode(); 1006 popCurrentNode();
1007 return; 1007 return;
1008 } 1008 }
1009 1009
1010 Element* element = toElement(n.get()); 1010 Element* element = toElement(n.get());
1011 1011
1012 // The element's parent may have already been removed from document. 1012 // The element's parent may have already been removed from document.
1013 // Parsing continues in this case, but scripts aren't executed. 1013 // Parsing continues in this case, but scripts aren't executed.
1014 if (!element->inDocument()) { 1014 if (!element->inDocument()) {
1015 popCurrentNode(); 1015 popCurrentNode();
1016 return; 1016 return;
1017 } 1017 }
1018 1018
1019 ScriptElement* scriptElement = toScriptElementIfPossible(element); 1019 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element);
1020 if (!scriptElement) { 1020 if (!scriptLoader) {
1021 popCurrentNode(); 1021 popCurrentNode();
1022 return; 1022 return;
1023 } 1023 }
1024 1024
1025 // Don't load external scripts for standalone documents (for now). 1025 // Don't load external scripts for standalone documents (for now).
1026 ASSERT(!m_pendingScript); 1026 ASSERT(!m_pendingScript);
1027 m_requestingScript = true; 1027 m_requestingScript = true;
1028 1028
1029 if (scriptElement->prepareScript(m_scriptStartPosition, ScriptElement::Allow LegacyTypeInTypeAttribute)) { 1029 if (scriptLoader->prepareScript(m_scriptStartPosition, ScriptLoader::AllowLe gacyTypeInTypeAttribute)) {
1030 // FIXME: Script execution should be shared between 1030 // FIXME: Script execution should be shared between
1031 // the libxml2 and Qt XMLDocumentParser implementations. 1031 // the libxml2 and Qt XMLDocumentParser implementations.
1032 1032
1033 if (scriptElement->readyToBeParserExecuted()) 1033 if (scriptLoader->readyToBeParserExecuted()) {
1034 scriptElement->executeScript(ScriptSourceCode(scriptElement->scriptC ontent(), document()->url(), m_scriptStartPosition)); 1034 scriptLoader->executeScript(ScriptSourceCode(scriptLoader->scriptCon tent(), document()->url(), m_scriptStartPosition));
1035 else if (scriptElement->willBeParserExecuted()) { 1035 } else if (scriptLoader->willBeParserExecuted()) {
1036 m_pendingScript = scriptElement->cachedScript(); 1036 m_pendingScript = scriptLoader->cachedScript();
1037 m_scriptElement = element; 1037 m_scriptElement = element;
1038 m_pendingScript->addClient(this); 1038 m_pendingScript->addClient(this);
1039 1039
1040 // m_pendingScript will be 0 if script was already loaded and addCli ent() executed it. 1040 // m_pendingScript will be 0 if script was already loaded and addCli ent() executed it.
1041 if (m_pendingScript) 1041 if (m_pendingScript)
1042 pauseParsing(); 1042 pauseParsing();
1043 } else 1043 } else {
1044 m_scriptElement = 0; 1044 m_scriptElement = 0;
1045 }
1045 1046
1046 // JavaScript may have detached the parser 1047 // JavaScript may have detached the parser
1047 if (isDetached()) 1048 if (isDetached())
1048 return; 1049 return;
1049 } 1050 }
1050 m_requestingScript = false; 1051 m_requestingScript = false;
1051 popCurrentNode(); 1052 popCurrentNode();
1052 } 1053 }
1053 1054
1054 void XMLDocumentParser::characters(const xmlChar* chars, int length) 1055 void XMLDocumentParser::characters(const xmlChar* chars, int length)
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 sax.initialized = XML_SAX2_MAGIC; 1595 sax.initialized = XML_SAX2_MAGIC;
1595 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax, &state); 1596 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax, &state);
1596 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; 1597 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />";
1597 parseChunk(parser->context(), parseString); 1598 parseChunk(parser->context(), parseString);
1598 finishParsing(parser->context()); 1599 finishParsing(parser->context());
1599 attrsOK = state.gotAttributes; 1600 attrsOK = state.gotAttributes;
1600 return state.attributes; 1601 return state.attributes;
1601 } 1602 }
1602 1603
1603 } // namespace WebCore 1604 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/svg/SVGScriptElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698