Chromium Code Reviews| 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 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 #ifndef HTMLToken_h | 26 #ifndef HTMLToken_h |
| 27 #define HTMLToken_h | 27 #define HTMLToken_h |
| 28 | 28 |
| 29 #include "core/dom/Attribute.h" | 29 #include "core/dom/Attribute.h" |
| 30 #include "core/html/parser/HTMLParserIdioms.h" | |
| 30 #include "wtf/PassOwnPtr.h" | 31 #include "wtf/PassOwnPtr.h" |
| 31 #include "wtf/RefCounted.h" | 32 #include "wtf/RefCounted.h" |
| 32 #include "wtf/RefPtr.h" | 33 #include "wtf/RefPtr.h" |
| 33 | 34 |
| 34 namespace WebCore { | 35 namespace WebCore { |
| 35 | 36 |
| 36 class DoctypeData { | 37 class DoctypeData { |
| 37 WTF_MAKE_NONCOPYABLE(DoctypeData); | 38 WTF_MAKE_NONCOPYABLE(DoctypeData); |
| 38 public: | 39 public: |
| 39 DoctypeData() | 40 DoctypeData() |
| 40 : m_hasPublicIdentifier(false) | 41 : m_hasPublicIdentifier(false) |
| 41 , m_hasSystemIdentifier(false) | 42 , m_hasSystemIdentifier(false) |
| 42 , m_forceQuirks(false) | 43 , m_forceQuirks(false) |
| 43 { | 44 { |
| 44 } | 45 } |
| 45 | 46 |
| 46 // FIXME: This should use String instead of Vector<UChar>. | |
| 47 bool m_hasPublicIdentifier; | 47 bool m_hasPublicIdentifier; |
| 48 bool m_hasSystemIdentifier; | 48 bool m_hasSystemIdentifier; |
| 49 WTF::Vector<UChar> m_publicIdentifier; | 49 String m_publicIdentifier; |
| 50 WTF::Vector<UChar> m_systemIdentifier; | 50 String m_systemIdentifier; |
| 51 bool m_forceQuirks; | 51 bool m_forceQuirks; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 static inline Attribute* findAttributeInVector(Vector<Attribute>& attributes, co nst QualifiedName& name) | 54 static inline Attribute* findAttributeInVector(Vector<Attribute>& attributes, co nst QualifiedName& name) |
| 55 { | 55 { |
| 56 for (unsigned i = 0; i < attributes.size(); ++i) { | 56 for (unsigned i = 0; i < attributes.size(); ++i) { |
| 57 if (attributes.at(i).name().matches(name)) | 57 if (attributes.at(i).name().matches(name)) |
| 58 return &attributes.at(i); | 58 return &attributes.at(i); |
| 59 } | 59 } |
| 60 return 0; | 60 return 0; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 m_baseOffset = 0; | 105 m_baseOffset = 0; |
| 106 // Don't call Vector::clear() as that would destroy the | 106 // Don't call Vector::clear() as that would destroy the |
| 107 // alloced VectorBuffer. If the innerHTML'd content has | 107 // alloced VectorBuffer. If the innerHTML'd content has |
| 108 // two 257 character text nodes in a row, we'll needlessly | 108 // two 257 character text nodes in a row, we'll needlessly |
| 109 // thrash malloc. When we finally finish the parse the | 109 // thrash malloc. When we finally finish the parse the |
| 110 // HTMLToken will be destroyed and the VectorBuffer released. | 110 // HTMLToken will be destroyed and the VectorBuffer released. |
| 111 m_data.shrink(0); | 111 m_data.shrink(0); |
| 112 m_orAllData = 0; | 112 m_orAllData = 0; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void finalizeDoctypePublicIdentifier() | |
| 116 { | |
| 117 m_doctypeData->m_publicIdentifier = attemptStaticStringCreation(m_identi fierBuffer, Likely8Bit); | |
| 118 m_identifierBuffer.clear(); | |
| 119 } | |
| 120 | |
| 121 void finalizeDoctypeSystemIdentifier() | |
| 122 { | |
| 123 m_doctypeData->m_systemIdentifier = StringImpl::create8BitIfPossible(m_i dentifierBuffer); | |
| 124 m_identifierBuffer.clear(); | |
| 125 } | |
| 126 | |
| 115 bool isUninitialized() { return m_type == Uninitialized; } | 127 bool isUninitialized() { return m_type == Uninitialized; } |
| 116 Type type() const { return m_type; } | 128 Type type() const { return m_type; } |
| 117 | 129 |
| 118 void makeEndOfFile() | 130 void makeEndOfFile() |
| 119 { | 131 { |
| 120 ASSERT(m_type == Uninitialized); | 132 ASSERT(m_type == Uninitialized); |
| 121 m_type = EndOfFile; | 133 m_type = EndOfFile; |
| 122 } | 134 } |
| 123 | 135 |
| 124 /* Range and offset methods exposed for HTMLSourceTracker and HTMLViewSource Parser */ | 136 /* Range and offset methods exposed for HTMLSourceTracker and HTMLViewSource Parser */ |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 195 |
| 184 void beginDOCTYPE(UChar character) | 196 void beginDOCTYPE(UChar character) |
| 185 { | 197 { |
| 186 ASSERT(character); | 198 ASSERT(character); |
| 187 beginDOCTYPE(); | 199 beginDOCTYPE(); |
| 188 m_data.append(character); | 200 m_data.append(character); |
| 189 m_orAllData |= character; | 201 m_orAllData |= character; |
| 190 } | 202 } |
| 191 | 203 |
| 192 // FIXME: Distinguish between a missing public identifer and an empty one. | 204 // FIXME: Distinguish between a missing public identifer and an empty one. |
| 193 const WTF::Vector<UChar>& publicIdentifier() const | 205 const String& publicIdentifier() const |
| 194 { | 206 { |
| 195 ASSERT(m_type == DOCTYPE); | 207 ASSERT(m_type == DOCTYPE); |
| 196 return m_doctypeData->m_publicIdentifier; | 208 return m_doctypeData->m_publicIdentifier; |
| 197 } | 209 } |
| 198 | 210 |
| 199 // FIXME: Distinguish between a missing system identifer and an empty one. | 211 // FIXME: Distinguish between a missing system identifer and an empty one. |
| 200 const WTF::Vector<UChar>& systemIdentifier() const | 212 const String& systemIdentifier() const |
| 201 { | 213 { |
| 202 ASSERT(m_type == DOCTYPE); | 214 ASSERT(m_type == DOCTYPE); |
| 203 return m_doctypeData->m_systemIdentifier; | 215 return m_doctypeData->m_systemIdentifier; |
| 204 } | 216 } |
| 205 | 217 |
| 206 void setPublicIdentifierToEmptyString() | 218 void setPublicIdentifierToEmptyString() |
| 207 { | 219 { |
| 208 ASSERT(m_type == DOCTYPE); | 220 ASSERT(m_type == DOCTYPE); |
| 209 m_doctypeData->m_hasPublicIdentifier = true; | 221 m_doctypeData->m_hasPublicIdentifier = true; |
| 210 m_doctypeData->m_publicIdentifier.clear(); | |
| 211 } | 222 } |
| 212 | 223 |
| 213 void setSystemIdentifierToEmptyString() | 224 void setSystemIdentifierToEmptyString() |
| 214 { | 225 { |
| 215 ASSERT(m_type == DOCTYPE); | 226 ASSERT(m_type == DOCTYPE); |
| 216 m_doctypeData->m_hasSystemIdentifier = true; | 227 m_doctypeData->m_hasSystemIdentifier = true; |
| 217 m_doctypeData->m_systemIdentifier.clear(); | |
| 218 } | 228 } |
| 219 | 229 |
| 220 void appendToPublicIdentifier(UChar character) | 230 void appendToPublicIdentifier(UChar character) |
| 221 { | 231 { |
| 222 ASSERT(character); | 232 ASSERT(character); |
| 223 ASSERT(m_type == DOCTYPE); | 233 ASSERT(m_type == DOCTYPE); |
| 224 ASSERT(m_doctypeData->m_hasPublicIdentifier); | 234 ASSERT(m_doctypeData->m_hasPublicIdentifier); |
| 225 m_doctypeData->m_publicIdentifier.append(character); | 235 m_identifierBuffer.append(character); |
| 226 } | 236 } |
| 227 | 237 |
| 228 void appendToSystemIdentifier(UChar character) | 238 void appendToSystemIdentifier(UChar character) |
| 229 { | 239 { |
| 230 ASSERT(character); | 240 ASSERT(character); |
| 231 ASSERT(m_type == DOCTYPE); | 241 ASSERT(m_type == DOCTYPE); |
| 232 ASSERT(m_doctypeData->m_hasSystemIdentifier); | 242 ASSERT(m_doctypeData->m_hasSystemIdentifier); |
| 233 m_doctypeData->m_systemIdentifier.append(character); | 243 m_identifierBuffer.append(character); |
| 234 } | 244 } |
| 235 | 245 |
| 236 PassOwnPtr<DoctypeData> releaseDoctypeData() | 246 PassOwnPtr<DoctypeData> releaseDoctypeData() |
| 237 { | 247 { |
| 238 return m_doctypeData.release(); | 248 return m_doctypeData.release(); |
| 239 } | 249 } |
| 240 | 250 |
| 241 /* Start/End Tag Tokens */ | 251 /* Start/End Tag Tokens */ |
| 242 | 252 |
| 243 bool selfClosing() const | 253 bool selfClosing() const |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 m_data.clear(); | 445 m_data.clear(); |
| 436 m_orAllData = 0; | 446 m_orAllData = 0; |
| 437 } | 447 } |
| 438 | 448 |
| 439 private: | 449 private: |
| 440 Type m_type; | 450 Type m_type; |
| 441 Attribute::Range m_range; // Always starts at zero. | 451 Attribute::Range m_range; // Always starts at zero. |
| 442 int m_baseOffset; | 452 int m_baseOffset; |
| 443 DataVector m_data; | 453 DataVector m_data; |
| 444 UChar m_orAllData; | 454 UChar m_orAllData; |
| 455 Vector<UChar> m_identifierBuffer; | |
|
abarth-chromium
2014/06/19 16:07:02
You haven't actually improved anything because you
| |
| 445 | 456 |
| 446 // For StartTag and EndTag | 457 // For StartTag and EndTag |
| 447 bool m_selfClosing; | 458 bool m_selfClosing; |
| 448 AttributeList m_attributes; | 459 AttributeList m_attributes; |
| 449 | 460 |
| 450 // A pointer into m_attributes used during lexing. | 461 // A pointer into m_attributes used during lexing. |
| 451 Attribute* m_currentAttribute; | 462 Attribute* m_currentAttribute; |
| 452 | 463 |
| 453 // For DOCTYPE | 464 // For DOCTYPE |
| 454 OwnPtr<DoctypeData> m_doctypeData; | 465 OwnPtr<DoctypeData> m_doctypeData; |
| 455 }; | 466 }; |
| 456 | 467 |
| 457 } | 468 } |
| 458 | 469 |
| 459 #endif | 470 #endif |
| OLD | NEW |