Changeset 61904 in webkit
- Timestamp:
- Jun 25, 2010 2:37:08 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r61898 r61904 1 2010-06-25 Eric Seidel <eric@webkit.org> 2 3 Reviewed by Adam Barth. 4 5 Split DocumentParser::write into separate append and insert calls 6 https://bugs.webkit.org/show_bug.cgi?id=41197 7 8 Unfortunately this is still somewhat confusing as 9 "insert" means "insert this data at the current 10 insertion point and run the parser synchronously 11 unless we're in a nested write call" and "append" 12 means "append this data to the end and run the 13 parser if not in a nested call or until possibly yielding". 14 15 This at least makes clearer which document parsers implement 16 which behavior, and paves the way for moving the decoding 17 logic into DocumentParser from DocumentWriter. 18 19 No functional changes, thus no tests. 20 21 * dom/Document.cpp: 22 (WebCore::Document::write): 23 * dom/DocumentParser.h: 24 * dom/RawDataDocumentParser.h: 25 (WebCore::RawDataDocumentParser::insert): 26 (WebCore::RawDataDocumentParser::append): 27 * dom/XMLDocumentParser.cpp: 28 (WebCore::XMLDocumentParser::insert): 29 (WebCore::XMLDocumentParser::append): 30 * dom/XMLDocumentParser.h: 31 * dom/XMLDocumentParserLibxml2.cpp: 32 (WebCore::XMLDocumentParser::resumeParsing): 33 * html/HTMLDocumentParser.cpp: 34 (WebCore::HTMLDocumentParser::insert): 35 (WebCore::HTMLDocumentParser::append): 36 (WebCore::HTMLDocumentParser::parseDocumentFragment): 37 * html/HTMLDocumentParser.h: 38 * html/LegacyHTMLDocumentParser.cpp: 39 (WebCore::LegacyHTMLDocumentParser::insert): 40 (WebCore::LegacyHTMLDocumentParser::append): 41 * html/LegacyHTMLDocumentParser.h: 42 * loader/DocumentWriter.cpp: 43 (WebCore::DocumentWriter::replaceDocument): 44 (WebCore::DocumentWriter::addData): 45 * loader/FTPDirectoryDocument.cpp: 46 (WebCore::FTPDirectoryDocumentParser::FTPDirectoryDocumentParser): 47 (WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate): 48 (WebCore::FTPDirectoryDocumentParser::append): 49 * loader/TextDocument.cpp: 50 (WebCore::TextDocumentParser::insert): 51 (WebCore::TextDocumentParser::append): 52 (WebCore::TextDocumentParser::finish): 53 1 54 2010-06-25 Daniel Cheng <dcheng@chromium.org> 2 55 -
trunk/WebCore/dom/Document.cpp
r61868 r61904 1999 1999 2000 2000 ASSERT(m_parser); 2001 // FIXME: forceSynchronous should always be the same as the bool passed to 2002 // write(). However LegacyHTMLDocumentParser uses write("", false) to pump 2003 // the parser (after running external scripts, etc.) thus necessitating a 2004 // separate state for forceSynchronous. 2005 bool wasForcedSynchronous = false; 2006 LegacyHTMLDocumentParser* parser = m_parser->asHTMLDocumentParser(); 2007 if (parser) { 2008 wasForcedSynchronous = parser->forceSynchronous(); 2009 parser->setForceSynchronous(true); 2010 } 2011 2012 m_parser->write(text, false); 2013 2014 if (m_parser && parser && m_parser->asHTMLDocumentParser() == parser) 2015 parser->setForceSynchronous(wasForcedSynchronous); 2001 m_parser->insert(text); 2016 2002 2017 2003 #ifdef INSTRUMENT_LAYOUT_SCHEDULING -
trunk/WebCore/dom/DocumentFragment.cpp
r61835 r61904 92 92 bool DocumentFragment::parseXML(const String& source, Element* parent, FragmentScriptingPermission scriptingPermission) 93 93 { 94 return parseXMLDocumentFragment(source, this, parent, scriptingPermission);94 return XMLDocumentParser::parseDocumentFragment(source, this, parent, scriptingPermission); 95 95 } 96 96 -
trunk/WebCore/dom/DocumentParser.h
r61789 r61904 39 39 virtual ~DocumentParser() { } 40 40 41 // Script output must be prepended, while new data42 // received during executing a script must be appended, hence the43 // extra bool to be able to distinguish between both cases.44 // document.write() always uses false, while the loader uses true.45 virtual void write(const SegmentedString&, bool isFromNetwork) = 0; 41 // insert is use by document.write 42 virtual void insert(const SegmentedString&) = 0; 43 // apend is used by DocumentWriter (the loader) 44 virtual void append(const SegmentedString&) = 0; 45 46 46 virtual void finish() = 0; 47 47 virtual bool finishWasCalled() = 0; -
trunk/WebCore/dom/RawDataDocumentParser.h
r61789 r61904 52 52 53 53 private: 54 virtual void write(const SegmentedString&, bool)54 virtual void insert(const SegmentedString&) 55 55 { 56 56 // <https://bugs.webkit.org/show_bug.cgi?id=25397>: JS code can always call document.write, we need to handle it. 57 ASSERT_NOT_REACHED(); 58 } 59 60 virtual void append(const SegmentedString&) 61 { 57 62 ASSERT_NOT_REACHED(); 58 63 } -
trunk/WebCore/dom/XMLDocumentParser.cpp
r61737 r61904 117 117 } 118 118 119 void XMLDocumentParser::write(const SegmentedString& s, bool /*appendData*/) 119 void XMLDocumentParser::insert(const SegmentedString& source) 120 { 121 // FIXME: This is a hack to work around the fact that XMLHttpRequest 122 // responseXML() calls Document::write() which in turn calls insert(). In 123 // HTML, that's correct, as insert() implies a synchronous parse. For XML, 124 // all parsing is synchronous but document.write shouldn't be supported. 125 append(source); 126 } 127 128 void XMLDocumentParser::append(const SegmentedString& s) 120 129 { 121 130 String parseString = s.toString(); -
trunk/WebCore/dom/XMLDocumentParser.h
r61835 r61904 91 91 #endif 92 92 93 static bool parseDocumentFragment(const String&, DocumentFragment*, Element* parent = 0, FragmentScriptingPermission = FragmentScriptingAllowed); 94 93 95 private: 94 96 // From DocumentParser 95 virtual void write(const SegmentedString&, bool appendData); 97 virtual void insert(const SegmentedString&); 98 virtual void append(const SegmentedString&); 96 99 virtual void finish(); 97 100 virtual bool finishWasCalled(); … … 139 142 #endif 140 143 private: 141 friend bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element*, FragmentScriptingPermission);142 143 144 void initializeParserContext(const char* chunk = 0); 144 145 … … 207 208 208 209 HashMap<String, String> parseAttributes(const String&, bool& attrsOK); 209 bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent = 0, FragmentScriptingPermission = FragmentScriptingAllowed);210 210 211 211 } // namespace WebCore -
trunk/WebCore/dom/XMLDocumentParserLibxml2.cpp
r61737 r61904 1364 1364 SegmentedString rest = m_pendingSrc; 1365 1365 m_pendingSrc.clear(); 1366 write(rest, false);1366 append(rest); 1367 1367 1368 1368 // Finally, if finish() has been called and write() didn't result … … 1374 1374 // FIXME: This method should be possible to implement using the DocumentParser 1375 1375 // API, instead of needing to grab at libxml2 state directly. 1376 bool parseXMLDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)1376 bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission) 1377 1377 { 1378 1378 if (!chunk.length()) -
trunk/WebCore/dom/XMLDocumentParserQt.cpp
r61738 r61904 246 246 SegmentedString rest = m_pendingSrc; 247 247 m_pendingSrc.clear(); 248 write(rest, false);249 250 // Finally, if finish() has been called and write() didn't result248 append(rest); 249 250 // Finally, if finish() has been called and append() didn't result 251 251 // in any further callbacks being queued, call end() 252 252 if (m_finishCalled && !m_parserPaused && !m_pendingScript) … … 254 254 } 255 255 256 bool parseXMLDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)256 bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission) 257 257 { 258 258 if (!chunk.length()) … … 261 261 XMLDocumentParser parser(fragment, parent, scriptingPermission); 262 262 263 parser. write(String("<qxmlstreamdummyelement>"), false);264 parser. write(chunk, false);265 parser. write(String("</qxmlstreamdummyelement>"), false);263 parser.append(String("<qxmlstreamdummyelement>")); 264 parser.append(chunk); 265 parser.append(String("</qxmlstreamdummyelement>")); 266 266 parser.finish(); 267 267 return !parser.hasError(); -
trunk/WebCore/html/HTMLDocumentParser.cpp
r61835 r61904 214 214 } 215 215 216 void HTMLDocumentParser:: write(const SegmentedString& source, bool isFromNetwork)216 void HTMLDocumentParser::insert(const SegmentedString& source) 217 217 { 218 218 if (m_parserStopped) … … 220 220 221 221 NestingLevelIncrementer nestingLevelIncrementer(m_writeNestingLevel); 222 223 if (isFromNetwork) { 224 m_input.appendToEnd(source); 225 if (m_preloadScanner) 226 m_preloadScanner->appendToEnd(source); 227 228 if (m_writeNestingLevel > 1) { 229 // We've gotten data off the network in a nested call to write(). 230 // We don't want to consume any more of the input stream now. Do 231 // not worry. We'll consume this data in a less-nested write(). 232 return; 233 } 234 } else 235 m_input.insertAtCurrentInsertionPoint(source); 236 237 pumpTokenizerIfPossible(isFromNetwork ? AllowYield : ForceSynchronous); 222 m_input.insertAtCurrentInsertionPoint(source); 223 pumpTokenizerIfPossible(ForceSynchronous); 224 endIfDelayed(); 225 } 226 227 void HTMLDocumentParser::append(const SegmentedString& source) 228 { 229 if (m_parserStopped) 230 return; 231 232 NestingLevelIncrementer nestingLevelIncrementer(m_writeNestingLevel); 233 234 m_input.appendToEnd(source); 235 if (m_preloadScanner) 236 m_preloadScanner->appendToEnd(source); 237 238 if (m_writeNestingLevel > 1) { 239 // We've gotten data off the network in a nested write. 240 // We don't want to consume any more of the input stream now. Do 241 // not worry. We'll consume this data in a less-nested write(). 242 return; 243 } 244 245 pumpTokenizerIfPossible(AllowYield); 238 246 endIfDelayed(); 239 247 } … … 399 407 { 400 408 HTMLDocumentParser parser(fragment, scriptingPermission); 401 parser. write(source, false);409 parser.insert(source); // Use insert() so that the parser will not yield. 402 410 parser.finish(); 403 411 ASSERT(!parser.processingData()); // Make sure we're done. <rdar://problem/3963151> -
trunk/WebCore/html/HTMLDocumentParser.h
r61835 r61904 65 65 private: 66 66 // DocumentParser 67 virtual void begin();68 virtual void write(const SegmentedString&, bool isFromNetwork);67 virtual void insert(const SegmentedString&); 68 virtual void append(const SegmentedString&); 69 69 virtual void finish(); 70 70 virtual bool finishWasCalled(); … … 102 102 void resumeParsingAfterScriptExecution(); 103 103 104 void begin(); 104 105 void attemptToEnd(); 105 106 void endIfDelayed(); -
trunk/WebCore/html/LegacyHTMLDocumentParser.cpp
r61835 r61904 1792 1792 } 1793 1793 1794 void LegacyHTMLDocumentParser::insert(const SegmentedString& source) 1795 { 1796 // FIXME: forceSynchronous should always be the same as the bool passed to 1797 // write(). However LegacyHTMLDocumentParser uses write("", false) to pump 1798 // the parser (after running external scripts, etc.) thus necessitating a 1799 // separate state for forceSynchronous. 1800 bool wasForcedSynchronous = forceSynchronous(); 1801 setForceSynchronous(true); 1802 write(source, false); 1803 setForceSynchronous(wasForcedSynchronous); 1804 } 1805 1806 void LegacyHTMLDocumentParser::append(const SegmentedString& source) 1807 { 1808 write(source, true); 1809 } 1810 1794 1811 void LegacyHTMLDocumentParser::stopParsing() 1795 1812 { -
trunk/WebCore/html/LegacyHTMLDocumentParser.h
r61835 r61904 158 158 protected: 159 159 // Exposed for FTPDirectoryDocumentParser 160 virtual void write(const SegmentedString&, bool appendData);160 virtual void insert(const SegmentedString&); 161 161 virtual void finish(); 162 162 163 163 private: 164 164 // DocumentParser 165 virtual void append(const SegmentedString&); 165 166 virtual bool finishWasCalled(); 166 167 virtual bool isWaitingForScripts() const; … … 184 185 185 186 void willWriteHTML(const SegmentedString&); 187 void write(const SegmentedString&, bool appendData); 186 188 ALWAYS_INLINE void advance(State&); 187 189 void didWriteHTML(); -
trunk/WebCore/loader/DocumentWriter.cpp
r61868 r61904 77 77 // case then we would need to call addData(char*, int) instead. 78 78 if (DocumentParser* parser = m_frame->document()->parser()) 79 parser-> write(source, true);79 parser->append(source); 80 80 } 81 81 … … 204 204 if (parser) { 205 205 ASSERT(!parser->wantsRawData()); 206 parser-> write(decoded, true);206 parser->append(decoded); 207 207 } 208 208 } -
trunk/WebCore/loader/FTPDirectoryDocument.cpp
r61868 r61904 53 53 FTPDirectoryDocumentParser(HTMLDocument*); 54 54 55 virtual void write(const SegmentedString&, bool appendData);55 virtual void append(const SegmentedString&); 56 56 virtual void finish(); 57 57 … … 101 101 , m_buffer(static_cast<UChar*>(fastMalloc(sizeof(UChar) * m_size))) 102 102 , m_dest(m_buffer) 103 { 103 { 104 104 } 105 105 … … 302 302 return false; 303 303 } 304 305 // Tokenize the template as an HTML document synchronously 306 setForceSynchronous(true); 307 LegacyHTMLDocumentParser::write(String(templateDocumentData->data(), templateDocumentData->size()), true); 308 setForceSynchronous(false); 304 305 LegacyHTMLDocumentParser::insert(String(templateDocumentData->data(), templateDocumentData->size())); 309 306 310 307 RefPtr<Element> tableElement = document()->getElementById("ftpDirectoryTable"); … … 355 352 } 356 353 357 void FTPDirectoryDocumentParser:: write(const SegmentedString& s, bool /*appendData*/)358 { 354 void FTPDirectoryDocumentParser::append(const SegmentedString& source) 355 { 359 356 // Make sure we have the table element to append to by loading the template set in the pref, or 360 357 // creating a very basic document with the appropriate table … … 368 365 369 366 m_dest = m_buffer; 370 SegmentedString str = s ;367 SegmentedString str = source; 371 368 while (!str.isEmpty()) { 372 369 UChar c = *str; -
trunk/WebCore/loader/TextDocument.cpp
r61868 r61904 26 26 #include "TextDocument.h" 27 27 28 #include "DocumentParser.h" 28 29 #include "Element.h" 29 30 #include "HTMLNames.h" … … 31 32 #include "SegmentedString.h" 32 33 #include "Text.h" 33 #include "XMLDocumentParser.h"34 34 35 35 using namespace std; … … 46 46 47 47 private: 48 virtual void write(const SegmentedString&, bool appendData); 48 virtual void insert(const SegmentedString&); 49 virtual void append(const SegmentedString&); 49 50 virtual void finish(); 50 51 virtual bool finishWasCalled(); … … 100 101 } 101 102 102 void TextDocumentParser::write(const SegmentedString& s, bool) 103 void TextDocumentParser::insert(const SegmentedString&) 104 { 105 ASSERT_NOT_REACHED(); 106 } 107 108 void TextDocumentParser::append(const SegmentedString& s) 103 109 { 104 110 ExceptionCode ec; … … 163 169 { 164 170 if (!m_preElement) 165 write(SegmentedString(), true); // Create document structure for an empty text document.171 append(SegmentedString()); // Create document structure for an empty text document. 166 172 m_preElement = 0; 167 173 fastFree(m_buffer);
Note: See TracChangeset
for help on using the changeset viewer.