代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/security_security_component_manager 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h
index 270d10a..0891ee0 100644
--- a/include/capi/cef_browser_capi.h
+++ b/include/capi/cef_browser_capi.h
@@ -513,7 +513,8 @@ typedef struct _cef_browser_t {
/// Set url trust list.
///
int(CEF_CALLBACK* set_url_trust_list)(struct _cef_browser_t* self,
- const cef_string_t* urlTrustList);
+ const cef_string_t* urlTrustList,
+ cef_string_t* detailErrMsg);
} cef_browser_t;
///
diff --git a/include/cef_browser.h b/include/cef_browser.h
index 95f14c7..a249f4e 100644
--- a/include/cef_browser.h
+++ b/include/cef_browser.h
@@ -510,7 +510,7 @@ class CefBrowser : public virtual CefBaseRefCounted {
/// Set url trust list.
///
/*--cef()--*/
- virtual int SetUrlTrustList(const CefString& urlTrustList) = 0;
+ virtual int SetUrlTrustList(const CefString& urlTrustList, CefString& detailErrMsg) = 0;
/* ---------- ohos_nweb_ex add end --------- */
#endif // BUILDFLAG(IS_OHOS)
diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc
index 39efe2b..65e1c5a 100644
--- a/libcef/browser/browser_host_base.cc
+++ b/libcef/browser/browser_host_base.cc
@@ -3800,9 +3800,10 @@ bool CefBrowserHostBase::WebPageSnapshot(
#endif
#if OHOS_URL_TRUST_LIST
-int CefBrowserHostBase::SetUrlTrustList(const CefString& urlTrustList) {
+int CefBrowserHostBase::SetUrlTrustList(const CefString& urlTrustList, CefString& detailErrMsg) {
std::string urlTrustListUpdated = urlTrustList.ToString();
content::WebContents* webContents = GetWebContents();
+ std::string detailErrMsgUpdated;
if (!webContents) {
LOG(ERROR) << "SetUrlTrustList failed, web contents is error.";
return static_cast<int>(ohos_safe_browsing::UrlListSetResult::INIT_ERROR);
@@ -3822,6 +3823,8 @@ int CefBrowserHostBase::SetUrlTrustList(const CefString& urlTrustList) {
&ohos_safe_browsing::OhosUrlTrustListInterface::interfaceKey,
std::unique_ptr<base::SupportsUserData::Data>(manager));
}
- return static_cast<int>(manager->SetUrlTrustList(urlTrustListUpdated));
+ int res = static_cast<int>(manager->SetUrlTrustList(urlTrustListUpdated, detailErrMsgUpdated));
+ detailErrMsg.FromString(detailErrMsgUpdated);
+ return res;
}
#endif
diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h
index dcd82cc..5d8e5f2 100644
--- a/libcef/browser/browser_host_base.h
+++ b/libcef/browser/browser_host_base.h
@@ -705,7 +705,7 @@ bool TerminateRenderProcess() override;
#endif
#ifdef OHOS_URL_TRUST_LIST
- int SetUrlTrustList(const CefString& urlTrustList) override;
+ int SetUrlTrustList(const CefString& urlTrustList, CefString& detailErrMsg) override;
#endif
#if defined(OHOS_SOFTWARE_COMPOSITOR)
diff --git a/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.cc b/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.cc
index 7caa790..0ce432f 100644
--- a/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.cc
+++ b/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.cc
@@ -25,10 +25,67 @@ char OhosUrlTrustListInterface::interfaceKey;
OhosUrlTrustListManager::OhosUrlTrustListManager() {}
+static bool FormatUrlRule(UrlTrustRule& urlRule)
+{
+ std::string scheme = urlRule.scheme.empty() ? "http" : urlRule.scheme;
+ std::string path = urlRule.path.empty() ? "" : urlRule.path;
+ std::string port = urlRule.port > 0 ? ":" + std::to_string(urlRule.port) : "";
+
+ std::string combine = scheme + "://" + urlRule.host + port + "/" + path;
+ GURL gurlRule(combine);
+ if (!gurlRule.is_valid()) {
+ LOG(ERROR) << "parse: url format is invalid, combine url is " << combine;
+ return false;
+ }
+ LOG(DEBUG) << "parse: combine url is " << combine;
+ if (gurlRule.host().empty()) {
+ LOG(ERROR) << "parse: format url host is invalid.";
+ return false;
+ }
+ urlRule.host = gurlRule.host();
+ if (!path.empty()) {
+ if (gurlRule.path().empty()) {
+ LOG(ERROR) << "parse: format url path is invalid";
+ return false;
+ }
+ urlRule.path = gurlRule.path();
+ }
+ return true;
+}
+
+static bool CheckUrlRuleValid(UrlTrustRule& urlRule)
+{
+ if (!urlRule.scheme.empty()) {
+ if (urlRule.scheme != "http" && urlRule.scheme != "https") {
+ LOG(ERROR) << "parse: host " << urlRule.host << " scheme is invalid.";
+ }
+ }
+
+ if (urlRule.host.empty()) {
+ LOG(ERROR) << "parse: empty host.";
+ return false;
+ }
+ if (urlRule.port <= -1) {
+ LOG(ERROR) << "parse: host " << urlRule.host << " port is invalid";
+ return false;
+ }
+ if (urlRule.path.size() > MAX_PATH_SIZE) {
+ LOG(ERROR) << "parse: host " << urlRule.host << " path len too long.";
+ return false;
+ }
+ if (!FormatUrlRule(urlRule)) {
+ return false;
+ }
+ LOG(DEBUG) << "parse: url host " << urlRule.host << " path " << urlRule.path;
+ return true;
+}
+
UrlListSetResult OhosUrlTrustListManager::SetUrlTrustList(
- const std::string& urlTrustList)
+ const std::string& urlTrustList, std::string& detailErrMsg)
{
+ detailErrMsg = "reached";
if (urlTrustList.empty()) {
+ LOG(INFO) << "parse: list is empty, disable url trust list.";
ruleMap_.clear();
return UrlListSetResult::SET_OK;
}
@@ -55,35 +112,16 @@ UrlListSetResult OhosUrlTrustListManager::SetUrlTrustList(
UrlTrustRule rule;
base::JSONValueConverter<UrlTrustRule> converter;
converter.Convert(ruleJson, &rule);
- if (rule.host.empty()) {
- LOG(ERROR) << "parse: empty host.";
- return UrlListSetResult::PARAM_ERROR;
- }
- if (rule.port == -1) {
- LOG(ERROR) << "parse: host " << rule.host << " port invalid.";
- return UrlListSetResult::PARAM_ERROR;
- }
- if (rule.path.size() > MAX_PATH_SIZE) {
- LOG(ERROR) << "parse: host " << rule.host << " path len too long.";
+ if (!CheckUrlRuleValid(rule)) {
return UrlListSetResult::PARAM_ERROR;
}
+
map.insert(std::make_pair(rule.host, rule));
}
ruleMap_ = map;
return UrlListSetResult::SET_OK;
}
-static std::string GetUrlRealPath(std::string path)
-{
- if (path.empty()) {
- return path;
- }
- if (path[0] == '/') {
- path.erase(0, 1);
- }
- return path;
-}
-
UrlTrustCheckResult OhosUrlTrustListManager::CheckUrlTrustList(
const GURL& url)
{
@@ -95,7 +133,7 @@ UrlTrustCheckResult OhosUrlTrustListManager::CheckUrlTrustList(
}
auto range = ruleMap_.equal_range(url.host());
- std::string realPath = GetUrlRealPath(url.path());
+ const std::string& path = url.path();
for (auto itr = range.first; itr != range.second; ++itr) {
auto& rule = itr->second;
if (!rule.scheme.empty() && (rule.scheme != url.scheme())) {
@@ -105,11 +143,11 @@ UrlTrustCheckResult OhosUrlTrustListManager::CheckUrlTrustList(
continue;
}
if (!rule.path.empty()) {
- if (realPath.find(rule.path) != 0) {
+ if (path.find(rule.path) != 0) {
continue;
}
size_t next = rule.path.size();
- if (next < realPath.size() && realPath[next] != '/') {
+ if (next < path.size() && !rule.path.ends_with('/') && path[next] != '/') {
continue;
}
}
diff --git a/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.h b/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.h
index 739888d..00caaa7 100644
--- a/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.h
+++ b/libcef/browser/ohos_safe_browsing/ohos_url_trust_list_manager.h
@@ -76,7 +76,7 @@ public:
OhosUrlTrustListManager();
virtual ~OhosUrlTrustListManager() = default;
UrlTrustCheckResult CheckUrlTrustList(const GURL& url) override;
- UrlListSetResult SetUrlTrustList(const std::string& urlTrustList);
+ UrlListSetResult SetUrlTrustList(const std::string& urlTrustList, std::string& detailErrMsg);
private:
std::multimap<std::string, UrlTrustRule> ruleMap_;
diff --git a/libcef/renderer/browser_impl.h b/libcef/renderer/browser_impl.h
index f980aeb..b70ea54 100644
--- a/libcef/renderer/browser_impl.h
+++ b/libcef/renderer/browser_impl.h
@@ -148,7 +148,9 @@ class CefBrowserImpl : public CefBrowser, public blink::WebViewObserver {
#endif
#ifdef OHOS_URL_TRUST_LIST
- int SetUrlTrustList(const CefString& urlTrustList) override { return 0; }
+ int SetUrlTrustList(const CefString& urlTrustList, CefString& detailErrMsg) override {
+ return 0;
+ }
#endif
// #if defined(OHOS_NWEB_EX)
diff --git a/libcef_dll/cpptoc/browser_cpptoc.cc b/libcef_dll/cpptoc/browser_cpptoc.cc
index fe5e23e..b16f082 100644
--- a/libcef_dll/cpptoc/browser_cpptoc.cc
+++ b/libcef_dll/cpptoc/browser_cpptoc.cc
@@ -969,7 +969,8 @@ void CEF_CALLBACK browser_enable_ads_block(struct _cef_browser_t* self,
}
int CEF_CALLBACK browser_set_url_trustList(struct _cef_browser_t* self,
- const cef_string_t* urlTrustList) {
+ const cef_string_t* urlTrustList,
+ cef_string_t* detailErrMsg) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@@ -979,11 +980,18 @@ int CEF_CALLBACK browser_set_url_trustList(struct _cef_browser_t* self,
return 0;
}
- // Execute
- int _retval = CefBrowserCppToC::Get(self)->SetUrlTrustList(CefString(urlTrustList));
+ DCHECK(urlTrustList);
+ if (!urlTrustList) {
+ return 0;
+ }
- // Return type: simple
- return _retval;
+ DCHECK(detailErrMsg);
+ if (!detailErrMsg) {
+ return 0;
+ }
+ // Execute
+ CefString cefStrMsg(detailErrMsg);
+ return CefBrowserCppToC::Get(self)->SetUrlTrustList(CefString(urlTrustList), cefStrMsg);
}
} // namespace
diff --git a/libcef_dll/ctocpp/browser_ctocpp.cc b/libcef_dll/ctocpp/browser_ctocpp.cc
index 244d360..f3d8650 100644
--- a/libcef_dll/ctocpp/browser_ctocpp.cc
+++ b/libcef_dll/ctocpp/browser_ctocpp.cc
@@ -938,7 +938,7 @@ NO_SANITIZE("cfi-icall") void CefBrowserCToCpp::EnableAdsBlock(bool enable) {
}
NO_SANITIZE("cfi-icall")
-int CefBrowserCToCpp::SetUrlTrustList(const CefString& urlTrustList) {
+int CefBrowserCToCpp::SetUrlTrustList(const CefString& urlTrustList, CefString& detailErrMsg) {
shutdown_checker::AssertNotShutdown();
cef_browser_t* _struct = GetStruct();
@@ -947,7 +947,8 @@ int CefBrowserCToCpp::SetUrlTrustList(const CefString& urlTrustList) {
}
// Execute
- return _struct->set_url_trust_list(_struct, urlTrustList.GetStruct());
+ return _struct->set_url_trust_list(_struct, urlTrustList.GetStruct(),
+ detailErrMsg.GetWritableStruct());
}
// CONSTRUCTOR - Do not edit by hand.
diff --git a/libcef_dll/ctocpp/browser_ctocpp.h b/libcef_dll/ctocpp/browser_ctocpp.h
index 0b2225c..0470950 100644
--- a/libcef_dll/ctocpp/browser_ctocpp.h
+++ b/libcef_dll/ctocpp/browser_ctocpp.h
@@ -92,7 +92,7 @@ class CefBrowserCToCpp
bool IsAdsBlockEnabled() override;
bool IsAdsBlockEnabledForCurPage() override;
void EnableAdsBlock(bool enable) override;
- int SetUrlTrustList(const CefString& urlTrustList) override;
+ int SetUrlTrustList(const CefString& urlTrustList, CefString& detailErrMsg) override;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_BROWSER_CTOCPP_H_
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。