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

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

Issue 201813002: Enable Media query evaluation in the preload scanner (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed GC transition types and commented code Created 6 years, 9 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
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "HTMLNames.h" 29 #include "HTMLNames.h"
30 #include "core/css/MediaQueryEvaluator.h"
30 #include "core/dom/DocumentFragment.h" 31 #include "core/dom/DocumentFragment.h"
31 #include "core/dom/Element.h" 32 #include "core/dom/Element.h"
32 #include "core/frame/LocalFrame.h" 33 #include "core/frame/LocalFrame.h"
33 #include "core/html/HTMLDocument.h" 34 #include "core/html/HTMLDocument.h"
34 #include "core/html/parser/AtomicHTMLToken.h" 35 #include "core/html/parser/AtomicHTMLToken.h"
35 #include "core/html/parser/BackgroundHTMLParser.h" 36 #include "core/html/parser/BackgroundHTMLParser.h"
36 #include "core/html/parser/HTMLParserScheduler.h" 37 #include "core/html/parser/HTMLParserScheduler.h"
37 #include "core/html/parser/HTMLParserThread.h" 38 #include "core/html/parser/HTMLParserThread.h"
38 #include "core/html/parser/HTMLScriptRunner.h" 39 #include "core/html/parser/HTMLScriptRunner.h"
39 #include "core/html/parser/HTMLTreeBuilder.h" 40 #include "core/html/parser/HTMLTreeBuilder.h"
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 489
489 InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt()); 490 InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt());
490 } 491 }
491 492
492 void HTMLDocumentParser::forcePlaintextForTextDocument() 493 void HTMLDocumentParser::forcePlaintextForTextDocument()
493 { 494 {
494 if (shouldUseThreading()) { 495 if (shouldUseThreading()) {
495 // This method is called before any data is appended, so we have to star t 496 // This method is called before any data is appended, so we have to star t
496 // the background parser ourselves. 497 // the background parser ourselves.
497 if (!m_haveBackgroundParser) 498 if (!m_haveBackgroundParser)
498 startBackgroundParser(); 499 startBackgroundParser(MediaValues::create(document()));
abarth-chromium 2014/03/24 19:43:31 This doesn't seem correct. We have a Config objec
499 500
500 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePl aintextForTextDocument, m_backgroundParser)); 501 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePl aintextForTextDocument, m_backgroundParser));
501 } else 502 } else
502 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); 503 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState);
503 } 504 }
504 505
505 Document* HTMLDocumentParser::contextForParsingSession() 506 Document* HTMLDocumentParser::contextForParsingSession()
506 { 507 {
507 // The parsing session should interact with the document only when parsing 508 // The parsing session should interact with the document only when parsing
508 // non-fragments. Otherwise, we might delay the load event mistakenly. 509 // non-fragments. Otherwise, we might delay the load event mistakenly.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (mode == ForceSynchronous) 565 if (mode == ForceSynchronous)
565 m_treeBuilder->flush(); 566 m_treeBuilder->flush();
566 RELEASE_ASSERT(!isStopped()); 567 RELEASE_ASSERT(!isStopped());
567 568
568 if (session.needsYield) 569 if (session.needsYield)
569 m_parserScheduler->scheduleForResume(); 570 m_parserScheduler->scheduleForResume();
570 571
571 if (isWaitingForScripts()) { 572 if (isWaitingForScripts()) {
572 ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState); 573 ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState);
573 if (!m_preloadScanner) { 574 if (!m_preloadScanner) {
574 m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, docume nt()->url(), document()->devicePixelRatio())); 575 m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, docume nt()->url(), document()->devicePixelRatio(), MediaValues::create(document())));
abarth-chromium 2014/03/24 19:43:31 Isn't devicePixelRatio contained in MediaValues?
575 m_preloadScanner->appendToEnd(m_input.current()); 576 m_preloadScanner->appendToEnd(m_input.current());
576 } 577 }
577 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); 578 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL());
578 } 579 }
579 580
580 InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine ().zeroBasedInt()); 581 InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine ().zeroBasedInt());
581 } 582 }
582 583
583 void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken) 584 void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken)
584 { 585 {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 642
642 SegmentedString excludedLineNumberSource(source); 643 SegmentedString excludedLineNumberSource(source);
643 excludedLineNumberSource.setExcludeLineNumbers(); 644 excludedLineNumberSource.setExcludeLineNumbers();
644 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource); 645 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource);
645 pumpTokenizerIfPossible(ForceSynchronous); 646 pumpTokenizerIfPossible(ForceSynchronous);
646 647
647 if (isWaitingForScripts()) { 648 if (isWaitingForScripts()) {
648 // Check the document.write() output with a separate preload scanner as 649 // Check the document.write() output with a separate preload scanner as
649 // the main scanner can't deal with insertions. 650 // the main scanner can't deal with insertions.
650 if (!m_insertionPreloadScanner) 651 if (!m_insertionPreloadScanner)
651 m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_option s, document()->url(), document()->devicePixelRatio())); 652 m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_option s, document()->url(), document()->devicePixelRatio(), MediaValues::create(docume nt())));
652 653
653 m_insertionPreloadScanner->appendToEnd(source); 654 m_insertionPreloadScanner->appendToEnd(source);
654 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme ntURL()); 655 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme ntURL());
655 } 656 }
656 657
657 endIfDelayed(); 658 endIfDelayed();
658 } 659 }
659 660
660 void HTMLDocumentParser::startBackgroundParser() 661 void HTMLDocumentParser::startBackgroundParser(PassRefPtr<MediaValues> mediaValu es)
661 { 662 {
662 ASSERT(!isStopped()); 663 ASSERT(!isStopped());
663 ASSERT(shouldUseThreading()); 664 ASSERT(shouldUseThreading());
664 ASSERT(!m_haveBackgroundParser); 665 ASSERT(!m_haveBackgroundParser);
665 m_haveBackgroundParser = true; 666 m_haveBackgroundParser = true;
666 667
667 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound(); 668 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound();
668 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); 669 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference);
669 670
670 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); 671 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration);
671 config->options = m_options; 672 config->options = m_options;
672 config->parser = m_weakFactory.createWeakPtr(); 673 config->parser = m_weakFactory.createWeakPtr();
673 config->xssAuditor = adoptPtr(new XSSAuditor); 674 config->xssAuditor = adoptPtr(new XSSAuditor);
674 config->xssAuditor->init(document(), &m_xssAuditorDelegate); 675 config->xssAuditor->init(document(), &m_xssAuditorDelegate);
675 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), document()->devicePixelRatio())); 676 // TODO
677 // Make sure we're on the main thread, and get frame and style to create the m
678 // Pass MediaValues to the TokenPreloadScanner directly
679 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), document()->devicePixelRatio(), mediaValues));
676 config->decoder = takeDecoder(); 680 config->decoder = takeDecoder();
677 681
678 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); 682 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread());
679 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); 683 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread());
680 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::start, refe rence.release(), config.release())); 684 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::start, refe rence.release(), config.release()));
681 } 685 }
682 686
683 void HTMLDocumentParser::stopBackgroundParser() 687 void HTMLDocumentParser::stopBackgroundParser()
684 { 688 {
685 ASSERT(shouldUseThreading()); 689 ASSERT(shouldUseThreading());
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 m_parserScheduler->resume(); 967 m_parserScheduler->resume();
964 } 968 }
965 969
966 void HTMLDocumentParser::appendBytes(const char* data, size_t length) 970 void HTMLDocumentParser::appendBytes(const char* data, size_t length)
967 { 971 {
968 if (!length || isStopped()) 972 if (!length || isStopped())
969 return; 973 return;
970 974
971 if (shouldUseThreading()) { 975 if (shouldUseThreading()) {
972 if (!m_haveBackgroundParser) 976 if (!m_haveBackgroundParser)
973 startBackgroundParser(); 977 startBackgroundParser(MediaValues::create(document()));
974 978
975 OwnPtr<Vector<char> > buffer = adoptPtr(new Vector<char>(length)); 979 OwnPtr<Vector<char> > buffer = adoptPtr(new Vector<char>(length));
976 memcpy(buffer->data(), data, length); 980 memcpy(buffer->data(), data, length);
977 TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned )length); 981 TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned )length);
978 982
979 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendB ytes, m_backgroundParser, buffer.release())); 983 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendB ytes, m_backgroundParser, buffer.release()));
980 return; 984 return;
981 } 985 }
982 986
983 DecodedDataDocumentParser::appendBytes(data, length); 987 DecodedDataDocumentParser::appendBytes(data, length);
(...skipping 14 matching lines...) Expand all
998 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1002 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
999 { 1003 {
1000 ASSERT(decoder); 1004 ASSERT(decoder);
1001 DecodedDataDocumentParser::setDecoder(decoder); 1005 DecodedDataDocumentParser::setDecoder(decoder);
1002 1006
1003 if (m_haveBackgroundParser) 1007 if (m_haveBackgroundParser)
1004 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1008 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1005 } 1009 }
1006 1010
1007 } 1011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698