Changeset 35744 in webkit
- Timestamp:
- Aug 13, 2008 7:22:35 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r35743 r35744 1 2008-08-13 Nikolas Zimmermann <zimmermann@kde.org> 2 3 Reviewed by Eric. 4 5 Fixes: https://bugs.webkit.org/show_bug.cgi?id=20372 6 7 Refactor HTMLScriptElement's code into a common base class: ScriptElement. 8 SVGScriptElement will be converted to use ScriptElement in a follow-up patch. 9 10 This resolves code duplications and allows us to completly replace the old 11 SVGScriptElement (which doesn't use CachedScript, no dynamic injected scripts etc..) 12 13 As ScriptElement, doesn't actually inherit from Element, we may want to rename 14 it, though StyleElement uses the same naming convention, so I left it as is for now. 15 Eventually we'll rename both files in future. 16 17 No functional changes yet, as SVGScriptElement doesn't yet use the new base class. 18 19 * WebCore.pro: Add new ScriptElement.cpp to build. 20 * WebCore.vcproj/WebCore.vcproj: Ditto. 21 * WebCore.xcodeproj/project.pbxproj: Ditto. 22 * WebCoreSources.bkl: Dutto. 23 * dom/ScriptElement.cpp: Added. 1:1 based on HTMLScriptElement 24 (WebCore::ScriptElement::insertedIntoDocument): 25 (WebCore::ScriptElement::removedFromDocument): 26 (WebCore::ScriptElement::childrenChanged): 27 (WebCore::ScriptElement::finishParsingChildren): 28 (WebCore::ScriptElement::handleSourceAttribute): 29 (WebCore::isSupportedJavaScriptLanguage): 30 (WebCore::ScriptElementData::ScriptElementData): 31 (WebCore::ScriptElementData::~ScriptElementData): 32 (WebCore::ScriptElementData::requestScript): 33 (WebCore::ScriptElementData::evaluateScript): 34 (WebCore::ScriptElementData::stopLoadRequest): 35 (WebCore::ScriptElementData::notifyFinished): 36 (WebCore::ScriptElementData::ignoresLoadRequest): 37 (WebCore::ScriptElementData::shouldExecuteAsJavaScript): 38 (WebCore::ScriptElementData::scriptCharset): 39 (WebCore::ScriptElementData::scriptContent): 40 * dom/ScriptElement.h: Added. 41 (WebCore::ScriptElement::ScriptElement): 42 (WebCore::ScriptElement::~ScriptElement): 43 (WebCore::ScriptElementData::element): 44 (WebCore::ScriptElementData::createdByParser): 45 (WebCore::ScriptElementData::setCreatedByParser): 46 * dom/XMLTokenizer.cpp: 47 (WebCore::isScriptElement): 48 (WebCore::castToScriptElement): 49 (WebCore::eventuallyMarkAsParserCreated): 50 (WebCore::XMLTokenizer::startElementNs): 51 (WebCore::XMLTokenizer::endElementNs): 52 (WebCore::createXHTMLParserErrorHeader): 53 (WebCore::XMLTokenizer::insertErrorMessageBlock): 54 * html/HTMLScriptElement.cpp: Refactored code, pushed most code down to ScriptElement. 55 (WebCore::HTMLScriptElement::HTMLScriptElement): 56 (WebCore::HTMLScriptElement::~HTMLScriptElement): 57 (WebCore::HTMLScriptElement::isURLAttribute): 58 (WebCore::HTMLScriptElement::setCreatedByParser): 59 (WebCore::HTMLScriptElement::shouldExecuteAsJavaScript): 60 (WebCore::HTMLScriptElement::childrenChanged): 61 (WebCore::HTMLScriptElement::parseMappedAttribute): 62 (WebCore::HTMLScriptElement::finishParsingChildren): 63 (WebCore::HTMLScriptElement::insertedIntoDocument): 64 (WebCore::HTMLScriptElement::removedFromDocument): 65 (WebCore::HTMLScriptElement::text): 66 (WebCore::HTMLScriptElement::setText): 67 (WebCore::HTMLScriptElement::setHtmlFor): 68 (WebCore::HTMLScriptElement::setEvent): 69 (WebCore::HTMLScriptElement::charset): 70 (WebCore::HTMLScriptElement::src): 71 (WebCore::HTMLScriptElement::type): 72 (WebCore::HTMLScriptElement::scriptCharset): 73 (WebCore::HTMLScriptElement::scriptContent): 74 (WebCore::HTMLScriptElement::sourceAttributeValue): 75 (WebCore::HTMLScriptElement::charsetAttributeValue): 76 (WebCore::HTMLScriptElement::typeAttributeValue): 77 (WebCore::HTMLScriptElement::languageAttributeValue): 78 (WebCore::HTMLScriptElement::dispatchLoadEvent): 79 (WebCore::HTMLScriptElement::dispatchErrorEvent): 80 * html/HTMLScriptElement.h: 81 * svg/SVGScriptElement.cpp: Inherit from ScriptElement, don't actually use it yet. 82 * svg/SVGScriptElement.cpp: 83 (WebCore::SVGScriptElement::SVGScriptElement): 84 (WebCore::SVGScriptElement::scriptContent): 85 (WebCore::SVGScriptElement::sourceAttributeValue): 86 (WebCore::SVGScriptElement::charsetAttributeValue): 87 (WebCore::SVGScriptElement::typeAttributeValue): 88 (WebCore::SVGScriptElement::languageAttributeValue): 89 (WebCore::SVGScriptElement::dispatchLoadEvent): 90 (WebCore::SVGScriptElement::dispatchErrorEvent): 91 * svg/SVGScriptElement.h: 92 (WebCore::SVGScriptElement::setCreatedByParser): 93 1 94 2008-08-13 Eric Seidel <eric@webkit.org> 2 95 -
trunk/WebCore/WebCore.pro
r35732 r35744 537 537 dom/Range.cpp \ 538 538 dom/RegisteredEventListener.cpp \ 539 dom/ScriptElement.cpp \ 539 540 dom/SelectorNodeList.cpp \ 540 541 dom/StaticNodeList.cpp \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r35732 r35744 10429 10429 </File> 10430 10430 <File 10431 RelativePath="..\dom\ScriptElement.cpp" 10432 > 10433 <FileConfiguration 10434 Name="Release_PGO|Win32" 10435 > 10436 <Tool 10437 Name="VCCLCompilerTool" 10438 WholeProgramOptimization="true" 10439 /> 10440 </FileConfiguration> 10441 </File> 10442 <File 10443 RelativePath="..\dom\ScriptElement.h" 10444 > 10445 </File> 10446 <File 10431 10447 RelativePath="..\dom\SelectorNodeList.cpp" 10432 10448 > -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r35732 r35744 40 40 06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 06E81ED60AB5D5E900C87837 /* LocalCurrentGraphicsContext.h */; }; 41 41 06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */; }; 42 08A484770E5272C500C3FE76 /* ScriptElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08A484750E5272C500C3FE76 /* ScriptElement.cpp */; }; 43 08A484780E5272C500C3FE76 /* ScriptElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 08A484760E5272C500C3FE76 /* ScriptElement.h */; }; 42 44 08E4FE460E2BD41400F4CAE0 /* JSSVGLengthCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08E4FE450E2BD41400F4CAE0 /* JSSVGLengthCustom.cpp */; }; 43 45 0A4844990CA44CB200B7BD48 /* SoftLinking.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A4844980CA44CB200B7BD48 /* SoftLinking.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 4544 4546 06E81ED60AB5D5E900C87837 /* LocalCurrentGraphicsContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalCurrentGraphicsContext.h; sourceTree = "<group>"; }; 4545 4547 06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentGraphicsContext.mm; sourceTree = "<group>"; }; 4548 08A484750E5272C500C3FE76 /* ScriptElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptElement.cpp; sourceTree = "<group>"; }; 4549 08A484760E5272C500C3FE76 /* ScriptElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptElement.h; sourceTree = "<group>"; }; 4546 4550 08E4FE450E2BD41400F4CAE0 /* JSSVGLengthCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGLengthCustom.cpp; sourceTree = "<group>"; }; 4547 4551 0A4844980CA44CB200B7BD48 /* SoftLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SoftLinking.h; sourceTree = "<group>"; }; … … 13332 13336 85031B350A44EFC700F992E0 /* RegisteredEventListener.cpp */, 13333 13337 85031B360A44EFC700F992E0 /* RegisteredEventListener.h */, 13338 08A484750E5272C500C3FE76 /* ScriptElement.cpp */, 13339 08A484760E5272C500C3FE76 /* ScriptElement.h */, 13334 13340 BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */, 13335 13341 BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */, … … 15395 15401 31C0FF4C0E4CEFDD007D6FE5 /* DOMWebKitTransitionEvent.h in Headers */, 15396 15402 31C0FF4E0E4CEFDD007D6FE5 /* DOMWebKitTransitionEventInternal.h in Headers */, 15403 08A484780E5272C500C3FE76 /* ScriptElement.h in Headers */, 15397 15404 A8FA6E5D0E4CFDED00D5CF49 /* Pattern.h in Headers */, 15398 15405 ); … … 17179 17186 31C0FF4A0E4CEFDD007D6FE5 /* DOMWebKitAnimationEvent.mm in Sources */, 17180 17187 31C0FF4D0E4CEFDD007D6FE5 /* DOMWebKitTransitionEvent.mm in Sources */, 17188 08A484770E5272C500C3FE76 /* ScriptElement.cpp in Sources */, 17181 17189 A8FA6E5E0E4CFDED00D5CF49 /* Pattern.cpp in Sources */, 17182 17190 A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */, -
trunk/WebCore/WebCoreSources.bkl
r35732 r35744 407 407 dom/Range.cpp 408 408 dom/RegisteredEventListener.cpp 409 dom/ScriptElement.cpp 409 410 dom/SelectorNodeList.cpp 410 411 dom/StaticNodeList.cpp -
trunk/WebCore/dom/XMLTokenizer.cpp
r35172 r35744 43 43 #include "HTMLTokenizer.h" 44 44 #include "ScriptController.h" 45 #include "ScriptElement.h" 45 46 #include "ProcessingInstruction.h" 46 47 #include "ResourceError.h" … … 66 67 #if ENABLE(SVG) 67 68 #include "SVGNames.h" 69 #include "SVGScriptElement.h" 68 70 #include "SVGStyleElement.h" 69 #include "XLinkNames.h"70 71 #endif 71 72 … … 75 76 76 77 using namespace EventNames; 77 using namespace HTMLNames;78 78 79 79 const int maxErrors = 25; … … 543 543 544 544 // -------------------------------- 545 546 inline bool isScriptElement(Element* element) 547 { 548 return element->hasTagName(HTMLNames::scriptTag) 549 #if ENABLE(SVG) 550 || element->hasTagName(SVGNames::scriptTag) 551 #endif 552 ; 553 } 554 555 inline ScriptElement* castToScriptElement(Element* element) 556 { 557 ASSERT(isScriptElement(element)); 558 559 if (element->hasTagName(HTMLNames::scriptTag)) 560 return static_cast<HTMLScriptElement*>(element); 561 562 #if ENABLE(SVG) 563 if (element->hasTagName(SVGNames::scriptTag)) 564 return static_cast<SVGScriptElement*>(element); 565 #endif 566 567 ASSERT_NOT_REACHED(); 568 return 0; 569 } 545 570 546 571 XMLTokenizer::XMLTokenizer(Document* _doc, FrameView* _view) … … 811 836 } 812 837 838 static void eventuallyMarkAsParserCreated(Element* element) 839 { 840 if (element->hasTagName(HTMLNames::scriptTag)) 841 static_cast<HTMLScriptElement*>(element)->setCreatedByParser(true); 842 #if ENABLE(SVG) 843 else if (element->hasTagName(SVGNames::scriptTag)) 844 static_cast<SVGScriptElement*>(element)->setCreatedByParser(true); 845 #endif 846 else if (element->hasTagName(HTMLNames::styleTag)) 847 static_cast<HTMLStyleElement*>(element)->setCreatedByParser(true); 848 #if ENABLE(SVG) 849 else if (element->hasTagName(SVGNames::styleTag)) 850 static_cast<SVGStyleElement*>(element)->setCreatedByParser(true); 851 #endif 852 else if (element->hasTagName(HTMLNames::linkTag)) 853 static_cast<HTMLLinkElement*>(element)->setCreatedByParser(true); 854 } 855 813 856 void XMLTokenizer::startElementNs(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, int nb_namespaces, 814 857 const xmlChar** libxmlNamespaces, int nb_attributes, int nb_defaulted, const xmlChar** libxmlAttributes) … … 866 909 867 910 newElement->beginParsingChildren(); 868 869 if (newElement->hasTagName(scriptTag)) 870 static_cast<HTMLScriptElement*>(newElement.get())->setCreatedByParser(true); 871 else if (newElement->hasTagName(HTMLNames::styleTag)) 872 static_cast<HTMLStyleElement*>(newElement.get())->setCreatedByParser(true); 873 #if ENABLE(SVG) 874 else if (newElement->hasTagName(SVGNames::styleTag)) 875 static_cast<SVGStyleElement*>(newElement.get())->setCreatedByParser(true); 876 #endif 877 else if (newElement->hasTagName(HTMLNames::linkTag)) 878 static_cast<HTMLLinkElement*>(newElement.get())->setCreatedByParser(true); 879 880 if (newElement->hasTagName(HTMLNames::scriptTag) 881 #if ENABLE(SVG) 882 || newElement->hasTagName(SVGNames::scriptTag) 883 #endif 884 ) 911 eventuallyMarkAsParserCreated(newElement.get()); 912 913 if (isScriptElement(newElement.get())) 885 914 m_scriptStartLine = lineNumber(); 886 915 887 916 if (!m_currentNode->addChild(newElement.get())) { 888 917 stopParsing(); 889 918 return; 890 919 } 891 920 892 921 setCurrentNode(newElement.get()); 893 922 if (m_view && !newElement->attached()) … … 912 941 913 942 // don't load external scripts for standalone documents (for now) 914 if (n->isElementNode() && m_view && (static_cast<Element*>(n)->hasTagName(scriptTag) 915 #if ENABLE(SVG) 916 || static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag) 917 #endif 918 )) { 919 920 943 if (n->isElementNode() && m_view && isScriptElement(static_cast<Element*>(n))) { 921 944 ASSERT(!m_pendingScript); 922 923 945 m_requestingScript = true; 924 925 Element* scriptElement = static_cast<Element*>(n); 926 String scriptHref; 927 928 if (static_cast<Element*>(n)->hasTagName(scriptTag)) 929 scriptHref = scriptElement->getAttribute(srcAttr); 930 #if ENABLE(SVG) 931 else if (static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag)) 932 scriptHref = scriptElement->getAttribute(XLinkNames::hrefAttr); 933 #endif 934 946 947 Element* element = static_cast<Element*>(n); 948 ScriptElement* scriptElement = castToScriptElement(element); 949 950 String scriptHref = scriptElement->sourceAttributeValue(); 935 951 if (!scriptHref.isEmpty()) { 936 952 // we have a src attribute 937 const AtomicString& charset = scriptElement->getAttribute(charsetAttr);938 if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, charset))) {939 m_scriptElement = scriptElement;953 String scriptCharset = scriptElement->charsetAttributeValue(); 954 if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) { 955 m_scriptElement = element; 940 956 m_pendingScript->addClient(this); 941 957 942 958 // m_pendingScript will be 0 if script was already loaded and ref() executed it 943 959 if (m_pendingScript) … … 947 963 948 964 } else { 949 String scriptCode = ""; 950 for (Node* child = scriptElement->firstChild(); child; child = child->nextSibling()) { 951 if (child->isTextNode() || child->nodeType() == Node::CDATA_SECTION_NODE) 952 scriptCode += static_cast<CharacterData*>(child)->data(); 953 } 965 String scriptCode = scriptElement->scriptContent(); 954 966 m_view->frame()->loader()->executeScript(m_doc->url().string(), m_scriptStartLine, scriptCode); 955 967 } 956 968 957 969 m_requestingScript = false; 958 970 } … … 1432 1444 { 1433 1445 ExceptionCode ec = 0; 1434 RefPtr<Element> reportElement = doc->createElementNS( xhtmlNamespaceURI, "parsererror", ec);1435 reportElement->setAttribute( styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black");1436 1437 RefPtr<Element> h3 = doc->createElementNS( xhtmlNamespaceURI, "h3", ec);1446 RefPtr<Element> reportElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "parsererror", ec); 1447 reportElement->setAttribute(HTMLNames::styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"); 1448 1449 RefPtr<Element> h3 = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "h3", ec); 1438 1450 reportElement->appendChild(h3.get(), ec); 1439 1451 h3->appendChild(doc->createTextNode("This page contains the following errors:"), ec); 1440 1452 1441 RefPtr<Element> fixed = doc->createElementNS( xhtmlNamespaceURI, "div", ec);1453 RefPtr<Element> fixed = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "div", ec); 1442 1454 reportElement->appendChild(fixed.get(), ec); 1443 fixed->setAttribute( styleAttr, "font-family:monospace;font-size:12px");1455 fixed->setAttribute(HTMLNames::styleAttr, "font-family:monospace;font-size:12px"); 1444 1456 fixed->appendChild(doc->createTextNode(errorMessages), ec); 1445 1457 1446 h3 = doc->createElementNS( xhtmlNamespaceURI, "h3", ec);1458 h3 = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "h3", ec); 1447 1459 reportElement->appendChild(h3.get(), ec); 1448 1460 h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), ec); … … 1466 1478 Node* documentElement = doc->documentElement(); 1467 1479 if (!documentElement) { 1468 RefPtr<Node> rootElement = doc->createElementNS( xhtmlNamespaceURI, "html", ec);1480 RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec); 1469 1481 doc->appendChild(rootElement, ec); 1470 RefPtr<Node> body = doc->createElementNS( xhtmlNamespaceURI, "body", ec);1482 RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec); 1471 1483 rootElement->appendChild(body, ec); 1472 1484 documentElement = body.get(); … … 1477 1489 // wrap the erroneous SVG document in an xhtml document and render 1478 1490 // the combined document with error messages. 1479 RefPtr<Node> rootElement = doc->createElementNS( xhtmlNamespaceURI, "html", ec);1480 RefPtr<Node> body = doc->createElementNS( xhtmlNamespaceURI, "body", ec);1491 RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec); 1492 RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec); 1481 1493 rootElement->appendChild(body, ec); 1482 1494 body->appendChild(documentElement, ec); … … 1490 1502 #if ENABLE(XSLT) 1491 1503 if (doc->transformSourceDocument()) { 1492 RefPtr<Element> par = doc->createElementNS( xhtmlNamespaceURI, "p", ec);1504 RefPtr<Element> par = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "p", ec); 1493 1505 reportElement->appendChild(par, ec); 1494 par->setAttribute( styleAttr, "white-space: normal");1506 par->setAttribute(HTMLNames::styleAttr, "white-space: normal"); 1495 1507 par->appendChild(doc->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."), ec); 1496 1508 } … … 1913 1925 } 1914 1926 1915 if (newElement->hasTagName(scriptTag)) 1916 static_cast<HTMLScriptElement*>(newElement.get())->setCreatedByParser(true); 1917 1918 if (newElement->hasTagName(HTMLNames::scriptTag) 1919 #if ENABLE(SVG) 1920 || newElement->hasTagName(SVGNames::scriptTag) 1921 #endif 1922 ) 1927 eventuallyMarkAsParserCreated(newElement.get()); 1928 1929 if (isScriptElement(newElement.get())) 1923 1930 m_scriptStartLine = lineNumber(); 1924 1931 … … 1938 1945 1939 1946 Node* n = m_currentNode; 1940 1941 // skip end of dummy element1942 // if (m_parsingFragment & n->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)1943 // return;1944 1945 1947 RefPtr<Node> parent = n->parentNode(); 1946 1948 n->finishParsingChildren(); 1947 1949 1948 1950 // don't load external scripts for standalone documents (for now) 1949 if (n->isElementNode() && m_view && (static_cast<Element*>(n)->hasTagName(scriptTag) 1950 #if ENABLE(SVG) 1951 || static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag) 1952 #endif 1953 )) { 1954 1955 1951 if (n->isElementNode() && m_view && isScriptElement(static_cast<Element*>(n))) { 1956 1952 ASSERT(!m_pendingScript); 1957 1958 1953 m_requestingScript = true; 1959 1954 1960 Element* scriptElement = static_cast<Element*>(n); 1961 String scriptHref; 1962 1963 if (static_cast<Element*>(n)->hasTagName(scriptTag)) 1964 scriptHref = scriptElement->getAttribute(srcAttr); 1965 #if ENABLE(SVG) 1966 else if (static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag)) 1967 scriptHref = scriptElement->getAttribute(XLinkNames::hrefAttr); 1968 #endif 1955 Element* element = static_cast<Element*>(n); 1956 ScriptElement* scriptElement = castToScriptElement(element); 1957 1958 String scriptHref = scriptElement->sourceAttributeValue(); 1969 1959 if (!scriptHref.isEmpty()) { 1970 1960 // we have a src attribute 1971 const AtomicString& charset = scriptElement->getAttribute(charsetAttr);1972 if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, charset))) {1973 m_scriptElement = scriptElement;1961 String scriptCharset = scriptElement->charsetAttributeValue(); 1962 if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) { 1963 m_scriptElement = element; 1974 1964 m_pendingScript->addClient(this); 1975 1965 … … 1981 1971 1982 1972 } else { 1983 String scriptCode = ""; 1984 for (Node* child = scriptElement->firstChild(); child; child = child->nextSibling()) { 1985 if (child->isTextNode() || child->nodeType() == Node::CDATA_SECTION_NODE) 1986 scriptCode += static_cast<CharacterData*>(child)->data(); 1987 } 1973 String scriptCode = scriptElement->scriptContent(); 1988 1974 m_view->frame()->loader()->executeScript(m_doc->url().string(), m_scriptStartLine, scriptCode); 1989 1975 } 1976 1990 1977 m_requestingScript = false; 1991 1978 } -
trunk/WebCore/html/HTMLScriptElement.cpp
r34589 r35744 24 24 #include "HTMLScriptElement.h" 25 25 26 #include "CachedScript.h"27 #include "DocLoader.h"28 26 #include "Document.h" 29 27 #include "EventNames.h" 30 #include "Frame.h"31 #include "FrameLoader.h"32 28 #include "HTMLNames.h" 33 #include "ScriptController.h"34 #include "MIMETypeRegistry.h"35 29 #include "Text.h" 36 30 … … 42 36 HTMLScriptElement::HTMLScriptElement(Document* doc) 43 37 : HTMLElement(scriptTag, doc) 44 , m_cachedScript(0) 45 , m_createdByParser(false) 46 , m_evaluated(false) 38 , m_data(this, this) 47 39 { 48 40 } … … 50 42 HTMLScriptElement::~HTMLScriptElement() 51 43 { 52 if (m_cachedScript)53 m_cachedScript->removeClient(this);54 44 } 55 45 56 46 bool HTMLScriptElement::isURLAttribute(Attribute* attr) const 57 47 { 58 return attr->name() == srcAttr; 48 return attr->name() == sourceAttributeValue(); 49 } 50 51 void HTMLScriptElement::setCreatedByParser(bool createdByParser) 52 { 53 m_data.setCreatedByParser(createdByParser); 54 } 55 56 bool HTMLScriptElement::shouldExecuteAsJavaScript() const 57 { 58 return m_data.shouldExecuteAsJavaScript(); 59 59 } 60 60 61 61 void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 62 62 { 63 // If a node is inserted as a child of the script element 64 // and the script element has been inserted in the document 65 // we evaluate the script. 66 if (!m_createdByParser && inDocument() && firstChild()) 67 evaluateScript(document()->url().string(), text()); 63 ScriptElement::childrenChanged(m_data); 68 64 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 69 65 } … … 72 68 { 73 69 const QualifiedName& attrName = attr->name(); 74 if (attrName == srcAttr) { 75 if (m_evaluated || m_cachedScript || m_createdByParser || !inDocument()) 76 return; 77 78 // FIXME: Evaluate scripts in viewless documents. 79 // See http://bugs.webkit.org/show_bug.cgi?id=5727 80 if (!document()->frame()) 81 return; 82 83 const AtomicString& url = attr->value(); 84 if (!url.isEmpty()) { 85 m_cachedScript = document()->docLoader()->requestScript(url, scriptCharset()); 86 if (m_cachedScript) 87 m_cachedScript->addClient(this); 88 else 89 dispatchHTMLEvent(errorEvent, true, false); 90 } 91 } else if (attrName == onloadAttr) 70 71 if (attrName == srcAttr) 72 handleSourceAttribute(m_data, attr->value()); 73 else if (attrName == onloadAttr) 92 74 setHTMLEventListener(loadEvent, attr); 93 75 else … … 97 79 void HTMLScriptElement::finishParsingChildren() 98 80 { 99 // The parser just reached </script>. If we have no src and no text, 100 // allow dynamic loading later. 101 if (getAttribute(srcAttr).isEmpty() && text().isEmpty()) 102 setCreatedByParser(false); 81 ScriptElement::finishParsingChildren(m_data, sourceAttributeValue()); 103 82 HTMLElement::finishParsingChildren(); 104 83 } … … 107 86 { 108 87 HTMLElement::insertedIntoDocument(); 109 110 ASSERT(!m_cachedScript); 111 112 if (m_createdByParser) 113 return; 114 115 // FIXME: Eventually we'd like to evaluate scripts which are inserted into a 116 // viewless document but this'll do for now. 117 // See http://bugs.webkit.org/show_bug.cgi?id=5727 118 if (!document()->frame()) 119 return; 120 121 const AtomicString& url = getAttribute(srcAttr); 122 if (!url.isEmpty()) { 123 m_cachedScript = document()->docLoader()->requestScript(url, scriptCharset()); 124 if (m_cachedScript) 125 m_cachedScript->addClient(this); 126 else 127 dispatchHTMLEvent(errorEvent, true, false); 88 ScriptElement::insertedIntoDocument(m_data, sourceAttributeValue()); 89 } 90 91 void HTMLScriptElement::removedFromDocument() 92 { 93 HTMLElement::removedFromDocument(); 94 ScriptElement::removedFromDocument(m_data); 95 } 96 97 String HTMLScriptElement::text() const 98 { 99 return m_data.scriptContent(); 100 } 101 102 void HTMLScriptElement::setText(const String &value) 103 { 104 ExceptionCode ec = 0; 105 int numChildren = childNodeCount(); 106 107 if (numChildren == 1 && firstChild()->isTextNode()) { 108 static_cast<Text*>(firstChild())->setData(value, ec); 128 109 return; 129 110 } 130 111 131 // If there's an empty script node, we shouldn't evaluate the script132 // because if a script is inserted afterwards (by setting text or innerText)133 // it should be evaluated, and evaluateScript only evaluates a script once.134 String scriptString = text();135 if (!scriptString.isEmpty())136 evaluateScript(document()->url().string(), scriptString);137 }138 139 void HTMLScriptElement::removedFromDocument()140 {141 HTMLElement::removedFromDocument();142 143 if (m_cachedScript) {144 m_cachedScript->removeClient(this);145 m_cachedScript = 0;146 }147 }148 149 void HTMLScriptElement::notifyFinished(CachedResource* o)150 {151 CachedScript* cs = static_cast<CachedScript*>(o);152 153 ASSERT(cs == m_cachedScript);154 155 // Evaluating the script could lead to a garbage collection which156 // can delete the script element so we need to protect it.157 RefPtr<HTMLScriptElement> protect(this);158 159 if (cs->errorOccurred())160 dispatchHTMLEvent(errorEvent, true, false);161 else {162 evaluateScript(cs->url(), cs->script());163 dispatchHTMLEvent(loadEvent, false, false);164 }165 166 // script evaluation may have dereffed it already167 if (m_cachedScript) {168 m_cachedScript->removeClient(this);169 m_cachedScript = 0;170 }171 }172 173 bool HTMLScriptElement::shouldExecuteAsJavaScript()174 {175 /*176 Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only javascript1.1 - javascript1.3.177 Mozilla 1.8 and WinIE 7 both accept javascript and livescript.178 WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.179 Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.180 We want to accept all the values that either of these browsers accept, but not other values.181 */182 static const AtomicString validLanguages[] = {183 "javascript",184 "javascript1.0",185 "javascript1.1",186 "javascript1.2",187 "javascript1.3",188 "javascript1.4",189 "javascript1.5",190 "javascript1.6",191 "javascript1.7",192 "livescript",193 "ecmascript",194 "jscript"195 };196 static const unsigned validLanguagesCount = sizeof(validLanguages) / sizeof(validLanguages[0]);197 198 const AtomicString& type = getAttribute(typeAttr);199 if (!type.isEmpty()) {200 String lowerType = type.string().stripWhiteSpace().lower();201 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(lowerType))202 return true;203 204 return false;205 }206 207 const AtomicString& language = getAttribute(languageAttr);208 if (!language.isEmpty()) {209 String lowerLanguage = language.string().lower();210 for (unsigned i = 0; i < validLanguagesCount; ++i)211 if (lowerLanguage == validLanguages[i])212 return true;213 214 return false;215 }216 217 // No type or language is specified, so we assume the script to be JavaScript218 return true;219 }220 221 void HTMLScriptElement::evaluateScript(const String& url, const String& script)222 {223 if (m_evaluated)224 return;225 226 if (!shouldExecuteAsJavaScript())227 return;228 229 Frame* frame = document()->frame();230 if (frame) {231 if (frame->script()->isEnabled()) {232 m_evaluated = true;233 // FIXME: This starting line number will be incorrect for evaluation triggered234 // from insertedIntoDocument or childrenChanged.235 frame->script()->evaluate(url, 1, script);236 Document::updateDocumentsRendering();237 }238 }239 }240 241 String HTMLScriptElement::text() const242 {243 Vector<UChar> val;244 Text* firstTextNode = 0;245 bool foundMultipleTextNodes = false;246 247 for (Node* n = firstChild(); n; n = n->nextSibling()) {248 if (n->isTextNode()) {249 if (foundMultipleTextNodes)250 append(val, static_cast<Text*>(n)->data());251 else if (firstTextNode) {252 append(val, firstTextNode->data());253 append(val, static_cast<Text*>(n)->data());254 foundMultipleTextNodes = true;255 } else {256 firstTextNode = static_cast<Text*>(n);257 }258 }259 }260 261 if (firstTextNode && !foundMultipleTextNodes)262 return firstTextNode->data();263 264 return String::adopt(val);265 }266 267 void HTMLScriptElement::setText(const String &value)268 {269 ExceptionCode ec = 0;270 int numChildren = childNodeCount();271 272 if (numChildren == 1 && firstChild()->isTextNode()) {273 static_cast<Text *>(firstChild())->setData(value, ec);274 return;275 }276 277 112 if (numChildren > 0) 278 113 removeChildren(); 279 114 280 115 appendChild(document()->createTextNode(value.impl()), ec); 281 116 } … … 287 122 } 288 123 289 void HTMLScriptElement::setHtmlFor(const String& /*value*/)124 void HTMLScriptElement::setHtmlFor(const String&) 290 125 { 291 126 // DOM Level 1 says: reserved for future use. … … 298 133 } 299 134 300 void HTMLScriptElement::setEvent(const String& /*value*/)135 void HTMLScriptElement::setEvent(const String&) 301 136 { 302 137 // DOM Level 1 says: reserved for future use. … … 305 140 String HTMLScriptElement::charset() const 306 141 { 307 return getAttribute(charsetAttr);142 return charsetAttributeValue(); 308 143 } 309 144 … … 325 160 KURL HTMLScriptElement::src() const 326 161 { 327 return document()->completeURL( getAttribute(srcAttr));162 return document()->completeURL(sourceAttributeValue()); 328 163 } 329 164 … … 335 170 String HTMLScriptElement::type() const 336 171 { 337 return getAttribute(typeAttr);172 return typeAttributeValue(); 338 173 } 339 174 … … 345 180 String HTMLScriptElement::scriptCharset() const 346 181 { 347 // First we try to get encoding from charset attribute. 348 String charset = getAttribute(charsetAttr).string().stripWhiteSpace(); 349 // If charset has not been declared in script tag, fall back 350 // to frame encoding. 351 if (charset.isEmpty()) { 352 if (Frame* frame = document()->frame()) 353 charset = frame->loader()->encoding(); 354 } 355 return charset; 182 return m_data.scriptCharset(); 183 } 184 185 String HTMLScriptElement::scriptContent() const 186 { 187 return m_data.scriptContent(); 356 188 } 357 189 … … 361 193 } 362 194 363 } 195 String HTMLScriptElement::sourceAttributeValue() const 196 { 197 return getAttribute(srcAttr).string(); 198 } 199 200 String HTMLScriptElement::charsetAttributeValue() const 201 { 202 return getAttribute(charsetAttr).string();; 203 } 204 205 String HTMLScriptElement::typeAttributeValue() const 206 { 207 return getAttribute(typeAttr).string();; 208 } 209 210 String HTMLScriptElement::languageAttributeValue() const 211 { 212 return getAttribute(languageAttr).string(); 213 } 214 215 void HTMLScriptElement::dispatchLoadEvent() 216 { 217 dispatchHTMLEvent(loadEvent, false, false); 218 } 219 220 void HTMLScriptElement::dispatchErrorEvent() 221 { 222 dispatchHTMLEvent(errorEvent, true, false); 223 } 224 225 } -
trunk/WebCore/html/HTMLScriptElement.h
r31357 r35744 3 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 24 25 #define HTMLScriptElement_h 25 26 26 #include " CachedResourceClient.h"27 #include "ScriptElement.h" 27 28 #include "HTMLElement.h" 28 29 29 30 namespace WebCore { 30 31 31 class CachedScript; 32 33 class HTMLScriptElement : public HTMLElement, public CachedResourceClient { 32 class HTMLScriptElement : public HTMLElement 33 , public ScriptElement { 34 34 public: 35 35 HTMLScriptElement(Document*); 36 36 ~HTMLScriptElement(); 37 38 void setCreatedByParser(bool); 39 bool shouldExecuteAsJavaScript() const; 40 virtual String scriptContent() const; 37 41 38 42 virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } … … 43 47 virtual void insertedIntoDocument(); 44 48 virtual void removedFromDocument(); 45 virtual void notifyFinished(CachedResource*);46 47 49 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 48 50 49 51 virtual bool isURLAttribute(Attribute*) const; 50 51 void setCreatedByParser(bool createdByParser) { m_createdByParser = createdByParser; }52 52 virtual void finishParsingChildren(); 53 54 bool shouldExecuteAsJavaScript();55 void evaluateScript(const String& url, const String& script);56 53 57 54 String text() const; … … 81 78 virtual void getSubresourceAttributeStrings(Vector<String>&) const; 82 79 80 protected: 81 virtual String sourceAttributeValue() const; 82 virtual String charsetAttributeValue() const; 83 virtual String typeAttributeValue() const; 84 virtual String languageAttributeValue() const; 85 86 virtual void dispatchLoadEvent(); 87 virtual void dispatchErrorEvent(); 88 83 89 private: 84 CachedScript* m_cachedScript; 85 bool m_createdByParser; 86 bool m_evaluated; 90 ScriptElementData m_data; 87 91 }; 88 92 -
trunk/WebCore/svg/SVGScriptElement.cpp
r35248 r35744 33 33 , SVGURIReference() 34 34 , SVGExternalResourcesRequired() 35 , m_data(this, this) 35 36 { 36 37 } … … 48 49 { 49 50 m_type = type; 51 } 52 53 String SVGScriptElement::scriptContent() const 54 { 55 return m_data.scriptContent(); 50 56 } 51 57 … … 69 75 } 70 76 77 String SVGScriptElement::sourceAttributeValue() const 78 { 79 return href(); 80 } 81 82 String SVGScriptElement::charsetAttributeValue() const 83 { 84 return String(); 85 } 86 87 String SVGScriptElement::typeAttributeValue() const 88 { 89 return type(); 90 } 91 92 String SVGScriptElement::languageAttributeValue() const 93 { 94 return String(); 95 } 96 97 void SVGScriptElement::dispatchLoadEvent() 98 { 99 // TODO! 100 // dispatchSVGEvent(loadEvent, false, false); 101 } 102 103 void SVGScriptElement::dispatchErrorEvent() 104 { 105 // TODO! 106 // dispatchSVGEvent(errorEvent, true, false); 107 } 71 108 } 72 109 -
trunk/WebCore/svg/SVGScriptElement.h
r35248 r35744 25 25 26 26 #if ENABLE(SVG) 27 #include "ScriptElement.h" 27 28 #include "SVGElement.h" 28 29 #include "SVGURIReference.h" … … 31 32 namespace WebCore { 32 33 33 class SVGScriptElement : public SVGElement, 34 public SVGURIReference, 35 public SVGExternalResourcesRequired { 34 class SVGScriptElement : public SVGElement 35 , public SVGURIReference 36 , public SVGExternalResourcesRequired 37 , public ScriptElement { 36 38 public: 37 39 SVGScriptElement(const QualifiedName&, Document*); 38 40 virtual ~SVGScriptElement(); 41 42 void setCreatedByParser(bool) { } 43 virtual String scriptContent() const; 39 44 40 45 String type() const; … … 47 52 virtual const SVGElement* contextElement() const { return this; } 48 53 54 virtual String sourceAttributeValue() const; 55 virtual String charsetAttributeValue() const; 56 virtual String typeAttributeValue() const; 57 virtual String languageAttributeValue() const; 58 59 virtual void dispatchLoadEvent(); 60 virtual void dispatchErrorEvent(); 61 49 62 private: 63 ScriptElementData m_data; 50 64 String m_type; 51 65 };
Note: See TracChangeset
for help on using the changeset viewer.