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 11 matching lines...) Expand all Loading... | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/html/parser/HTMLDocumentParser.h" | 27 #include "core/html/parser/HTMLDocumentParser.h" |
28 | 28 |
29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
30 #include "core/css/MediaValuesCached.h" | 30 #include "core/css/MediaValuesCached.h" |
31 #include "core/dom/DocumentFragment.h" | 31 #include "core/dom/DocumentFragment.h" |
32 #include "core/dom/DocumentLifecycleNotifier.h" | |
32 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
33 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
34 #include "core/html/HTMLDocument.h" | 35 #include "core/html/HTMLDocument.h" |
35 #include "core/html/parser/AtomicHTMLToken.h" | 36 #include "core/html/parser/AtomicHTMLToken.h" |
36 #include "core/html/parser/BackgroundHTMLParser.h" | 37 #include "core/html/parser/BackgroundHTMLParser.h" |
37 #include "core/html/parser/HTMLParserScheduler.h" | 38 #include "core/html/parser/HTMLParserScheduler.h" |
38 #include "core/html/parser/HTMLParserThread.h" | 39 #include "core/html/parser/HTMLParserThread.h" |
39 #include "core/html/parser/HTMLScriptRunner.h" | 40 #include "core/html/parser/HTMLScriptRunner.h" |
40 #include "core/html/parser/HTMLTreeBuilder.h" | 41 #include "core/html/parser/HTMLTreeBuilder.h" |
41 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
69 || (contextTag.matches(noscriptTag) && options.scriptEnabled) | 70 || (contextTag.matches(noscriptTag) && options.scriptEnabled) |
70 || contextTag.matches(noframesTag)) | 71 || contextTag.matches(noframesTag)) |
71 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN TEXTState; | 72 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN TEXTState; |
72 if (contextTag.matches(scriptTag)) | 73 if (contextTag.matches(scriptTag)) |
73 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL AINTEXTState; | 74 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL AINTEXTState; |
74 if (contextTag.matches(plaintextTag)) | 75 if (contextTag.matches(plaintextTag)) |
75 return HTMLTokenizer::PLAINTEXTState; | 76 return HTMLTokenizer::PLAINTEXTState; |
76 return HTMLTokenizer::DataState; | 77 return HTMLTokenizer::DataState; |
77 } | 78 } |
78 | 79 |
79 class ParserDataReceiver : public blink::WebThreadedDataReceiver { | 80 class ParserDataReceiver : public WebThreadedDataReceiver, public DocumentLifecy cleObserver { |
80 public: | 81 public: |
81 explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser) | 82 explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser, Document* document) |
82 : m_backgroundParser(backgroundParser) | 83 : DocumentLifecycleObserver(document) |
84 , m_backgroundParser(backgroundParser) | |
85 , m_document(document) | |
83 { | 86 { |
87 ASSERT(document); | |
88 document->lifecycleNotifier().addObserver(this); | |
haraken
2015/01/16 01:01:59
This won't be needed. DocumentLifecycleObserver's
oystein (OOO til 10th of July)
2015/01/16 04:31:49
Done.
| |
89 } | |
90 | |
91 virtual ~ParserDataReceiver() | |
92 { | |
93 if (m_document) | |
94 m_document->lifecycleNotifier().removeObserver(this); | |
haraken
2015/01/16 01:01:59
Ditto. DocumentLifecycleObserver's destructor will
oystein (OOO til 10th of July)
2015/01/16 04:31:49
Done.
| |
95 } | |
96 | |
97 // DocumentLifecycleObserver | |
98 virtual void documentWasDetached() override final | |
99 { | |
100 m_document = nullptr; | |
84 } | 101 } |
85 | 102 |
86 // WebThreadedDataReceiver | 103 // WebThreadedDataReceiver |
87 virtual void acceptData(const char* data, int dataLength) override final | 104 virtual void acceptData(const char* data, int dataLength) override final |
88 { | 105 { |
89 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); | 106 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); |
90 if (m_backgroundParser.get()) | 107 if (m_backgroundParser.get()) |
91 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength); | 108 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength); |
92 } | 109 } |
93 | 110 |
94 virtual blink::WebThread* backgroundThread() override final | 111 virtual blink::WebThread* backgroundThread() override final |
95 { | 112 { |
96 if (HTMLParserThread::shared()) | 113 if (HTMLParserThread::shared()) |
97 return &HTMLParserThread::shared()->platformThread(); | 114 return &HTMLParserThread::shared()->platformThread(); |
98 | 115 |
99 return nullptr; | 116 return nullptr; |
100 } | 117 } |
101 | 118 |
119 virtual bool needsMainthreadDataCopy() override final { return InspectorInst rumentation::hasFrontends(); } | |
120 virtual void acceptMainthreadDataNotification(const char* data, int dataLeng th, int encodedDataLength) override final | |
121 { | |
122 ASSERT(!data || needsMainthreadDataCopy()); | |
123 if (m_document) | |
124 m_document->loader()->acceptDataFromThreadedReceiver(data, dataLengt h, encodedDataLength); | |
125 } | |
126 | |
102 private: | 127 private: |
103 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 128 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
129 Document* m_document; | |
haraken
2015/01/16 01:01:59
Remove this. Instead you should use DocumentLifecy
oystein (OOO til 10th of July)
2015/01/16 04:31:49
Done.
| |
104 }; | 130 }; |
105 | 131 |
106 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors , ParserSynchronizationPolicy syncPolicy) | 132 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors , ParserSynchronizationPolicy syncPolicy) |
107 : ScriptableDocumentParser(document) | 133 : ScriptableDocumentParser(document) |
108 , m_options(&document) | 134 , m_options(&document) |
109 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) : nullptr) | 135 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) : nullptr) |
110 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create( m_options) : nullptr) | 136 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create( m_options) : nullptr) |
111 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) | 137 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) |
112 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy (), reportErrors, m_options)) | 138 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy (), reportErrors, m_options)) |
113 , m_parserScheduler(HTMLParserScheduler::create(this)) | 139 , m_parserScheduler(HTMLParserScheduler::create(this)) |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 ASSERT(shouldUseThreading()); | 748 ASSERT(shouldUseThreading()); |
723 ASSERT(!m_haveBackgroundParser); | 749 ASSERT(!m_haveBackgroundParser); |
724 m_haveBackgroundParser = true; | 750 m_haveBackgroundParser = true; |
725 | 751 |
726 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr oundHTMLParser>::createUnbound(); | 752 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr oundHTMLParser>::createUnbound(); |
727 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); | 753 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); |
728 | 754 |
729 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented. | 755 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented. |
730 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { | 756 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { |
731 if (DocumentLoader* loader = document()->loader()) | 757 if (DocumentLoader* loader = document()->loader()) |
732 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser))); | 758 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser, document()->contextDocument().get()))); |
733 } | 759 } |
734 | 760 |
735 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); | 761 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); |
736 config->options = m_options; | 762 config->options = m_options; |
737 config->parser = m_weakFactory.createWeakPtr(); | 763 config->parser = m_weakFactory.createWeakPtr(); |
738 config->xssAuditor = adoptPtr(new XSSAuditor); | 764 config->xssAuditor = adoptPtr(new XSSAuditor); |
739 config->xssAuditor->init(document(), &m_xssAuditorDelegate); | 765 config->xssAuditor->init(document(), &m_xssAuditorDelegate); |
740 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document()))); | 766 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document()))); |
741 config->decoder = takeDecoder(); | 767 config->decoder = takeDecoder(); |
742 | 768 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1089 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
1064 { | 1090 { |
1065 ASSERT(decoder); | 1091 ASSERT(decoder); |
1066 DecodedDataDocumentParser::setDecoder(decoder); | 1092 DecodedDataDocumentParser::setDecoder(decoder); |
1067 | 1093 |
1068 if (m_haveBackgroundParser) | 1094 if (m_haveBackgroundParser) |
1069 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); | 1095 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); |
1070 } | 1096 } |
1071 | 1097 |
1072 } | 1098 } |
OLD | NEW |