Commit cae0ffba authored by tkent@chromium.org's avatar tkent@chromium.org

Fix style errors in core/xml/.

BUG=

Review URL: https://codereview.chromium.org/333143003

git-svn-id: svn://svn.chromium.org/blink/trunk@176505 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3adad0ac
......@@ -61,13 +61,13 @@ void XMLErrors::handleError(ErrorType type, const char* message, int lineNumber,
void XMLErrors::handleError(ErrorType type, const char* message, TextPosition position)
{
if (type == fatal || (m_errorCount < maxErrors && m_lastErrorPosition.m_line != position.m_line && m_lastErrorPosition.m_column != position.m_column)) {
if (type == ErrorTypeFatal || (m_errorCount < maxErrors && m_lastErrorPosition.m_line != position.m_line && m_lastErrorPosition.m_column != position.m_column)) {
switch (type) {
case warning:
case ErrorTypeWarning:
appendErrorMessage("warning", position, message);
break;
case fatal:
case nonFatal:
case ErrorTypeFatal:
case ErrorTypeNonFatal:
appendErrorMessage("error", position, message);
}
......
......@@ -44,7 +44,7 @@ public:
void trace(Visitor*);
// Exposed for callbacks:
enum ErrorType { warning, nonFatal, fatal };
enum ErrorType { ErrorTypeWarning, ErrorTypeNonFatal, ErrorTypeFatal };
void handleError(ErrorType, const char* message, int lineNumber, int columnNumber);
void handleError(ErrorType, const char* message, TextPosition);
......
......@@ -717,10 +717,11 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
if (areMethodAndURLValidForSend()) {
if (getRequestHeader("Content-Type").isEmpty()) {
const String& blobType = body->type();
if (!blobType.isEmpty() && isValidContentType(blobType))
if (!blobType.isEmpty() && isValidContentType(blobType)) {
setRequestHeaderInternal("Content-Type", AtomicString(blobType));
else {
// From FileAPI spec, whenever media type cannot be determined, empty string must be returned.
} else {
// From FileAPI spec, whenever media type cannot be determined,
// empty string must be returned.
setRequestHeaderInternal("Content-Type", "");
}
}
......@@ -1345,19 +1346,22 @@ void XMLHttpRequest::didReceiveData(const char* data, int len)
bool useDecoder = m_responseTypeCode == ResponseTypeDefault || m_responseTypeCode == ResponseTypeText || m_responseTypeCode == ResponseTypeJSON || m_responseTypeCode == ResponseTypeDocument;
if (useDecoder && !m_decoder) {
if (m_responseTypeCode == ResponseTypeJSON)
if (m_responseTypeCode == ResponseTypeJSON) {
m_decoder = TextResourceDecoder::create("application/json", "UTF-8");
else if (!m_responseEncoding.isEmpty())
} else if (!m_responseEncoding.isEmpty()) {
m_decoder = TextResourceDecoder::create("text/plain", m_responseEncoding);
// allow TextResourceDecoder to look inside the m_response if it's XML or HTML
else if (responseIsXML()) {
} else if (responseIsXML()) {
m_decoder = TextResourceDecoder::create("application/xml");
// Don't stop on encoding errors, unlike it is done for other kinds of XML resources. This matches the behavior of previous WebKit versions, Firefox and Opera.
// Don't stop on encoding errors, unlike it is done for other kinds
// of XML resources. This matches the behavior of previous WebKit
// versions, Firefox and Opera.
m_decoder->useLenientXMLDecoding();
} else if (equalIgnoringCase(responseMIMEType(), "text/html"))
} else if (equalIgnoringCase(responseMIMEType(), "text/html")) {
m_decoder = TextResourceDecoder::create("text/html", "UTF-8");
else
} else {
m_decoder = TextResourceDecoder::create("text/plain", "UTF-8");
}
}
if (!len)
......
......@@ -53,7 +53,12 @@ class ThreadableLoader;
typedef int ExceptionCode;
class XMLHttpRequest FINAL : public RefCountedWillBeRefCountedGarbageCollected<XMLHttpRequest>, public ScriptWrappable, public XMLHttpRequestEventTarget, private ThreadableLoaderClient, public ActiveDOMObject {
class XMLHttpRequest FINAL
: public RefCountedWillBeRefCountedGarbageCollected<XMLHttpRequest>
, public ScriptWrappable
, public XMLHttpRequestEventTarget
, private ThreadableLoaderClient
, public ActiveDOMObject {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
REFCOUNTED_EVENT_TARGET(XMLHttpRequest);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(XMLHttpRequest);
......
......@@ -101,8 +101,9 @@ void XMLHttpRequestProgressEventThrottle::dispatchEvent(PassRefPtrWillBeRawPtr<E
return;
}
m_deferredEvents.append(event);
} else
} else {
m_target->dispatchEvent(event);
}
}
bool XMLHttpRequestProgressEventThrottle::flushDeferredProgressEvent()
......
......@@ -69,13 +69,12 @@ void XSLImportRule::setXSLStyleSheet(const String& href, const KURL& baseURL, co
bool XSLImportRule::isLoading()
{
return (m_loading || (m_styleSheet && m_styleSheet->isLoading()));
return m_loading || (m_styleSheet && m_styleSheet->isLoading());
}
void XSLImportRule::loadSheet()
{
ResourceFetcher* fetcher = 0;
XSLStyleSheet* rootSheet = parentStyleSheet();
if (rootSheet) {
......@@ -88,12 +87,13 @@ void XSLImportRule::loadSheet()
String absHref = m_strHref;
XSLStyleSheet* parentSheet = parentStyleSheet();
if (!parentSheet->baseURL().isNull())
// use parent styleheet's URL as the base URL
if (!parentSheet->baseURL().isNull()) {
// Use parent styleheet's URL as the base URL
absHref = KURL(parentSheet->baseURL(), m_strHref).string();
}
// Check for a cycle in our import chain. If we encounter a stylesheet
// in our parent chain with the same URL, then just bail.
// Check for a cycle in our import chain. If we encounter a stylesheet in
// our parent chain with the same URL, then just bail.
for (XSLStyleSheet* parentSheet = parentStyleSheet(); parentSheet; parentSheet = parentSheet->parentStyleSheet()) {
if (absHref == parentSheet->baseURL().string())
return;
......@@ -105,10 +105,10 @@ void XSLImportRule::loadSheet()
if (m_resource) {
m_resource->addClient(this);
// If the imported sheet is in the cache, then setXSLStyleSheet gets called,
// and the sheet even gets parsed (via parseString). In this case we have
// loaded (even if our subresources haven't), so if we have a stylesheet after
// checking the cache, then we've clearly loaded.
// If the imported sheet is in the cache, then setXSLStyleSheet gets
// called, and the sheet even gets parsed (via parseString). In this
// case we have loaded (even if our subresources haven't), so if we have
// a stylesheet after checking the cache, then we've clearly loaded.
if (!m_styleSheet)
m_loading = true;
}
......
......@@ -27,7 +27,6 @@
#include "core/dom/ProcessingInstruction.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/PassRefPtr.h"
#include <libxml/tree.h>
#include <libxslt/transform.h>
......@@ -54,8 +53,9 @@ public:
return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, finalURL.string(), finalURL, true));
}
// Taking an arbitrary node is unsafe, because owner node pointer can become stale.
// XSLTProcessor ensures that the stylesheet doesn't outlive its parent, in part by not exposing it to JavaScript.
// Taking an arbitrary node is unsafe, because owner node pointer can become
// stale. XSLTProcessor ensures that the stylesheet doesn't outlive its
// parent, in part by not exposing it to JavaScript.
static PassRefPtrWillBeRawPtr<XSLStyleSheet> createForXSLTProcessor(Node* parentNode, const String& originalURL, const KURL& finalURL)
{
ASSERT(RuntimeEnabledFeatures::xsltEnabled());
......@@ -77,7 +77,7 @@ public:
Document* ownerDocument();
virtual XSLStyleSheet* parentStyleSheet() const OVERRIDE { return m_parentStyleSheet; }
void setParentStyleSheet(XSLStyleSheet* parent);
void setParentStyleSheet(XSLStyleSheet*);
xmlDocPtr document();
xsltStylesheetPtr compileStyleSheet();
......
......@@ -32,7 +32,6 @@
#include "core/xml/parser/XMLDocumentParserScope.h"
#include "core/xml/parser/XMLParserInput.h"
#include "wtf/text/CString.h"
#include <libxml/uri.h>
#include <libxslt/xsltutils.h>
......@@ -44,7 +43,9 @@ XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& originalUR
, m_finalURL(finalURL)
, m_isDisabled(false)
, m_embedded(false)
, m_processed(false) // Child sheets get marked as processed when the libxslt engine has finally seen them.
// Child sheets get marked as processed when the libxslt engine has finally
// seen them.
, m_processed(false)
, m_stylesheetDoc(0)
, m_stylesheetDocTaken(false)
, m_compilationFailed(false)
......@@ -116,10 +117,9 @@ void XSLStyleSheet::clearDocuments()
ResourceFetcher* XSLStyleSheet::fetcher()
{
Document* document = ownerDocument();
if (!document)
return 0;
return document->fetcher();
if (Document* document = ownerDocument())
return document->fetcher();
return 0;
}
bool XSLStyleSheet::parseString(const String& source)
......@@ -130,8 +130,7 @@ bool XSLStyleSheet::parseString(const String& source)
m_stylesheetDocTaken = false;
FrameConsole* console = 0;
LocalFrame* frame = ownerDocument()->frame();
if (frame)
if (LocalFrame* frame = ownerDocument()->frame())
console = &frame->console();
XMLDocumentParserScope scope(fetcher(), XSLTProcessor::genericErrorFunc, XSLTProcessor::parseErrorFunc, console);
......@@ -169,25 +168,26 @@ void XSLStyleSheet::loadChildSheets()
xmlNodePtr stylesheetRoot = document()->children;
// Top level children may include other things such as DTD nodes, we ignore those.
// Top level children may include other things such as DTD nodes, we ignore
// those.
while (stylesheetRoot && stylesheetRoot->type != XML_ELEMENT_NODE)
stylesheetRoot = stylesheetRoot->next;
if (m_embedded) {
// We have to locate (by ID) the appropriate embedded stylesheet element, so that we can walk the
// import/include list.
// We have to locate (by ID) the appropriate embedded stylesheet
// element, so that we can walk the import/include list.
xmlAttrPtr idNode = xmlGetID(document(), (const xmlChar*)(finalURL().string().utf8().data()));
if (!idNode)
return;
stylesheetRoot = idNode->parent;
} else {
// FIXME: Need to handle an external URI with a # in it. This is a pretty minor edge case, so we'll deal
// with it later.
// FIXME: Need to handle an external URI with a # in it. This is a
// pretty minor edge case, so we'll deal with it later.
}
if (stylesheetRoot) {
// Walk the children of the root element and look for import/include elements.
// Imports must occur first.
// Walk the children of the root element and look for import/include
// elements. Imports must occur first.
xmlNodePtr curr = stylesheetRoot->children;
while (curr) {
if (curr->type != XML_ELEMENT_NODE) {
......@@ -198,8 +198,9 @@ void XSLStyleSheet::loadChildSheets()
xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);
loadChildSheet(String::fromUTF8((const char*)uriRef));
xmlFree(uriRef);
} else
} else {
break;
}
curr = curr->next;
}
......@@ -229,8 +230,8 @@ xsltStylesheetPtr XSLStyleSheet::compileStyleSheet()
if (m_embedded)
return xsltLoadStylesheetPI(document());
// Certain libxslt versions are corrupting the xmlDoc on compilation failures -
// hence attempting to recompile after a failure is unsafe.
// Certain libxslt versions are corrupting the xmlDoc on compilation
// failures - hence attempting to recompile after a failure is unsafe.
if (m_compilationFailed)
return 0;
......@@ -273,9 +274,9 @@ xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const
continue; // libxslt has been given this sheet already.
// Check the URI of the child stylesheet against the doc URI.
// In order to ensure that libxml canonicalized both URLs, we get the original href
// string from the import rule and canonicalize it using libxml before comparing it
// with the URI argument.
// In order to ensure that libxml canonicalized both URLs, we get
// the original href string from the import rule and canonicalize it
// using libxml before comparing it with the URI argument.
CString importHref = import->href().utf8();
xmlChar* base = xmlNodeGetBase(parentDoc, (xmlNodePtr)parentDoc);
xmlChar* childURI = xmlBuildURI((const xmlChar*)importHref.data(), base);
......
......@@ -25,23 +25,22 @@
*/
#include "config.h"
#include "core/xml/XSLTExtensions.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/Assertions.h"
#include <libxml/xpathInternals.h>
#include <libxslt/extensions.h>
#include <libxslt/extra.h>
#include <libxslt/xsltutils.h>
namespace WebCore {
// FIXME: This code is taken from libexslt 1.1.11; should sync with newer versions.
// FIXME: This code is taken from libexslt 1.1.11; should sync with newer
// versions.
static void exsltNodeSetFunction(xmlXPathParserContextPtr ctxt, int nargs)
{
xmlChar *strval;
xmlChar* strval;
xmlNodePtr retNode;
xmlXPathObjectPtr ret;
......@@ -56,15 +55,15 @@ static void exsltNodeSetFunction(xmlXPathParserContextPtr ctxt, int nargs)
}
strval = xmlXPathPopString(ctxt);
retNode = xmlNewDocText(NULL, strval);
retNode = xmlNewDocText(0, strval);
ret = xmlXPathNewValueTree(retNode);
// FIXME: It might be helpful to push any errors from xmlXPathNewValueTree
// up to the Javascript Console.
if (ret != NULL)
if (ret)
ret->type = XPATH_NODESET;
if (strval != NULL)
if (strval)
xmlFree(strval);
valuePush(ctxt, ret);
......
......@@ -85,11 +85,9 @@ void XSLTProcessor::parseErrorFunc(void* userData, xmlError* error)
// FIXME: There seems to be no way to control the ctxt pointer for loading here, thus we have globals.
static XSLTProcessor* globalProcessor = 0;
static ResourceFetcher* globalResourceFetcher = 0;
static xmlDocPtr docLoaderFunc(const xmlChar* uri,
xmlDictPtr,
int options,
void* ctxt,
xsltLoadType type)
static xmlDocPtr docLoaderFunc(
const xmlChar* uri, xmlDictPtr, int options, void* ctxt, xsltLoadType type)
{
if (!globalProcessor)
return 0;
......@@ -179,7 +177,8 @@ static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, Str
if (retval < 0)
return false;
// Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: libxslt appends an extra line feed to the result.
// Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>:
// libxslt appends an extra line feed to the result.
if (resultBuilder.length() > 0 && resultBuilder[resultBuilder.length() - 1] == '\n')
resultBuilder.resize(resultBuilder.length() - 1);
......@@ -193,7 +192,7 @@ static const char** xsltParamArrayFromParameterMap(XSLTProcessor::ParameterMap&
if (parameters.isEmpty())
return 0;
const char** parameterArray = (const char**)fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*));
const char** parameterArray = static_cast<const char**>(fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*)));
XSLTProcessor::ParameterMap::iterator end = parameters.end();
unsigned index = 0;
......@@ -213,8 +212,8 @@ static void freeXsltParamArray(const char** params)
return;
while (*temp) {
fastFree((void*)*(temp++));
fastFree((void*)*(temp++));
fastFree(const_cast<char*>(*(temp++)));
fastFree(const_cast<char*>(*(temp++)));
}
fastFree(params);
}
......@@ -222,12 +221,14 @@ static void freeXsltParamArray(const char** params)
static xsltStylesheetPtr xsltStylesheetPointer(RefPtrWillBeMember<XSLStyleSheet>& cachedStylesheet, Node* stylesheetRootNode)
{
if (!cachedStylesheet && stylesheetRootNode) {
cachedStylesheet = XSLStyleSheet::createForXSLTProcessor(stylesheetRootNode->parentNode() ? stylesheetRootNode->parentNode() : stylesheetRootNode,
cachedStylesheet = XSLStyleSheet::createForXSLTProcessor(
stylesheetRootNode->parentNode() ? stylesheetRootNode->parentNode() : stylesheetRootNode,
stylesheetRootNode->document().url().string(),
stylesheetRootNode->document().url()); // FIXME: Should we use baseURL here?
// According to Mozilla documentation, the node must be a Document node, an xsl:stylesheet or xsl:transform element.
// But we just use text content regardless of node type.
// According to Mozilla documentation, the node must be a Document node,
// an xsl:stylesheet or xsl:transform element. But we just use text
// content regardless of node type.
cachedStylesheet->parseString(createMarkup(stylesheetRootNode));
}
......@@ -292,8 +293,9 @@ bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String
bool success = false;
bool shouldFreeSourceDoc = false;
if (xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode, shouldFreeSourceDoc)) {
// The XML declaration would prevent parsing the result as a fragment, and it's not needed even for documents,
// as the result of this function is always immediately parsed.
// The XML declaration would prevent parsing the result as a fragment,
// and it's not needed even for documents, as the result of this
// function is always immediately parsed.
sheet->omitXmlDeclaration = true;
xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc);
......@@ -310,13 +312,15 @@ bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String
if (0 != xsltSetCtxtSecurityPrefs(securityPrefs, transformContext))
CRASH();
// <http://bugs.webkit.org/show_bug.cgi?id=16077>: XSLT processor <xsl:sort> algorithm only compares by code point.
// <http://bugs.webkit.org/show_bug.cgi?id=16077>: XSLT processor
// <xsl:sort> algorithm only compares by code point.
xsltSetCtxtSortFunc(transformContext, xsltUnicodeSortFunction);
// This is a workaround for a bug in libxslt.
// The bug has been fixed in version 1.1.13, so once we ship that this can be removed.
// The bug has been fixed in version 1.1.13, so once we ship that this
// can be removed.
if (!transformContext->globalVars)
transformContext->globalVars = xmlHashCreate(20);
transformContext->globalVars = xmlHashCreate(20);
const char** params = xsltParamArrayFromParameterMap(m_parameters);
xsltQuoteUserParams(transformContext, params);
......
......@@ -32,7 +32,7 @@
namespace WebCore {
void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr* sorts, int nbsorts);
void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr* sorts, int nbsorts);
}
......
......@@ -33,23 +33,22 @@ namespace WebCore {
class ResourceFetcher;
class XMLDocumentParserScope {
WTF_MAKE_NONCOPYABLE(XMLDocumentParserScope);
public:
explicit XMLDocumentParserScope(ResourceFetcher*);
~XMLDocumentParserScope();
static ResourceFetcher* currentFetcher;
XMLDocumentParserScope(ResourceFetcher*, xmlGenericErrorFunc, xmlStructuredErrorFunc = 0, void* errorContext = 0);
private:
ResourceFetcher* m_oldFetcher;
xmlGenericErrorFunc m_oldGenericErrorFunc;
xmlStructuredErrorFunc m_oldStructuredErrorFunc;
void* m_oldErrorContext;
};
class XMLDocumentParserScope {
WTF_MAKE_NONCOPYABLE(XMLDocumentParserScope);
public:
explicit XMLDocumentParserScope(ResourceFetcher*);
XMLDocumentParserScope(ResourceFetcher*, xmlGenericErrorFunc, xmlStructuredErrorFunc = 0, void* errorContext = 0);
~XMLDocumentParserScope();
static ResourceFetcher* currentFetcher;
private:
ResourceFetcher* m_oldFetcher;
xmlGenericErrorFunc m_oldGenericErrorFunc;
xmlStructuredErrorFunc m_oldStructuredErrorFunc;
void* m_oldErrorContext;
};
} // namespace WebCore
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment