OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2013 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 GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE 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 GOOGLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE 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/CompactHTMLToken.h" | 27 #include "core/html/parser/CompactHTMLToken.h" |
28 | 28 |
29 #include "core/dom/QualifiedName.h" | 29 #include "core/dom/QualifiedName.h" |
| 30 #include "core/html/parser/HTMLIdentifier.h" |
30 #include "core/html/parser/HTMLParserIdioms.h" | 31 #include "core/html/parser/HTMLParserIdioms.h" |
31 | 32 |
32 namespace WebCore { | 33 namespace WebCore { |
33 | 34 |
34 struct SameSizeAsCompactHTMLToken { | 35 struct SameSizeAsCompactHTMLToken { |
35 unsigned bitfields; | 36 unsigned bitfields; |
36 HTMLIdentifier data; | 37 String data; |
37 Vector<Attribute> vector; | 38 Vector<Attribute> vector; |
38 TextPosition textPosition; | 39 TextPosition textPosition; |
39 }; | 40 }; |
40 | 41 |
41 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), C
ompactHTMLToken_should_stay_small); | 42 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), C
ompactHTMLToken_should_stay_small); |
42 | 43 |
43 CompactHTMLToken::CompactHTMLToken(const HTMLToken* token, const TextPosition& t
extPosition) | 44 CompactHTMLToken::CompactHTMLToken(const HTMLToken* token, const TextPosition& t
extPosition) |
44 : m_type(token->type()) | 45 : m_type(token->type()) |
45 , m_isAll8BitData(false) | 46 , m_isAll8BitData(false) |
46 , m_doctypeForcesQuirks(false) | 47 , m_doctypeForcesQuirks(false) |
47 , m_textPosition(textPosition) | 48 , m_textPosition(textPosition) |
48 { | 49 { |
49 switch (m_type) { | 50 switch (m_type) { |
50 case HTMLToken::Uninitialized: | 51 case HTMLToken::Uninitialized: |
51 ASSERT_NOT_REACHED(); | 52 ASSERT_NOT_REACHED(); |
52 break; | 53 break; |
53 case HTMLToken::DOCTYPE: { | 54 case HTMLToken::DOCTYPE: { |
54 m_data = HTMLIdentifier(token->name(), Likely8Bit); | 55 m_data = HTMLIdentifier::create(token->name(), Likely8Bit); |
| 56 |
55 // There is only 1 DOCTYPE token per document, so to avoid increasing th
e | 57 // There is only 1 DOCTYPE token per document, so to avoid increasing th
e |
56 // size of CompactHTMLToken, we just use the m_attributes vector. | 58 // size of CompactHTMLToken, we just use the m_attributes vector. |
57 m_attributes.append(Attribute(HTMLIdentifier(token->publicIdentifier(),
Likely8Bit), String(token->systemIdentifier()))); | 59 m_attributes.append(Attribute(HTMLIdentifier::create(token->publicIdenti
fier(), Likely8Bit), String(token->systemIdentifier()))); |
58 m_doctypeForcesQuirks = token->forceQuirks(); | 60 m_doctypeForcesQuirks = token->forceQuirks(); |
59 break; | 61 break; |
60 } | 62 } |
61 case HTMLToken::EndOfFile: | 63 case HTMLToken::EndOfFile: |
62 break; | 64 break; |
63 case HTMLToken::StartTag: | 65 case HTMLToken::StartTag: |
64 m_attributes.reserveInitialCapacity(token->attributes().size()); | 66 m_attributes.reserveInitialCapacity(token->attributes().size()); |
65 for (Vector<HTMLToken::Attribute>::const_iterator it = token->attributes
().begin(); it != token->attributes().end(); ++it) | 67 for (Vector<HTMLToken::Attribute>::const_iterator it = token->attributes
().begin(); it != token->attributes().end(); ++it) |
66 m_attributes.append(Attribute(HTMLIdentifier(it->name, Likely8Bit),
StringImpl::create8BitIfPossible(it->value))); | 68 m_attributes.append(Attribute(HTMLIdentifier::create(it->name, Likel
y8Bit), StringImpl::create8BitIfPossible(it->value))); |
67 // Fall through! | 69 // Fall through! |
68 case HTMLToken::EndTag: | 70 case HTMLToken::EndTag: |
69 m_selfClosing = token->selfClosing(); | 71 m_selfClosing = token->selfClosing(); |
70 // Fall through! | 72 // Fall through! |
71 case HTMLToken::Comment: | 73 case HTMLToken::Comment: |
72 case HTMLToken::Character: { | 74 case HTMLToken::Character: { |
73 m_isAll8BitData = token->isAll8BitData(); | 75 m_isAll8BitData = token->isAll8BitData(); |
74 m_data = HTMLIdentifier(token->data(), token->isAll8BitData() ? Force8Bi
t : Force16Bit); | 76 m_data = HTMLIdentifier::create(token->data(), token->isAll8BitData() ?
Force8Bit : Force16Bit); |
75 break; | 77 break; |
76 } | 78 } |
77 default: | 79 default: |
78 ASSERT_NOT_REACHED(); | 80 ASSERT_NOT_REACHED(); |
79 break; | 81 break; |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const Qual
ifiedName& name) const | 85 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const Qual
ifiedName& name) const |
84 { | 86 { |
85 for (unsigned i = 0; i < m_attributes.size(); ++i) { | 87 for (unsigned i = 0; i < m_attributes.size(); ++i) { |
86 if (threadSafeMatch(m_attributes.at(i).name, name)) | 88 if (threadSafeMatch(m_attributes.at(i).name, name)) |
87 return &m_attributes.at(i); | 89 return &m_attributes.at(i); |
88 } | 90 } |
89 return 0; | 91 return 0; |
90 } | 92 } |
91 | 93 |
92 bool CompactHTMLToken::isSafeToSendToAnotherThread() const | 94 bool CompactHTMLToken::isSafeToSendToAnotherThread() const |
93 { | 95 { |
94 for (Vector<Attribute>::const_iterator it = m_attributes.begin(); it != m_at
tributes.end(); ++it) { | 96 for (Vector<Attribute>::const_iterator it = m_attributes.begin(); it != m_at
tributes.end(); ++it) { |
95 if (!it->name.isSafeToSendToAnotherThread()) | 97 if (!it->name.isSafeToSendToAnotherThread()) |
96 return false; | 98 return false; |
97 if (!it->value.isSafeToSendToAnotherThread()) | 99 if (!it->value.isSafeToSendToAnotherThread()) |
98 return false; | 100 return false; |
99 } | 101 } |
100 return m_data.isSafeToSendToAnotherThread(); | 102 return m_data.isSafeToSendToAnotherThread(); |
101 } | 103 } |
102 | 104 |
103 } | 105 } |
OLD | NEW |