From e0c878df5f17e517ad758f1932c7c15ba8a3a980 Mon Sep 17 00:00:00 2001 From: Jelle Bleyaert Date: Mon, 3 Oct 2022 17:46:50 +0000 Subject: [PATCH] Add CefResolveURL function (fixes issue #3402) --- include/capi/cef_parser_capi.h | 10 +++++++- include/cef_api_hash.h | 8 +++--- include/cef_parser.h | 9 +++++++ libcef/common/parser_impl.cc | 15 ++++++++++++ libcef_dll/libcef_dll.cc | 31 +++++++++++++++++++++++- libcef_dll/wrapper/libcef_dll_dylib.cc | 12 ++++++++- libcef_dll/wrapper/libcef_dll_wrapper.cc | 25 ++++++++++++++++++- tests/ceftests/parser_unittest.cc | 12 +++++++++ 8 files changed, 114 insertions(+), 8 deletions(-) diff --git a/include/capi/cef_parser_capi.h b/include/capi/cef_parser_capi.h index 2b76f3984..c9bbdcb13 100644 --- a/include/capi/cef_parser_capi.h +++ b/include/capi/cef_parser_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=a6cb0abd77320cfd9ddfa3f16ca0a6ff3987521a$ +// $hash=f6dfdfa5b8c77931d8e083a66f5a9445a2fdbf45$ // #ifndef CEF_INCLUDE_CAPI_CEF_PARSER_CAPI_H_ @@ -46,6 +46,14 @@ extern "C" { #endif +/// +/// Combines specified |base_url| and |relative_url| into |resolved_url|. +/// Returns false (0) if one of the URLs is NULL or invalid. +/// +CEF_EXPORT int cef_resolve_url(const cef_string_t* base_url, + const cef_string_t* relative_url, + cef_string_t* resolved_url); + /// /// Parse the specified |url| into its component parts. Returns false (0) if the /// URL is NULL or invalid. diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index ee41f9f98..0d00b405d 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "44197292401010f8fce5b053733edd8642d01095" +#define CEF_API_HASH_UNIVERSAL "c06406b23dc4a845177dcd306541ce527d061364" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "95bf7fa1356070be95b7a6fee958355c6619fb63" +#define CEF_API_HASH_PLATFORM "edd206c50f636a935872c9cc251ccb9448b9050e" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "8ec5426d7aa0418fca147380e97623a49cd8eaf4" +#define CEF_API_HASH_PLATFORM "a74e6429302d2d947cc614688e83cd3b29e74c17" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "b2cbc2e6a3048d2415566d35ba434967fd796491" +#define CEF_API_HASH_PLATFORM "e119b68ec7e406ca74ddea5e244af7150eef7118" #endif #ifdef __cplusplus diff --git a/include/cef_parser.h b/include/cef_parser.h index c287a2622..7482c7fea 100644 --- a/include/cef_parser.h +++ b/include/cef_parser.h @@ -43,6 +43,15 @@ #include "include/cef_base.h" #include "include/cef_values.h" +/// +/// Combines specified |base_url| and |relative_url| into |resolved_url|. +/// Returns false if one of the URLs is empty or invalid. +/// +/*--cef()--*/ +bool CefResolveURL(const CefString& base_url, + const CefString& relative_url, + CefString& resolved_url); + /// /// Parse the specified |url| into its component parts. /// Returns false if the URL is empty or invalid. diff --git a/libcef/common/parser_impl.cc b/libcef/common/parser_impl.cc index 219e192fd..073a0700a 100644 --- a/libcef/common/parser_impl.cc +++ b/libcef/common/parser_impl.cc @@ -13,6 +13,21 @@ #include "net/base/mime_util.h" #include "url/gurl.h" +bool CefResolveURL(const CefString& base_url, + const CefString& relative_url, + CefString& resolved_url) { + GURL base_gurl(base_url.ToString()); + if (!base_gurl.is_valid()) + return false; + + GURL combined_gurl = base_gurl.Resolve(relative_url.ToString()); + if (!combined_gurl.is_valid()) + return false; + + resolved_url = combined_gurl.spec(); + return true; +} + bool CefParseURL(const CefString& url, CefURLParts& parts) { GURL gurl(url.ToString()); if (!gurl.is_valid()) diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index c54750e48..c16d94855 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=70f3e95dc09c7676072c8f8ecae04a9c631523ee$ +// $hash=a3be9b3f96ebf8c8840856a6f454729d77459a22$ // #include "include/capi/cef_app_capi.h" @@ -400,6 +400,35 @@ CEF_EXPORT int cef_clear_cross_origin_whitelist() { return _retval; } +CEF_EXPORT int cef_resolve_url(const cef_string_t* base_url, + const cef_string_t* relative_url, + cef_string_t* resolved_url) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: base_url; type: string_byref_const + DCHECK(base_url); + if (!base_url) + return 0; + // Verify param: relative_url; type: string_byref_const + DCHECK(relative_url); + if (!relative_url) + return 0; + // Verify param: resolved_url; type: string_byref + DCHECK(resolved_url); + if (!resolved_url) + return 0; + + // Translate param: resolved_url; type: string_byref + CefString resolved_urlStr(resolved_url); + + // Execute + bool _retval = CefResolveURL(CefString(base_url), CefString(relative_url), + resolved_urlStr); + + // Return type: bool + return _retval; +} + CEF_EXPORT int cef_parse_url(const cef_string_t* url, struct _cef_urlparts_t* parts) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING diff --git a/libcef_dll/wrapper/libcef_dll_dylib.cc b/libcef_dll/wrapper/libcef_dll_dylib.cc index abac1534a..3e6e9e9ac 100644 --- a/libcef_dll/wrapper/libcef_dll_dylib.cc +++ b/libcef_dll/wrapper/libcef_dll_dylib.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=93d56886080f7dc864034a17ce1f794198b14259$ +// $hash=6c8f094d04b36c879f379e87ebf45dc4698eb41e$ // #include @@ -114,6 +114,7 @@ struct libcef_pointers { decltype(&cef_remove_cross_origin_whitelist_entry) cef_remove_cross_origin_whitelist_entry; decltype(&cef_clear_cross_origin_whitelist) cef_clear_cross_origin_whitelist; + decltype(&cef_resolve_url) cef_resolve_url; decltype(&cef_parse_url) cef_parse_url; decltype(&cef_create_url) cef_create_url; decltype(&cef_format_url_for_security_display) @@ -346,6 +347,7 @@ int libcef_init_pointers(const char* path) { INIT_ENTRY(cef_add_cross_origin_whitelist_entry); INIT_ENTRY(cef_remove_cross_origin_whitelist_entry); INIT_ENTRY(cef_clear_cross_origin_whitelist); + INIT_ENTRY(cef_resolve_url); INIT_ENTRY(cef_parse_url); INIT_ENTRY(cef_create_url); INIT_ENTRY(cef_format_url_for_security_display); @@ -677,6 +679,14 @@ NO_SANITIZE("cfi-icall") int cef_clear_cross_origin_whitelist() { return g_libcef_pointers.cef_clear_cross_origin_whitelist(); } +NO_SANITIZE("cfi-icall") +int cef_resolve_url(const cef_string_t* base_url, + const cef_string_t* relative_url, + cef_string_t* resolved_url) { + return g_libcef_pointers.cef_resolve_url(base_url, relative_url, + resolved_url); +} + NO_SANITIZE("cfi-icall") int cef_parse_url(const cef_string_t* url, struct _cef_urlparts_t* parts) { return g_libcef_pointers.cef_parse_url(url, parts); diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index cf70644c1..f3dd3aab1 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=52ee2d630fed6972270fa16ca2ad5c474f723da1$ +// $hash=f1ec7f73b35927e943a058141d73d449dd31e43c$ // #include "include/capi/cef_app_capi.h" @@ -381,6 +381,29 @@ NO_SANITIZE("cfi-icall") CEF_GLOBAL bool CefClearCrossOriginWhitelist() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") +CEF_GLOBAL bool CefResolveURL(const CefString& base_url, + const CefString& relative_url, + CefString& resolved_url) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: base_url; type: string_byref_const + DCHECK(!base_url.empty()); + if (base_url.empty()) + return false; + // Verify param: relative_url; type: string_byref_const + DCHECK(!relative_url.empty()); + if (relative_url.empty()) + return false; + + // Execute + int _retval = cef_resolve_url(base_url.GetStruct(), relative_url.GetStruct(), + resolved_url.GetWritableStruct()); + + // Return type: bool + return _retval ? true : false; +} + NO_SANITIZE("cfi-icall") CEF_GLOBAL bool CefParseURL(const CefString& url, CefURLParts& parts) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING diff --git a/tests/ceftests/parser_unittest.cc b/tests/ceftests/parser_unittest.cc index b4544afb3..28c5cbcbb 100644 --- a/tests/ceftests/parser_unittest.cc +++ b/tests/ceftests/parser_unittest.cc @@ -264,6 +264,18 @@ TEST(ParserTest, ParseURLNonStandard) { EXPECT_STREQ("ref", ref.ToString().c_str()); } +// Combine and parse an absolute and relative URL. +TEST(ParserTest, ParseAbsoluteAndRelativeURL) { + CefString base_url; + base_url.FromASCII("https://www.example.com"); + CefString relative_url; + relative_url.FromASCII("/example"); + CefString resolved_url; + EXPECT_TRUE(CefResolveURL(base_url, relative_url, resolved_url)); + EXPECT_STREQ("https://www.example.com/example", + resolved_url.ToString().c_str()); +} + TEST(ParserTest, FormatUrlForSecurityDisplay) { CefString result;