| 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/DocumentLifecycleObserver.h" | 32 #include "core/dom/DocumentLifecycleObserver.h" |
| 33 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
| 34 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
| 35 #include "core/html/HTMLDocument.h" | 35 #include "core/html/HTMLDocument.h" |
| 36 #include "core/html/parser/AtomicHTMLToken.h" | 36 #include "core/html/parser/AtomicHTMLToken.h" |
| 37 #include "core/html/parser/BackgroundHTMLParser.h" | 37 #include "core/html/parser/BackgroundHTMLParser.h" |
| 38 #include "core/html/parser/HTMLParserScheduler.h" | 38 #include "core/html/parser/HTMLParserScheduler.h" |
| 39 #include "core/html/parser/HTMLParserThread.h" | 39 #include "core/html/parser/HTMLParserThread.h" |
| 40 #include "core/html/parser/HTMLScriptRunner.h" | 40 #include "core/html/parser/HTMLScriptRunner.h" |
| 41 #include "core/html/parser/HTMLTreeBuilder.h" | 41 #include "core/html/parser/HTMLTreeBuilder.h" |
| 42 #include "core/html/parser/ThreadedDataReceiver.h" |
| 42 #include "core/inspector/InspectorInstrumentation.h" | 43 #include "core/inspector/InspectorInstrumentation.h" |
| 43 #include "core/inspector/InspectorTraceEvents.h" | 44 #include "core/inspector/InspectorTraceEvents.h" |
| 44 #include "core/loader/DocumentLoader.h" | 45 #include "core/loader/DocumentLoader.h" |
| 45 #include "platform/SharedBuffer.h" | 46 #include "platform/SharedBuffer.h" |
| 46 #include "platform/TraceEvent.h" | 47 #include "platform/TraceEvent.h" |
| 47 #include "public/platform/WebThreadedDataReceiver.h" | 48 #include "platform/heap/Handle.h" |
| 48 #include "wtf/Functional.h" | 49 #include "wtf/Functional.h" |
| 50 #include "wtf/RefCounted.h" |
| 49 #include "wtf/TemporaryChange.h" | 51 #include "wtf/TemporaryChange.h" |
| 50 | 52 |
| 51 namespace blink { | 53 namespace blink { |
| 52 | 54 |
| 53 using namespace HTMLNames; | 55 using namespace HTMLNames; |
| 54 | 56 |
| 55 // This is a direct transcription of step 4 from: | 57 // This is a direct transcription of step 4 from: |
| 56 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#frag
ment-case | 58 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#frag
ment-case |
| 57 static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem
ent, bool reportErrors, const HTMLParserOptions& options) | 59 static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem
ent, bool reportErrors, const HTMLParserOptions& options) |
| 58 { | 60 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 70 || (contextTag.matches(noscriptTag) && options.scriptEnabled) | 72 || (contextTag.matches(noscriptTag) && options.scriptEnabled) |
| 71 || contextTag.matches(noframesTag)) | 73 || contextTag.matches(noframesTag)) |
| 72 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN
TEXTState; | 74 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN
TEXTState; |
| 73 if (contextTag.matches(scriptTag)) | 75 if (contextTag.matches(scriptTag)) |
| 74 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; | 76 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; |
| 75 if (contextTag.matches(plaintextTag)) | 77 if (contextTag.matches(plaintextTag)) |
| 76 return HTMLTokenizer::PLAINTEXTState; | 78 return HTMLTokenizer::PLAINTEXTState; |
| 77 return HTMLTokenizer::DataState; | 79 return HTMLTokenizer::DataState; |
| 78 } | 80 } |
| 79 | 81 |
| 80 class ParserDataReceiver : public WebThreadedDataReceiver, public DocumentLifecy
cleObserver { | 82 class ParserDataReceiver final : public RefCountedWillBeGarbageCollectedFinalize
d<ParserDataReceiver>, public ThreadedDataReceiver, public DocumentLifecycleObse
rver { |
| 83 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ParserDataReceiver); |
| 81 public: | 84 public: |
| 82 explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser,
Document* document) | 85 static PassRefPtrWillBeRawPtr<ParserDataReceiver> create(WeakPtr<BackgroundH
TMLParser> backgroundParser, Document* document) |
| 83 : DocumentLifecycleObserver(document) | |
| 84 , m_backgroundParser(backgroundParser) | |
| 85 { | 86 { |
| 87 return adoptRefWillBeNoop(new ParserDataReceiver(backgroundParser, docum
ent)); |
| 86 } | 88 } |
| 87 | 89 |
| 88 // WebThreadedDataReceiver | 90 #if !ENABLE(OILPAN) |
| 89 virtual void acceptData(const char* data, int dataLength) override final | 91 virtual void ref() override { RefCounted<ParserDataReceiver>::ref(); } |
| 92 virtual void deref() override { RefCounted<ParserDataReceiver>::deref(); } |
| 93 #endif |
| 94 |
| 95 // ThreadedDataReceiver |
| 96 void acceptData(const char* data, int dataLength) override |
| 90 { | 97 { |
| 91 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); | 98 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); |
| 92 if (m_backgroundParser.get()) | 99 if (m_backgroundParser.get()) |
| 93 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL
ength); | 100 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL
ength); |
| 94 } | 101 } |
| 95 | 102 |
| 96 virtual blink::WebThread* backgroundThread() override final | 103 WebThread* backgroundThread() override |
| 97 { | 104 { |
| 98 if (HTMLParserThread::shared()) | 105 if (HTMLParserThread::shared()) |
| 99 return &HTMLParserThread::shared()->platformThread(); | 106 return &HTMLParserThread::shared()->platformThread(); |
| 100 | 107 |
| 101 return nullptr; | 108 return nullptr; |
| 102 } | 109 } |
| 103 | 110 |
| 104 virtual bool needsMainthreadDataCopy() override final { return InspectorInst
rumentation::hasFrontends(); } | 111 bool needsMainthreadDataCopy() override { return InspectorInstrumentation::h
asFrontends(); } |
| 105 virtual void acceptMainthreadDataNotification(const char* data, int dataLeng
th, int encodedDataLength) override final | 112 void acceptMainthreadDataNotification(const char* data, int dataLength, int
encodedDataLength) override |
| 106 { | 113 { |
| 107 ASSERT(!data || needsMainthreadDataCopy()); | 114 ASSERT(!data || needsMainthreadDataCopy()); |
| 108 if (lifecycleContext()) | 115 if (lifecycleContext()) |
| 109 lifecycleContext()->loader()->acceptDataFromThreadedReceiver(data, d
ataLength, encodedDataLength); | 116 lifecycleContext()->loader()->acceptDataFromThreadedReceiver(data, d
ataLength, encodedDataLength); |
| 110 } | 117 } |
| 111 | 118 |
| 119 void trace(Visitor* visitor) override |
| 120 { |
| 121 DocumentLifecycleObserver::trace(visitor); |
| 122 } |
| 123 |
| 112 private: | 124 private: |
| 125 ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser, Document*
document) |
| 126 : DocumentLifecycleObserver(document) |
| 127 , m_backgroundParser(backgroundParser) |
| 128 { |
| 129 } |
| 130 |
| 113 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 131 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
| 114 }; | 132 }; |
| 115 | 133 |
| 116 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
, ParserSynchronizationPolicy syncPolicy) | 134 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
, ParserSynchronizationPolicy syncPolicy) |
| 117 : ScriptableDocumentParser(document) | 135 : ScriptableDocumentParser(document) |
| 118 , m_options(&document) | 136 , m_options(&document) |
| 119 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) :
nullptr) | 137 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) :
nullptr) |
| 120 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) | 138 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) |
| 121 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) | 139 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) |
| 122 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) | 140 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 ASSERT(shouldUseThreading()); | 766 ASSERT(shouldUseThreading()); |
| 749 ASSERT(!m_haveBackgroundParser); | 767 ASSERT(!m_haveBackgroundParser); |
| 750 m_haveBackgroundParser = true; | 768 m_haveBackgroundParser = true; |
| 751 | 769 |
| 752 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr
oundHTMLParser>::createUnbound(); | 770 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr
oundHTMLParser>::createUnbound(); |
| 753 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); | 771 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); |
| 754 | 772 |
| 755 // FIXME(oysteine): Disabled due to crbug.com/398076 until a full fix can be
implemented. | 773 // FIXME(oysteine): Disabled due to crbug.com/398076 until a full fix can be
implemented. |
| 756 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { | 774 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { |
| 757 if (DocumentLoader* loader = document()->loader()) | 775 if (DocumentLoader* loader = document()->loader()) |
| 758 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m
_backgroundParser, document()->contextDocument().get()))); | 776 loader->attachThreadedDataReceiver(ParserDataReceiver::create(m_back
groundParser, document()->contextDocument().get())); |
| 759 } | 777 } |
| 760 | 778 |
| 761 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); | 779 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); |
| 762 config->options = m_options; | 780 config->options = m_options; |
| 763 config->parser = m_weakFactory.createWeakPtr(); | 781 config->parser = m_weakFactory.createWeakPtr(); |
| 764 config->xssAuditor = adoptPtr(new XSSAuditor); | 782 config->xssAuditor = adoptPtr(new XSSAuditor); |
| 765 config->xssAuditor->init(document(), &m_xssAuditorDelegate); | 783 config->xssAuditor->init(document(), &m_xssAuditorDelegate); |
| 766 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), createMediaValues(document()))); | 784 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), createMediaValues(document()))); |
| 767 config->decoder = takeDecoder(); | 785 config->decoder = takeDecoder(); |
| 768 | 786 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1107 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| 1090 { | 1108 { |
| 1091 ASSERT(decoder); | 1109 ASSERT(decoder); |
| 1092 DecodedDataDocumentParser::setDecoder(decoder); | 1110 DecodedDataDocumentParser::setDecoder(decoder); |
| 1093 | 1111 |
| 1094 if (m_haveBackgroundParser) | 1112 if (m_haveBackgroundParser) |
| 1095 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); | 1113 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); |
| 1096 } | 1114 } |
| 1097 | 1115 |
| 1098 } | 1116 } |
| OLD | NEW |