From ab09f88f4adcffa50b5fdd3135bd2e83f309fd2b Mon Sep 17 00:00:00 2001 From: zhangyanchuan Date: Mon, 18 Nov 2024 15:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=81=B6=E6=84=8F=E7=BD=91?= =?UTF-8?q?=E5=9D=80=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyanchuan --- include/cef_client.h | 15 ++++++++ include/cef_safe_browsing_check_callback.h | 38 +++++++++++++++++++ libcef/browser/browser_host_base.cc | 43 ++++++++++++++++------ libcef/browser/browser_host_base.h | 18 ++++++--- 4 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 include/cef_safe_browsing_check_callback.h diff --git a/include/cef_client.h b/include/cef_client.h index e6905e71b..14fffc59e 100644 --- a/include/cef_client.h +++ b/include/cef_client.h @@ -71,6 +71,8 @@ #include "include/cef_media_player_listener.h" #endif // OHOS_CUSTOM_VIDEO_PLAYER +#include "include/cef_safe_browsing_check_callback.h" + /// /// Implement this interface to provide handler implementations. /// @@ -316,6 +318,19 @@ class CefClient : public virtual CefBaseRefCounted { CefOwnPtr listener, const CefCustomMediaInfo& media_info) { return nullptr; } #endif // OHOS_CUSTOM_VIDEO_PLAYER + + /// + /// Check whether the website has security risks. + /// + /*--cef()--*/ + virtual void HandleSafeBrowsingCheck(const CefString& url) {} + + /// + /// Set the callback for checking whether the website has security risks. + /// + /*--cef()--*/ + virtual void SetSafeBrowsingCheckCallback( + CefRefPtr callback) {} }; #endif // CEF_INCLUDE_CEF_CLIENT_H_ diff --git a/include/cef_safe_browsing_check_callback.h b/include/cef_safe_browsing_check_callback.h new file mode 100644 index 000000000..d9abf32d7 --- /dev/null +++ b/include/cef_safe_browsing_check_callback.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CEF_INCLUDE_CEF_SAFE_BROWSING_CHECK_CALLBACK_H_ +#define CEF_INCLUDE_CEF_SAFE_BROWSING_CHECK_CALLBACK_H_ +#pragma once + +#include "include/cef_base.h" + +/// +/// Interface to implement to be notified of asynchronous completion via +/// CefClient::HandleSafeBrowsingCheck. +/// +/*--cef(source=library)--*/ +class CefSafeBrowsingCheckCallback : public virtual CefBaseRefCounted { + public: + /// + /// Method that will be called upon completion. + /// + /*--cef()--*/ + virtual void OnCheckResult(int hwCode, + int policy, + const std::string& mappingType) = 0; +}; + +#endif // CEF_INCLUDE_CEF_SAFE_BROWSING_CHECK_CALLBACK_H_ diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index e3a2ae424..873ee56e7 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -3660,6 +3660,38 @@ void CefBrowserHostBase::SetAdBlockEnabledForSite( } #endif +void CefBrowserHostBase::EnableSafeBrowsing(bool enable) { +#if defined(OHOS_SAFE_BROWSING_CHECK) + if (settings_.is_safe_browsing_enable != enable) { + LOG(INFO) << "enable safe browsing" << enable; + settings_.is_safe_browsing_enable = enable; + } +#endif +} + +bool CefBrowserHostBase::IsSafeBrowsingEnabled() { +#if defined(OHOS_SAFE_BROWSING_CHECK) + return settings_.is_safe_browsing_enable; +#else + return false; +#endif +} + +#if defined(OHOS_SAFE_BROWSING_CHECK) +void CefBrowserHostBase::HandleSafeBrowsingCheck(const std::string& url) { + if (client_) { + client_->HandleSafeBrowsingCheck(CefString(url)); + } +} + +void CefBrowserHostBase::SetSafeBrowsingCheckCallback( + CefRefPtr callback) { + if (client_) { + client_->SetSafeBrowsingCheckCallback(callback); + } +} +#endif // OHOS_SAFE_BROWSING_CHECK + void CefBrowserHostBase::SetSavePasswordAutomatically(bool enable) { #if defined(OHOS_EX_PASSWORD) if (!GetWebContents()) { @@ -3731,17 +3763,6 @@ void CefBrowserHostBase::PasswordSuggestionSelected(int list_index) { autofill_client->FillData(message); } } - - bool CefBrowserHostBase::IsSafeBrowsingEnabled() { - return settings_.is_safe_browsing_enable; - } - - void CefBrowserHostBase::EnableSafeBrowsing(bool enable) { - if (settings_.is_safe_browsing_enable != enable) { - LOG(INFO) << "enable safe browsing" << enable; - settings_.is_safe_browsing_enable = enable; - } - } #endif #if defined(OHOS_PASSWORD_AUTOFILL) diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h index f81875a7b..542232551 100644 --- a/libcef/browser/browser_host_base.h +++ b/libcef/browser/browser_host_base.h @@ -283,6 +283,19 @@ class CefBrowserHostBase : public CefBrowserHost, int main_frame_tree_node_id) override; #endif +#if BUILDFLAG(IS_OHOS) + void EnableSafeBrowsing(bool enable) override; + + bool IsSafeBrowsingEnabled() override; +#endif + +#if defined(OHOS_SAFE_BROWSING_CHECK) + void HandleSafeBrowsingCheck(const std::string& url); + + void SetSafeBrowsingCheckCallback( + CefRefPtr callback); +#endif // OHOS_SAFE_BROWSING_CHECK + void RegisterArkJSfunction(const CefString& object_name, const std::vector& method_list, const std::vector& async_method_list, @@ -566,11 +579,6 @@ bool NeedsReload() override; bool TerminateRenderProcess() override; #endif -#if BUILDFLAG(IS_OHOS) - bool IsSafeBrowsingEnabled() override; - void EnableSafeBrowsing(bool enable) override; -#endif - // CefBrowserContentsDelegate::Observer methods: void OnStateChanged(CefBrowserContentsState state_changed) override; void OnWebContentsDestroyed(content::WebContents* web_contents) override; -- Gitee