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

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: Fix Debug crash. Values based MediaValues::create 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
« no previous file with comments | « Source/core/css/MediaValues.cpp ('k') | Source/core/html/parser/HTMLPreloadScanner.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
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/MediaValues.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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
509 if (isParsingFragment()) 510 if (isParsingFragment())
510 return 0; 511 return 0;
511 return document(); 512 return document();
512 } 513 }
513 514
515 static PassRefPtr<MediaValues> createMediaValues(Document* document)
516 {
517 RefPtr<MediaValues> mediaValues = MediaValues::create(document, MediaValues: :CachingMode);
518 ASSERT(mediaValues->isSafeToSendToAnotherThread());
519 return mediaValues;
520 }
521
514 void HTMLDocumentParser::pumpTokenizer(SynchronousMode mode) 522 void HTMLDocumentParser::pumpTokenizer(SynchronousMode mode)
515 { 523 {
516 ASSERT(!isStopped()); 524 ASSERT(!isStopped());
517 ASSERT(!isScheduledForResume()); 525 ASSERT(!isScheduledForResume());
518 // ASSERT that this object is both attached to the Document and protected. 526 // ASSERT that this object is both attached to the Document and protected.
519 ASSERT(refCount() >= 2); 527 ASSERT(refCount() >= 2);
520 ASSERT(m_tokenizer); 528 ASSERT(m_tokenizer);
521 ASSERT(m_token); 529 ASSERT(m_token);
522 ASSERT(!m_haveBackgroundParser || mode == ForceSynchronous); 530 ASSERT(!m_haveBackgroundParser || mode == ForceSynchronous);
523 531
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (mode == ForceSynchronous) 572 if (mode == ForceSynchronous)
565 m_treeBuilder->flush(); 573 m_treeBuilder->flush();
566 RELEASE_ASSERT(!isStopped()); 574 RELEASE_ASSERT(!isStopped());
567 575
568 if (session.needsYield) 576 if (session.needsYield)
569 m_parserScheduler->scheduleForResume(); 577 m_parserScheduler->scheduleForResume();
570 578
571 if (isWaitingForScripts()) { 579 if (isWaitingForScripts()) {
572 ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState); 580 ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState);
573 if (!m_preloadScanner) { 581 if (!m_preloadScanner) {
574 m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, docume nt()->url(), document()->devicePixelRatio())); 582 m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, docume nt()->url(), createMediaValues(document())));
575 m_preloadScanner->appendToEnd(m_input.current()); 583 m_preloadScanner->appendToEnd(m_input.current());
576 } 584 }
577 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); 585 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL());
578 } 586 }
579 587
580 InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine ().zeroBasedInt()); 588 InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine ().zeroBasedInt());
581 } 589 }
582 590
583 void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken) 591 void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken)
584 { 592 {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 649
642 SegmentedString excludedLineNumberSource(source); 650 SegmentedString excludedLineNumberSource(source);
643 excludedLineNumberSource.setExcludeLineNumbers(); 651 excludedLineNumberSource.setExcludeLineNumbers();
644 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource); 652 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource);
645 pumpTokenizerIfPossible(ForceSynchronous); 653 pumpTokenizerIfPossible(ForceSynchronous);
646 654
647 if (isWaitingForScripts()) { 655 if (isWaitingForScripts()) {
648 // Check the document.write() output with a separate preload scanner as 656 // Check the document.write() output with a separate preload scanner as
649 // the main scanner can't deal with insertions. 657 // the main scanner can't deal with insertions.
650 if (!m_insertionPreloadScanner) 658 if (!m_insertionPreloadScanner)
651 m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_option s, document()->url(), document()->devicePixelRatio())); 659 m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_option s, document()->url(), createMediaValues(document())));
652 660
653 m_insertionPreloadScanner->appendToEnd(source); 661 m_insertionPreloadScanner->appendToEnd(source);
654 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme ntURL()); 662 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme ntURL());
655 } 663 }
656 664
657 endIfDelayed(); 665 endIfDelayed();
658 } 666 }
659 667
660 void HTMLDocumentParser::startBackgroundParser() 668 void HTMLDocumentParser::startBackgroundParser()
661 { 669 {
662 ASSERT(!isStopped()); 670 ASSERT(!isStopped());
663 ASSERT(shouldUseThreading()); 671 ASSERT(shouldUseThreading());
664 ASSERT(!m_haveBackgroundParser); 672 ASSERT(!m_haveBackgroundParser);
665 m_haveBackgroundParser = true; 673 m_haveBackgroundParser = true;
666 674
667 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound(); 675 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg roundHTMLParser>::createUnbound();
668 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); 676 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference);
669 677
670 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); 678 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration);
671 config->options = m_options; 679 config->options = m_options;
672 config->parser = m_weakFactory.createWeakPtr(); 680 config->parser = m_weakFactory.createWeakPtr();
673 config->xssAuditor = adoptPtr(new XSSAuditor); 681 config->xssAuditor = adoptPtr(new XSSAuditor);
674 config->xssAuditor->init(document(), &m_xssAuditorDelegate); 682 config->xssAuditor->init(document(), &m_xssAuditorDelegate);
675 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), document()->devicePixelRatio())); 683 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), createMediaValues(document())));
676 config->decoder = takeDecoder(); 684 config->decoder = takeDecoder();
677 685
678 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); 686 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread());
679 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); 687 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread());
680 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::start, refe rence.release(), config.release())); 688 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::start, refe rence.release(), config.release()));
681 } 689 }
682 690
683 void HTMLDocumentParser::stopBackgroundParser() 691 void HTMLDocumentParser::stopBackgroundParser()
684 { 692 {
685 ASSERT(shouldUseThreading()); 693 ASSERT(shouldUseThreading());
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1006 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
999 { 1007 {
1000 ASSERT(decoder); 1008 ASSERT(decoder);
1001 DecodedDataDocumentParser::setDecoder(decoder); 1009 DecodedDataDocumentParser::setDecoder(decoder);
1002 1010
1003 if (m_haveBackgroundParser) 1011 if (m_haveBackgroundParser)
1004 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1012 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1005 } 1013 }
1006 1014
1007 } 1015 }
OLDNEW
« no previous file with comments | « Source/core/css/MediaValues.cpp ('k') | Source/core/html/parser/HTMLPreloadScanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698