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

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

Issue 656723005: Use C++11 features in core/html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: mike's comments 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
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread()); 88 ASSERT(backgroundThread() && backgroundThread()->isCurrentThread());
89 if (m_backgroundParser.get()) 89 if (m_backgroundParser.get())
90 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength); 90 m_backgroundParser.get()->appendRawBytesFromParserThread(data, dataL ength);
91 } 91 }
92 92
93 virtual blink::WebThread* backgroundThread() override final 93 virtual blink::WebThread* backgroundThread() override final
94 { 94 {
95 if (HTMLParserThread::shared()) 95 if (HTMLParserThread::shared())
96 return &HTMLParserThread::shared()->platformThread(); 96 return &HTMLParserThread::shared()->platformThread();
97 97
98 return 0; 98 return nullptr;
99 } 99 }
100 100
101 private: 101 private:
102 WeakPtr<BackgroundHTMLParser> m_backgroundParser; 102 WeakPtr<BackgroundHTMLParser> m_backgroundParser;
103 }; 103 };
104 104
105 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors ) 105 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors )
106 : ScriptableDocumentParser(document) 106 : ScriptableDocumentParser(document)
107 , m_options(&document) 107 , m_options(&document)
108 , m_token(nullptr) 108 , m_token(nullptr)
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 ASSERT(shouldUseThreading()); 428 ASSERT(shouldUseThreading());
429 ASSERT(!m_tokenizer); 429 ASSERT(!m_tokenizer);
430 ASSERT(!m_token); 430 ASSERT(!m_token);
431 ASSERT(!m_lastChunkBeforeScript); 431 ASSERT(!m_lastChunkBeforeScript);
432 432
433 OwnPtr<ParsedChunk> chunk(popChunk); 433 OwnPtr<ParsedChunk> chunk(popChunk);
434 OwnPtr<CompactHTMLTokenStream> tokens = chunk->tokens.release(); 434 OwnPtr<CompactHTMLTokenStream> tokens = chunk->tokens.release();
435 435
436 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::startedChun kWithCheckpoint, m_backgroundParser, chunk->inputCheckpoint)); 436 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::startedChun kWithCheckpoint, m_backgroundParser, chunk->inputCheckpoint));
437 437
438 for (XSSInfoStream::const_iterator it = chunk->xssInfos.begin(); it != chunk ->xssInfos.end(); ++it) { 438 for (const auto& xssInfo : chunk->xssInfos) {
439 m_textPosition = (*it)->m_textPosition; 439 m_textPosition = xssInfo->m_textPosition;
440 m_xssAuditorDelegate.didBlockScript(**it); 440 m_xssAuditorDelegate.didBlockScript(*xssInfo);
441 if (isStopped()) 441 if (isStopped())
442 break; 442 break;
443 } 443 }
444 444
445 for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != to kens->end(); ++it) { 445 for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != to kens->end(); ++it) {
446 ASSERT(!isWaitingForScripts()); 446 ASSERT(!isWaitingForScripts());
447 447
448 if (document()->frame() && document()->frame()->navigationScheduler().lo cationChangePending()) { 448 if (document()->frame() && document()->frame()->navigationScheduler().lo cationChangePending()) {
449 449
450 // To match main-thread parser behavior (which never checks location ChangePending on the EOF path) 450 // To match main-thread parser behavior (which never checks location ChangePending on the EOF path)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePl aintextForTextDocument, m_backgroundParser)); 536 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePl aintextForTextDocument, m_backgroundParser));
537 } else 537 } else
538 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); 538 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState);
539 } 539 }
540 540
541 Document* HTMLDocumentParser::contextForParsingSession() 541 Document* HTMLDocumentParser::contextForParsingSession()
542 { 542 {
543 // The parsing session should interact with the document only when parsing 543 // The parsing session should interact with the document only when parsing
544 // non-fragments. Otherwise, we might delay the load event mistakenly. 544 // non-fragments. Otherwise, we might delay the load event mistakenly.
545 if (isParsingFragment()) 545 if (isParsingFragment())
546 return 0; 546 return nullptr;
547 return document(); 547 return document();
548 } 548 }
549 549
550 static PassRefPtr<MediaValues> createMediaValues(Document* document) 550 static PassRefPtr<MediaValues> createMediaValues(Document* document)
551 { 551 {
552 ASSERT(document); 552 ASSERT(document);
553 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(*document); 553 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(*document);
554 ASSERT(mediaValues->isSafeToSendToAnotherThread()); 554 ASSERT(mediaValues->isSafeToSendToAnotherThread());
555 return mediaValues; 555 return mediaValues;
556 } 556 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 endIfDelayed(); 709 endIfDelayed();
710 } 710 }
711 711
712 void HTMLDocumentParser::startBackgroundParser() 712 void HTMLDocumentParser::startBackgroundParser()
713 { 713 {
714 ASSERT(!isStopped()); 714 ASSERT(!isStopped());
715 ASSERT(shouldUseThreading()); 715 ASSERT(shouldUseThreading());
716 ASSERT(!m_haveBackgroundParser); 716 ASSERT(!m_haveBackgroundParser);
717 m_haveBackgroundParser = true; 717 m_haveBackgroundParser = true;
718 718
719 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound(); 719 RefPtr<WeakReference<BackgroundHTMLParser>> reference = WeakReference<Backgr oundHTMLParser>::createUnbound();
720 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); 720 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference);
721 721
722 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented. 722 // TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented.
723 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) { 723 if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) {
724 if (DocumentLoader* loader = document()->loader()) 724 if (DocumentLoader* loader = document()->loader())
725 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser))); 725 loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m _backgroundParser)));
726 } 726 }
727 727
728 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); 728 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration);
729 config->options = m_options; 729 config->options = m_options;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1015
1016 void HTMLDocumentParser::appendBytes(const char* data, size_t length) 1016 void HTMLDocumentParser::appendBytes(const char* data, size_t length)
1017 { 1017 {
1018 if (!length || isStopped()) 1018 if (!length || isStopped())
1019 return; 1019 return;
1020 1020
1021 if (shouldUseThreading()) { 1021 if (shouldUseThreading()) {
1022 if (!m_haveBackgroundParser) 1022 if (!m_haveBackgroundParser)
1023 startBackgroundParser(); 1023 startBackgroundParser();
1024 1024
1025 OwnPtr<Vector<char> > buffer = adoptPtr(new Vector<char>(length)); 1025 OwnPtr<Vector<char>> buffer = adoptPtr(new Vector<char>(length));
1026 memcpy(buffer->data(), data, length); 1026 memcpy(buffer->data(), data, length);
1027 TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned )length); 1027 TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned )length);
1028 1028
1029 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendR awBytesFromMainThread, m_backgroundParser, buffer.release())); 1029 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendR awBytesFromMainThread, m_backgroundParser, buffer.release()));
1030 return; 1030 return;
1031 } 1031 }
1032 1032
1033 DecodedDataDocumentParser::appendBytes(data, length); 1033 DecodedDataDocumentParser::appendBytes(data, length);
1034 } 1034 }
1035 1035
(...skipping 12 matching lines...) Expand all
1048 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1048 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1049 { 1049 {
1050 ASSERT(decoder); 1050 ASSERT(decoder);
1051 DecodedDataDocumentParser::setDecoder(decoder); 1051 DecodedDataDocumentParser::setDecoder(decoder);
1052 1052
1053 if (m_haveBackgroundParser) 1053 if (m_haveBackgroundParser)
1054 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1054 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1055 } 1055 }
1056 1056
1057 } 1057 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLDocumentParser.h ('k') | Source/core/html/parser/HTMLElementStack.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698