diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/html/HTMLTokenizer.cpp')
-rw-r--r-- | src/3rdparty/webkit/WebCore/html/HTMLTokenizer.cpp | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/src/3rdparty/webkit/WebCore/html/HTMLTokenizer.cpp b/src/3rdparty/webkit/WebCore/html/HTMLTokenizer.cpp index 6de9951..341eecc 100644 --- a/src/3rdparty/webkit/WebCore/html/HTMLTokenizer.cpp +++ b/src/3rdparty/webkit/WebCore/html/HTMLTokenizer.cpp @@ -5,8 +5,9 @@ (C) 1999 Lars Knoll (knoll@kde.org) (C) 1999 Antti Koivisto (koivisto@kde.org) (C) 2001 Dirk Mueller (mueller@kde.org) - Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. Copyright (C) 2005, 2006 Alexey Proskuryakov (ap@nypop.com) + Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -41,13 +42,14 @@ #include "HTMLParser.h" #include "HTMLScriptElement.h" #include "HTMLViewSourceDocument.h" +#include "MappedAttribute.h" #include "Page.h" #include "PreloadScanner.h" #include "ScriptController.h" #include "ScriptSourceCode.h" #include "ScriptValue.h" -#include "SystemTime.h" #include <wtf/ASCIICType.h> +#include <wtf/CurrentTime.h> #include "HTMLEntityNames.c" @@ -133,14 +135,14 @@ static inline bool tagMatch(const char* s1, const UChar* s2, unsigned length) return true; } -inline void Token::addAttribute(Document* doc, AtomicString& attrName, const AtomicString& attributeValue, bool viewSourceMode) +inline void Token::addAttribute(AtomicString& attrName, const AtomicString& attributeValue, bool viewSourceMode) { if (!attrName.isEmpty()) { ASSERT(!attrName.contains('/')); RefPtr<MappedAttribute> a = MappedAttribute::create(attrName, attributeValue); if (!attrs) { attrs = NamedMappedAttrMap::create(); - attrs->reserveCapacity(10); + attrs->reserveInitialCapacity(10); } attrs->insertAttribute(a.release(), viewSourceMode); } @@ -445,16 +447,11 @@ HTMLTokenizer::State HTMLTokenizer::scriptHandler(State state) m_scriptTagSrcAttrValue = String(); } else { // Parse m_scriptCode containing <script> info -#if USE(LOW_BANDWIDTH_DISPLAY) - if (m_doc->inLowBandwidthDisplay()) { - // ideal solution is only skipping internal JavaScript if there is external JavaScript. - // but internal JavaScript can use document.write() to create an external JavaScript, - // so we have to skip internal JavaScript all the time. - m_doc->frame()->loader()->needToSwitchOutLowBandwidthDisplay(); - doScriptExec = false; - } else -#endif doScriptExec = m_scriptNode->shouldExecuteAsJavaScript(); +#if ENABLE(XHTMLMP) + if (!doScriptExec) + m_doc->setShouldProcessNoscriptElement(true); +#endif m_scriptNode = 0; } } @@ -1309,7 +1306,7 @@ HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state) m_currentToken.addViewSourceChar(curchar); src.advancePastNonNewline(); } else { - m_currentToken.addAttribute(m_doc, m_attrName, emptyAtom, inViewSourceMode()); + m_currentToken.addAttribute(m_attrName, emptyAtom, inViewSourceMode()); m_dest = m_buffer; state.setTagState(SearchAttribute); lastIsSlash = false; @@ -1363,7 +1360,7 @@ HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state) AtomicString attributeValue(m_buffer + 1, m_dest - m_buffer - 1); if (!attributeValue.contains('/')) m_attrName = attributeValue; // Just make the name/value match. (FIXME: Is this some WinIE quirk?) - m_currentToken.addAttribute(m_doc, m_attrName, attributeValue, inViewSourceMode()); + m_currentToken.addAttribute(m_attrName, attributeValue, inViewSourceMode()); if (inViewSourceMode()) m_currentToken.addViewSourceChar('x'); state.setTagState(SearchAttribute); @@ -1389,7 +1386,7 @@ HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state) m_currentToken.addViewSourceChar('x'); } else if (inViewSourceMode()) m_currentToken.addViewSourceChar('v'); - m_currentToken.addAttribute(m_doc, m_attrName, attributeValue, inViewSourceMode()); + m_currentToken.addAttribute(m_attrName, attributeValue, inViewSourceMode()); m_dest = m_buffer; state.setTagState(SearchAttribute); tquote = NoQuote; @@ -1419,7 +1416,7 @@ HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state) // '/' does not delimit in IE! if (isASCIISpace(curchar) || curchar == '>') { AtomicString attributeValue(m_buffer + 1, m_dest - m_buffer - 1); - m_currentToken.addAttribute(m_doc, m_attrName, attributeValue, inViewSourceMode()); + m_currentToken.addAttribute(m_attrName, attributeValue, inViewSourceMode()); if (inViewSourceMode()) m_currentToken.addViewSourceChar('v'); m_dest = m_buffer; @@ -1588,13 +1585,13 @@ inline bool HTMLTokenizer::continueProcessing(int& processedCount, double startT return true; } -bool HTMLTokenizer::write(const SegmentedString& str, bool appendData) +void HTMLTokenizer::write(const SegmentedString& str, bool appendData) { if (!m_buffer) - return false; + return; if (m_parserStopped) - return false; + return; SegmentedString source(str); if (m_executingScript) @@ -1611,7 +1608,7 @@ bool HTMLTokenizer::write(const SegmentedString& str, bool appendData) m_preloadScanner->write(source); #endif } - return false; + return; } #if PRELOAD_SCANNER_ENABLED @@ -1626,7 +1623,7 @@ bool HTMLTokenizer::write(const SegmentedString& str, bool appendData) // Once a timer is set, it has control of when the tokenizer continues. if (m_timer.isActive()) - return false; + return; bool wasInWrite = m_inWrite; m_inWrite = true; @@ -1764,11 +1761,8 @@ bool HTMLTokenizer::write(const SegmentedString& str, bool appendData) m_state = state; - if (m_noMoreData && !m_inWrite && !state.loadingExtScript() && !m_executingScript && !m_timer.isActive()) { + if (m_noMoreData && !m_inWrite && !state.loadingExtScript() && !m_executingScript && !m_timer.isActive()) end(); // this actually causes us to be deleted - return true; - } - return false; } void HTMLTokenizer::stopParsing() @@ -1872,7 +1866,7 @@ PassRefPtr<Node> HTMLTokenizer::processToken() ScriptController* scriptController = (!m_fragment && m_doc->frame()) ? m_doc->frame()->script() : 0; if (scriptController && scriptController->isEnabled()) // FIXME: Why isn't this m_currentScriptTagStartLineNumber? I suspect this is wrong. - scriptController->setEventHandlerLineno(m_currentTagStartLineNumber + 1); // Script line numbers are 1 based. + scriptController->setEventHandlerLineNumber(m_currentTagStartLineNumber + 1); // Script line numbers are 1 based. if (m_dest > m_buffer) { m_currentToken.text = StringImpl::createStrippingNullCharacters(m_buffer, m_dest - m_buffer); if (m_currentToken.tagName != commentAtom) @@ -1880,7 +1874,7 @@ PassRefPtr<Node> HTMLTokenizer::processToken() } else if (m_currentToken.tagName == nullAtom) { m_currentToken.reset(); if (scriptController) - scriptController->setEventHandlerLineno(m_lineNumber + 1); // Script line numbers are 1 based. + scriptController->setEventHandlerLineNumber(m_lineNumber + 1); // Script line numbers are 1 based. return 0; } @@ -1899,7 +1893,7 @@ PassRefPtr<Node> HTMLTokenizer::processToken() } m_currentToken.reset(); if (scriptController) - scriptController->setEventHandlerLineno(0); + scriptController->setEventHandlerLineNumber(0); return n.release(); } @@ -1921,7 +1915,16 @@ HTMLTokenizer::~HTMLTokenizer() void HTMLTokenizer::enlargeBuffer(int len) { - int newSize = max(m_bufferSize * 2, m_bufferSize + len); + // Resize policy: Always at least double the size of the buffer each time. + int delta = max(len, m_bufferSize); + + // Check for overflow. + // For now, handle overflow the same way we handle fastRealloc failure, with CRASH. + static const int maxSize = INT_MAX / sizeof(UChar); + if (delta > maxSize - m_bufferSize) + CRASH(); + + int newSize = m_bufferSize + delta; int oldOffset = m_dest - m_buffer; m_buffer = static_cast<UChar*>(fastRealloc(m_buffer, newSize * sizeof(UChar))); m_dest = m_buffer + oldOffset; @@ -1930,7 +1933,16 @@ void HTMLTokenizer::enlargeBuffer(int len) void HTMLTokenizer::enlargeScriptBuffer(int len) { - int newSize = max(m_scriptCodeCapacity * 2, m_scriptCodeCapacity + len); + // Resize policy: Always at least double the size of the buffer each time. + int delta = max(len, m_scriptCodeCapacity); + + // Check for overflow. + // For now, handle overflow the same way we handle fastRealloc failure, with CRASH. + static const int maxSize = INT_MAX / sizeof(UChar); + if (delta > maxSize - m_scriptCodeCapacity) + CRASH(); + + int newSize = m_scriptCodeCapacity + delta; m_scriptCode = static_cast<UChar*>(fastRealloc(m_scriptCode, newSize * sizeof(UChar))); m_scriptCodeCapacity = newSize; } @@ -1980,11 +1992,15 @@ void HTMLTokenizer::notifyFinished(CachedResource*) #endif if (errorOccurred) - EventTargetNodeCast(n.get())->dispatchEventForType(eventNames().errorEvent, true, false); + n->dispatchEvent(eventNames().errorEvent, true, false); else { if (static_cast<HTMLScriptElement*>(n.get())->shouldExecuteAsJavaScript()) m_state = scriptExecution(sourceCode, m_state); - EventTargetNodeCast(n.get())->dispatchEventForType(eventNames().loadEvent, false, false); +#if ENABLE(XHTMLMP) + else + m_doc->setShouldProcessNoscriptElement(true); +#endif + n->dispatchEvent(eventNames().loadEvent, false, false); } // The state of m_pendingScripts.isEmpty() can change inside the scriptExecution() |