diff options
author | Steve Block <steveblock@google.com> | 2010-02-02 14:57:50 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-04 15:06:55 +0000 |
commit | d0825bca7fe65beaee391d30da42e937db621564 (patch) | |
tree | 7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebCore/html/HTMLTokenizer.cpp | |
parent | 3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff) | |
download | external_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2 |
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebCore/html/HTMLTokenizer.cpp')
-rw-r--r-- | WebCore/html/HTMLTokenizer.cpp | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/WebCore/html/HTMLTokenizer.cpp b/WebCore/html/HTMLTokenizer.cpp index a552442..6fa3e20 100644 --- a/WebCore/html/HTMLTokenizer.cpp +++ b/WebCore/html/HTMLTokenizer.cpp @@ -171,10 +171,12 @@ HTMLTokenizer::HTMLTokenizer(HTMLDocument* doc, bool reportErrors) , m_requestingScript(false) , m_hasScriptsWaitingForStylesheets(false) , m_timer(this, &HTMLTokenizer::timerFired) + , m_externalScriptsTimer(this, &HTMLTokenizer::executeExternalScriptsTimerFired) , m_doc(doc) , m_parser(new HTMLParser(doc, reportErrors)) , m_inWrite(false) , m_fragment(false) + , m_scriptingPermission(FragmentScriptingAllowed) { begin(); } @@ -190,15 +192,17 @@ HTMLTokenizer::HTMLTokenizer(HTMLViewSourceDocument* doc) , m_requestingScript(false) , m_hasScriptsWaitingForStylesheets(false) , m_timer(this, &HTMLTokenizer::timerFired) + , m_externalScriptsTimer(this, &HTMLTokenizer::executeExternalScriptsTimerFired) , m_doc(doc) , m_parser(0) , m_inWrite(false) , m_fragment(false) + , m_scriptingPermission(FragmentScriptingAllowed) { begin(); } -HTMLTokenizer::HTMLTokenizer(DocumentFragment* frag) +HTMLTokenizer::HTMLTokenizer(DocumentFragment* frag, FragmentScriptingPermission scriptingPermission) : m_buffer(0) , m_scriptCode(0) , m_scriptCodeSize(0) @@ -208,10 +212,12 @@ HTMLTokenizer::HTMLTokenizer(DocumentFragment* frag) , m_requestingScript(false) , m_hasScriptsWaitingForStylesheets(false) , m_timer(this, &HTMLTokenizer::timerFired) + , m_externalScriptsTimer(this, &HTMLTokenizer::executeExternalScriptsTimerFired) , m_doc(frag->document()) - , m_parser(new HTMLParser(frag)) + , m_parser(new HTMLParser(frag, scriptingPermission)) , m_inWrite(false) , m_fragment(true) + , m_scriptingPermission(scriptingPermission) { begin(); } @@ -236,6 +242,8 @@ void HTMLTokenizer::reset() m_scriptCodeSize = m_scriptCodeCapacity = m_scriptCodeResync = 0; m_timer.stop(); + m_externalScriptsTimer.stop(); + m_state.setAllowYield(false); m_state.setForceSynchronous(false); @@ -467,6 +475,13 @@ HTMLTokenizer::State HTMLTokenizer::scriptHandler(State state) state = processListing(SegmentedString(m_scriptCode, m_scriptCodeSize), state); RefPtr<Node> node = processToken(); + + if (node && m_scriptingPermission == FragmentScriptingNotAllowed) { + ExceptionCode ec; + node->remove(ec); + node = 0; + } + String scriptString = node ? node->textContent() : ""; m_currentToken.tagName = scriptTag.localName(); m_currentToken.beginTag = false; @@ -1508,7 +1523,7 @@ HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state) m_scriptTagSrcAttrValue = String(); m_scriptTagCharsetAttrValue = String(); if (m_currentToken.attrs && !m_fragment) { - if (m_doc->frame() && m_doc->frame()->script()->isEnabled()) { + if (m_doc->frame() && m_doc->frame()->script()->canExecuteScripts()) { if ((a = m_currentToken.attrs->getAttributeItem(srcAttr))) m_scriptTagSrcAttrValue = m_doc->completeURL(deprecatedParseURL(a->value())).string(); } @@ -1682,7 +1697,7 @@ void HTMLTokenizer::write(const SegmentedString& str, bool appendData) #if ENABLE(INSPECTOR) if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) - timelineAgent->willWriteHTML(); + timelineAgent->willWriteHTML(source.length(), m_lineNumber); #endif Frame* frame = m_doc->frame(); @@ -1808,7 +1823,7 @@ void HTMLTokenizer::write(const SegmentedString& str, bool appendData) #if ENABLE(INSPECTOR) if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) - timelineAgent->didWriteHTML(); + timelineAgent->didWriteHTML(m_lineNumber); #endif m_inWrite = wasInWrite; @@ -1822,8 +1837,8 @@ void HTMLTokenizer::write(const SegmentedString& str, bool appendData) if (m_noMoreData && !m_inWrite && !state.loadingExtScript() && !m_executingScript && !m_timer.isActive()) end(); // this actually causes us to be deleted - // After parsing, go ahead and dispatch image beforeload/load events. - ImageLoader::dispatchPendingEvents(); + // After parsing, go ahead and dispatch image beforeload events. + ImageLoader::dispatchPendingBeforeLoadEvents(); } void HTMLTokenizer::stopParsing() @@ -1925,7 +1940,7 @@ void HTMLTokenizer::finish() PassRefPtr<Node> HTMLTokenizer::processToken() { ScriptController* scriptController = (!m_fragment && m_doc->frame()) ? m_doc->frame()->script() : 0; - if (scriptController && scriptController->isEnabled()) + if (scriptController && scriptController->canExecuteScripts()) // FIXME: Why isn't this m_currentScriptTagStartLineNumber? I suspect this is wrong. scriptController->setEventHandlerLineNumber(m_currentTagStartLineNumber + 1); // Script line numbers are 1 based. if (m_dest > m_buffer) { @@ -2026,6 +2041,11 @@ void HTMLTokenizer::executeScriptsWaitingForStylesheets() void HTMLTokenizer::notifyFinished(CachedResource*) { + executeExternalScriptsIfReady(); +} + +void HTMLTokenizer::executeExternalScriptsIfReady() +{ #ifdef INSTRUMENT_LAYOUT_SCHEDULING if (!m_doc->ownerElement()) printf("script loaded at %d\n", m_doc->elapsedTime()); @@ -2040,7 +2060,12 @@ void HTMLTokenizer::notifyFinished(CachedResource*) return; bool finished = false; + + double startTime = currentTime(); while (!finished && m_pendingScripts.first()->isLoaded()) { + if (!continueExecutingExternalScripts(startTime)) + break; + CachedScript* cs = m_pendingScripts.first().get(); m_pendingScripts.removeFirst(); ASSERT(cache()->disabled() || cs->accessCount() > 0); @@ -2100,6 +2125,31 @@ void HTMLTokenizer::notifyFinished(CachedResource*) } } +void HTMLTokenizer::executeExternalScriptsTimerFired(Timer<HTMLTokenizer>*) +{ + if (m_doc->view() && m_doc->view()->layoutPending() && !m_doc->minimumLayoutDelay()) { + // Restart the timer and do layout first. + m_externalScriptsTimer.startOneShot(0); + return; + } + + // Continue executing external scripts. + executeExternalScriptsIfReady(); +} + +bool HTMLTokenizer::continueExecutingExternalScripts(double startTime) +{ + if (m_externalScriptsTimer.isActive()) + return false; + + if (currentTime() - startTime > m_tokenizerTimeDelay) { + // Schedule the timer to keep processing as soon as possible. + m_externalScriptsTimer.startOneShot(0); + return false; + } + return true; +} + bool HTMLTokenizer::isWaitingForScripts() const { return m_state.loadingExtScript(); @@ -2110,9 +2160,9 @@ void HTMLTokenizer::setSrc(const SegmentedString& source) m_src = source; } -void parseHTMLDocumentFragment(const String& source, DocumentFragment* fragment) +void parseHTMLDocumentFragment(const String& source, DocumentFragment* fragment, FragmentScriptingPermission scriptingPermission) { - HTMLTokenizer tok(fragment); + HTMLTokenizer tok(fragment, scriptingPermission); tok.setForceSynchronous(true); tok.write(source, true); tok.finish(); |