OLD | NEW |
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/html/parser/AtomicHTMLToken.h" | 33 #include "core/html/parser/AtomicHTMLToken.h" |
33 #include "core/html/parser/BackgroundHTMLParser.h" | 34 #include "core/html/parser/BackgroundHTMLParser.h" |
34 #include "core/html/parser/CompactHTMLToken.h" | 35 #include "core/html/parser/CompactHTMLToken.h" |
35 #include "core/html/parser/HTMLIdentifier.h" | 36 #include "core/html/parser/HTMLIdentifier.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/HTMLPreloadScanner.h" | 39 #include "core/html/parser/HTMLPreloadScanner.h" |
39 #include "core/html/parser/HTMLScriptRunner.h" | 40 #include "core/html/parser/HTMLScriptRunner.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 472 |
472 InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt()); | 473 InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt()); |
473 } | 474 } |
474 | 475 |
475 void HTMLDocumentParser::forcePlaintextForTextDocument() | 476 void HTMLDocumentParser::forcePlaintextForTextDocument() |
476 { | 477 { |
477 if (shouldUseThreading()) { | 478 if (shouldUseThreading()) { |
478 // This method is called before any data is appended, so we have to star
t | 479 // This method is called before any data is appended, so we have to star
t |
479 // the background parser ourselves. | 480 // the background parser ourselves. |
480 if (!m_haveBackgroundParser) | 481 if (!m_haveBackgroundParser) |
481 startBackgroundParser(); | 482 startBackgroundParser(MediaValues::create(document())); |
482 | 483 |
483 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePl
aintextForTextDocument, m_backgroundParser)); | 484 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePl
aintextForTextDocument, m_backgroundParser)); |
484 } else | 485 } else |
485 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); | 486 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); |
486 } | 487 } |
487 | 488 |
488 Document* HTMLDocumentParser::contextForParsingSession() | 489 Document* HTMLDocumentParser::contextForParsingSession() |
489 { | 490 { |
490 // The parsing session should interact with the document only when parsing | 491 // The parsing session should interact with the document only when parsing |
491 // non-fragments. Otherwise, we might delay the load event mistakenly. | 492 // non-fragments. Otherwise, we might delay the load event mistakenly. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 542 |
542 if (isStopped()) | 543 if (isStopped()) |
543 return; | 544 return; |
544 | 545 |
545 if (session.needsYield) | 546 if (session.needsYield) |
546 m_parserScheduler->scheduleForResume(); | 547 m_parserScheduler->scheduleForResume(); |
547 | 548 |
548 if (isWaitingForScripts()) { | 549 if (isWaitingForScripts()) { |
549 ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState); | 550 ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState); |
550 if (!m_preloadScanner) { | 551 if (!m_preloadScanner) { |
551 m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, docume
nt()->url())); | 552 m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, docume
nt()->url(), MediaValues::create(document()))); |
552 m_preloadScanner->appendToEnd(m_input.current()); | 553 m_preloadScanner->appendToEnd(m_input.current()); |
553 } | 554 } |
554 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); | 555 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); |
555 } | 556 } |
556 | 557 |
557 InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine
().zeroBasedInt()); | 558 InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine
().zeroBasedInt()); |
558 } | 559 } |
559 | 560 |
560 void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken) | 561 void HTMLDocumentParser::constructTreeFromHTMLToken(HTMLToken& rawToken) |
561 { | 562 { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 617 |
617 SegmentedString excludedLineNumberSource(source); | 618 SegmentedString excludedLineNumberSource(source); |
618 excludedLineNumberSource.setExcludeLineNumbers(); | 619 excludedLineNumberSource.setExcludeLineNumbers(); |
619 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource); | 620 m_input.insertAtCurrentInsertionPoint(excludedLineNumberSource); |
620 pumpTokenizerIfPossible(ForceSynchronous); | 621 pumpTokenizerIfPossible(ForceSynchronous); |
621 | 622 |
622 if (isWaitingForScripts()) { | 623 if (isWaitingForScripts()) { |
623 // Check the document.write() output with a separate preload scanner as | 624 // Check the document.write() output with a separate preload scanner as |
624 // the main scanner can't deal with insertions. | 625 // the main scanner can't deal with insertions. |
625 if (!m_insertionPreloadScanner) | 626 if (!m_insertionPreloadScanner) |
626 m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_option
s, document()->url())); | 627 m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_option
s, document()->url(), MediaValues::create(document()))); |
627 m_insertionPreloadScanner->appendToEnd(source); | 628 m_insertionPreloadScanner->appendToEnd(source); |
628 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme
ntURL()); | 629 m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseEleme
ntURL()); |
629 } | 630 } |
630 | 631 |
631 endIfDelayed(); | 632 endIfDelayed(); |
632 } | 633 } |
633 | 634 |
634 void HTMLDocumentParser::startBackgroundParser() | 635 void HTMLDocumentParser::startBackgroundParser(PassRefPtr<MediaValues> mediaValu
es) |
635 { | 636 { |
636 ASSERT(shouldUseThreading()); | 637 ASSERT(shouldUseThreading()); |
637 ASSERT(!m_haveBackgroundParser); | 638 ASSERT(!m_haveBackgroundParser); |
638 m_haveBackgroundParser = true; | 639 m_haveBackgroundParser = true; |
639 | 640 |
640 HTMLIdentifier::init(); | 641 HTMLIdentifier::init(); |
641 | 642 |
642 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg
roundHTMLParser>::createUnbound(); | 643 RefPtr<WeakReference<BackgroundHTMLParser> > reference = WeakReference<Backg
roundHTMLParser>::createUnbound(); |
643 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); | 644 m_backgroundParser = WeakPtr<BackgroundHTMLParser>(reference); |
644 | 645 |
645 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); | 646 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); |
646 config->options = m_options; | 647 config->options = m_options; |
647 config->parser = m_weakFactory.createWeakPtr(); | 648 config->parser = m_weakFactory.createWeakPtr(); |
648 config->xssAuditor = adoptPtr(new XSSAuditor); | 649 config->xssAuditor = adoptPtr(new XSSAuditor); |
649 config->xssAuditor->init(document(), &m_xssAuditorDelegate); | 650 config->xssAuditor->init(document(), &m_xssAuditorDelegate); |
650 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy())); | 651 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), mediaValues)); |
651 | 652 |
652 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); | 653 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); |
653 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); | 654 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); |
654 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::create, ref
erence.release(), config.release())); | 655 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::create, ref
erence.release(), config.release())); |
655 } | 656 } |
656 | 657 |
657 void HTMLDocumentParser::stopBackgroundParser() | 658 void HTMLDocumentParser::stopBackgroundParser() |
658 { | 659 { |
659 ASSERT(shouldUseThreading()); | 660 ASSERT(shouldUseThreading()); |
660 ASSERT(m_haveBackgroundParser); | 661 ASSERT(m_haveBackgroundParser); |
661 m_haveBackgroundParser = false; | 662 m_haveBackgroundParser = false; |
662 | 663 |
663 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::stop, m_bac
kgroundParser)); | 664 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::stop, m_bac
kgroundParser)); |
664 m_weakFactory.revokeAll(); | 665 m_weakFactory.revokeAll(); |
665 } | 666 } |
666 | 667 |
667 void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource) | 668 void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource) |
668 { | 669 { |
669 if (isStopped()) | 670 if (isStopped()) |
670 return; | 671 return; |
671 | 672 |
672 if (shouldUseThreading()) { | 673 if (shouldUseThreading()) { |
673 if (!m_haveBackgroundParser) | 674 if (!m_haveBackgroundParser) { |
674 startBackgroundParser(); | 675 startBackgroundParser(MediaValues::create(document())); |
| 676 } |
675 | 677 |
676 ASSERT(inputSource->hasOneRef()); | 678 ASSERT(inputSource->hasOneRef()); |
677 Closure closure = bind(&BackgroundHTMLParser::append, m_backgroundParser
, String(inputSource)); | 679 Closure closure = bind(&BackgroundHTMLParser::append, m_backgroundParser
, String(inputSource)); |
678 // NOTE: Important that the String temporary is destroyed before we post
the task | 680 // NOTE: Important that the String temporary is destroyed before we post
the task |
679 // otherwise the String could call deref() on a StringImpl now owned by
the background parser. | 681 // otherwise the String could call deref() on a StringImpl now owned by
the background parser. |
680 // We would like to ASSERT(closure.arg3()->hasOneRef()) but sadly the ar
gs are private. | 682 // We would like to ASSERT(closure.arg3()->hasOneRef()) but sadly the ar
gs are private. |
681 HTMLParserThread::shared()->postTask(closure); | 683 HTMLParserThread::shared()->postTask(closure); |
682 return; | 684 return; |
683 } | 685 } |
684 | 686 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 m_parserScheduler->suspend(); | 933 m_parserScheduler->suspend(); |
932 } | 934 } |
933 | 935 |
934 void HTMLDocumentParser::resumeScheduledTasks() | 936 void HTMLDocumentParser::resumeScheduledTasks() |
935 { | 937 { |
936 if (m_parserScheduler) | 938 if (m_parserScheduler) |
937 m_parserScheduler->resume(); | 939 m_parserScheduler->resume(); |
938 } | 940 } |
939 | 941 |
940 } | 942 } |
OLD | NEW |