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

Side by Side Diff: Source/core/html/parser/HTMLParserIdioms.cpp

Issue 141143007: Revert of Revert "Moved text decoding to the parser thread" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 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 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple 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. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/html/parser/HTMLParserIdioms.h" 26 #include "core/html/parser/HTMLParserIdioms.h"
27 27
28 #include "HTMLNames.h"
28 #include <limits> 29 #include <limits>
29 #include "wtf/MathExtras.h" 30 #include "wtf/MathExtras.h"
30 #include "wtf/text/AtomicString.h" 31 #include "wtf/text/AtomicString.h"
31 #include "wtf/text/StringBuilder.h" 32 #include "wtf/text/StringBuilder.h"
32 #include "wtf/text/StringHash.h" 33 #include "wtf/text/StringHash.h"
34 #include "wtf/text/TextEncoding.h"
33 35
34 namespace WebCore { 36 namespace WebCore {
35 37
38 using namespace HTMLNames;
39
36 template <typename CharType> 40 template <typename CharType>
37 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c haracters, unsigned length) 41 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c haracters, unsigned length)
38 { 42 {
39 unsigned numLeadingSpaces = 0; 43 unsigned numLeadingSpaces = 0;
40 unsigned numTrailingSpaces = 0; 44 unsigned numTrailingSpaces = 0;
41 45
42 for (; numLeadingSpaces < length; ++numLeadingSpaces) { 46 for (; numLeadingSpaces < length; ++numLeadingSpaces) {
43 if (isNotHTMLSpace<CharType>(characters[numLeadingSpaces])) 47 if (isNotHTMLSpace<CharType>(characters[numLeadingSpaces]))
44 break; 48 break;
45 } 49 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 unsigned length = input.length(); 262 unsigned length = input.length();
259 if (length && input.is8Bit()) { 263 if (length && input.is8Bit()) {
260 const LChar* start = input.characters8(); 264 const LChar* start = input.characters8();
261 return parseHTMLNonNegativeIntegerInternal(start, start + length, value) ; 265 return parseHTMLNonNegativeIntegerInternal(start, start + length, value) ;
262 } 266 }
263 267
264 const UChar* start = input.characters16(); 268 const UChar* start = input.characters16();
265 return parseHTMLNonNegativeIntegerInternal(start, start + length, value); 269 return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
266 } 270 }
267 271
272 static const char charsetString[] = "charset";
273 static const size_t charsetLength = sizeof("charset") - 1;
274
275 String extractCharset(const String& value)
276 {
277 size_t pos = 0;
278 unsigned length = value.length();
279
280 while (pos < length) {
281 pos = value.find(charsetString, pos, false);
282 if (pos == kNotFound)
283 break;
284
285 pos += charsetLength;
286
287 // Skip whitespace.
288 while (pos < length && value[pos] <= ' ')
289 ++pos;
290
291 if (value[pos] != '=')
292 continue;
293
294 ++pos;
295
296 while (pos < length && value[pos] <= ' ')
297 ++pos;
298
299 char quoteMark = 0;
300 if (pos < length && (value[pos] == '"' || value[pos] == '\'')) {
301 quoteMark = static_cast<char>(value[pos++]);
302 ASSERT(!(quoteMark & 0x80));
303 }
304
305 if (pos == length)
306 break;
307
308 unsigned end = pos;
309 while (end < length && ((quoteMark && value[end] != quoteMark) || (!quot eMark && value[end] > ' ' && value[end] != '"' && value[end] != '\'' && value[en d] != ';')))
310 ++end;
311
312 if (quoteMark && (end == length))
313 break; // Close quote not found.
314
315 return value.substring(pos, end - pos);
316 }
317
318 return "";
319 }
320
321 enum Mode {
322 None,
323 Charset,
324 Pragma,
325 };
326
327 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList& attributes )
328 {
329 bool gotPragma = false;
330 Mode mode = None;
331 String charset;
332
333 for (HTMLAttributeList::const_iterator iter = attributes.begin(); iter != at tributes.end(); ++iter) {
334 const String& attributeName = iter->first;
335 const String& attributeValue = AtomicString(iter->second);
336
337 if (threadSafeMatch(attributeName, http_equivAttr)) {
338 if (equalIgnoringCase(attributeValue, "content-type"))
339 gotPragma = true;
340 } else if (charset.isEmpty()) {
341 if (threadSafeMatch(attributeName, charsetAttr)) {
342 charset = attributeValue;
343 mode = Charset;
344 } else if (threadSafeMatch(attributeName, contentAttr)) {
345 charset = extractCharset(attributeValue);
346 if (charset.length())
347 mode = Pragma;
348 }
349 }
350 }
351
352 if (mode == Charset || (mode == Pragma && gotPragma))
353 return WTF::TextEncoding(stripLeadingAndTrailingHTMLSpaces(charset));
354
355 return WTF::TextEncoding();
356 }
357
268 static bool threadSafeEqual(const StringImpl* a, const StringImpl* b) 358 static bool threadSafeEqual(const StringImpl* a, const StringImpl* b)
269 { 359 {
270 if (a == b) 360 if (a == b)
271 return true; 361 return true;
272 if (a->hash() != b->hash()) 362 if (a->hash() != b->hash())
273 return false; 363 return false;
274 return equalNonNull(a, b); 364 return equalNonNull(a, b);
275 } 365 }
276 366
277 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) 367 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b)
(...skipping 22 matching lines...) Expand all
300 // It's possible to have hash collisions between arbitrary strings and 390 // It's possible to have hash collisions between arbitrary strings and
301 // known identifiers (e.g. "bvvfg" collides with "script"). 391 // known identifiers (e.g. "bvvfg" collides with "script").
302 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions 392 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions
303 // between static strings. 393 // between static strings.
304 if (!equal(it->value, characters, length)) 394 if (!equal(it->value, characters, length))
305 return 0; 395 return 0;
306 return it->value; 396 return it->value;
307 } 397 }
308 398
309 } 399 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLParserIdioms.h ('k') | Source/core/html/parser/HTMLPreloadScanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698