diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index 3ada0a209780465913b98ce149405de9dc019ac6..9d9d8c2f6fdf785debed9ff2b6c31499335099b8 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -1438,6 +1438,11 @@ void AlloyBrowserHostImpl::SetAudioResumeInterval(int resumeInterval) { content::MediaSessionImpl* mediaSession = content::MediaSessionImpl::Get(web_contents()); if (!mediaSession) { LOG(ERROR) << "AlloyBrowserHostImpl::SetAudioResumeInterval get mediaSession failed."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "AlloyBrowserHostImpl::SetAudioResumeInterval get mediaSession failed."; +#endif + return; } mediaSession->audioResumeInterval_ = resumeInterval; @@ -1447,6 +1452,11 @@ void AlloyBrowserHostImpl::SetAudioExclusive(bool audioExclusive) { content::MediaSessionImpl* mediaSession = content::MediaSessionImpl::Get(web_contents()); if (!mediaSession) { LOG(ERROR) << "AlloyBrowserHostImpl::SetAudioExclusive get mediaSession failed."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "AlloyBrowserHostImpl::SetAudioExclusive get mediaSession failed."; +#endif + return; } mediaSession->audioExclusive_ = audioExclusive; @@ -2014,6 +2024,11 @@ void AlloyBrowserHostImpl::DidFinishNavigation( void AlloyBrowserHostImpl::OnAudioStateChanged(bool audible) { #if defined(OHOS_MEDIA_MUTE_AUDIO) LOG(INFO) << "OnAudioStateChanged: " << audible; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "OnAudioStateChanged: " << audible; +#endif + if (client_.get() && client_->GetMediaHandler().get()) { client_->GetMediaHandler()->OnAudioStateChanged(this, audible); } diff --git a/libcef/browser/alloy/alloy_browser_main.cc b/libcef/browser/alloy/alloy_browser_main.cc index 7a454913c5f1ba931647f7ef7894e19b984f8623..0f0467e1547750b4a4e26508aa4a5b6b8db04bbd 100644 --- a/libcef/browser/alloy/alloy_browser_main.cc +++ b/libcef/browser/alloy/alloy_browser_main.cc @@ -403,6 +403,11 @@ void AlloyBrowserMainParts::PostMainMessageLoopRun() { #if BUILDFLAG(IS_OHOS) && defined(OHOS_PERFORMANCE_PERSISTENT_TASK) if (performance_manager_lifetime_) { LOG(INFO) << "performance_manager_lifetime_ reset"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "performance_manager_lifetime_ reset"; +#endif + performance_manager_lifetime_.reset(); } #endif diff --git a/libcef/browser/alloy/chrome_browser_process_alloy.cc b/libcef/browser/alloy/chrome_browser_process_alloy.cc index d744e75caf4eaa781989379aef48183c4af746a6..9be6632c4f238b5b19719ab54a136568aa3f4b04 100644 --- a/libcef/browser/alloy/chrome_browser_process_alloy.cc +++ b/libcef/browser/alloy/chrome_browser_process_alloy.cc @@ -212,6 +212,9 @@ PrefService* ChromeBrowserProcessAlloy::local_state() { if (!base::PathExists(root_cache_path)) { if (!base::CreateDirectory(root_cache_path)) { LOG(ERROR) << "Create directory failed:" << root_cache_path.value(); +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "Create directory failed:" << root_cache_path.value(); +#endif } } } @@ -422,6 +425,11 @@ void ChromeBrowserProcessAlloy::CreateSubresourceFilterRulesetService() { user_data_dir.Append(::subresource_filter::kTopLevelDirectoryName) .Append(::subresource_filter::kUnindexedRulesetBaseDirectoryName); LOG(INFO) << "[AdBlock] Create subresource filter ruleset service"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "[AdBlock] Create subresource filter ruleset service"; +#endif + subresource_filter_ruleset_service_ = std::make_unique<::subresource_filter::RulesetService>( local_state(), background_task_runner, indexed_ruleset_base_dir, @@ -472,6 +480,10 @@ void ChromeBrowserProcessAlloy::CreateSubresourceFilterUserRulesetService() { LOG(INFO) << "[AdBlock] Create user subresource filter ruleset service"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "[AdBlock] Create user subresource filter ruleset service"; +#endif + subresource_filter_user_ruleset_service_ = std::make_unique<::subresource_filter::UserRulesetService>( local_state(), background_task_runner, user_indexed_ruleset_base_dir, diff --git a/libcef/browser/browser_contents_delegate.cc b/libcef/browser/browser_contents_delegate.cc index 69878711559d38a23c76a94cc63a38b5e5547e81..46b2906ffec7607631bf83ae51fbb5483c0a760f 100644 --- a/libcef/browser/browser_contents_delegate.cc +++ b/libcef/browser/browser_contents_delegate.cc @@ -1229,6 +1229,11 @@ void CefBrowserContentsDelegate::OnLoadError(CefRefPtr request, void CefBrowserContentsDelegate::OnOldPageNoLongerRendered(const GURL& url, bool success) { LOG(INFO) << "CefBrowserContentsDelegate::OldPageNoLongerRendered"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "CefBrowserContentsDelegate::OldPageNoLongerRendered"; +#endif + if (!browser_info_) { return; } @@ -1259,12 +1264,22 @@ void CefBrowserContentsDelegate::OnRefreshAccessedHistory( CefRefPtr cefClient = client(); if (!cefClient.get()) { LOG(ERROR) << "cef client is null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "cef client is null"; +#endif + return; } auto handler = cefClient->GetLoadHandler(); if (!handler.get()) { LOG(ERROR) << "cef client handler is null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "cef client handler is null"; +#endif + return; } diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index b9d110e60c42abe1a7c1c5f8414f31ca10f2d6c7..3f2166d9ea475c87053b2467e17e37647cd8f169 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -951,7 +951,11 @@ void CefBrowserHostBase::UpdateBrowserSettings( void CefBrowserHostBase::SetWebPreferences( const CefBrowserSettings& browser_settings) { UpdateBrowserSettings(browser_settings); +#ifdef OHOS_LOGGER_REPORT + GetWebContents()->OnWebPreferencesChanged(settings_.usage_scenario); +#else GetWebContents()->OnWebPreferencesChanged(); +#endif } void CefBrowserHostBase::OnWebPreferencesChanged() { @@ -3534,6 +3538,9 @@ void CefBrowserHostBase::ResumeMedia() { content::MediaSessionImpl* mediaSession = content::MediaSessionImpl::Get(GetWebContents()); if (!mediaSession || !GetWebContents()) { LOG(ERROR) << "CefBrowserHostBase::ResumeMedia get mediaSession or webContents failed."; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "CefBrowserHostBase::ResumeMedia get mediaSession or webContents failed."; +#endif return; } mediaSession->Resume(content::MediaSession::SuspendType::kSystem); @@ -3544,6 +3551,9 @@ void CefBrowserHostBase::PauseMedia() { content::MediaSessionImpl* mediaSession = content::MediaSessionImpl::Get(GetWebContents()); if (!mediaSession || !GetWebContents()) { LOG(ERROR) << "CefBrowserHostBase::PauseMedia get mediaSession or webContents failed."; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "CefBrowserHostBase::PauseMedia get mediaSession or webContents failed."; +#endif return; } mediaSession->Suspend(content::MediaSession::SuspendType::kSystem); @@ -3554,6 +3564,9 @@ void CefBrowserHostBase::StopMedia() { content::MediaSessionImpl* mediaSession = content::MediaSessionImpl::Get(GetWebContents()); if (!mediaSession) { LOG(ERROR) << "CefBrowserHostBase::StopMedia get mediaSession failed."; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "CefBrowserHostBase::StopMedia get mediaSession failed."; +#endif return; } mediaSession->Stop(content::MediaSession::SuspendType::kSystem); @@ -3563,6 +3576,9 @@ int CefBrowserHostBase::GetMediaPlaybackState() { content::MediaSessionImpl* mediaSession = content::MediaSessionImpl::Get(GetWebContents()); if (!mediaSession || !GetWebContents()) { LOG(ERROR) << "CefBrowserHostBase::GetMediaPlaybackState get mediaSession or webContents failed."; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "CefBrowserHostBase::GetMediaPlaybackState get mediaSession or webContents failed."; +#endif return static_cast(content::MediaSessionImpl::NWebPlaybackState::NONE); } if (!GetWebContents()->IsHtmlPlayEnabled()) { @@ -3626,11 +3642,20 @@ void CefBrowserHostBase::EnableAdsBlock(bool enable) { LOG(INFO) << "web adblock enabled : " << enable; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "web adblock enabled :" << enable; +#endif + OHOS::adblock::AdBlockConfig::GetInstance()->ReadFromPrefService(); if (!OHOS::adblock::AdBlockConfig::GetInstance() ->GetUserEasylistReplaceSwitch() && enable) { LOG(INFO) << "[Adblock] enable cloud control for easylist"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "[Adblock] enable cloud control for easylist"; +#endif + ohos_adblock::AdblockConfigBridge::GetInstance()->EnableAdsBlock( GetBrowserContext(), true); } else { @@ -3704,6 +3729,11 @@ void CefBrowserHostBase::PasswordSuggestionSelected(int list_index) { auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif + return; } @@ -3718,6 +3748,9 @@ void CefBrowserHostBase::PasswordSuggestionSelected(int list_index) { auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif return; } @@ -3734,6 +3767,9 @@ void CefBrowserHostBase::PasswordSuggestionSelected(int list_index) { void CefBrowserHostBase::EnableSafeBrowsing(bool enable) { LOG(INFO) << "enable safe browsing" << enable; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "enable safe browsing" << enable; +#endif if (settings_.is_safe_browsing_enable != enable) { settings_.is_safe_browsing_enable = enable; } @@ -3746,6 +3782,9 @@ void CefBrowserHostBase::ProcessAutofillCancel( auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif return; } @@ -3763,6 +3802,9 @@ void CefBrowserHostBase::AutoFillWithIMFEvent(bool is_username, auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif return; } @@ -3872,6 +3914,11 @@ void CefBrowserHostBase::EnableIntelligentTrackingPrevention(bool enable) { intelligent_tracking_prevention_cookies_enabled_ = enable; } LOG(INFO) << "Intelligent tracking prevention cookies enabled " << enable; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "Intelligent tracking prevention cookies enabled " << enable; +#endif + ohos_anti_tracking::ThirdPartyCookieAccessPolicy::GetInstance()-> EnableIntelligentTrackingPrevention(GetBrowserContext(), enable); } @@ -3902,6 +3949,11 @@ void CefBrowserHostBase::StartCamera() { auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif + return; } web_contents->StartCamera(web_contents->GetNWebId()); @@ -3913,6 +3965,11 @@ void CefBrowserHostBase::StopCamera() { auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif + return; } web_contents->StopCamera(web_contents->GetNWebId()); @@ -3924,6 +3981,11 @@ void CefBrowserHostBase::CloseCamera() { auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif + return; } web_contents->CloseCamera(web_contents->GetNWebId()); @@ -3935,6 +3997,11 @@ void CefBrowserHostBase::SetNWebId(int NWebID) { auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "GetWebContents null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "GetWebContents null"; +#endif + return; } web_contents->SetNWebId(NWebID); @@ -3983,6 +4050,9 @@ oh_code_cache::NextOp CefBrowserHostBase::WriteResponseCache( if (!response_cache) { LOG(DEBUG) << "Create response cache error."; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(DEBUG) << "Create response cache error"; +#endif return oh_code_cache::NextOp::THROW_ERROR; } @@ -4014,6 +4084,11 @@ void CefBrowserHostBase::GenerateCodeCache(const std::string& url, auto wc = GetWebContents(); if (wc == nullptr) { LOG(ERROR) << "WebContents has not initialized."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "WebContents has not initialized"; +#endif + callback->OnPrecompileFinished( static_cast(oh_code_cache::CacheError::INTERNAL_ERROR)); return; @@ -4026,6 +4101,11 @@ void CefBrowserHostBase::GenerateCodeCache(const std::string& url, void CefBrowserHostBase::OnDidGenerateCodeCache(CefRefPtr callback, int32_t result) { LOG(DEBUG) << "Get generate code cache result: " << result; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(DEBUG) << "Get generate code cache result: " << result; +#endif + callback->OnPrecompileFinished(result); } #endif @@ -4090,6 +4170,11 @@ int CefBrowserHostBase::SetUrlTrustListWithErrMsg( std::string detailErrMsgUpdated; if (!webContents) { LOG(ERROR) << "SetUrlTrustListWithErrMsg failed, web contents is error."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "SetUrlTrustListWithErrMsg failed, web contents is error."; +#endif + return static_cast(ohos_safe_browsing::UrlListSetResult::INIT_ERROR); } ohos_safe_browsing::UrlTrustListManager* manager = @@ -4100,6 +4185,11 @@ int CefBrowserHostBase::SetUrlTrustListWithErrMsg( manager = new ohos_safe_browsing::UrlTrustListManager(); if (!manager) { LOG(ERROR) << "SetUrlTrustListWithErrMsg failed, new UrlTrustListManager failed."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "SetUrlTrustListWithErrMsg failed, new UrlTrustListManager failed."; +#endif + return static_cast(ohos_safe_browsing::UrlListSetResult::INIT_ERROR); } webContents->SetUserData( @@ -4124,12 +4214,22 @@ void CefBrowserHostBase::WebExtensionTabUpdated( content::WebContents* web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "TabUpdated get contents failed."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "TabUpdated get contents failed."; +#endif + return; } auto browser_context = web_contents->GetBrowserContext(); if (!browser_context) { LOG(ERROR) << "TabUpdated get browser context failed."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "TabUpdated get browser contents failed."; +#endif + return; } @@ -4149,11 +4249,22 @@ void CefBrowserHostBase::SetBackForwardCacheOptions(int32_t size, int32_t timeTo auto web_contents = GetWebContents(); if (!web_contents) { LOG(ERROR) << "SetBackForwardCacheOptions failed to get web contents in CefBrowserHostBase."; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "SetBackForwardCacheOptions failed to get web contents in CefBrowserHostBase."; +#endif + return; } LOG(INFO) << "SetBackForwardCacheOptions size: " << size << " timeToLive: " << timeToLive; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "SetBackForwardCacheOptions size: " << size + << " timeToLive: " << timeToLive; +#endif + content::NavigationController& controller = web_contents->GetController(); controller.GetBackForwardCache().SetCacheSize(size); controller.GetBackForwardCache().SetTimeToLive(timeToLive); diff --git a/libcef/browser/certificate_query.cc b/libcef/browser/certificate_query.cc index 6d1b75c270e31ff61cdcd743104c4c13853c41d5..c1508510b92c399ea0476588fd65495dfec4a6d9 100644 --- a/libcef/browser/certificate_query.cc +++ b/libcef/browser/certificate_query.cc @@ -1,276 +1,276 @@ -// Copyright 2022 The Chromium Embedded Framework Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be found -// in the LICENSE file. - -#include "libcef/browser/certificate_query.h" - -#include "include/cef_request_handler.h" -#include "libcef/browser/browser_host_base.h" -#include "libcef/browser/ssl_info_impl.h" -#include "libcef/browser/thread_util.h" - -#include "base/functional/callback.h" -#include "base/functional/callback_helpers.h" -#include "base/logging.h" -#include "content/public/browser/web_contents.h" -#include "net/ssl/ssl_info.h" -#include "url/gurl.h" - -#ifdef OHOS_LOGGER_REPORT -#include "content/public/common/content_switches.h" -#include "base/command_line.h" -#include "url/ohos/log_utils.h" -#endif - -namespace certificate_query { - -namespace { - -class CefAllowCertificateErrorCallbackImpl : public CefCallback { - public: - using CallbackType = CertificateErrorCallback; - - explicit CefAllowCertificateErrorCallbackImpl(CallbackType callback) - : callback_(std::move(callback)) {} - - CefAllowCertificateErrorCallbackImpl( - const CefAllowCertificateErrorCallbackImpl&) = delete; - CefAllowCertificateErrorCallbackImpl& operator=( - const CefAllowCertificateErrorCallbackImpl&) = delete; - - ~CefAllowCertificateErrorCallbackImpl() { - if (!callback_.is_null()) { - // The callback is still pending. Cancel it now. - if (CEF_CURRENTLY_ON_UIT()) { - RunNow(std::move(callback_), false); - } else { - CEF_POST_TASK( - CEF_UIT, - base::BindOnce(&CefAllowCertificateErrorCallbackImpl::RunNow, - std::move(callback_), false)); - } - } - } - - void Continue() override { ContinueNow(true); } - - void Cancel() override { ContinueNow(false); } - - [[nodiscard]] CallbackType Disconnect() { return std::move(callback_); } - - private: - void ContinueNow(bool allow) { - if (CEF_CURRENTLY_ON_UIT()) { - if (!callback_.is_null()) { - RunNow(std::move(callback_), allow); - } - } else { - CEF_POST_TASK( - CEF_UIT, - base::BindOnce(&CefAllowCertificateErrorCallbackImpl::ContinueNow, - this, allow)); - } - } - - static void RunNow(CallbackType callback, bool allow) { - CEF_REQUIRE_UIT(); - std::move(callback).Run( - allow ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE - : content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); - } - - CallbackType callback_; - - IMPLEMENT_REFCOUNTING(CefAllowCertificateErrorCallbackImpl); -}; - -} // namespace - -CertificateErrorCallback AllowCertificateError( - content::WebContents* web_contents, - int cert_error, - const net::SSLInfo& ssl_info, - const GURL& request_url, - bool is_main_frame_request, - bool strict_enforcement, - CertificateErrorCallback callback, - bool default_disallow) { - CEF_REQUIRE_UIT(); - - if (!is_main_frame_request) { - // A sub-resource has a certificate error. The user doesn't really - // have a context for making the right decision, so block the request - // hard. - std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); - return base::NullCallback(); - } - - if (auto browser = CefBrowserHostBase::GetBrowserForContents(web_contents)) { - if (auto client = browser->GetClient()) { - if (auto handler = client->GetRequestHandler()) { - CefRefPtr sslInfo(new CefSSLInfoImpl(ssl_info)); - CefRefPtr callbackImpl( - new CefAllowCertificateErrorCallbackImpl(std::move(callback))); - - bool proceed = handler->OnCertificateError( - browser.get(), static_cast(cert_error), - request_url.spec(), sslInfo, callbackImpl.get()); - if (!proceed) { - callback = callbackImpl->Disconnect(); - LOG_IF(ERROR, callback.is_null()) - << "Should return true from OnCertificateError when executing " - "the callback"; - } - } - } - } - - if (!callback.is_null() && default_disallow) { - std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); - return base::NullCallback(); - } - - return callback; -} - -#ifdef OHOS_NETWORK_LOAD -bool OnCertificateError( - content::WebContents* webContents, - int certError, - CefRefPtr sslInfo, - const GURL& requestUrl, - bool isMainFrameRequest, - bool strictEnforcement, - const GURL& originUrl, - const std::string& referrer, - CefRefPtr callbackImpl, - bool onlyMainError) { - auto browser = CefBrowserHostBase::GetBrowserForContents(webContents); - if (!browser) { - return false; - } - auto client = browser->GetClient(); - if (!client) { - return false; - } - auto handler = client->GetRequestHandler(); - if (!handler) { - return false; - } - - bool proceed; - if (onlyMainError) { - proceed = handler->OnCertificateError(browser.get(), static_cast(certError), requestUrl.spec(), - sslInfo, callbackImpl.get()); - } else { - proceed = handler->OnAllCertificateError( - browser.get(), static_cast(certError), - requestUrl.spec(), originUrl.spec(), referrer, isMainFrameRequest, - strictEnforcement, sslInfo, callbackImpl.get()); - } - if (proceed) { - return true; - } - - return false; -} -#endif - -#ifdef OHOS_LOGGER_REPORT -int IsSslCertErrorFatal(int cert_error) { - switch (cert_error) { - case net::ERR_CERT_COMMON_NAME_INVALID: - case net::ERR_CERT_DATE_INVALID: - case net::ERR_CERT_AUTHORITY_INVALID: - case net::ERR_CERT_NO_REVOCATION_MECHANISM: - case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION: - case net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM: - case net::ERR_CERT_WEAK_KEY: - case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION: - case net::ERR_CERT_VALIDITY_TOO_LONG: - case net::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED: - case net::ERR_CERT_SYMANTEC_LEGACY: - case net::ERR_CERT_KNOWN_INTERCEPTION_BLOCKED: - case net::ERR_SSL_OBSOLETE_VERSION_OR_CIPHER: - return false; - case net::ERR_CERT_CONTAINS_ERRORS: - case net::ERR_CERT_REVOKED: - case net::ERR_CERT_INVALID: - case net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN: - return true; - default: - NOTREACHED(); - return true; - } -} -#endif - -#ifdef OHOS_NETWORK_LOAD -CertificateErrorCallback AllowAllCertificateError( - content::WebContents* web_contents, - int cert_error, - const net::SSLInfo& ssl_info, - const GURL& request_url, - bool is_main_frame_request, - bool strict_enforcement, - const GURL& origin_url, - const std::string& referrer, - CertificateErrorCallback callback, - bool default_disallow) { - CEF_REQUIRE_UIT(); - -#ifdef OHOS_LOGGER_REPORT - bool is_fatal_error = false; - bool is_incognito = false; - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kForBrowser)) { - is_fatal_error = IsSslCertErrorFatal(cert_error) || is_fatal_error; - std::string err_msg = - "a ssl error occurred, err_code: " + std::to_string(cert_error) + - ", is_fatal_error: " + std::to_string(is_fatal_error) + - ", origin: " + origin_url.spec() + - ", refer: " + referrer; - if (!is_incognito) { - LOG(URL) << "event_message: " << err_msg << ", url: " << url::LogUtils::ConvertUrl(origin_url.spec()); - } - } -#endif - bool result; - CefRefPtr sslInfo(new CefSSLInfoImpl(ssl_info)); - CefRefPtr callbackImpl( - new CefAllowCertificateErrorCallbackImpl(std::move(callback))); - - result = OnCertificateError(web_contents, cert_error, sslInfo, request_url, is_main_frame_request, - strict_enforcement, origin_url, referrer, callbackImpl, false); - if (!result) { - callback = callbackImpl->Disconnect(); - LOG_IF(ERROR, callback.is_null()) << "Should return true from OnCertificateError when executing the callback"; - } - - if (!is_main_frame_request) { - if (!callback.is_null() && default_disallow) { - std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); - return base::NullCallback(); - } else { - return callback; - } - } - - CefRefPtr mainCallbackImpl( - new CefAllowCertificateErrorCallbackImpl(std::move(callback))); - result = OnCertificateError(web_contents, cert_error, sslInfo, request_url, is_main_frame_request, - strict_enforcement, origin_url, referrer, mainCallbackImpl, true); - if (!result) { - callback = mainCallbackImpl->Disconnect(); - LOG_IF(ERROR, callback.is_null()) << "Should return true from OnCertificateError when executing the callback"; - } - if (!callback.is_null() && default_disallow) { - std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); - return base::NullCallback(); - } - - return callback; -} -#endif - +// Copyright 2022 The Chromium Embedded Framework Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be found +// in the LICENSE file. + +#include "libcef/browser/certificate_query.h" + +#include "include/cef_request_handler.h" +#include "libcef/browser/browser_host_base.h" +#include "libcef/browser/ssl_info_impl.h" +#include "libcef/browser/thread_util.h" + +#include "base/functional/callback.h" +#include "base/functional/callback_helpers.h" +#include "base/logging.h" +#include "content/public/browser/web_contents.h" +#include "net/ssl/ssl_info.h" +#include "url/gurl.h" + +#ifdef OHOS_LOGGER_REPORT +#include "base/base_switches.h" +#include "base/command_line.h" +#include "url/ohos/log_utils.h" +#include "third_party/blink/renderer/core/frame/settings.h" +#endif + +namespace certificate_query { + +namespace { + +class CefAllowCertificateErrorCallbackImpl : public CefCallback { + public: + using CallbackType = CertificateErrorCallback; + + explicit CefAllowCertificateErrorCallbackImpl(CallbackType callback) + : callback_(std::move(callback)) {} + + CefAllowCertificateErrorCallbackImpl( + const CefAllowCertificateErrorCallbackImpl&) = delete; + CefAllowCertificateErrorCallbackImpl& operator=( + const CefAllowCertificateErrorCallbackImpl&) = delete; + + ~CefAllowCertificateErrorCallbackImpl() { + if (!callback_.is_null()) { + // The callback is still pending. Cancel it now. + if (CEF_CURRENTLY_ON_UIT()) { + RunNow(std::move(callback_), false); + } else { + CEF_POST_TASK( + CEF_UIT, + base::BindOnce(&CefAllowCertificateErrorCallbackImpl::RunNow, + std::move(callback_), false)); + } + } + } + + void Continue() override { ContinueNow(true); } + + void Cancel() override { ContinueNow(false); } + + [[nodiscard]] CallbackType Disconnect() { return std::move(callback_); } + + private: + void ContinueNow(bool allow) { + if (CEF_CURRENTLY_ON_UIT()) { + if (!callback_.is_null()) { + RunNow(std::move(callback_), allow); + } + } else { + CEF_POST_TASK( + CEF_UIT, + base::BindOnce(&CefAllowCertificateErrorCallbackImpl::ContinueNow, + this, allow)); + } + } + + static void RunNow(CallbackType callback, bool allow) { + CEF_REQUIRE_UIT(); + std::move(callback).Run( + allow ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE + : content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + } + + CallbackType callback_; + + IMPLEMENT_REFCOUNTING(CefAllowCertificateErrorCallbackImpl); +}; + +} // namespace + +CertificateErrorCallback AllowCertificateError( + content::WebContents* web_contents, + int cert_error, + const net::SSLInfo& ssl_info, + const GURL& request_url, + bool is_main_frame_request, + bool strict_enforcement, + CertificateErrorCallback callback, + bool default_disallow) { + CEF_REQUIRE_UIT(); + + if (!is_main_frame_request) { + // A sub-resource has a certificate error. The user doesn't really + // have a context for making the right decision, so block the request + // hard. + std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + return base::NullCallback(); + } + + if (auto browser = CefBrowserHostBase::GetBrowserForContents(web_contents)) { + if (auto client = browser->GetClient()) { + if (auto handler = client->GetRequestHandler()) { + CefRefPtr sslInfo(new CefSSLInfoImpl(ssl_info)); + CefRefPtr callbackImpl( + new CefAllowCertificateErrorCallbackImpl(std::move(callback))); + + bool proceed = handler->OnCertificateError( + browser.get(), static_cast(cert_error), + request_url.spec(), sslInfo, callbackImpl.get()); + if (!proceed) { + callback = callbackImpl->Disconnect(); + LOG_IF(ERROR, callback.is_null()) + << "Should return true from OnCertificateError when executing " + "the callback"; + } + } + } + } + + if (!callback.is_null() && default_disallow) { + std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + return base::NullCallback(); + } + + return callback; +} + +#ifdef OHOS_NETWORK_LOAD +bool OnCertificateError( + content::WebContents* webContents, + int certError, + CefRefPtr sslInfo, + const GURL& requestUrl, + bool isMainFrameRequest, + bool strictEnforcement, + const GURL& originUrl, + const std::string& referrer, + CefRefPtr callbackImpl, + bool onlyMainError) { + auto browser = CefBrowserHostBase::GetBrowserForContents(webContents); + if (!browser) { + return false; + } + auto client = browser->GetClient(); + if (!client) { + return false; + } + auto handler = client->GetRequestHandler(); + if (!handler) { + return false; + } + + bool proceed; + if (onlyMainError) { + proceed = handler->OnCertificateError(browser.get(), static_cast(certError), requestUrl.spec(), + sslInfo, callbackImpl.get()); + } else { + proceed = handler->OnAllCertificateError( + browser.get(), static_cast(certError), + requestUrl.spec(), originUrl.spec(), referrer, isMainFrameRequest, + strictEnforcement, sslInfo, callbackImpl.get()); + } + if (proceed) { + return true; + } + + return false; +} +#endif + +#ifdef OHOS_LOGGER_REPORT +int IsSslCertErrorFatal(int cert_error) { + switch (cert_error) { + case net::ERR_CERT_COMMON_NAME_INVALID: + case net::ERR_CERT_DATE_INVALID: + case net::ERR_CERT_AUTHORITY_INVALID: + case net::ERR_CERT_NO_REVOCATION_MECHANISM: + case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION: + case net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM: + case net::ERR_CERT_WEAK_KEY: + case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION: + case net::ERR_CERT_VALIDITY_TOO_LONG: + case net::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED: + case net::ERR_CERT_SYMANTEC_LEGACY: + case net::ERR_CERT_KNOWN_INTERCEPTION_BLOCKED: + case net::ERR_SSL_OBSOLETE_VERSION_OR_CIPHER: + return false; + case net::ERR_CERT_CONTAINS_ERRORS: + case net::ERR_CERT_REVOKED: + case net::ERR_CERT_INVALID: + case net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN: + return true; + default: + NOTREACHED(); + return true; + } +} +#endif + +#ifdef OHOS_NETWORK_LOAD +CertificateErrorCallback AllowAllCertificateError( + content::WebContents* web_contents, + int cert_error, + const net::SSLInfo& ssl_info, + const GURL& request_url, + bool is_main_frame_request, + bool strict_enforcement, + const GURL& origin_url, + const std::string& referrer, + CertificateErrorCallback callback, + bool default_disallow) { + CEF_REQUIRE_UIT(); + +#ifdef OHOS_LOGGER_REPORT + bool is_fatal_error = false; + bool is_incognito = false; + if ( base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableLoggerReport )) { + is_fatal_error = IsSslCertErrorFatal(cert_error) || is_fatal_error; + std::string err_msg = + "a ssl error occurred, err_code: " + std::to_string(cert_error) + + ", is_fatal_error: " + std::to_string(is_fatal_error) + + ", origin: " + origin_url.spec() + ", refer: " + referrer; + if (!is_incognito) { + int32_t usage_scenario = web_contents->GetOrCreateWebPreferences().usage_scenario; + LOG(URL) << "event_message: " << err_msg << ", url: " + << url::LogUtils::ConvertUrl(origin_url.spec(), usage_scenario); + } + } +#endif + bool result; + CefRefPtr sslInfo(new CefSSLInfoImpl(ssl_info)); + CefRefPtr callbackImpl( + new CefAllowCertificateErrorCallbackImpl(std::move(callback))); + + result = OnCertificateError(web_contents, cert_error, sslInfo, request_url, is_main_frame_request, + strict_enforcement, origin_url, referrer, callbackImpl, false); + if (!result) { + callback = callbackImpl->Disconnect(); + LOG_IF(ERROR, callback.is_null()) << "Should return true from OnCertificateError when executing the callback"; + } + if (!is_main_frame_request) { + if (!callback.is_null() && default_disallow) { + std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + return base::NullCallback(); + } else { + return callback; + } + } + CefRefPtr mainCallbackImpl( + new CefAllowCertificateErrorCallbackImpl(std::move(callback))); + result = OnCertificateError(web_contents, cert_error, sslInfo, request_url, is_main_frame_request, + strict_enforcement, origin_url, referrer, mainCallbackImpl, true); + if (!result) { + callback = mainCallbackImpl->Disconnect(); + LOG_IF(ERROR, callback.is_null()) << "Should return true from OnCertificateError when executing the callback"; + } + if (!callback.is_null() && default_disallow) { + std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + return base::NullCallback(); + } + + return callback; +} +#endif + } // namespace certificate_query \ No newline at end of file diff --git a/libcef/browser/osr/browser_platform_delegate_osr.cc b/libcef/browser/osr/browser_platform_delegate_osr.cc index 5b5c2020a34919e59959bbc45ed0db7705c3a1e0..72a727b0ee7170fc9ffbe27d8b0038b0ebb8ea27 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.cc +++ b/libcef/browser/osr/browser_platform_delegate_osr.cc @@ -867,6 +867,14 @@ void CefBrowserPlatformDelegateOsr::OnShowAutofillPopup( << ", y: " << element_bounds.y() << ", element_bounds width: " << element_bounds.width() << ", element_bounds height:" << element_bounds.height(); + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(INFO) << "element is screen bounds x:" << element_bounds.x() + << ", y: " << element_bounds.y() + << ", element_bounds width: " << element_bounds.width() + << ", element_bounds height:" << element_bounds.height(); +#endif + handler->OnShowAutofillPopup( browser_, CefRect(element_bounds.x(), element_bounds.y(), element_bounds.width(), diff --git a/libcef/renderer/alloy/alloy_content_renderer_client.cc b/libcef/renderer/alloy/alloy_content_renderer_client.cc index 0287d35e21a13d279da3ddc8b18db09cc7816546..13cd11a1679daf10ab2a5437b0945919d3ac5bec 100644 --- a/libcef/renderer/alloy/alloy_content_renderer_client.cc +++ b/libcef/renderer/alloy/alloy_content_renderer_client.cc @@ -143,6 +143,10 @@ #include "printing/metafile_agent.h" #endif +#ifdef OHOS_LOGGER_REPORT +#include "url/ohos/log_utils.h" +#endif + #include "libcef/renderer/alloy/ohos_safe_browsing_error_page_controller_delegate_impl.h" AlloyContentRendererClient::AlloyContentRendererClient() @@ -996,52 +1000,65 @@ void AlloyContentRendererClient::TriggerElementHidingInFrame(int routing_id) { auto* render_frame = content::RenderFrame::FromRoutingID(routing_id); if (!render_frame) { LOG(ERROR) << "[AdBlock] TriggerElementHidingInFrame render_frame null"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "[AdBlock] TriggerElementHidingInFrame render_frame null"; +#endif return; } - blink::WebLocalFrame* web_frame = render_frame->GetWebFrame(); if (!web_frame) { LOG(ERROR) << "[AdBlock] TriggerElementHidingInFrame web_frame null"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "[AdBlock] TriggerElementHidingInFrame web_frame null"; +#endif return; } - blink::WebDocumentSubresourceFilter* filter = web_frame->GetDocumentLoader()->GetWebSubresourceFilter(); if (!filter) { LOG(DEBUG) << "[AdBlock] TriggerElementHidingInFrame filter null"; return; } - blink::WebDocument document = web_frame->GetDocument(); if (!document.Url().ProtocolIs("https") && !document.Url().ProtocolIs("http")) { LOG(ERROR) << "[AdBlock] TriggerElementHidingInFrame scheme error"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "[AdBlock] TriggerElementHidingInFrame scheme error"; +#endif return; } - if (web_frame->GetHasDocumentTypeOption()) { LOG(WARNING) << "[AdBlock] Match $document for " << "***"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(WARNING) << "[AdBlock] Match $document for " + << url::LogUtils::ConvertUrlWithMask(document.Url().GetString().Utf8()); +#endif return; } - if (web_frame->GetHasElemHideTypeOption()) { LOG(WARNING) << "[AdBlock] Match selemhide for " << "***"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(WARNING) << "[AdBlock] Match $elemhide for " + << url::LogUtils::ConvertUrlWithMask(document.Url().GetString().Utf8()); +#endif return; } - bool has_generichide = web_frame->GetHasGenericHideTypeOption(); if (has_generichide) { LOG(WARNING) << "[AdBlock] Match sgenerichide for " << "***"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(WARNING) << "[AdBlock] Match $generichide for " + << url::LogUtils::ConvertUrlWithMask(document.Url().GetString().Utf8()); +#endif } - base::TimeTicks start = base::TimeTicks::Now(); std::unique_ptr selectors; selectors = filter->GetElementHidingSelectors(document.Url(), !has_generichide); - if (!selectors->empty()) { document.InsertStyleSheet(blink::WebString::FromUTF8(*selectors), nullptr, blink::WebCssOrigin::kAuthor, @@ -1051,9 +1068,13 @@ void AlloyContentRendererClient::TriggerElementHidingInFrame(int routing_id) { LOG(WARNING) << "[AdBlock] Element hiding for " << "***" << "assumming " << duration.InMicroseconds() << "microseconds"; +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(WARNING) << "[AdBlock] Element hiding for " + << url::LogUtils::ConvertUrlWithMask(document.Url().GetString().Utf8()) + << " assumming " << duration.InMicroseconds() << " microseconds"; +#endif return; } - selectors.reset(); } @@ -1063,6 +1084,11 @@ void AlloyContentRendererClient::TriggerUserElementHidingInFrame( auto* render_frame = content::RenderFrame::FromRoutingID(routing_id); if (!render_frame) { LOG(ERROR) << "[AdBlock] TriggerUserElementHidingInFrame render_frame null"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(ERROR) << "[AdBlock] TriggerUserElementHidingInFrame render_frame null"; +#endif + return; } @@ -1093,6 +1119,14 @@ void AlloyContentRendererClient::TriggerUserElementHidingInFrame( LOG(WARNING) << "[User AdBlock] Element hiding for " << "***" << " assumming " << duration.InMicroseconds() << " microseconds"; + +#ifdef OHOS_LOGGER_REPORT + LOG_FEEDBACK(WARNING) << "[User AdBlock] Element hiding for " + << url::LogUtils::ConvertUrlWithMask(document.Url().GetString().Utf8()) + << " assumming " << duration.InMicroseconds() + << " microseconds"; +#endif + return; } selectors.reset();