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

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: Added test Created 6 years, 1 month 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 || (contextTag.matches(noscriptTag) && options.scriptEnabled) 68 || (contextTag.matches(noscriptTag) && options.scriptEnabled)
69 || contextTag.matches(noframesTag)) 69 || contextTag.matches(noframesTag))
70 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN TEXTState; 70 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN TEXTState;
71 if (contextTag.matches(scriptTag)) 71 if (contextTag.matches(scriptTag))
72 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL AINTEXTState; 72 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL AINTEXTState;
73 if (contextTag.matches(plaintextTag)) 73 if (contextTag.matches(plaintextTag))
74 return HTMLTokenizer::PLAINTEXTState; 74 return HTMLTokenizer::PLAINTEXTState;
75 return HTMLTokenizer::DataState; 75 return HTMLTokenizer::DataState;
76 } 76 }
77 77
78 class ParserDataReceiver : public blink::WebThreadedDataReceiver { 78 class ParserDataReceiver : public WebThreadedDataReceiver {
79 public: 79 public:
80 explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser) 80 explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser, WeakPtrWillBeRawPtr<Document> document)
81 : m_backgroundParser(backgroundParser) 81 : m_backgroundParser(backgroundParser)
82 , m_document(document)
82 { 83 {
84 m_needMainthreadDataCopy = InspectorInstrumentation::hasFrontends();
yurys 2014/11/12 06:47:09 It is safe to read InspectorInstrumentation::hasFr
oystein (OOO til 10th of July) 2014/11/17 18:41:42 Done.
83 } 85 }
84 86
85 // WebThreadedDataReceiver 87 // WebThreadedDataReceiver
86 virtual void acceptData(const char* data, int dataLength) override final 88 virtual void acceptData(const char* data, int dataLength) override final
87 { 89 {
88 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); 90 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread());
89 if (m_backgroundParser.get()) 91 if (m_backgroundParser.get())
90 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength); 92 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength);
91 } 93 }
92 94
93 virtual blink::WebThread* backgroundThread() override final 95 virtual blink::WebThread* backgroundThread() override final
94 { 96 {
95 if (HTMLParserThread::shared()) 97 if (HTMLParserThread::shared())
96 return &HTMLParserThread::shared()->platformThread(); 98 return &HTMLParserThread::shared()->platformThread();
97 99
98 return 0; 100 return 0;
99 } 101 }
100 102
103 virtual bool needsMainthreadDataCopy() override final { return m_needMainthr eadDataCopy; }
104 virtual void acceptMainthreadDataNotification(const char* data, int dataLeng th, int encodedDataLength) override final
105 {
106 ASSERT(!data || m_needMainthreadDataCopy);
107 if (m_document.get())
108 m_document.get()->loader()->acceptDataFromThreadedReceiver(data, dat aLength, encodedDataLength);
109 }
110
101 private: 111 private:
102 WeakPtr<BackgroundHTMLParser> m_backgroundParser; 112 WeakPtr<BackgroundHTMLParser> m_backgroundParser;
113 WeakPtrWillBeRawPtr<Document> m_document;
114 bool m_needMainthreadDataCopy;
103 }; 115 };
104 116
105 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors ) 117 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors )
106 : ScriptableDocumentParser(document) 118 : ScriptableDocumentParser(document)
107 , m_options(&document) 119 , m_options(&document)
108 , m_token(nullptr) 120 , m_token(nullptr)
109 , m_tokenizer(nullptr) 121 , m_tokenizer(nullptr)
110 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) 122 , m_scriptRunner(HTMLScriptRunner::create(&document, this))
111 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy (), reportErrors, m_options)) 123 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy (), reportErrors, m_options))
112 , m_parserScheduler(HTMLParserScheduler::create(this)) 124 , m_parserScheduler(HTMLParserScheduler::create(this))
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 ASSERT(shouldUseThreading()); 717 ASSERT(shouldUseThreading());
706 ASSERT(!m_haveBackgroundParser); 718 ASSERT(!m_haveBackgroundParser);
707 m_haveBackgroundParser = true; 719 m_haveBackgroundParser = true;
708 720
709 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound(); 721 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound();
710 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); 722 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference);
711 723
712 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented. 724 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented.
713 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { 725 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) {
714 if (DocumentLoader* loader = document()->loader()) 726 if (DocumentLoader* loader = document()->loader())
715 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser))); 727 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser, document()->contextDocument())));
716 } 728 }
717 729
718 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); 730 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration);
719 config->options = m_options; 731 config->options = m_options;
720 config->parser = m_weakFactory.createWeakPtr(); 732 config->parser = m_weakFactory.createWeakPtr();
721 config->xssAuditor = adoptPtr(new XSSAuditor); 733 config->xssAuditor = adoptPtr(new XSSAuditor);
722 config->xssAuditor->init(document(), &m_xssAuditorDelegate); 734 config->xssAuditor->init(document(), &m_xssAuditorDelegate);
723 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document()))); 735 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document())));
724 config->decoder = takeDecoder(); 736 config->decoder = takeDecoder();
725 737
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1050 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1039 { 1051 {
1040 ASSERT(decoder); 1052 ASSERT(decoder);
1041 DecodedDataDocumentParser::setDecoder(decoder); 1053 DecodedDataDocumentParser::setDecoder(decoder);
1042 1054
1043 if (m_haveBackgroundParser) 1055 if (m_haveBackgroundParser)
1044 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1056 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1045 } 1057 }
1046 1058
1047 } 1059 }
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