Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions libcef/browser/xml_reader_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "cef/libcef/browser/xml_reader_impl.h"

#include <format>

#include "base/logging.h"
#include "base/notreached.h"
#include "cef/include/cef_stream.h"
Expand Down Expand Up @@ -62,13 +64,13 @@ void XMLCALL xml_error_callback(void* arg,
error_str.resize(error_str.length() - 1);
}

std::stringstream ss;
ss << error_str << ", line " << xmlTextReaderLocatorLineNumber(locator);
auto formatted_error = std::format("{}, line {}", error_str,
xmlTextReaderLocatorLineNumber(locator));

LOG(INFO) << ss.str();
LOG(INFO) << formatted_error;

CefRefPtr<CefXmlReaderImpl> impl(static_cast<CefXmlReaderImpl*>(arg));
impl->AppendError(ss.str());
impl->AppendError(formatted_error);
}

/**
Expand All @@ -90,13 +92,12 @@ void XMLCALL xml_structured_error_callback(void* userData,
error_str.resize(error_str.length() - 1);
}

std::stringstream ss;
ss << error_str << ", line " << error->line;
auto formatted_error = std::format("{}, line {}", error_str, error->line);

LOG(INFO) << ss.str();
LOG(INFO) << formatted_error;

CefRefPtr<CefXmlReaderImpl> impl(static_cast<CefXmlReaderImpl*>(userData));
impl->AppendError(ss.str());
impl->AppendError(formatted_error);
}

CefString xmlCharToString(const xmlChar* xmlStr, bool free) {
Expand Down Expand Up @@ -205,15 +206,15 @@ bool CefXmlReaderImpl::HasError() {
return false;
}

return !error_buf_.str().empty();
return !error_buf_.empty();
}

CefString CefXmlReaderImpl::GetError() {
if (!VerifyContext()) {
return CefString();
}

return error_buf_.str();
return error_buf_;
}

CefXmlReader::NodeType CefXmlReaderImpl::GetType() {
Expand Down Expand Up @@ -476,10 +477,10 @@ bool CefXmlReaderImpl::MoveToCarryingElement() {
}

void CefXmlReaderImpl::AppendError(const CefString& error_str) {
if (!error_buf_.str().empty()) {
error_buf_ << L"\n";
if (!error_buf_.empty()) {
error_buf_ += '\n';
}
error_buf_ << error_str.ToString();
error_buf_ += error_str.ToString();
}

bool CefXmlReaderImpl::VerifyContext() {
Expand Down
4 changes: 2 additions & 2 deletions libcef/browser/xml_reader_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <libxml/xmlreader.h>

#include <sstream>
#include <string>

#include "base/threading/platform_thread.h"
#include "cef/include/cef_xml_reader.h"
Expand Down Expand Up @@ -67,7 +67,7 @@ class CefXmlReaderImpl : public CefXmlReader {
base::PlatformThreadId supported_thread_id_;
CefRefPtr<CefStreamReader> stream_;
xmlTextReaderPtr reader_ = nullptr;
std::stringstream error_buf_;
std::string error_buf_;

IMPLEMENT_REFCOUNTING(CefXmlReaderImpl);
};
Expand Down
2 changes: 0 additions & 2 deletions libcef/browser/zip_reader_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#define CEF_LIBCEF_BROWSER_ZIP_READER_IMPL_H_
#pragma once

#include <sstream>

#include "base/threading/platform_thread.h"
#include "cef/include/cef_zip_reader.h"
#include "third_party/zlib/contrib/minizip/unzip.h"
Expand Down
27 changes: 15 additions & 12 deletions libcef/common/parser_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.

#include <sstream>
#include <string>

#include "base/base64.h"
#include "base/strings/escape.h"
Expand Down Expand Up @@ -67,29 +67,32 @@ bool CefCreateURL(const CefURLParts& parts, CefString& url) {
if (!spec.empty()) {
gurl = GURL(spec);
} else if (!scheme.empty() && !host.empty()) {
std::stringstream ss;
ss << scheme << "://";
std::string url_str = scheme + "://";
if (!username.empty()) {
ss << username;
url_str += username;
if (!password.empty()) {
ss << ":" << password;
url_str += ':';
url_str += password;
}
ss << "@";
url_str += '@';
}
ss << host;
url_str += host;
if (!port.empty()) {
ss << ":" << port;
url_str += ':';
url_str += port;
}
if (!path.empty()) {
ss << path;
url_str += path;
}
if (!query.empty()) {
ss << "?" << query;
url_str += '?';
url_str += query;
}
if (!fragment.empty()) {
ss << "#" << fragment;
url_str += '#';
url_str += fragment;
}
gurl = GURL(ss.str());
gurl = GURL(url_str);
}

if (gurl.is_valid()) {
Expand Down
57 changes: 25 additions & 32 deletions libcef_dll/base/cef_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include <mach/mach_time.h>
#endif

#include <iomanip>
#include <format>
#include <iostream>
#include <sstream>
#include <string>

#include "include/base/cef_immediate_crash.h"

Expand Down Expand Up @@ -353,31 +353,30 @@ void ScopedEarlySupport::log(const char* file,
std::min(std::size_t{6}, strlen(file)))
: file;

std::stringstream stream;

stream << '[';
std::string log_line = "[";
if (config.log_prefix) {
stream << config.log_prefix << ':';
log_line += config.log_prefix;
log_line += ':';
}
if (config.log_process_id) {
#if defined(OS_WIN)
stream << ::GetCurrentProcessId() << ':';
log_line += std::format("{}:", ::GetCurrentProcessId());
#elif defined(OS_POSIX)
stream << getpid() << ':';
log_line += std::format("{}:", getpid());
#else
#error Unsupported platform
#endif
}
if (config.log_thread_id) {
#if defined(OS_WIN)
stream << ::GetCurrentThreadId() << ':';
log_line += std::format("{}:", ::GetCurrentThreadId());
#elif defined(OS_APPLE)
uint64_t tid;
if (pthread_threadid_np(nullptr, &tid) == 0) {
stream << tid << ':';
log_line += std::format("{}:", tid);
}
#elif defined(OS_POSIX)
stream << pthread_self() << ':';
log_line += std::format("{}:", pthread_self());
#else
#error Unsupported platform
#endif
Expand All @@ -386,38 +385,34 @@ void ScopedEarlySupport::log(const char* file,
#if defined(OS_WIN)
SYSTEMTIME local_time;
GetLocalTime(&local_time);
stream << std::setfill('0') << std::setw(2) << local_time.wMonth
<< std::setw(2) << local_time.wDay << '/' << std::setw(2)
<< local_time.wHour << std::setw(2) << local_time.wMinute
<< std::setw(2) << local_time.wSecond << '.' << std::setw(3)
<< local_time.wMilliseconds << ':';
log_line +=
std::format("{:02}{:02}/{:02}{:02}{:02}.{:03}:", local_time.wMonth,
local_time.wDay, local_time.wHour, local_time.wMinute,
local_time.wSecond, local_time.wMilliseconds);
#elif defined(OS_POSIX)
timeval tv;
gettimeofday(&tv, nullptr);
time_t t = tv.tv_sec;
struct tm local_time;
localtime_r(&t, &local_time);
struct tm* tm_time = &local_time;
stream << std::setfill('0') << std::setw(2) << 1 + tm_time->tm_mon
<< std::setw(2) << tm_time->tm_mday << '/' << std::setw(2)
<< tm_time->tm_hour << std::setw(2) << tm_time->tm_min
<< std::setw(2) << tm_time->tm_sec << '.' << std::setw(6)
<< tv.tv_usec << ':';
log_line +=
std::format("{:02}{:02}/{:02}{:02}{:02}.{:06}:", 1 + tm_time->tm_mon,
tm_time->tm_mday, tm_time->tm_hour, tm_time->tm_min,
tm_time->tm_sec, tv.tv_usec);
#else
#error Unsupported platform
#endif
}
if (config.log_tickcount) {
stream << TickCount() << ':';
log_line += std::format("{}:", TickCount());
}
if (severity >= 0) {
stream << log_severity_name(severity);
log_line += log_severity_name(severity);
} else {
stream << "VERBOSE" << -severity;
log_line += std::format("VERBOSE{}", -severity);
}
stream << ":" << filename << ":" << line << "] " << message;

const std::string& log_line = stream.str();
log_line += std::format(":{}:{}] {}", filename, line, message);

if (!config.formatted_log_handler ||
!config.formatted_log_handler(log_line.c_str())) {
Expand Down Expand Up @@ -521,17 +516,15 @@ std::string SystemErrorCodeToString(SystemErrorCode error_code) {
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
DWORD len = FormatMessageA(flags, NULL, error_code, 0, msgbuf,
static_cast<DWORD>(std::size(msgbuf)), NULL);
std::stringstream ss;
if (len) {
std::string s(msgbuf);
// Messages returned by system end with line breaks.
s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
ss << s << " (0x" << std::hex << error_code << ")";
return std::format("{} ({:#x})", s, error_code);
} else {
ss << "Error (0x" << std::hex << GetLastError()
<< ") while retrieving error. (0x" << error_code << ")";
return std::format("Error ({:#x}) while retrieving error. ({:#x})",
GetLastError(), error_code);
}
return ss.str();
}
#elif defined(OS_POSIX)
std::string SystemErrorCodeToString(SystemErrorCode error_code) {
Expand Down
9 changes: 4 additions & 5 deletions libcef_dll/wrapper/cef_scoped_library_loader_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <mach-o/dyld.h>
#include <stdio.h>

#include <format>
#include <memory>
#include <sstream>

#include "include/wrapper/cef_library_loader.h"

Expand Down Expand Up @@ -38,10 +38,9 @@
}

// Append the relative path to the framework.
std::stringstream ss;
ss << parent_dir << "/" << (helper ? kPathFromHelperExe : kPathFromMainExe)
<< "/" << kFrameworkPath;
return ss.str();
return std::format("{}/{}/{}", parent_dir,
helper ? kPathFromHelperExe : kPathFromMainExe,
kFrameworkPath);
}

} // namespace
Expand Down
6 changes: 2 additions & 4 deletions libcef_dll/wrapper/cef_scoped_sandbox_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <mach-o/dyld.h>
#include <stdio.h>

#include <format>
#include <memory>
#include <sstream>

#include "include/cef_sandbox_mac.h"

Expand Down Expand Up @@ -39,9 +39,7 @@
}

// Append the relative path to the library.
std::stringstream ss;
ss << parent_dir << "/" << kLibraryPath;
return ss.str();
return std::format("{}/{}", parent_dir, kLibraryPath);
}

void* LoadLibrary(const char* path) {
Expand Down
Loading