OLD | NEW |
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 Apple Inc. All rights reserved. | 3 * Copyright (C) 2005, 2006, 2008 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, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 9 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
10 * | 10 * |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "XMLDocumentParserScope.h" | 59 #include "XMLDocumentParserScope.h" |
60 #include <libxml/parser.h> | 60 #include <libxml/parser.h> |
61 #include <libxml/parserInternals.h> | 61 #include <libxml/parserInternals.h> |
62 #include <wtf/text/CString.h> | 62 #include <wtf/text/CString.h> |
63 #include <wtf/StringExtras.h> | 63 #include <wtf/StringExtras.h> |
64 #include <wtf/Threading.h> | 64 #include <wtf/Threading.h> |
65 #include <wtf/UnusedParam.h> | 65 #include <wtf/UnusedParam.h> |
66 #include <wtf/Vector.h> | 66 #include <wtf/Vector.h> |
67 #include <wtf/unicode/UTF8.h> | 67 #include <wtf/unicode/UTF8.h> |
68 | 68 |
69 #if ENABLE(XSLT) | |
70 #include "XMLTreeViewer.h" | 69 #include "XMLTreeViewer.h" |
71 #include <libxslt/xslt.h> | 70 #include <libxslt/xslt.h> |
72 #endif | |
73 | 71 |
74 using namespace std; | 72 using namespace std; |
75 | 73 |
76 namespace WebCore { | 74 namespace WebCore { |
77 | 75 |
78 class PendingCallbacks { | 76 class PendingCallbacks { |
79 WTF_MAKE_NONCOPYABLE(PendingCallbacks); WTF_MAKE_FAST_ALLOCATED; | 77 WTF_MAKE_NONCOPYABLE(PendingCallbacks); WTF_MAKE_FAST_ALLOCATED; |
80 public: | 78 public: |
81 ~PendingCallbacks() { } | 79 ~PendingCallbacks() { } |
82 static PassOwnPtr<PendingCallbacks> create() | 80 static PassOwnPtr<PendingCallbacks> create() |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 469 |
472 static int closeFunc(void* context) | 470 static int closeFunc(void* context) |
473 { | 471 { |
474 if (context != &globalDescriptor) { | 472 if (context != &globalDescriptor) { |
475 OffsetBuffer* data = static_cast<OffsetBuffer*>(context); | 473 OffsetBuffer* data = static_cast<OffsetBuffer*>(context); |
476 delete data; | 474 delete data; |
477 } | 475 } |
478 return 0; | 476 return 0; |
479 } | 477 } |
480 | 478 |
481 #if ENABLE(XSLT) | |
482 static void errorFunc(void*, const char*, ...) | 479 static void errorFunc(void*, const char*, ...) |
483 { | 480 { |
484 // FIXME: It would be nice to display error messages somewhere. | 481 // FIXME: It would be nice to display error messages somewhere. |
485 } | 482 } |
486 #endif | |
487 | 483 |
488 static bool didInit = false; | 484 static bool didInit = false; |
489 | 485 |
490 PassRefPtr<XMLParserContext> XMLParserContext::createStringParser(xmlSAXHandlerP
tr handlers, void* userData) | 486 PassRefPtr<XMLParserContext> XMLParserContext::createStringParser(xmlSAXHandlerP
tr handlers, void* userData) |
491 { | 487 { |
492 if (!didInit) { | 488 if (!didInit) { |
493 xmlInitParser(); | 489 xmlInitParser(); |
494 xmlRegisterInputCallbacks(matchFunc, openFunc, readFunc, closeFunc); | 490 xmlRegisterInputCallbacks(matchFunc, openFunc, readFunc, closeFunc); |
495 xmlRegisterOutputCallbacks(matchFunc, openFunc, writeFunc, closeFunc); | 491 xmlRegisterOutputCallbacks(matchFunc, openFunc, writeFunc, closeFunc); |
496 libxmlLoaderThread = currentThread(); | 492 libxmlLoaderThread = currentThread(); |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 pi->setCreatedByParser(true); | 977 pi->setCreatedByParser(true); |
982 | 978 |
983 m_currentNode->parserAppendChild(pi.get()); | 979 m_currentNode->parserAppendChild(pi.get()); |
984 if (m_view && !pi->attached()) | 980 if (m_view && !pi->attached()) |
985 pi->attach(); | 981 pi->attach(); |
986 | 982 |
987 pi->finishParsingChildren(); | 983 pi->finishParsingChildren(); |
988 | 984 |
989 if (pi->isCSS()) | 985 if (pi->isCSS()) |
990 m_sawCSS = true; | 986 m_sawCSS = true; |
991 #if ENABLE(XSLT) | |
992 m_sawXSLTransform = !m_sawFirstElement && pi->isXSL(); | 987 m_sawXSLTransform = !m_sawFirstElement && pi->isXSL(); |
993 if (m_sawXSLTransform && !document()->transformSourceDocument()) | 988 if (m_sawXSLTransform && !document()->transformSourceDocument()) |
994 stopParsing(); | 989 stopParsing(); |
995 #endif | |
996 } | 990 } |
997 | 991 |
998 void XMLDocumentParser::cdataBlock(const xmlChar* s, int len) | 992 void XMLDocumentParser::cdataBlock(const xmlChar* s, int len) |
999 { | 993 { |
1000 if (isStopped()) | 994 if (isStopped()) |
1001 return; | 995 return; |
1002 | 996 |
1003 if (m_parserPaused) { | 997 if (m_parserPaused) { |
1004 m_pendingCallbacks->appendCDATABlockCallback(s, len); | 998 m_pendingCallbacks->appendCDATABlockCallback(s, len); |
1005 return; | 999 return; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 // Tell libxml we're done. | 1344 // Tell libxml we're done. |
1351 { | 1345 { |
1352 XMLDocumentParserScope scope(document()->cachedResourceLoader())
; | 1346 XMLDocumentParserScope scope(document()->cachedResourceLoader())
; |
1353 xmlParseChunk(context(), 0, 0, 1); | 1347 xmlParseChunk(context(), 0, 0, 1); |
1354 } | 1348 } |
1355 | 1349 |
1356 m_context = 0; | 1350 m_context = 0; |
1357 } | 1351 } |
1358 } | 1352 } |
1359 | 1353 |
1360 #if ENABLE(XSLT) | |
1361 XMLTreeViewer xmlTreeViewer(document()); | 1354 XMLTreeViewer xmlTreeViewer(document()); |
1362 bool xmlViewerMode = !m_sawError && !m_sawCSS && !m_sawXSLTransform && xmlTr
eeViewer.hasNoStyleInformation(); | 1355 bool xmlViewerMode = !m_sawError && !m_sawCSS && !m_sawXSLTransform && xmlTr
eeViewer.hasNoStyleInformation(); |
1363 if (xmlViewerMode) | 1356 if (xmlViewerMode) |
1364 xmlTreeViewer.transformDocumentToTreeView(); | 1357 xmlTreeViewer.transformDocumentToTreeView(); |
1365 | 1358 |
1366 if (m_sawXSLTransform) { | 1359 if (m_sawXSLTransform) { |
1367 void* doc = xmlDocPtrForString(document()->cachedResourceLoader(), m_ori
ginalSourceForTransform.toString(), document()->url().string()); | 1360 void* doc = xmlDocPtrForString(document()->cachedResourceLoader(), m_ori
ginalSourceForTransform.toString(), document()->url().string()); |
1368 document()->setTransformSource(adoptPtr(new TransformSource(doc))); | 1361 document()->setTransformSource(adoptPtr(new TransformSource(doc))); |
1369 | 1362 |
1370 document()->setParsing(false); // Make the document think it's done, so
it will apply XSL stylesheets. | 1363 document()->setParsing(false); // Make the document think it's done, so
it will apply XSL stylesheets. |
1371 document()->styleResolverChanged(RecalcStyleImmediately); | 1364 document()->styleResolverChanged(RecalcStyleImmediately); |
1372 | 1365 |
1373 // styleResolverChanged() call can detach the parser and null out its do
cument. | 1366 // styleResolverChanged() call can detach the parser and null out its do
cument. |
1374 // In that case, we just bail out. | 1367 // In that case, we just bail out. |
1375 if (isDetached()) | 1368 if (isDetached()) |
1376 return; | 1369 return; |
1377 | 1370 |
1378 document()->setParsing(true); | 1371 document()->setParsing(true); |
1379 DocumentParser::stopParsing(); | 1372 DocumentParser::stopParsing(); |
1380 } | 1373 } |
1381 #endif | |
1382 } | 1374 } |
1383 | 1375 |
1384 #if ENABLE(XSLT) | |
1385 void* xmlDocPtrForString(CachedResourceLoader* cachedResourceLoader, const Strin
g& source, const String& url) | 1376 void* xmlDocPtrForString(CachedResourceLoader* cachedResourceLoader, const Strin
g& source, const String& url) |
1386 { | 1377 { |
1387 if (source.isEmpty()) | 1378 if (source.isEmpty()) |
1388 return 0; | 1379 return 0; |
1389 | 1380 |
1390 // Parse in a single chunk into an xmlDocPtr | 1381 // Parse in a single chunk into an xmlDocPtr |
1391 // FIXME: Hook up error handlers so that a failure to parse the main documen
t results in | 1382 // FIXME: Hook up error handlers so that a failure to parse the main documen
t results in |
1392 // good error messages. | 1383 // good error messages. |
1393 const UChar BOM = 0xFEFF; | 1384 const UChar BOM = 0xFEFF; |
1394 const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&B
OM); | 1385 const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&B
OM); |
1395 | 1386 |
1396 XMLDocumentParserScope scope(cachedResourceLoader, errorFunc, 0); | 1387 XMLDocumentParserScope scope(cachedResourceLoader, errorFunc, 0); |
1397 xmlDocPtr sourceDoc = xmlReadMemory(reinterpret_cast<const char*>(source.cha
racters()), | 1388 xmlDocPtr sourceDoc = xmlReadMemory(reinterpret_cast<const char*>(source.cha
racters()), |
1398 source.length() * sizeof(UChar), | 1389 source.length() * sizeof(UChar), |
1399 url.latin1().data(), | 1390 url.latin1().data(), |
1400 BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-
16BE", | 1391 BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-
16BE", |
1401 XSLT_PARSE_OPTIONS); | 1392 XSLT_PARSE_OPTIONS); |
1402 return sourceDoc; | 1393 return sourceDoc; |
1403 } | 1394 } |
1404 #endif | |
1405 | 1395 |
1406 OrdinalNumber XMLDocumentParser::lineNumber() const | 1396 OrdinalNumber XMLDocumentParser::lineNumber() const |
1407 { | 1397 { |
1408 return OrdinalNumber::fromOneBasedInt(context() ? context()->input->line : 1
); | 1398 return OrdinalNumber::fromOneBasedInt(context() ? context()->input->line : 1
); |
1409 } | 1399 } |
1410 | 1400 |
1411 OrdinalNumber XMLDocumentParser::columnNumber() const | 1401 OrdinalNumber XMLDocumentParser::columnNumber() const |
1412 { | 1402 { |
1413 return OrdinalNumber::fromOneBasedInt(context() ? context()->input->col : 1)
; | 1403 return OrdinalNumber::fromOneBasedInt(context() ? context()->input->col : 1)
; |
1414 } | 1404 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 sax.startElementNs = attributesStartElementNsHandler; | 1520 sax.startElementNs = attributesStartElementNsHandler; |
1531 sax.initialized = XML_SAX2_MAGIC; | 1521 sax.initialized = XML_SAX2_MAGIC; |
1532 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); | 1522 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); |
1533 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; | 1523 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; |
1534 xmlParseChunk(parser->context(), reinterpret_cast<const char*>(parseString.c
haracters()), parseString.length() * sizeof(UChar), 1); | 1524 xmlParseChunk(parser->context(), reinterpret_cast<const char*>(parseString.c
haracters()), parseString.length() * sizeof(UChar), 1); |
1535 attrsOK = state.gotAttributes; | 1525 attrsOK = state.gotAttributes; |
1536 return state.attributes; | 1526 return state.attributes; |
1537 } | 1527 } |
1538 | 1528 |
1539 } | 1529 } |
OLD | NEW |