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 |
(...skipping 12 matching lines...) Expand all Loading... |
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 "core/html/parser/HTMLViewSourceParser.h" | 26 #include "core/html/parser/HTMLViewSourceParser.h" |
27 | 27 |
28 #include "core/dom/DOMImplementation.h" | 28 #include "core/dom/DOMImplementation.h" |
29 #include "core/html/parser/HTMLParserIdioms.h" | 29 #include "core/html/parser/HTMLParserIdioms.h" |
30 #include "core/html/parser/HTMLParserOptions.h" | 30 #include "core/html/parser/HTMLParserOptions.h" |
31 #include "core/html/parser/HTMLToken.h" | 31 #include "core/html/parser/HTMLToken.h" |
32 #include "core/html/parser/XSSAuditorDelegate.h" | 32 #include "core/html/parser/XSSAuditorDelegate.h" |
33 #include <memory> | |
34 | 33 |
35 namespace blink { | 34 namespace blink { |
36 | 35 |
37 HTMLViewSourceParser::HTMLViewSourceParser(HTMLViewSourceDocument& document, con
st String& mimeType) | 36 HTMLViewSourceParser::HTMLViewSourceParser(HTMLViewSourceDocument& document, con
st String& mimeType) |
38 : DecodedDataDocumentParser(document) | 37 : DecodedDataDocumentParser(document) |
39 , m_tokenizer(HTMLTokenizer::create(HTMLParserOptions(&document))) | 38 , m_tokenizer(HTMLTokenizer::create(HTMLParserOptions(&document))) |
40 { | 39 { |
41 if (mimeType != "text/html" && !DOMImplementation::isXMLMIMEType(mimeType)) | 40 if (mimeType != "text/html" && !DOMImplementation::isXMLMIMEType(mimeType)) |
42 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); | 41 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); |
43 } | 42 } |
44 | 43 |
45 void HTMLViewSourceParser::pumpTokenizer() | 44 void HTMLViewSourceParser::pumpTokenizer() |
46 { | 45 { |
47 m_xssAuditor.init(document(), 0); | 46 m_xssAuditor.init(document(), 0); |
48 | 47 |
49 while (true) { | 48 while (true) { |
50 m_sourceTracker.start(m_input.current(), m_tokenizer.get(), m_token); | 49 m_sourceTracker.start(m_input.current(), m_tokenizer.get(), m_token); |
51 if (!m_tokenizer->nextToken(m_input.current(), m_token)) | 50 if (!m_tokenizer->nextToken(m_input.current(), m_token)) |
52 return; | 51 return; |
53 m_sourceTracker.end(m_input.current(), m_tokenizer.get(), m_token); | 52 m_sourceTracker.end(m_input.current(), m_tokenizer.get(), m_token); |
54 | 53 |
55 std::unique_ptr<XSSInfo> xssInfo = m_xssAuditor.filterToken(FilterTokenR
equest(m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA())); | 54 OwnPtr<XSSInfo> xssInfo = m_xssAuditor.filterToken(FilterTokenRequest(m_
token, m_sourceTracker, m_tokenizer->shouldAllowCDATA())); |
56 HTMLViewSourceDocument::SourceAnnotation annotation = xssInfo ? HTMLView
SourceDocument::AnnotateSourceAsXSS : HTMLViewSourceDocument::AnnotateSourceAsSa
fe; | 55 HTMLViewSourceDocument::SourceAnnotation annotation = xssInfo ? HTMLView
SourceDocument::AnnotateSourceAsXSS : HTMLViewSourceDocument::AnnotateSourceAsSa
fe; |
57 document()->addSource(m_sourceTracker.sourceForToken(m_token), m_token,
annotation); | 56 document()->addSource(m_sourceTracker.sourceForToken(m_token), m_token,
annotation); |
58 | 57 |
59 // FIXME: The tokenizer should do this work for us. | 58 // FIXME: The tokenizer should do this work for us. |
60 if (m_token.type() == HTMLToken::StartTag) | 59 if (m_token.type() == HTMLToken::StartTag) |
61 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 60 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
62 m_token.clear(); | 61 m_token.clear(); |
63 } | 62 } |
64 } | 63 } |
65 | 64 |
66 void HTMLViewSourceParser::append(const String& input) | 65 void HTMLViewSourceParser::append(const String& input) |
67 { | 66 { |
68 m_input.appendToEnd(input); | 67 m_input.appendToEnd(input); |
69 pumpTokenizer(); | 68 pumpTokenizer(); |
70 } | 69 } |
71 | 70 |
72 void HTMLViewSourceParser::finish() | 71 void HTMLViewSourceParser::finish() |
73 { | 72 { |
74 if (!m_input.haveSeenEndOfFile()) | 73 if (!m_input.haveSeenEndOfFile()) |
75 m_input.markEndOfFile(); | 74 m_input.markEndOfFile(); |
76 pumpTokenizer(); | 75 pumpTokenizer(); |
77 document()->finishedParsing(); | 76 document()->finishedParsing(); |
78 } | 77 } |
79 | 78 |
80 } // namespace blink | 79 } // namespace blink |
OLD | NEW |