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

Side by Side Diff: third_party/WebKit/Source/core/xml/parser/XMLDocumentParser.cpp

Issue 2389883005: reflow comments in core/xml* (Closed)
Patch Set: Created 4 years, 2 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) 2000 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2000 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2005, 2006, 2008, 2014 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2008, 2014 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2008 Holger Hans Peter Freyther 7 * Copyright (C) 2008 Holger Hans Peter Freyther
8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/)
9 * 10 *
10 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public 12 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version. 14 * version 2 of the License, or (at your option) any later version.
14 * 15 *
15 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details. 19 * Library General Public License for more details.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 m_pendingScript->removeClient(this); 381 m_pendingScript->removeClient(this);
381 m_pendingScript = nullptr; 382 m_pendingScript = nullptr;
382 m_parserBlockingPendingScriptLoadStartTime = 0.0; 383 m_parserBlockingPendingScriptLoadStartTime = 0.0;
383 } 384 }
384 clearCurrentNodeStack(); 385 clearCurrentNodeStack();
385 ScriptableDocumentParser::detach(); 386 ScriptableDocumentParser::detach();
386 } 387 }
387 388
388 void XMLDocumentParser::end() { 389 void XMLDocumentParser::end() {
389 TRACE_EVENT0("blink", "XMLDocumentParser::end"); 390 TRACE_EVENT0("blink", "XMLDocumentParser::end");
390 // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is c alled. 391 // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is
391 // I don't believe XMLDocumentParserQt needs doEnd called in the fragment case . 392 // called. I don't believe XMLDocumentParserQt needs doEnd called in the
jbroman 2016/10/04 19:56:51 super-duper-nit: vim likes to put two spaces betwe
Nico 2016/10/04 20:17:12 I use vim's gq to join lines manually, and it defa
393 // fragment case.
392 DCHECK(!m_parsingFragment); 394 DCHECK(!m_parsingFragment);
393 395
394 doEnd(); 396 doEnd();
395 397
396 // doEnd() call above can detach the parser and null out its document. 398 // doEnd() call above can detach the parser and null out its document.
397 // In that case, we just bail out. 399 // In that case, we just bail out.
398 if (isDetached()) 400 if (isDetached())
399 return; 401 return;
400 402
401 // doEnd() could process a script tag, thus pausing parsing. 403 // doEnd() could process a script tag, thus pausing parsing.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 return false; 604 return false;
603 605
604 // The libxml doesn't give us a lot of context for deciding whether to allow 606 // The libxml doesn't give us a lot of context for deciding whether to allow
605 // this request. In the worst case, this load could be for an external 607 // this request. In the worst case, this load could be for an external
606 // entity and the resulting document could simply read the retrieved 608 // entity and the resulting document could simply read the retrieved
607 // content. If we had more context, we could potentially allow the parser to 609 // content. If we had more context, we could potentially allow the parser to
608 // load a DTD. As things stand, we take the conservative route and allow 610 // load a DTD. As things stand, we take the conservative route and allow
609 // same-origin requests only. 611 // same-origin requests only.
610 if (!XMLDocumentParserScope::currentDocument->getSecurityOrigin()->canRequest( 612 if (!XMLDocumentParserScope::currentDocument->getSecurityOrigin()->canRequest(
611 url)) { 613 url)) {
612 // FIXME: This is copy/pasted. We should probably build console logging into canRequest(). 614 // FIXME: This is copy/pasted. We should probably build console logging into
615 // canRequest().
613 if (!url.isNull()) { 616 if (!url.isNull()) {
614 String message = 617 String message =
615 "Unsafe attempt to load URL " + url.elidedString() + 618 "Unsafe attempt to load URL " + url.elidedString() +
616 " from frame with URL " + 619 " from frame with URL " +
617 XMLDocumentParserScope::currentDocument->url().elidedString() + 620 XMLDocumentParserScope::currentDocument->url().elidedString() +
618 ". Domains, protocols and ports must match.\n"; 621 ". Domains, protocols and ports must match.\n";
619 XMLDocumentParserScope::currentDocument->addConsoleMessage( 622 XMLDocumentParserScope::currentDocument->addConsoleMessage(
620 ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel, 623 ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel,
621 message)); 624 message));
622 } 625 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 Element* element = elemStack.last(); 821 Element* element = elemStack.last();
819 AttributeCollection attributes = element->attributes(); 822 AttributeCollection attributes = element->attributes();
820 for (auto& attribute : attributes) { 823 for (auto& attribute : attributes) {
821 if (attribute.localName() == xmlnsAtom) 824 if (attribute.localName() == xmlnsAtom)
822 m_defaultNamespaceURI = attribute.value(); 825 m_defaultNamespaceURI = attribute.value();
823 else if (attribute.prefix() == xmlnsAtom) 826 else if (attribute.prefix() == xmlnsAtom)
824 m_prefixToNamespaceMap.set(attribute.localName(), attribute.value()); 827 m_prefixToNamespaceMap.set(attribute.localName(), attribute.value());
825 } 828 }
826 } 829 }
827 830
828 // If the parent element is not in document tree, there may be no xmlns attrib ute; just default to the parent's namespace. 831 // If the parent element is not in document tree, there may be no xmlns
832 // attribute; just default to the parent's namespace.
829 if (m_defaultNamespaceURI.isNull() && !parentElement->isConnected()) 833 if (m_defaultNamespaceURI.isNull() && !parentElement->isConnected())
830 m_defaultNamespaceURI = parentElement->namespaceURI(); 834 m_defaultNamespaceURI = parentElement->namespaceURI();
831 } 835 }
832 836
833 XMLParserContext::~XMLParserContext() { 837 XMLParserContext::~XMLParserContext() {
834 if (m_context->myDoc) 838 if (m_context->myDoc)
835 xmlFreeDoc(m_context->myDoc); 839 xmlFreeDoc(m_context->myDoc);
836 xmlFreeParserCtxt(m_context); 840 xmlFreeParserCtxt(m_context);
837 } 841 }
838 842
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 char* target, 1383 char* target,
1380 size_t targetSize) { 1384 size_t targetSize) {
1381 const char* originalTarget = target; 1385 const char* originalTarget = target;
1382 WTF::Unicode::ConversionResult conversionResult = 1386 WTF::Unicode::ConversionResult conversionResult =
1383 WTF::Unicode::convertUTF16ToUTF8(&utf16Entity, 1387 WTF::Unicode::convertUTF16ToUTF8(&utf16Entity,
1384 utf16Entity + numberOfCodeUnits, &target, 1388 utf16Entity + numberOfCodeUnits, &target,
1385 target + targetSize); 1389 target + targetSize);
1386 if (conversionResult != WTF::Unicode::conversionOK) 1390 if (conversionResult != WTF::Unicode::conversionOK)
1387 return 0; 1391 return 0;
1388 1392
1389 // Even though we must pass the length, libxml expects the entity string to be null terminated. 1393 // Even though we must pass the length, libxml expects the entity string to be
1394 // null terminated.
1390 DCHECK_GT(target, originalTarget + 1); 1395 DCHECK_GT(target, originalTarget + 1);
1391 *target = '\0'; 1396 *target = '\0';
1392 return target - originalTarget; 1397 return target - originalTarget;
1393 } 1398 }
1394 1399
1395 static xmlEntityPtr getXHTMLEntity(const xmlChar* name) { 1400 static xmlEntityPtr getXHTMLEntity(const xmlChar* name) {
1396 UChar utf16DecodedEntity[4]; 1401 UChar utf16DecodedEntity[4];
1397 size_t numberOfCodeUnits = decodeNamedEntityToUCharArray( 1402 size_t numberOfCodeUnits = decodeNamedEntityToUCharArray(
1398 reinterpret_cast<const char*>(name), utf16DecodedEntity); 1403 reinterpret_cast<const char*>(name), utf16DecodedEntity);
1399 if (!numberOfCodeUnits) 1404 if (!numberOfCodeUnits)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 // http://bugzilla.gnome.org/show_bug.cgi?id=172255 1484 // http://bugzilla.gnome.org/show_bug.cgi?id=172255
1480 // http://bugs.webkit.org/show_bug.cgi?id=5792 1485 // http://bugs.webkit.org/show_bug.cgi?id=5792
1481 } 1486 }
1482 1487
1483 void XMLDocumentParser::initializeParserContext(const CString& chunk) { 1488 void XMLDocumentParser::initializeParserContext(const CString& chunk) {
1484 xmlSAXHandler sax; 1489 xmlSAXHandler sax;
1485 memset(&sax, 0, sizeof(sax)); 1490 memset(&sax, 0, sizeof(sax));
1486 1491
1487 // According to http://xmlsoft.org/html/libxml-tree.html#xmlSAXHandler and 1492 // According to http://xmlsoft.org/html/libxml-tree.html#xmlSAXHandler and
1488 // http://xmlsoft.org/html/libxml-parser.html#fatalErrorSAXFunc the SAX 1493 // http://xmlsoft.org/html/libxml-parser.html#fatalErrorSAXFunc the SAX
1489 // fatalError callback is unused; error gets all the errors. Use normalErrorHa ndler 1494 // fatalError callback is unused; error gets all the errors. Use
1490 // for both the error and fatalError callbacks. 1495 // normalErrorHandler for both the error and fatalError callbacks.
1491 sax.error = normalErrorHandler; 1496 sax.error = normalErrorHandler;
1492 sax.fatalError = normalErrorHandler; 1497 sax.fatalError = normalErrorHandler;
1493 sax.characters = charactersHandler; 1498 sax.characters = charactersHandler;
1494 sax.processingInstruction = processingInstructionHandler; 1499 sax.processingInstruction = processingInstructionHandler;
1495 sax.cdataBlock = cdataBlockHandler; 1500 sax.cdataBlock = cdataBlockHandler;
1496 sax.comment = commentHandler; 1501 sax.comment = commentHandler;
1497 sax.warning = warningHandler; 1502 sax.warning = warningHandler;
1498 sax.startElementNs = startElementNsHandler; 1503 sax.startElementNs = startElementNsHandler;
1499 sax.endElementNs = endElementNsHandler; 1504 sax.endElementNs = endElementNsHandler;
1500 sax.getEntity = getEntityHandler; 1505 sax.getEntity = getEntityHandler;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 RefPtr<XMLParserContext> parser = 1707 RefPtr<XMLParserContext> parser =
1703 XMLParserContext::createStringParser(&sax, &state); 1708 XMLParserContext::createStringParser(&sax, &state);
1704 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; 1709 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />";
1705 parseChunk(parser->context(), parseString); 1710 parseChunk(parser->context(), parseString);
1706 finishParsing(parser->context()); 1711 finishParsing(parser->context());
1707 attrsOK = state.gotAttributes; 1712 attrsOK = state.gotAttributes;
1708 return state.attributes; 1713 return state.attributes;
1709 } 1714 }
1710 1715
1711 } // namespace blink 1716 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698