mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	Add CefResolveURL function (fixes issue #3402)
This commit is contained in:
		
				
					committed by
					
						 Marshall Greenblatt
						Marshall Greenblatt
					
				
			
			
				
	
			
			
			
						parent
						
							5433d9fe5c
						
					
				
				
					commit
					e0c878df5f
				
			| @@ -33,7 +33,7 @@ | |||||||
| // by hand. See the translator.README.txt file in the tools directory for | // by hand. See the translator.README.txt file in the tools directory for | ||||||
| // more information. | // more information. | ||||||
| // | // | ||||||
| // $hash=a6cb0abd77320cfd9ddfa3f16ca0a6ff3987521a$ | // $hash=f6dfdfa5b8c77931d8e083a66f5a9445a2fdbf45$ | ||||||
| // | // | ||||||
|  |  | ||||||
| #ifndef CEF_INCLUDE_CAPI_CEF_PARSER_CAPI_H_ | #ifndef CEF_INCLUDE_CAPI_CEF_PARSER_CAPI_H_ | ||||||
| @@ -46,6 +46,14 @@ | |||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #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 | /// Parse the specified |url| into its component parts. Returns false (0) if the | ||||||
| /// URL is NULL or invalid. | /// URL is NULL or invalid. | ||||||
|   | |||||||
| @@ -42,13 +42,13 @@ | |||||||
| // way that may cause binary incompatibility with other builds. The universal | // way that may cause binary incompatibility with other builds. The universal | ||||||
| // hash value will change if any platform is affected whereas the platform hash | // hash value will change if any platform is affected whereas the platform hash | ||||||
| // values will change only if that particular platform is affected. | // 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) | #if defined(OS_WIN) | ||||||
| #define CEF_API_HASH_PLATFORM "95bf7fa1356070be95b7a6fee958355c6619fb63" | #define CEF_API_HASH_PLATFORM "edd206c50f636a935872c9cc251ccb9448b9050e" | ||||||
| #elif defined(OS_MAC) | #elif defined(OS_MAC) | ||||||
| #define CEF_API_HASH_PLATFORM "8ec5426d7aa0418fca147380e97623a49cd8eaf4" | #define CEF_API_HASH_PLATFORM "a74e6429302d2d947cc614688e83cd3b29e74c17" | ||||||
| #elif defined(OS_LINUX) | #elif defined(OS_LINUX) | ||||||
| #define CEF_API_HASH_PLATFORM "b2cbc2e6a3048d2415566d35ba434967fd796491" | #define CEF_API_HASH_PLATFORM "e119b68ec7e406ca74ddea5e244af7150eef7118" | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
|   | |||||||
| @@ -43,6 +43,15 @@ | |||||||
| #include "include/cef_base.h" | #include "include/cef_base.h" | ||||||
| #include "include/cef_values.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. | /// Parse the specified |url| into its component parts. | ||||||
| /// Returns false if the URL is empty or invalid. | /// Returns false if the URL is empty or invalid. | ||||||
|   | |||||||
| @@ -13,6 +13,21 @@ | |||||||
| #include "net/base/mime_util.h" | #include "net/base/mime_util.h" | ||||||
| #include "url/gurl.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) { | bool CefParseURL(const CefString& url, CefURLParts& parts) { | ||||||
|   GURL gurl(url.ToString()); |   GURL gurl(url.ToString()); | ||||||
|   if (!gurl.is_valid()) |   if (!gurl.is_valid()) | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
| // implementations. See the translator.README.txt file in the tools directory | // implementations. See the translator.README.txt file in the tools directory | ||||||
| // for more information. | // for more information. | ||||||
| // | // | ||||||
| // $hash=70f3e95dc09c7676072c8f8ecae04a9c631523ee$ | // $hash=a3be9b3f96ebf8c8840856a6f454729d77459a22$ | ||||||
| // | // | ||||||
|  |  | ||||||
| #include "include/capi/cef_app_capi.h" | #include "include/capi/cef_app_capi.h" | ||||||
| @@ -400,6 +400,35 @@ CEF_EXPORT int cef_clear_cross_origin_whitelist() { | |||||||
|   return _retval; |   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, | CEF_EXPORT int cef_parse_url(const cef_string_t* url, | ||||||
|                              struct _cef_urlparts_t* parts) { |                              struct _cef_urlparts_t* parts) { | ||||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING |   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
| // implementations. See the translator.README.txt file in the tools directory | // implementations. See the translator.README.txt file in the tools directory | ||||||
| // for more information. | // for more information. | ||||||
| // | // | ||||||
| // $hash=93d56886080f7dc864034a17ce1f794198b14259$ | // $hash=6c8f094d04b36c879f379e87ebf45dc4698eb41e$ | ||||||
| // | // | ||||||
|  |  | ||||||
| #include <dlfcn.h> | #include <dlfcn.h> | ||||||
| @@ -114,6 +114,7 @@ struct libcef_pointers { | |||||||
|   decltype(&cef_remove_cross_origin_whitelist_entry) |   decltype(&cef_remove_cross_origin_whitelist_entry) | ||||||
|       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_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_parse_url) cef_parse_url; | ||||||
|   decltype(&cef_create_url) cef_create_url; |   decltype(&cef_create_url) cef_create_url; | ||||||
|   decltype(&cef_format_url_for_security_display) |   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_add_cross_origin_whitelist_entry); | ||||||
|   INIT_ENTRY(cef_remove_cross_origin_whitelist_entry); |   INIT_ENTRY(cef_remove_cross_origin_whitelist_entry); | ||||||
|   INIT_ENTRY(cef_clear_cross_origin_whitelist); |   INIT_ENTRY(cef_clear_cross_origin_whitelist); | ||||||
|  |   INIT_ENTRY(cef_resolve_url); | ||||||
|   INIT_ENTRY(cef_parse_url); |   INIT_ENTRY(cef_parse_url); | ||||||
|   INIT_ENTRY(cef_create_url); |   INIT_ENTRY(cef_create_url); | ||||||
|   INIT_ENTRY(cef_format_url_for_security_display); |   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(); |   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") | NO_SANITIZE("cfi-icall") | ||||||
| int cef_parse_url(const cef_string_t* url, struct _cef_urlparts_t* parts) { | int cef_parse_url(const cef_string_t* url, struct _cef_urlparts_t* parts) { | ||||||
|   return g_libcef_pointers.cef_parse_url(url, parts); |   return g_libcef_pointers.cef_parse_url(url, parts); | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
| // implementations. See the translator.README.txt file in the tools directory | // implementations. See the translator.README.txt file in the tools directory | ||||||
| // for more information. | // for more information. | ||||||
| // | // | ||||||
| // $hash=52ee2d630fed6972270fa16ca2ad5c474f723da1$ | // $hash=f1ec7f73b35927e943a058141d73d449dd31e43c$ | ||||||
| // | // | ||||||
|  |  | ||||||
| #include "include/capi/cef_app_capi.h" | #include "include/capi/cef_app_capi.h" | ||||||
| @@ -381,6 +381,29 @@ NO_SANITIZE("cfi-icall") CEF_GLOBAL bool CefClearCrossOriginWhitelist() { | |||||||
|   return _retval ? true : false; |   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") | NO_SANITIZE("cfi-icall") | ||||||
| CEF_GLOBAL bool CefParseURL(const CefString& url, CefURLParts& parts) { | CEF_GLOBAL bool CefParseURL(const CefString& url, CefURLParts& parts) { | ||||||
|   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING |   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING | ||||||
|   | |||||||
| @@ -264,6 +264,18 @@ TEST(ParserTest, ParseURLNonStandard) { | |||||||
|   EXPECT_STREQ("ref", ref.ToString().c_str()); |   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) { | TEST(ParserTest, FormatUrlForSecurityDisplay) { | ||||||
|   CefString result; |   CefString result; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user