diff options
author | dtu@chromium.org <dtu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 21:20:06 +0000 |
---|---|---|
committer | dtu@chromium.org <dtu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 21:20:06 +0000 |
commit | e99274704e1603e54a3d21fd4d87986984d55a58 (patch) | |
tree | 4d5a8b6aa7c4aa86bed7766c71bb9bd64275457d /chrome | |
parent | b02d469b9e0f240e52ea453d13c43cf08ac52e23 (diff) | |
download | chromium_src-e99274704e1603e54a3d21fd4d87986984d55a58.zip chromium_src-e99274704e1603e54a3d21fd4d87986984d55a58.tar.gz chromium_src-e99274704e1603e54a3d21fd4d87986984d55a58.tar.bz2 |
Move libxml_utils from chrome/common to third_party/libxml/chromium.
Why here? Discussion at:
https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/fafe7c6bb54c4ed5/
BUG=chromium:119817
TEST=Chrome builds on all platforms and trybots succeed.
Review URL: https://chromiumcodereview.appspot.com/10251004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/introspect_util.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_operations.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_parser.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_parser_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_util.cc | 2 | ||||
-rw-r--r-- | chrome/browser/importer/toolbar_importer.cc | 2 | ||||
-rw-r--r-- | chrome/browser/importer/toolbar_importer_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/extensions/update_manifest.cc | 4 | ||||
-rw-r--r-- | chrome/common/libxml_utils.cc | 153 | ||||
-rw-r--r-- | chrome/common/libxml_utils.h | 185 | ||||
-rw-r--r-- | chrome/test/reliability/automated_ui_tests.cc | 1 | ||||
-rw-r--r-- | chrome/test/reliability/automated_ui_tests.h | 3 |
14 files changed, 13 insertions, 352 deletions
diff --git a/chrome/DEPS b/chrome/DEPS index 949cb3b..ccba66e 100644 --- a/chrome/DEPS +++ b/chrome/DEPS @@ -44,6 +44,7 @@ include_rules = [ # Allow inclusion of third-party code: "+third_party/hunspell", "+third_party/icon_family", # IconFamily for Mac. + "+third_party/libxml", "+third_party/mozilla", # Mozilla interface headers. "+third_party/npapi", # NPAPI interface headers. "+third_party/skia", diff --git a/chrome/browser/chromeos/dbus/introspect_util.cc b/chrome/browser/chromeos/dbus/introspect_util.cc index 6b7dc5f..997fd7b 100644 --- a/chrome/browser/chromeos/dbus/introspect_util.cc +++ b/chrome/browser/chromeos/dbus/introspect_util.cc @@ -4,7 +4,7 @@ #include "chrome/browser/chromeos/dbus/introspect_util.h" -#include "chrome/common/libxml_utils.h" +#include "third_party/libxml/chromium/libxml_utils.h" namespace { diff --git a/chrome/browser/chromeos/gdata/gdata_operations.cc b/chrome/browser/chromeos/gdata/gdata_operations.cc index ad6df46..2217dd7 100644 --- a/chrome/browser/chromeos/gdata/gdata_operations.cc +++ b/chrome/browser/chromeos/gdata/gdata_operations.cc @@ -12,12 +12,12 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/gdata/gdata_file_system.h" #include "chrome/browser/chromeos/gdata/gdata_util.h" -#include "chrome/common/libxml_utils.h" #include "chrome/common/net/gaia/gaia_urls.h" #include "chrome/common/net/gaia/google_service_auth_error.h" #include "chrome/common/net/url_util.h" #include "net/base/escape.h" #include "net/http/http_util.h" +#include "third_party/libxml/chromium/libxml_utils.h" using content::BrowserThread; using content::URLFetcher; diff --git a/chrome/browser/chromeos/gdata/gdata_parser.cc b/chrome/browser/chromeos/gdata/gdata_parser.cc index 4ee0e3a..b51a805 100644 --- a/chrome/browser/chromeos/gdata/gdata_parser.cc +++ b/chrome/browser/chromeos/gdata/gdata_parser.cc @@ -13,7 +13,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/common/libxml_utils.h" +#include "third_party/libxml/chromium/libxml_utils.h" using base::Value; using base::DictionaryValue; diff --git a/chrome/browser/chromeos/gdata/gdata_parser_unittest.cc b/chrome/browser/chromeos/gdata/gdata_parser_unittest.cc index 26f7ca2..c6dd674 100644 --- a/chrome/browser/chromeos/gdata/gdata_parser_unittest.cc +++ b/chrome/browser/chromeos/gdata/gdata_parser_unittest.cc @@ -12,8 +12,8 @@ #include "base/values.h" #include "chrome/browser/chromeos/gdata/gdata_parser.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/libxml_utils.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/libxml/chromium/libxml_utils.h" using base::Value; using base::DictionaryValue; diff --git a/chrome/browser/chromeos/gdata/gdata_util.cc b/chrome/browser/chromeos/gdata/gdata_util.cc index 7b755b3..8674c93 100644 --- a/chrome/browser/chromeos/gdata/gdata_util.cc +++ b/chrome/browser/chromeos/gdata/gdata_util.cc @@ -19,7 +19,6 @@ #include "base/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "chrome/common/chrome_version_info.h" -#include "chrome/common/libxml_utils.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/browser/chromeos/gdata/gdata_file_system.h" @@ -33,6 +32,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" #include "net/base/escape.h" +#include "third_party/libxml/chromium/libxml_utils.h" namespace gdata { namespace util { diff --git a/chrome/browser/importer/toolbar_importer.cc b/chrome/browser/importer/toolbar_importer.cc index f3d9673..5c601a6 100644 --- a/chrome/browser/importer/toolbar_importer.cc +++ b/chrome/browser/importer/toolbar_importer.cc @@ -15,11 +15,11 @@ #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/libxml_utils.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/url_fetcher.h" #include "grit/generated_resources.h" #include "net/base/load_flags.h" +#include "third_party/libxml/chromium/libxml_utils.h" using content::BrowserThread; diff --git a/chrome/browser/importer/toolbar_importer_unittest.cc b/chrome/browser/importer/toolbar_importer_unittest.cc index 29c0a35..832bb49 100644 --- a/chrome/browser/importer/toolbar_importer_unittest.cc +++ b/chrome/browser/importer/toolbar_importer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,8 @@ #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/first_run/first_run_internal.h" #include "chrome/browser/importer/toolbar_importer.h" -#include "chrome/common/libxml_utils.h" #include "googleurl/src/gurl.h" +#include "third_party/libxml/chromium/libxml_utils.h" // See http://crbug.com/11838 TEST(Toolbar5ImporterTest, BookmarkParse) { diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index b0a3075..cfd765f 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -229,8 +229,6 @@ 'common/nacl_messages.h', 'common/nacl_types.cc', 'common/nacl_types.h', - 'common/libxml_utils.cc', - 'common/libxml_utils.h', 'common/pepper_flash.cc', 'common/pepper_flash.h', 'common/persistent_pref_store.h', diff --git a/chrome/common/extensions/update_manifest.cc b/chrome/common/extensions/update_manifest.cc index 60ac292..acc02b6 100644 --- a/chrome/common/extensions/update_manifest.cc +++ b/chrome/common/extensions/update_manifest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,8 +12,8 @@ #include "base/string_number_conversions.h" #include "base/stringprintf.h" #include "base/version.h" -#include "chrome/common/libxml_utils.h" #include "libxml/tree.h" +#include "third_party/libxml/chromium/libxml_utils.h" static const char* kExpectedGupdateProtocol = "2.0"; static const char* kExpectedGupdateXmlns = diff --git a/chrome/common/libxml_utils.cc b/chrome/common/libxml_utils.cc deleted file mode 100644 index 61d4237..0000000 --- a/chrome/common/libxml_utils.cc +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/common/libxml_utils.h" - -#include "base/compiler_specific.h" -#include "base/file_path.h" -#include "base/logging.h" -#include "base/stringprintf.h" -#include "base/utf_string_conversions.h" - -#include "libxml/xmlreader.h" - -std::string XmlStringToStdString(const xmlChar* xmlstring) { - // xmlChar*s are UTF-8, so this cast is safe. - if (xmlstring) - return std::string(reinterpret_cast<const char*>(xmlstring)); - else - return ""; -} - -XmlReader::XmlReader() - : reader_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - error_func_(this, &XmlReader::GenericErrorCallback)) { -} - -XmlReader::~XmlReader() { - if (reader_) - xmlFreeTextReader(reader_); -} - -// static -void XmlReader::GenericErrorCallback(void* context, const char* msg, ...) { - va_list args; - va_start(args, msg); - - XmlReader* reader = static_cast<XmlReader*>(context); - reader->errors_.append(base::StringPrintV(msg, args)); - va_end(args); -} - -bool XmlReader::Load(const std::string& input) { - const int kParseOptions = XML_PARSE_RECOVER | // recover on errors - XML_PARSE_NONET; // forbid network access - // TODO(evanm): Verify it's OK to pass NULL for the URL and encoding. - // The libxml code allows for these, but it's unclear what effect is has. - reader_ = xmlReaderForMemory(input.data(), static_cast<int>(input.size()), - NULL, NULL, kParseOptions); - return reader_ != NULL; -} - -bool XmlReader::LoadFile(const FilePath& file_path) { - const int kParseOptions = XML_PARSE_RECOVER | // recover on errors - XML_PARSE_NONET; // forbid network access - reader_ = xmlReaderForFile( -#if defined(OS_WIN) - // libxml takes UTF-8 paths on Windows; search the source for - // xmlWrapOpenUtf8 to see it converting UTF-8 back to wide - // characters. - WideToUTF8(file_path.value()).c_str(), -#else - file_path.value().c_str(), -#endif - NULL, kParseOptions); - return reader_ != NULL; -} - -bool XmlReader::NodeAttribute(const char* name, std::string* out) { - xmlChar* value = xmlTextReaderGetAttribute(reader_, BAD_CAST name); - if (!value) - return false; - *out = XmlStringToStdString(value); - xmlFree(value); - return true; -} - -bool XmlReader::ReadElementContent(std::string* content) { - DCHECK(NodeType() == XML_READER_TYPE_ELEMENT); - const int start_depth = Depth(); - - if (xmlTextReaderIsEmptyElement(reader_)) { - // Empty tag. We succesfully read the content, but it's - // empty. - *content = ""; - // Advance past this empty tag. - if (!Read()) - return false; - return true; - } - - // Advance past opening element tag. - if (!Read()) - return false; - - // Read the content. We read up until we hit a closing tag at the - // same level as our starting point. - while (NodeType() != XML_READER_TYPE_END_ELEMENT || Depth() != start_depth) { - *content += XmlStringToStdString(xmlTextReaderConstValue(reader_)); - if (!Read()) - return false; - } - - // Advance past ending element tag. - DCHECK_EQ(NodeType(), XML_READER_TYPE_END_ELEMENT); - if (!Read()) - return false; - - return true; -} - -bool XmlReader::SkipToElement() { - do { - switch (NodeType()) { - case XML_READER_TYPE_ELEMENT: - return true; - case XML_READER_TYPE_END_ELEMENT: - return false; - default: - // Skip all other node types. - continue; - } - } while (Read()); - return false; -} - - -// XmlWriter functions - -XmlWriter::XmlWriter() - : writer_(NULL), - buffer_(NULL) {} - -XmlWriter::~XmlWriter() { - if (writer_) - xmlFreeTextWriter(writer_); - if (buffer_) - xmlBufferFree(buffer_); -} - -void XmlWriter::StartWriting() { - buffer_ = xmlBufferCreate(); - writer_ = xmlNewTextWriterMemory(buffer_, 0); - xmlTextWriterSetIndent(writer_, 1); - xmlTextWriterStartDocument(writer_, NULL, NULL, NULL); -} - -void XmlWriter::StopWriting() { - xmlTextWriterEndDocument(writer_); - xmlFreeTextWriter(writer_); - writer_ = NULL; -} diff --git a/chrome/common/libxml_utils.h b/chrome/common/libxml_utils.h deleted file mode 100644 index cf53341..0000000 --- a/chrome/common/libxml_utils.h +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_COMMON_LIBXML_UTILS_H__ -#define CHROME_COMMON_LIBXML_UTILS_H__ -#pragma once - -#include <string> - -#include "libxml/xmlreader.h" -#include "libxml/xmlwriter.h" - -class FilePath; - -// Converts a libxml xmlChar* into a UTF-8 std::string. -// NULL inputs produce an empty string. -std::string XmlStringToStdString(const xmlChar* xmlstring); - -// libxml uses a global error function pointer for reporting errors. -// A ScopedXmlErrorFunc object lets you change the global error pointer -// for the duration of the object's lifetime. -class ScopedXmlErrorFunc { - public: - ScopedXmlErrorFunc(void* context, xmlGenericErrorFunc func) { - old_error_func_ = xmlGenericError; - old_error_context_ = xmlGenericErrorContext; - xmlSetGenericErrorFunc(context, func); - } - ~ScopedXmlErrorFunc() { - xmlSetGenericErrorFunc(old_error_context_, old_error_func_); - } - - private: - xmlGenericErrorFunc old_error_func_; - void* old_error_context_; -}; - -// XmlReader is a wrapper class around libxml's xmlReader, -// providing a simplified C++ API. -class XmlReader { - public: - XmlReader(); - ~XmlReader(); - - // Load a document into the reader from memory. |input| must be UTF-8 and - // exist for the lifetime of this object. Returns false on error. - // TODO(evanm): handle encodings other than UTF-8? - bool Load(const std::string& input); - - // Load a document into the reader from a file. Returns false on error. - bool LoadFile(const FilePath& file_path); - - // Wrappers around libxml functions ----------------------------------------- - - // Read() advances to the next node. Returns false on EOF or error. - bool Read() { return xmlTextReaderRead(reader_) == 1; } - - // Next(), when pointing at an opening tag, advances to the node after - // the matching closing tag. Returns false on EOF or error. - bool Next() { return xmlTextReaderNext(reader_) == 1; } - - // Return the depth in the tree of the current node. - int Depth() { return xmlTextReaderDepth(reader_); } - - // Returns the "local" name of the current node. - // For a tag like <foo:bar>, this is the string "foo:bar". - std::string NodeName() { - return XmlStringToStdString(xmlTextReaderConstLocalName(reader_)); - } - - // When pointing at a tag, retrieves the value of an attribute. - // Returns false on failure. - // E.g. for <foo bar:baz="a">, NodeAttribute("bar:baz", &value) - // returns true and |value| is set to "a". - bool NodeAttribute(const char* name, std::string* value); - - // Helper functions not provided by libxml ---------------------------------- - - // Return the string content within an element. - // "<foo>bar</foo>" is a sequence of three nodes: - // (1) open tag, (2) text, (3) close tag. - // With the reader currently at (1), this returns the text of (2), - // and advances past (3). - // Returns false on error. - bool ReadElementContent(std::string* content); - - // Skip to the next opening tag, returning false if we reach a closing - // tag or EOF first. - // If currently on an opening tag, doesn't advance at all. - bool SkipToElement(); - - // Returns the errors reported by libxml, if any. - // (libxml normally just dumps these errors to stderr.) - const std::string& errors() const { return errors_; } - - private: - // A callback for libxml to report errors. - static void GenericErrorCallback(void* context, const char* msg, ...); - - // Returns the libxml node type of the current node. - int NodeType() { return xmlTextReaderNodeType(reader_); } - - // The underlying libxml xmlTextReader. - xmlTextReaderPtr reader_; - - // error_func_ is used to reassign libxml's global error function - // to report errors into |errors_| for the lifetime of this object. - ScopedXmlErrorFunc error_func_; - std::string errors_; -}; - -// XmlWriter is a wrapper class around libxml's xmlWriter, -// providing a simplified C++ API. -// StartWriting must be called before other methods, and StopWriting -// must be called before GetWrittenString() will return results. -class XmlWriter { - public: - XmlWriter(); - ~XmlWriter(); - - // Allocates the xmlTextWriter and an xmlBuffer and starts an XML document. - // This must be called before any other functions. By default, indenting is - // set to true. - void StartWriting(); - - // Ends the XML document and frees the xmlTextWriter. - // This must be called before GetWrittenString() is called. - void StopWriting(); - // Wrappers around libxml functions ----------------------------------------- - - // All following elements will be indented to match their depth. - void StartIndenting() { xmlTextWriterSetIndent(writer_, 1); } - - // All follow elements will not be indented. - void StopIndenting() { xmlTextWriterSetIndent(writer_, 0); } - - // Start an element with the given name. All future elements added will be - // children of this element, until it is ended. Returns false on error. - bool StartElement(const std::string& element_name) { - return xmlTextWriterStartElement(writer_, - BAD_CAST element_name.c_str()) >= 0; - } - - // Ends the current open element. Returns false on error. - bool EndElement() { - return xmlTextWriterEndElement(writer_) >= 0; - } - - // Adds an attribute to the current open element. Returns false on error. - bool AddAttribute(const std::string& attribute_name, - const std::string& attribute_value) { - return xmlTextWriterWriteAttribute(writer_, - BAD_CAST attribute_name.c_str(), - BAD_CAST attribute_value.c_str()) >= 0; - } - - // Adds a new element with name |element_name| and content |content| - // to the buffer. Example: <|element_name|>|content|</|element_name|> - // Returns false on errors. - bool WriteElement(const std::string& element_name, - const std::string& content) { - return xmlTextWriterWriteElement(writer_, - BAD_CAST element_name.c_str(), - BAD_CAST content.c_str()) >= 0; - } - - // Helper functions not provided by xmlTextWriter --------------------------- - - // Returns the string that has been written to the buffer. - std::string GetWrittenString() { - if (buffer_ == NULL) - return ""; - return XmlStringToStdString(buffer_->content); - } - - private: - // The underlying libxml xmlTextWriter. - xmlTextWriterPtr writer_; - - // Stores the output. - xmlBufferPtr buffer_; -}; - -#endif // CHROME_COMMON_LIBXML_UTILS_H__ diff --git a/chrome/test/reliability/automated_ui_tests.cc b/chrome/test/reliability/automated_ui_tests.cc index 7710f73..46b23b0 100644 --- a/chrome/test/reliability/automated_ui_tests.cc +++ b/chrome/test/reliability/automated_ui_tests.cc @@ -27,7 +27,6 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/env_vars.h" -#include "chrome/common/libxml_utils.h" #include "chrome/common/url_constants.h" #include "chrome/test/automation/automation_proxy.h" #include "chrome/test/automation/browser_proxy.h" diff --git a/chrome/test/reliability/automated_ui_tests.h b/chrome/test/reliability/automated_ui_tests.h index 25bdccf..73fc5c0 100644 --- a/chrome/test/reliability/automated_ui_tests.h +++ b/chrome/test/reliability/automated_ui_tests.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -105,6 +105,7 @@ #include "chrome/test/reliability/automated_ui_test_base.h" #include "chrome/test/ui/ui_test.h" +#include "third_party/libxml/chromium/libxml_utils.h" #include "ui/base/keycodes/keyboard_codes.h" namespace base { |