Introduce CefString and cef_string_t implementations that support string type conversions and customization of the API string type (issue #146).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@145 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2010-11-22 17:49:46 +00:00
parent 1e1c2ad8d7
commit 7d60642638
121 changed files with 2598 additions and 3209 deletions

View File

@@ -18,7 +18,7 @@ public:
bool Load(CefRefPtr<CefStreamReader> stream,
CefXmlReader::EncodingType encodingType,
const std::wstring& URI)
const CefString& URI)
{
CefRefPtr<CefXmlReader> reader(
CefXmlReader::Create(stream, encodingType, URI));
@@ -31,7 +31,7 @@ public:
CefXmlObject::ObjectVector queue;
int cur_depth, value_depth = -1;
CefXmlReader::NodeType cur_type;
std::wstringstream cur_value;
std::stringstream cur_value;
bool last_has_ns = false;
queue.push_back(root_object_);
@@ -47,17 +47,17 @@ public:
if (cur_type == XML_NODE_ELEMENT_START) {
if (cur_depth == value_depth) {
// Add to the current value.
cur_value << reader->GetOuterXml();
cur_value << std::string(reader->GetOuterXml());
continue;
} else if(last_has_ns && reader->GetPrefix().empty()) {
if (!cur_object->HasChildren()) {
// Start a new value because the last element has a namespace and
// this element does not.
value_depth = cur_depth;
cur_value << reader->GetOuterXml();
cur_value << std::string(reader->GetOuterXml());
} else {
// Value following a child element is not allowed.
std::wstringstream ss;
std::stringstream ss;
ss << L"Value following child element, line " <<
reader->GetLineNumber();
load_error_ = ss.str();
@@ -93,7 +93,7 @@ public:
} else if (cur_depth < value_depth) {
// Done with parsing the value portion of the current element.
cur_object->SetValue(cur_value.str());
cur_value.str(L"");
cur_value.str("");
value_depth = -1;
}
@@ -105,9 +105,10 @@ public:
// Open tag without close tag or close tag without open tag should
// never occur (the parser catches this error).
DCHECK(false);
std::wstringstream ss;
ss << L"Mismatched end tag for " << cur_object->GetName() <<
L", line " << reader->GetLineNumber();
std::stringstream ss;
ss << "Mismatched end tag for " <<
std::string(cur_object->GetName()) <<
", line " << reader->GetLineNumber();
load_error_ = ss.str();
ret = false;
break;
@@ -119,15 +120,15 @@ public:
cur_type == XML_NODE_ENTITY_REFERENCE) {
if (cur_depth == value_depth) {
// Add to the current value.
cur_value << reader->GetValue();
cur_value << std::string(reader->GetValue());
} else if (!cur_object->HasChildren()) {
// Start a new value.
value_depth = cur_depth;
cur_value << reader->GetValue();
cur_value << std::string(reader->GetValue());
} else {
// Value following a child element is not allowed.
std::wstringstream ss;
ss << L"Value following child element, line " <<
std::stringstream ss;
ss << "Value following child element, line " <<
reader->GetLineNumber();
load_error_ = ss.str();
ret = false;
@@ -145,16 +146,16 @@ public:
return ret;
}
std::wstring GetLoadError() { return load_error_; }
CefString GetLoadError() { return load_error_; }
private:
std::wstring load_error_;
CefString load_error_;
CefRefPtr<CefXmlObject> root_object_;
};
} // namespace
CefXmlObject::CefXmlObject(const std::wstring& name)
CefXmlObject::CefXmlObject(const CefString& name)
: name_(name), parent_(NULL)
{
}
@@ -165,7 +166,7 @@ CefXmlObject::~CefXmlObject()
bool CefXmlObject::Load(CefRefPtr<CefStreamReader> stream,
CefXmlReader::EncodingType encodingType,
const std::wstring& URI, std::wstring* loadError)
const CefString& URI, CefString* loadError)
{
AutoLock lock_scope(this);
Clear();
@@ -236,9 +237,9 @@ void CefXmlObject::Clear()
ClearAttributes();
}
std::wstring CefXmlObject::GetName()
CefString CefXmlObject::GetName()
{
std::wstring name;
CefString name;
{
AutoLock lock_scope(this);
name = name_;
@@ -246,7 +247,7 @@ std::wstring CefXmlObject::GetName()
return name;
}
bool CefXmlObject::SetName(const std::wstring& name)
bool CefXmlObject::SetName(const CefString& name)
{
DCHECK(!name.empty());
if (name.empty())
@@ -279,9 +280,9 @@ bool CefXmlObject::HasValue()
return !value_.empty();
}
std::wstring CefXmlObject::GetValue()
CefString CefXmlObject::GetValue()
{
std::wstring value;
CefString value;
{
AutoLock lock_scope(this);
value = value_;
@@ -289,7 +290,7 @@ std::wstring CefXmlObject::GetValue()
return value;
}
bool CefXmlObject::SetValue(const std::wstring& value)
bool CefXmlObject::SetValue(const CefString& value)
{
AutoLock lock_scope(this);
DCHECK(children_.empty());
@@ -311,7 +312,7 @@ size_t CefXmlObject::GetAttributeCount()
return attributes_.size();
}
bool CefXmlObject::HasAttribute(const std::wstring& name)
bool CefXmlObject::HasAttribute(const CefString& name)
{
if (name.empty())
return false;
@@ -321,10 +322,10 @@ bool CefXmlObject::HasAttribute(const std::wstring& name)
return (it != attributes_.end());
}
std::wstring CefXmlObject::GetAttributeValue(const std::wstring& name)
CefString CefXmlObject::GetAttributeValue(const CefString& name)
{
DCHECK(!name.empty());
std::wstring value;
CefString value;
if (!name.empty()) {
AutoLock lock_scope(this);
AttributeMap::const_iterator it = attributes_.find(name);
@@ -334,8 +335,8 @@ std::wstring CefXmlObject::GetAttributeValue(const std::wstring& name)
return value;
}
bool CefXmlObject::SetAttributeValue(const std::wstring& name,
const std::wstring& value)
bool CefXmlObject::SetAttributeValue(const CefString& name,
const CefString& value)
{
DCHECK(!name.empty());
if (name.empty())
@@ -346,8 +347,7 @@ bool CefXmlObject::SetAttributeValue(const std::wstring& name,
if (it != attributes_.end()) {
it->second = value;
} else {
attributes_.insert(
std::make_pair<std::wstring,std::wstring>(name, value));
attributes_.insert(std::make_pair(name, value));
}
return true;
}
@@ -441,7 +441,7 @@ void CefXmlObject::ClearChildren()
children_.clear();
}
CefRefPtr<CefXmlObject> CefXmlObject::FindChild(const std::wstring& name)
CefRefPtr<CefXmlObject> CefXmlObject::FindChild(const CefString& name)
{
DCHECK(!name.empty());
if (name.empty())
@@ -456,7 +456,7 @@ CefRefPtr<CefXmlObject> CefXmlObject::FindChild(const std::wstring& name)
return NULL;
}
size_t CefXmlObject::FindChildren(const std::wstring& name,
size_t CefXmlObject::FindChildren(const CefString& name,
ObjectVector& children)
{
DCHECK(!name.empty());

View File

@@ -70,7 +70,7 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
continue;
}
if (!reader->OpenFile(L""))
if (!reader->OpenFile(CefString()))
break;
name = reader->GetFileName();
@@ -99,8 +99,7 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
count++;
// Add the file to the map.
contents_.insert(
std::make_pair<std::wstring, CefRefPtr<File> >(name, contents.get()));
contents_.insert(std::make_pair(name, contents.get()));
} while (reader->MoveToNextFile());
return count;
@@ -118,36 +117,36 @@ size_t CefZipArchive::GetFileCount()
return contents_.size();
}
bool CefZipArchive::HasFile(const std::wstring& fileName)
bool CefZipArchive::HasFile(const CefString& fileName)
{
std::wstring str = fileName;
std::transform(str.begin(), str.end(), str.begin(), towlower);
AutoLock lock_scope(this);
FileMap::const_iterator it = contents_.find(str);
FileMap::const_iterator it = contents_.find(CefString(str));
return (it != contents_.end());
}
CefRefPtr<CefZipArchive::File> CefZipArchive::GetFile(
const std::wstring& fileName)
const CefString& fileName)
{
std::wstring str = fileName;
std::transform(str.begin(), str.end(), str.begin(), towlower);
AutoLock lock_scope(this);
FileMap::const_iterator it = contents_.find(str);
FileMap::const_iterator it = contents_.find(CefString(str));
if (it != contents_.end())
return it->second;
return NULL;
}
bool CefZipArchive::RemoveFile(const std::wstring& fileName)
bool CefZipArchive::RemoveFile(const CefString& fileName)
{
std::wstring str = fileName;
std::transform(str.begin(), str.end(), str.begin(), towlower);
AutoLock lock_scope(this);
FileMap::iterator it = contents_.find(str);
FileMap::iterator it = contents_.find(CefString(str));
if (it != contents_.end()) {
contents_.erase(it);
return true;

View File

@@ -61,30 +61,40 @@ void CefDoMessageLoopWork()
cef_do_message_loop_work();
}
bool CefRegisterExtension(const std::wstring& extension_name,
const std::wstring& javascript_code,
bool CefRegisterExtension(const CefString& extension_name,
const CefString& javascript_code,
CefRefPtr<CefV8Handler> handler)
{
return cef_register_extension(extension_name.c_str(), javascript_code.c_str(),
CefV8HandlerCppToC::Wrap(handler))?true:false;
return cef_register_extension(extension_name.GetStruct(),
javascript_code.GetStruct(), CefV8HandlerCppToC::Wrap(handler))?
true:false;
}
bool CefRegisterPlugin(const struct CefPluginInfo& plugin_info)
{
cef_plugin_info_t pluginInfo;
memset(&pluginInfo, 0, sizeof(pluginInfo));
pluginInfo.unique_name = plugin_info.unique_name.c_str();
pluginInfo.display_name = plugin_info.display_name.c_str();
pluginInfo.version =plugin_info.version.c_str();
pluginInfo.description = plugin_info.description.c_str();
cef_string_set(plugin_info.unique_name.c_str(),
plugin_info.unique_name.length(),
&pluginInfo.unique_name, false);
cef_string_set(plugin_info.display_name.c_str(),
plugin_info.display_name.length(),
&pluginInfo.display_name, false);
cef_string_set(plugin_info.version.c_str(),
plugin_info.version.length(),
&pluginInfo.version, false);
cef_string_set(plugin_info.description.c_str(),
plugin_info.description.length(),
&pluginInfo.description, false);
std::wstring mimeTypes, fileExtensions, typeDescriptions;
std::string mimeTypes, fileExtensions, typeDescriptions;
for(size_t i = 0; i < plugin_info.mime_types.size(); ++i) {
if(i > 0) {
mimeTypes += L"|";
fileExtensions += L"|";
typeDescriptions += L"|";
mimeTypes += "|";
fileExtensions += "|";
typeDescriptions += "|";
}
mimeTypes += plugin_info.mime_types[i].mime_type;
@@ -93,28 +103,37 @@ bool CefRegisterPlugin(const struct CefPluginInfo& plugin_info)
for(size_t j = 0;
j < plugin_info.mime_types[i].file_extensions.size(); ++j) {
if(j > 0) {
fileExtensions += L",";
fileExtensions += ",";
}
fileExtensions += plugin_info.mime_types[i].file_extensions[j];
}
}
pluginInfo.mime_types = mimeTypes.c_str();
pluginInfo.file_extensions = fileExtensions.c_str();
pluginInfo.type_descriptions = typeDescriptions.c_str();
cef_string_from_utf8(mimeTypes.c_str(), mimeTypes.length(),
&pluginInfo.mime_types);
cef_string_from_utf8(fileExtensions.c_str(), fileExtensions.length(),
&pluginInfo.file_extensions);
cef_string_from_utf8(typeDescriptions.c_str(), typeDescriptions.length(),
&pluginInfo.type_descriptions);
pluginInfo.np_getentrypoints = plugin_info.np_getentrypoints;
pluginInfo.np_initialize = plugin_info.np_initialize;
pluginInfo.np_shutdown = plugin_info.np_shutdown;
return (cef_register_plugin(&pluginInfo) ? true : false);
bool ret = cef_register_plugin(&pluginInfo) ? true : false;
cef_string_clear(&pluginInfo.mime_types);
cef_string_clear(&pluginInfo.file_extensions);
cef_string_clear(&pluginInfo.type_descriptions);
return ret;
}
bool CefRegisterScheme(const std::wstring& scheme_name,
const std::wstring& host_name,
bool CefRegisterScheme(const CefString& scheme_name,
const CefString& host_name,
CefRefPtr<CefSchemeHandlerFactory> factory)
{
return cef_register_scheme(scheme_name.c_str(), host_name.c_str(),
return cef_register_scheme(scheme_name.GetStruct(), host_name.GetStruct(),
CefSchemeHandlerFactoryCppToC::Wrap(factory))?true:false;
}