| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/Element.h" | 32 #include "core/dom/Element.h" |
| 33 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
| 34 #include "core/html/HTMLDocument.h" | 34 #include "core/html/HTMLDocument.h" |
| 35 #include "core/html/parser/AtomicHTMLToken.h" | 35 #include "core/html/parser/AtomicHTMLToken.h" |
| 36 #include "core/html/parser/BackgroundHTMLParser.h" | 36 #include "core/html/parser/BackgroundHTMLParser.h" |
| 37 #include "core/html/parser/HTMLParserScheduler.h" | 37 #include "core/html/parser/HTMLParserScheduler.h" |
| 38 #include "core/html/parser/HTMLParserThread.h" | 38 #include "core/html/parser/HTMLParserThread.h" |
| 39 #include "core/html/parser/HTMLScriptRunner.h" | 39 #include "core/html/parser/HTMLScriptRunner.h" |
| 40 #include "core/html/parser/HTMLTreeBuilder.h" | 40 #include "core/html/parser/HTMLTreeBuilder.h" |
| 41 #include "core/inspector/InspectorInstrumentation.h" | 41 #include "core/inspector/InspectorInstrumentation.h" |
| 42 #include "core/loader/DocumentLoader.h" |
| 42 #include "platform/SharedBuffer.h" | 43 #include "platform/SharedBuffer.h" |
| 43 #include "platform/TraceEvent.h" | 44 #include "platform/TraceEvent.h" |
| 45 #include "public/platform/WebThreadedDataReceiver.h" |
| 44 #include "wtf/Functional.h" | 46 #include "wtf/Functional.h" |
| 45 | 47 |
| 46 namespace WebCore { | 48 namespace WebCore { |
| 47 | 49 |
| 48 using namespace HTMLNames; | 50 using namespace HTMLNames; |
| 49 | 51 |
| 50 // This is a direct transcription of step 4 from: | 52 // This is a direct transcription of step 4 from: |
| 51 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#frag
ment-case | 53 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#frag
ment-case |
| 52 static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem
ent, bool reportErrors, const HTMLParserOptions& options) | 54 static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem
ent, bool reportErrors, const HTMLParserOptions& options) |
| 53 { | 55 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 || (contextTag.matches(noscriptTag) && options.scriptEnabled) | 67 || (contextTag.matches(noscriptTag) && options.scriptEnabled) |
| 66 || contextTag.matches(noframesTag)) | 68 || contextTag.matches(noframesTag)) |
| 67 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN
TEXTState; | 69 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN
TEXTState; |
| 68 if (contextTag.matches(scriptTag)) | 70 if (contextTag.matches(scriptTag)) |
| 69 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; | 71 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; |
| 70 if (contextTag.matches(plaintextTag)) | 72 if (contextTag.matches(plaintextTag)) |
| 71 return HTMLTokenizer::PLAINTEXTState; | 73 return HTMLTokenizer::PLAINTEXTState; |
| 72 return HTMLTokenizer::DataState; | 74 return HTMLTokenizer::DataState; |
| 73 } | 75 } |
| 74 | 76 |
| 77 class ParserDataReceiver : public blink::WebThreadedDataReceiver { |
| 78 public: |
| 79 explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser) |
| 80 : m_backgroundParser(backgroundParser) |
| 81 { |
| 82 } |
| 83 |
| 84 // WebThreadedDataReceiver |
| 85 virtual void acceptData(const char* data, int dataLength) OVERRIDE FINAL |
| 86 { |
| 87 ASSERT(backgroundThread()->isCurrentThread()); |
| 88 if (m_backgroundParser.get()) |
| 89 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL
ength); |
| 90 } |
| 91 |
| 92 virtual blink::WebThread* backgroundThread() OVERRIDE FINAL |
| 93 { |
| 94 return &HTMLParserThread::shared()->platformThread(); |
| 95 } |
| 96 |
| 97 private: |
| 98 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
| 99 }; |
| 100 |
| 75 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument* document, bool reportErrors
) | 101 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument* document, bool reportErrors
) |
| 76 : ScriptableDocumentParser(document) | 102 : ScriptableDocumentParser(document) |
| 77 , m_options(document) | 103 , m_options(document) |
| 78 , m_token(m_options.useThreading ? nullptr : adoptPtr(new HTMLToken)) | 104 , m_token(m_options.useThreading ? nullptr : adoptPtr(new HTMLToken)) |
| 79 , m_tokenizer(m_options.useThreading ? nullptr : HTMLTokenizer::create(m_opt
ions)) | 105 , m_tokenizer(m_options.useThreading ? nullptr : HTMLTokenizer::create(m_opt
ions)) |
| 80 , m_scriptRunner(HTMLScriptRunner::create(document, this)) | 106 , m_scriptRunner(HTMLScriptRunner::create(document, this)) |
| 81 , m_treeBuilder(HTMLTreeBuilder::create(this, document, parserContentPolicy(
), reportErrors, m_options)) | 107 , m_treeBuilder(HTMLTreeBuilder::create(this, document, parserContentPolicy(
), reportErrors, m_options)) |
| 82 , m_parserScheduler(HTMLParserScheduler::create(this)) | 108 , m_parserScheduler(HTMLParserScheduler::create(this)) |
| 83 , m_xssAuditorDelegate(document) | 109 , m_xssAuditorDelegate(document) |
| 84 , m_weakFactory(this) | 110 , m_weakFactory(this) |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 void HTMLDocumentParser::startBackgroundParser() | 694 void HTMLDocumentParser::startBackgroundParser() |
| 669 { | 695 { |
| 670 ASSERT(!isStopped()); | 696 ASSERT(!isStopped()); |
| 671 ASSERT(shouldUseThreading()); | 697 ASSERT(shouldUseThreading()); |
| 672 ASSERT(!m_haveBackgroundParser); | 698 ASSERT(!m_haveBackgroundParser); |
| 673 m_haveBackgroundParser = true; | 699 m_haveBackgroundParser = true; |
| 674 | 700 |
| 675 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg
roundHTMLParser>::createUnbound(); | 701 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg
roundHTMLParser>::createUnbound(); |
| 676 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); | 702 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); |
| 677 | 703 |
| 704 document()->loader()->attachThreadedDataReceiver(adoptPtr(new ParserDataRece
iver(m_backgroundParser))); |
| 705 |
| 678 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); | 706 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); |
| 679 config->options = m_options; | 707 config->options = m_options; |
| 680 config->parser = m_weakFactory.createWeakPtr(); | 708 config->parser = m_weakFactory.createWeakPtr(); |
| 681 config->xssAuditor = adoptPtr(new XSSAuditor); | 709 config->xssAuditor = adoptPtr(new XSSAuditor); |
| 682 config->xssAuditor->init(document(), &m_xssAuditorDelegate); | 710 config->xssAuditor->init(document(), &m_xssAuditorDelegate); |
| 683 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), createMediaValues(document()))); | 711 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), createMediaValues(document()))); |
| 684 config->decoder = takeDecoder(); | 712 config->decoder = takeDecoder(); |
| 685 | 713 |
| 686 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); | 714 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); |
| 687 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); | 715 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 return; | 1005 return; |
| 978 | 1006 |
| 979 if (shouldUseThreading()) { | 1007 if (shouldUseThreading()) { |
| 980 if (!m_haveBackgroundParser) | 1008 if (!m_haveBackgroundParser) |
| 981 startBackgroundParser(); | 1009 startBackgroundParser(); |
| 982 | 1010 |
| 983 OwnPtr<Vector<char> > buffer = adoptPtr(new Vector<char>(length)); | 1011 OwnPtr<Vector<char> > buffer = adoptPtr(new Vector<char>(length)); |
| 984 memcpy(buffer->data(), data, length); | 1012 memcpy(buffer->data(), data, length); |
| 985 TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned
)length); | 1013 TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned
)length); |
| 986 | 1014 |
| 987 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendB
ytes, m_backgroundParser, buffer.release())); | 1015 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendR
awBytesFromMainThread, m_backgroundParser, buffer.release())); |
| 988 return; | 1016 return; |
| 989 } | 1017 } |
| 990 | 1018 |
| 991 DecodedDataDocumentParser::appendBytes(data, length); | 1019 DecodedDataDocumentParser::appendBytes(data, length); |
| 992 } | 1020 } |
| 993 | 1021 |
| 994 void HTMLDocumentParser::flush() | 1022 void HTMLDocumentParser::flush() |
| 995 { | 1023 { |
| 996 // If we've got no decoder, we never received any data. | 1024 // If we've got no decoder, we never received any data. |
| 997 if (isDetached() || needsDecoder()) | 1025 if (isDetached() || needsDecoder()) |
| 998 return; | 1026 return; |
| 999 | 1027 |
| 1000 if (m_haveBackgroundParser) | 1028 if (m_haveBackgroundParser) |
| 1001 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::flush,
m_backgroundParser)); | 1029 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::flush,
m_backgroundParser)); |
| 1002 else | 1030 else |
| 1003 DecodedDataDocumentParser::flush(); | 1031 DecodedDataDocumentParser::flush(); |
| 1004 } | 1032 } |
| 1005 | 1033 |
| 1006 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1034 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| 1007 { | 1035 { |
| 1008 ASSERT(decoder); | 1036 ASSERT(decoder); |
| 1009 DecodedDataDocumentParser::setDecoder(decoder); | 1037 DecodedDataDocumentParser::setDecoder(decoder); |
| 1010 | 1038 |
| 1011 if (m_haveBackgroundParser) | 1039 if (m_haveBackgroundParser) |
| 1012 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); | 1040 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); |
| 1013 } | 1041 } |
| 1014 | 1042 |
| 1015 } | 1043 } |
| OLD | NEW |