Skip to content

Commit

Permalink
feat: unify string type
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Jan 14, 2025
1 parent 45fc5a8 commit 00e3899
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 92 deletions.
47 changes: 23 additions & 24 deletions include/CefViewBrowserApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#pragma once

#pragma region stl_headers
#include <string>
#include <unordered_map>
#include <list>
#pragma endregion
Expand All @@ -21,16 +20,16 @@

struct FolderResourceMapping
{
std::string path;
std::string url;
CefString path;
CefString url;
int priority;
};

struct ArchiveResourceMapping
{
std::string path;
std::string url;
std::string password;
CefString path;
CefString url;
CefString password;
int priority;
};

Expand All @@ -42,8 +41,8 @@ class CefViewBrowserApp

private:
// The name of the bridge object
std::string builtin_scheme_name_;
std::string bridge_object_name_;
CefString builtin_scheme_name_;
CefString bridge_object_name_;
std::unordered_map<void*, CefViewBrowserClientDelegateInterface::WeakPtr> client_handler_map_;

// The app delegate
Expand All @@ -54,8 +53,8 @@ class CefViewBrowserApp
std::list<ArchiveResourceMapping> archiveResourceMappingList_;

public:
CefViewBrowserApp(const std::string& scheme_name,
const std::string& bridge_name,
CefViewBrowserApp(const CefString& scheme_name,
const CefString& bridge_name,
CefViewBrowserAppDelegateInterface::RefPtr delegate);

~CefViewBrowserApp();
Expand All @@ -66,30 +65,30 @@ class CefViewBrowserApp

CefViewBrowserClientDelegateInterface::RefPtr GetClientHandler(void* ctx);

void AddLocalFolderResource(const std::string& path, const std::string& url, int priority = 0);
void AddLocalFolderResource(const CefString& path, const CefString& url, int priority = 0);
const std::list<FolderResourceMapping>& FolderResourceMappingList();

void AddArchiveResource(const std::string& path,
const std::string& url,
const std::string& password = "",
void AddArchiveResource(const CefString& path,
const CefString& url,
const CefString& password = "",
int priority = 0);
const std::list<ArchiveResourceMapping>& ArchiveResourceMappingList();

bool AddGlobalCookie(const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& url);
bool AddGlobalCookie(const CefString& name,
const CefString& value,
const CefString& domain,
const CefString& url);

bool DeleteAllCookies();

bool AddCrossOriginWhitelistEntry(const std::string& sourceOrigin,
const std::string& targetSchema,
const std::string& targetDomain,
bool AddCrossOriginWhitelistEntry(const CefString& sourceOrigin,
const CefString& targetSchema,
const CefString& targetDomain,
bool allowTargetSubdomains);

bool RemoveCrossOriginWhitelistEntry(const std::string& sourceOrigin,
const std::string& targetSchema,
const std::string& targetDomain,
bool RemoveCrossOriginWhitelistEntry(const CefString& sourceOrigin,
const CefString& targetSchema,
const CefString& targetDomain,
bool allowTargetSubdomains);

bool ClearCrossOriginWhitelistEntry();
Expand Down
1 change: 0 additions & 1 deletion include/CefViewBrowserAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#pragma region stl_headers
#include <memory>
#include <string>
#pragma endregion

#include <CefViewCoreGlobal.h>
Expand Down
9 changes: 4 additions & 5 deletions include/CefViewBrowserClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#pragma once

#pragma region stl_headers
#include <string>
#include <unordered_map>
#pragma endregion

Expand Down Expand Up @@ -110,7 +109,7 @@ class CefViewBrowserClient
/// <param name="dir_path"></param>
/// <param name="url"></param>
/// <param name="priority"></param>
void AddLocalDirectoryResourceProvider(const std::string& dir_path, const std::string& url, int priority = 0);
void AddLocalDirectoryResourceProvider(const CefString& dir_path, const CefString& url, int priority = 0);

/// <summary>
///
Expand All @@ -119,9 +118,9 @@ class CefViewBrowserClient
/// <param name="url"></param>
/// <param name="password"></param>
/// <param name="priority"></param>
void AddArchiveResourceProvider(const std::string& archive_path,
const std::string& url,
const std::string& password,
void AddArchiveResourceProvider(const CefString& archive_path,
const CefString& url,
const CefString& password,
int priority = 0);

bool TriggerEvent(CefRefPtr<CefBrowser> browser, const CefFrameId& frame_id, const CefRefPtr<CefProcessMessage> msg);
Expand Down
1 change: 0 additions & 1 deletion include/CefViewBrowserClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#pragma region stl_headers
#include <memory>
#include <string>
#pragma endregion

#include <CefViewCoreGlobal.h>
Expand Down
60 changes: 31 additions & 29 deletions src/CefView/CefBrowserApp/CefViewBrowserApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "CefViewSchemeHandler/CefViewSchemeHandlerFactory.h"

CefViewBrowserApp::CefViewBrowserApp(const std::string& scheme_name,
const std::string& bridge_name,
CefViewBrowserApp::CefViewBrowserApp(const CefString& scheme_name,
const CefString& bridge_name,
CefViewBrowserAppDelegateInterface::RefPtr delegate)
: builtin_scheme_name_(scheme_name.empty() ? kCefViewDefaultBuiltinSchemaName : scheme_name)
, bridge_object_name_(bridge_name.empty() ? kCefViewDefaultBridgeObjectName : bridge_name)
Expand All @@ -26,7 +26,7 @@ CefViewBrowserApp::CefViewBrowserApp(const std::string& scheme_name,

CefViewBrowserApp::~CefViewBrowserApp()
{
log_debug("CefViewBrowserApp::~CefViewBrowserApp");
logD("CefViewBrowserApp::~CefViewBrowserApp");
}

void
Expand All @@ -51,7 +51,7 @@ CefViewBrowserApp::GetClientHandler(void* ctx)
}

void
CefViewBrowserApp::AddLocalFolderResource(const std::string& path, const std::string& url, int priority /*= 0*/)
CefViewBrowserApp::AddLocalFolderResource(const CefString& path, const CefString& url, int priority /*= 0*/)
{
folderResourceMappingList_.emplace_back(FolderResourceMapping{ path, url, priority });
}
Expand All @@ -63,9 +63,9 @@ CefViewBrowserApp::FolderResourceMappingList()
}

void
CefViewBrowserApp::AddArchiveResource(const std::string& path,
const std::string& url,
const std::string& password /*= ""*/,
CefViewBrowserApp::AddArchiveResource(const CefString& path,
const CefString& url,
const CefString& password /*= ""*/,
int priority /*= 0*/)
{
archiveResourceMappingList_.emplace_back(ArchiveResourceMapping{ path, url, password, priority });
Expand All @@ -78,15 +78,15 @@ CefViewBrowserApp::ArchiveResourceMappingList()
}

bool
CefViewBrowserApp::AddGlobalCookie(const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& url)
CefViewBrowserApp::AddGlobalCookie(const CefString& name,
const CefString& value,
const CefString& domain,
const CefString& url)
{
CefCookie cookie;
CefString(&cookie.name).FromString(name);
CefString(&cookie.value).FromString(value);
CefString(&cookie.domain).FromString(domain);
CefString(&cookie.name) = name;
CefString(&cookie.value) = value;
CefString(&cookie.domain) = domain;
return CefCookieManager::GetGlobalManager(nullptr)->SetCookie(CefString(url), cookie, nullptr);
}

Expand All @@ -97,27 +97,21 @@ CefViewBrowserApp::DeleteAllCookies()
}

bool
CefViewBrowserApp::AddCrossOriginWhitelistEntry(const std::string& sourceOrigin,
const std::string& targetSchema,
const std::string& targetDomain,
CefViewBrowserApp::AddCrossOriginWhitelistEntry(const CefString& sourceOrigin,
const CefString& targetSchema,
const CefString& targetDomain,
bool allowTargetSubdomains)
{
CefString source(sourceOrigin);
CefString schema(targetSchema);
CefString domain(targetDomain);
return CefAddCrossOriginWhitelistEntry(source, schema, domain, allowTargetSubdomains);
return CefAddCrossOriginWhitelistEntry(sourceOrigin, targetSchema, targetDomain, allowTargetSubdomains);
}

bool
CefViewBrowserApp::RemoveCrossOriginWhitelistEntry(const std::string& sourceOrigin,
const std::string& targetSchema,
const std::string& targetDomain,
CefViewBrowserApp::RemoveCrossOriginWhitelistEntry(const CefString& sourceOrigin,
const CefString& targetSchema,
const CefString& targetDomain,
bool allowTargetSubdomains)
{
CefString source(sourceOrigin);
CefString schema(targetSchema);
CefString domain(targetDomain);
return CefRemoveCrossOriginWhitelistEntry(source, schema, domain, allowTargetSubdomains);
return CefRemoveCrossOriginWhitelistEntry(sourceOrigin, targetSchema, targetDomain, allowTargetSubdomains);
}

bool
Expand Down Expand Up @@ -146,7 +140,15 @@ CefViewBrowserApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registr
{
if (registrar) {
// register custom scheme
registrar->AddCustomScheme(builtin_scheme_name_, 0);
int options = 0 //
| CEF_SCHEME_OPTION_STANDARD //
| CEF_SCHEME_OPTION_SECURE //
| CEF_SCHEME_OPTION_CORS_ENABLED //
| CEF_SCHEME_OPTION_FETCH_ENABLED //
| 0;
if (!registrar->AddCustomScheme(builtin_scheme_name_, options)) {
logE("faield to add built-in scheme: %s", builtin_scheme_name_.c_str());
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/CefView/CefBrowserApp/CefViewBrowserClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ CefViewBrowserClient::CloseAllBrowsers()
}

void
CefViewBrowserClient::AddLocalDirectoryResourceProvider(const std::string& dir_path,
const std::string& url,
CefViewBrowserClient::AddLocalDirectoryResourceProvider(const CefString& dir_path,
const CefString& url,
int priority /* = 0*/)
{
if (dir_path.empty() || url.empty())
return;

// convert to lower case
auto lower_url = url;
auto lower_url = url.ToString();
std::transform(
lower_url.begin(), lower_url.end(), lower_url.begin(), [](unsigned char c) { return std::tolower(c); });

Expand All @@ -75,9 +75,9 @@ CefViewBrowserClient::AddLocalDirectoryResourceProvider(const std::string& dir_p
}

void
CefViewBrowserClient::AddArchiveResourceProvider(const std::string& archive_path,
const std::string& url,
const std::string& password,
CefViewBrowserClient::AddArchiveResourceProvider(const CefString& archive_path,
const CefString& url,
const CefString& password,
int priority /*= 0*/)
{
if (archive_path.empty() || url.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#pragma once

#include <string>

#include <CefViewCoreGlobal.h>
#include <CefViewBrowserClientDelegate.h>

Expand Down
24 changes: 16 additions & 8 deletions src/CefWing/App/CefViewAppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const char kProcessType[] = "type";
const char kZygoteProcess[] = "zygote";
const char kRendererProcess[] = "renderer";

CefViewAppBase::CefViewAppBase(const std::string& scheme_name)
CefViewAppBase::CefViewAppBase(const CefString& scheme_name)
: builtin_scheme_name_(scheme_name)
{
}
Expand All @@ -22,7 +22,7 @@ CefViewAppBase::GetProcessType(CefRefPtr<CefCommandLine> command_line)
if (!command_line->HasSwitch(kProcessType))
return UnkownProcess;

const std::string& process_type = command_line->GetSwitchValue(kProcessType);
auto process_type = command_line->GetSwitchValue(kProcessType);
logI("process type parameter is: %s", process_type.c_str());
if (process_type == kZygoteProcess) {
// for linux only
Expand All @@ -34,24 +34,24 @@ CefViewAppBase::GetProcessType(CefRefPtr<CefCommandLine> command_line)
return OtherProcess;
}

std::string
CefString
CefViewAppBase::GetBridgeObjectName(CefRefPtr<CefCommandLine> command_line)
{
if (!command_line->HasSwitch(kCefViewBridgeObjectNameKey))
return "";

const std::string& name = command_line->GetSwitchValue(kCefViewBridgeObjectNameKey);
auto name = command_line->GetSwitchValue(kCefViewBridgeObjectNameKey);
logI("bridge object name: %s", name.c_str());
return name;
}

std::string
CefString
CefViewAppBase::GetBuiltinSchemeName(CefRefPtr<CefCommandLine> command_line)
{
if (!command_line->HasSwitch(kCefViewBuiltinSchemeNameKey))
return "";

const std::string& name = command_line->GetSwitchValue(kCefViewBuiltinSchemeNameKey);
auto name = command_line->GetSwitchValue(kCefViewBuiltinSchemeNameKey);
logI("built-in scheme name: %s", name.c_str());
return name;
}
Expand All @@ -60,7 +60,15 @@ void
CefViewAppBase::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
if (registrar) {
registrar->AddCustomScheme(builtin_scheme_name_.empty() ? kCefViewDefaultBuiltinSchemaName : builtin_scheme_name_,
0);
int options = 0 //
| CEF_SCHEME_OPTION_STANDARD //
| CEF_SCHEME_OPTION_SECURE //
| CEF_SCHEME_OPTION_CORS_ENABLED //
| CEF_SCHEME_OPTION_FETCH_ENABLED //
| 0;
auto scheme = builtin_scheme_name_.empty() ? kCefViewDefaultBuiltinSchemaName : builtin_scheme_name_;
if (!registrar->AddCustomScheme(scheme, options)) {
logE("faield to add built-in scheme: %s", scheme.c_str());
}
}
}
8 changes: 4 additions & 4 deletions src/CefWing/App/CefViewAppBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class CefViewAppBase : public CefApp
/// <summary>
///
/// </summary>
std::string builtin_scheme_name_;
CefString builtin_scheme_name_;

public:
CefViewAppBase(const std::string& scheme_name);
CefViewAppBase(const CefString& scheme_name);

enum ProcessType
{
Expand All @@ -47,14 +47,14 @@ class CefViewAppBase : public CefApp
/// </summary>
/// <param name="command_line">The command line</param>
/// <returns>The bridge object name</returns>
static std::string GetBridgeObjectName(CefRefPtr<CefCommandLine> command_line);
static CefString GetBridgeObjectName(CefRefPtr<CefCommandLine> command_line);

/// <summary>
/// Gets the built-in scheme name
/// </summary>
/// <param name="command_line">The command line</param>
/// <returns>The built-in scheme name</returns>
static std::string GetBuiltinSchemeName(CefRefPtr<CefCommandLine> command_line);
static CefString GetBuiltinSchemeName(CefRefPtr<CefCommandLine> command_line);

private:
/// <summary>
Expand Down
Loading

0 comments on commit 00e3899

Please sign in to comment.