Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: Source/core/html/parser/HTMLDocumentParser.cpp

Issue 690793003: Threaded data provider: Support main thread data notifications (Blink side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
haraken 2015/01/16 04:58:36 DocumentLifecycleNotifier.h => DocumentLifecycleOb
oystein (OOO til 10th of July) 2015/01/16 05:04:37 Done.
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
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)
83 { 85 {
84 } 86 }
85 87
86 // WebThreadedDataReceiver 88 // WebThreadedDataReceiver
87 virtual void acceptData(const char* data, int dataLength) override final 89 virtual void acceptData(const char* data, int dataLength) override final
88 { 90 {
89 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); 91 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread());
90 if (m_backgroundParser.get()) 92 if (m_backgroundParser.get())
91 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength); 93 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength);
92 } 94 }
93 95
94 virtual blink::WebThread* backgroundThread() override final 96 virtual blink::WebThread* backgroundThread() override final
95 { 97 {
96 if (HTMLParserThread::shared()) 98 if (HTMLParserThread::shared())
97 return &HTMLParserThread::shared()->platformThread(); 99 return &HTMLParserThread::shared()->platformThread();
98 100
99 return nullptr; 101 return nullptr;
100 } 102 }
101 103
104 virtual bool needsMainthreadDataCopy() override final { return InspectorInst rumentation::hasFrontends(); }
105 virtual void acceptMainthreadDataNotification(const char* data, int dataLeng th, int encodedDataLength) override final
106 {
107 ASSERT(!data || needsMainthreadDataCopy());
108 if (lifecycleContext())
109 lifecycleContext()->loader()->acceptDataFromThreadedReceiver(data, d ataLength, encodedDataLength);
110 }
111
102 private: 112 private:
103 WeakPtr<BackgroundHTMLParser> m_backgroundParser; 113 WeakPtr<BackgroundHTMLParser> m_backgroundParser;
104 }; 114 };
105 115
106 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors , ParserSynchronizationPolicy syncPolicy) 116 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors , ParserSynchronizationPolicy syncPolicy)
107 : ScriptableDocumentParser(document) 117 : ScriptableDocumentParser(document)
108 , m_options(&document) 118 , m_options(&document)
109 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) : nullptr) 119 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) : nullptr)
110 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create( m_options) : nullptr) 120 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create( m_options) : nullptr)
111 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) 121 , m_scriptRunner(HTMLScriptRunner::create(&document, this))
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 void HTMLDocumentParser::startBackgroundParser() 729 void HTMLDocumentParser::startBackgroundParser()
720 { 730 {
721 ASSERT(!isStopped()); 731 ASSERT(!isStopped());
722 ASSERT(shouldUseThreading()); 732 ASSERT(shouldUseThreading());
723 ASSERT(!m_haveBackgroundParser); 733 ASSERT(!m_haveBackgroundParser);
724 m_haveBackgroundParser = true; 734 m_haveBackgroundParser = true;
725 735
726 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr oundHTMLParser>::createUnbound(); 736 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr oundHTMLParser>::createUnbound();
727 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); 737 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference);
728 738
729 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented. 739 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented.
haraken 2015/01/16 04:58:36 TODO => FIXME
oystein (OOO til 10th of July) 2015/01/16 05:04:37 Done.
730 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { 740 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) {
731 if (DocumentLoader* loader = document()->loader()) 741 if (DocumentLoader* loader = document()->loader())
732 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser))); 742 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser, document()->contextDocument().get())));
733 } 743 }
734 744
735 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); 745 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration);
736 config->options = m_options; 746 config->options = m_options;
737 config->parser = m_weakFactory.createWeakPtr(); 747 config->parser = m_weakFactory.createWeakPtr();
738 config->xssAuditor = adoptPtr(new XSSAuditor); 748 config->xssAuditor = adoptPtr(new XSSAuditor);
739 config->xssAuditor->init(document(), &m_xssAuditorDelegate); 749 config->xssAuditor->init(document(), &m_xssAuditorDelegate);
740 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document()))); 750 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document())));
741 config->decoder = takeDecoder(); 751 config->decoder = takeDecoder();
742 752
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1073 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1064 { 1074 {
1065 ASSERT(decoder); 1075 ASSERT(decoder);
1066 DecodedDataDocumentParser::setDecoder(decoder); 1076 DecodedDataDocumentParser::setDecoder(decoder);
1067 1077
1068 if (m_haveBackgroundParser) 1078 if (m_haveBackgroundParser)
1069 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1079 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1070 } 1080 }
1071 1081
1072 } 1082 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698