gfx/skia/trunk/src/ports/SkXMLParser_tinyxml.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkXMLParser.h"
michael@0 11 #include "SkStream.h"
michael@0 12 #include "SkTemplates.h"
michael@0 13 #include "tinyxml.h"
michael@0 14
michael@0 15 static void walk_elem(SkXMLParser* parser, const TiXmlElement* elem)
michael@0 16 {
michael@0 17 //printf("walk_elem(%s) ", elem->Value());
michael@0 18
michael@0 19 parser->startElement(elem->Value());
michael@0 20
michael@0 21 const TiXmlAttribute* attr = elem->FirstAttribute();
michael@0 22 while (attr)
michael@0 23 {
michael@0 24 //printf("walk_elem_attr(%s=\"%s\") ", attr->Name(), attr->Value());
michael@0 25
michael@0 26 parser->addAttribute(attr->Name(), attr->Value());
michael@0 27 attr = attr->Next();
michael@0 28 }
michael@0 29 //printf("\n");
michael@0 30
michael@0 31 const TiXmlNode* node = elem->FirstChild();
michael@0 32 while (node)
michael@0 33 {
michael@0 34 if (node->ToElement())
michael@0 35 walk_elem(parser, node->ToElement());
michael@0 36 else if (node->ToText())
michael@0 37 parser->text(node->Value(), strlen(node->Value()));
michael@0 38 node = node->NextSibling();
michael@0 39 }
michael@0 40
michael@0 41 parser->endElement(elem->Value());
michael@0 42 }
michael@0 43
michael@0 44 static bool load_buf(SkXMLParser* parser, const char buf[])
michael@0 45 {
michael@0 46 TiXmlDocument doc;
michael@0 47
michael@0 48 (void)doc.Parse(buf);
michael@0 49 if (doc.Error())
michael@0 50 {
michael@0 51 printf("tinyxml error: <%s> row[%d] col[%d]\n", doc.ErrorDesc(), doc.ErrorRow(), doc.ErrorCol());
michael@0 52 return false;
michael@0 53 }
michael@0 54
michael@0 55 walk_elem(parser, doc.RootElement());
michael@0 56 return true;
michael@0 57 }
michael@0 58
michael@0 59 bool SkXMLParser::parse(SkStream& stream)
michael@0 60 {
michael@0 61 size_t size = stream.getLength();
michael@0 62
michael@0 63 SkAutoMalloc buffer(size + 1);
michael@0 64 char* buf = (char*)buffer.get();
michael@0 65
michael@0 66 stream.read(buf, size);
michael@0 67 buf[size] = 0;
michael@0 68
michael@0 69 return load_buf(this, buf);
michael@0 70 }
michael@0 71
michael@0 72 bool SkXMLParser::parse(const char doc[], size_t len)
michael@0 73 {
michael@0 74 SkAutoMalloc buffer(len + 1);
michael@0 75 char* buf = (char*)buffer.get();
michael@0 76
michael@0 77 memcpy(buf, doc, len);
michael@0 78 buf[len] = 0;
michael@0 79
michael@0 80 return load_buf(this, buf);
michael@0 81 }
michael@0 82
michael@0 83 void SkXMLParser::GetNativeErrorString(int error, SkString* str)
michael@0 84 {
michael@0 85 if (str)
michael@0 86 str->set("GetNativeErrorString not implemented for TinyXml");
michael@0 87 }

mercurial