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

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

Issue 133273007: Revert "Moved text decoding to the parser thread" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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"
29 #include <limits> 28 #include <limits>
30 #include "wtf/MathExtras.h" 29 #include "wtf/MathExtras.h"
31 #include "wtf/text/AtomicString.h" 30 #include "wtf/text/AtomicString.h"
32 #include "wtf/text/StringBuilder.h" 31 #include "wtf/text/StringBuilder.h"
33 #include "wtf/text/StringHash.h" 32 #include "wtf/text/StringHash.h"
34 #include "wtf/text/TextEncoding.h"
35 33
36 namespace WebCore { 34 namespace WebCore {
37 35
38 using namespace HTMLNames;
39
40 template <typename CharType> 36 template <typename CharType>
41 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c haracters, unsigned length) 37 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c haracters, unsigned length)
42 { 38 {
43 unsigned numLeadingSpaces = 0; 39 unsigned numLeadingSpaces = 0;
44 unsigned numTrailingSpaces = 0; 40 unsigned numTrailingSpaces = 0;
45 41
46 for (; numLeadingSpaces < length; ++numLeadingSpaces) { 42 for (; numLeadingSpaces < length; ++numLeadingSpaces) {
47 if (isNotHTMLSpace<CharType>(characters[numLeadingSpaces])) 43 if (isNotHTMLSpace<CharType>(characters[numLeadingSpaces]))
48 break; 44 break;
49 } 45 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 unsigned length = input.length(); 258 unsigned length = input.length();
263 if (length && input.is8Bit()) { 259 if (length && input.is8Bit()) {
264 const LChar* start = input.characters8(); 260 const LChar* start = input.characters8();
265 return parseHTMLNonNegativeIntegerInternal(start, start + length, value) ; 261 return parseHTMLNonNegativeIntegerInternal(start, start + length, value) ;
266 } 262 }
267 263
268 const UChar* start = input.characters16(); 264 const UChar* start = input.characters16();
269 return parseHTMLNonNegativeIntegerInternal(start, start + length, value); 265 return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
270 } 266 }
271 267
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
358 static bool threadSafeEqual(const StringImpl* a, const StringImpl* b) 268 static bool threadSafeEqual(const StringImpl* a, const StringImpl* b)
359 { 269 {
360 if (a == b) 270 if (a == b)
361 return true; 271 return true;
362 if (a->hash() != b->hash()) 272 if (a->hash() != b->hash())
363 return false; 273 return false;
364 return equalNonNull(a, b); 274 return equalNonNull(a, b);
365 } 275 }
366 276
367 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) 277 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b)
(...skipping 22 matching lines...) Expand all
390 // It's possible to have hash collisions between arbitrary strings and 300 // It's possible to have hash collisions between arbitrary strings and
391 // known identifiers (e.g. "bvvfg" collides with "script"). 301 // known identifiers (e.g. "bvvfg" collides with "script").
392 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions 302 // However ASSERTs in StringImpl::createStatic guard against there ever bein g collisions
393 // between static strings. 303 // between static strings.
394 if (!equal(it->value, characters, length)) 304 if (!equal(it->value, characters, length))
395 return 0; 305 return 0;
396 return it->value; 306 return it->value;
397 } 307 }
398 308
399 } 309 }
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