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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLSourceTracker.cpp

Issue 2717303002: Considering HTMLTokenizer state in HTMLSourceTracker (Closed)
Patch Set: Considering HTMLTokenizer state in HTMLSourceTracker Created 3 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 Adam Barth. All Rights Reserved. 2 * Copyright (C) 2010 Adam Barth. 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 19 matching lines...) Expand all
30 30
31 namespace blink { 31 namespace blink {
32 32
33 HTMLSourceTracker::HTMLSourceTracker() : m_isStarted(false) {} 33 HTMLSourceTracker::HTMLSourceTracker() : m_isStarted(false) {}
34 34
35 void HTMLSourceTracker::start(SegmentedString& currentInput, 35 void HTMLSourceTracker::start(SegmentedString& currentInput,
36 HTMLTokenizer* tokenizer, 36 HTMLTokenizer* tokenizer,
37 HTMLToken& token) { 37 HTMLToken& token) {
38 if (token.type() == HTMLToken::Uninitialized && !m_isStarted) { 38 if (token.type() == HTMLToken::Uninitialized && !m_isStarted) {
39 m_previousSource.clear(); 39 m_previousSource.clear();
40 if (tokenizer->numberOfBufferedCharacters()) 40 if (needToCheckTokenizerBuffer(tokenizer) &&
41 tokenizer->numberOfBufferedCharacters())
41 m_previousSource = tokenizer->bufferedCharacters(); 42 m_previousSource = tokenizer->bufferedCharacters();
42 } else 43 } else {
43 m_previousSource.append(m_currentSource); 44 m_previousSource.append(m_currentSource);
45 }
44 46
45 m_isStarted = true; 47 m_isStarted = true;
46 m_currentSource = currentInput; 48 m_currentSource = currentInput;
47 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() - 49 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() -
48 m_previousSource.length()); 50 m_previousSource.length());
49 } 51 }
50 52
51 void HTMLSourceTracker::end(SegmentedString& currentInput, 53 void HTMLSourceTracker::end(SegmentedString& currentInput,
52 HTMLTokenizer* tokenizer, 54 HTMLTokenizer* tokenizer,
53 HTMLToken& token) { 55 HTMLToken& token) {
54 m_isStarted = false; 56 m_isStarted = false;
55 57
56 m_cachedSourceForToken = String(); 58 m_cachedSourceForToken = String();
57 59
58 // FIXME: This work should really be done by the HTMLTokenizer. 60 // FIXME: This work should really be done by the HTMLTokenizer.
61 size_t numberOfBufferedCharacters = 0u;
62 if (needToCheckTokenizerBuffer(tokenizer)) {
63 numberOfBufferedCharacters = tokenizer->numberOfBufferedCharacters();
64 }
59 token.end(currentInput.numberOfCharactersConsumed() - 65 token.end(currentInput.numberOfCharactersConsumed() -
60 tokenizer->numberOfBufferedCharacters()); 66 numberOfBufferedCharacters);
61 } 67 }
62 68
63 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) { 69 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) {
64 if (!m_cachedSourceForToken.isEmpty()) 70 if (!m_cachedSourceForToken.isEmpty())
65 return m_cachedSourceForToken; 71 return m_cachedSourceForToken;
66 72
67 size_t length; 73 size_t length;
68 if (token.type() == HTMLToken::EndOfFile) { 74 if (token.type() == HTMLToken::EndOfFile) {
69 // Consume the remainder of the input, omitting the null character we use to 75 // Consume the remainder of the input, omitting the null character we use to
70 // mark the end of the file. 76 // mark the end of the file.
(...skipping 14 matching lines...) Expand all
85 for (; i < length; ++i) { 91 for (; i < length; ++i) {
86 ASSERT(!m_currentSource.isEmpty()); 92 ASSERT(!m_currentSource.isEmpty());
87 source.append(m_currentSource.currentChar()); 93 source.append(m_currentSource.currentChar());
88 m_currentSource.advance(); 94 m_currentSource.advance();
89 } 95 }
90 96
91 m_cachedSourceForToken = source.toString(); 97 m_cachedSourceForToken = source.toString();
92 return m_cachedSourceForToken; 98 return m_cachedSourceForToken;
93 } 99 }
94 100
101 bool HTMLSourceTracker::needToCheckTokenizerBuffer(HTMLTokenizer* tokenizer) {
102 HTMLTokenizer::State state = tokenizer->getState();
103 // The temporary buffer must not be used unconditionally, because in some
104 // states (e.g. ScriptDataDoubleEscapedStartState), data is appended to
105 // both the temporary buffer and the token itself.
106 return state == HTMLTokenizer::DataState ||
107 HTMLTokenizer::isEndTagBufferingState(state);
108 }
109
95 } // namespace blink 110 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698