diff --git a/base/base_switches.cc b/base/base_switches.cc index d1d5bf32c41b1e1f19c669da6c3fabd7483df632..b501f885947f5be0bf57df4f09f1670a55f86745 100644 --- a/base/base_switches.cc +++ b/base/base_switches.cc @@ -189,4 +189,8 @@ const char kBundleInstallationDir[] = "bundle-installation-dir"; const char kBundleName[] = "bundle-name"; #endif +#ifdef OHOS_VIDEO_ASSISTANT +const char kEnableVideoAssistant[] = "enable-nweb-ex-video-assistant"; +#endif // OHOS_VIDEO_ASSISTANT + } // namespace switches diff --git a/base/base_switches.h b/base/base_switches.h index a427a88feb895931317068a2e55fdb5b66956b4a..5e966f1605c315ead0a79b8e8d5fc4a6165e7e5e 100644 --- a/base/base_switches.h +++ b/base/base_switches.h @@ -72,6 +72,9 @@ extern const char kForTest[]; extern const char kBundleInstallationDir[]; extern const char kBundleName[]; #endif +#ifdef OHOS_VIDEO_ASSISTANT +extern const char kEnableVideoAssistant[]; +#endif // OHOS_VIDEO_ASSISTANT } // namespace switches diff --git a/cc/layers/layer.h b/cc/layers/layer.h index 890978aa946f4463ef69270e0d7b9eee50b83375..7cf83dd8e0f93dbe4c36d1987d85149f6cdd9415 100644 --- a/cc/layers/layer.h +++ b/cc/layers/layer.h @@ -846,6 +846,10 @@ class CC_EXPORT Layer : public base::RefCounted, // surface, returns the ID of that resource. virtual viz::ViewTransitionElementResourceId ViewTransitionResourceId() const; +#ifdef OHOS_VIDEO_ASSISTANT + virtual void OnLayerBoundsUpdate(const gfx::Rect& bounds) {} +#endif // OHOS_VIDEO_ASSISTANT + protected: friend class LayerImpl; friend class TreeSynchronizer; diff --git a/cc/layers/surface_layer.cc b/cc/layers/surface_layer.cc index cbcd4d5a60bd3a324606579e5f0cf5e56d5fd16f..fb10d156114de7973a42d7f08848907ae33cdc05 100644 --- a/cc/layers/surface_layer.cc +++ b/cc/layers/surface_layer.cc @@ -190,4 +190,16 @@ void SurfaceLayer::PushPropertiesTo( layer_impl->set_may_contain_video(may_contain_video_.Read(*this)); } +#ifdef OHOS_VIDEO_ASSISTANT +void SurfaceLayer::SetLayerBoundsChangeCallback( + LayerBoundsChangeCallback callback) { + layer_bounds_change_callback_ = std::move(callback); +} +void SurfaceLayer::OnLayerBoundsUpdate(const gfx::Rect& bounds) { + if (layer_bounds_change_callback_) { + layer_bounds_change_callback_.Run(bounds); + } +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace cc diff --git a/cc/layers/surface_layer.h b/cc/layers/surface_layer.h index 04b949ffdb68a6d7cba3c098b0b8e390bbcc851d..56fee301350e04dbb78372549ce43ab6d5bb2a03 100644 --- a/cc/layers/surface_layer.h +++ b/cc/layers/surface_layer.h @@ -61,6 +61,12 @@ class CC_EXPORT SurfaceLayer : public Layer { void SetMayContainVideo(bool may_contain_video); +#ifdef OHOS_VIDEO_ASSISTANT + using LayerBoundsChangeCallback = + base::RepeatingCallback; + void SetLayerBoundsChangeCallback(LayerBoundsChangeCallback callback); +#endif // OHOS_VIDEO_ASSISTANT + // Layer overrides. std::unique_ptr CreateLayerImpl( LayerTreeImpl* tree_impl) const override; @@ -69,6 +75,10 @@ class CC_EXPORT SurfaceLayer : public Layer { const CommitState& commit_state, const ThreadUnsafeCommitState& unsafe_state) override; +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(const gfx::Rect& bounds) override; +#endif // OHOS_VIDEO_ASSISTANT + const viz::SurfaceId& surface_id() const { return surface_range_.Read(*this).end(); } @@ -114,6 +124,10 @@ class CC_EXPORT SurfaceLayer : public Layer { // This surface layer is reflecting the root surface of another display. ProtectedSequenceReadable is_reflection_; + +#ifdef OHOS_VIDEO_ASSISTANT + LayerBoundsChangeCallback layer_bounds_change_callback_; +#endif // OHOS_VIDEO_ASSISTANT }; } // namespace cc diff --git a/cc/layers/surface_layer_impl.cc b/cc/layers/surface_layer_impl.cc index 71584f2ddb38ab40f1761043737d0a6f827339ec..783e0346366e38af1a250dccb48d19dcf81bc28f 100644 --- a/cc/layers/surface_layer_impl.cc +++ b/cc/layers/surface_layer_impl.cc @@ -19,6 +19,8 @@ #include "components/viz/common/quads/solid_color_draw_quad.h" #include "components/viz/common/quads/surface_draw_quad.h" +#include "base/logging.h" + namespace cc { // static @@ -211,6 +213,13 @@ void SurfaceLayerImpl::AppendQuads(viz::CompositorRenderPass* render_pass, // Unless the client explicitly specifies otherwise, don't block on // |surface_range_| more than once. deadline_in_frames_ = 0u; + +#ifdef OHOS_VIDEO_ASSISTANT + OnLayerBoundsUpdate(visible_quad_rect); +#endif // OHOS_VIDEO_ASSISTANT +#if defined(OHOS_CUSTOM_VIDEO_PLAYER) + OnLayerRectUpdate(visible_quad_rect); +#endif // OHOS_CUSTOM_VIDEO_PLAYER } bool SurfaceLayerImpl::is_surface_layer() const { @@ -325,4 +334,24 @@ const char* SurfaceLayerImpl::LayerTypeAsString() const { return "cc::SurfaceLayerImpl"; } +#ifdef OHOS_VIDEO_ASSISTANT +void SurfaceLayerImpl::OnLayerBoundsUpdate(gfx::Rect visible_quad_rect) { + gfx::Rect layer_bounds = + ScreenSpaceTransform().MapRect(visible_quad_rect); + if (!layer_bounds_.ApproximatelyEqual(layer_bounds, 1)) { + layer_bounds_ = layer_bounds; + layer_tree_impl()->OnLayerBoundsUpdate(id(), layer_bounds); + } +} +#endif // OHOS_VIDEO_ASSISTANT +#if defined(OHOS_CUSTOM_VIDEO_PLAYER) +void SurfaceLayerImpl::OnLayerRectUpdate(gfx::Rect visible_quad_rect) { + visible_quad_rect.set_origin( + ScreenSpaceTransform().MapPoint(visible_quad_rect.origin())); + if (!visible_quad_rect_.ApproximatelyEqual(visible_quad_rect, 1)) { + visible_quad_rect_ = visible_quad_rect; + layer_tree_impl()->OnLayerRectUpdate(id(), visible_quad_rect); + } +} +#endif // OHOS_CUSTOM_VIDEO_PLAYER } // namespace cc diff --git a/cc/layers/surface_layer_impl.h b/cc/layers/surface_layer_impl.h index cc9344548e1f4fcb01c80cec9e2686f8c785b73a..1ea550571245b148d470708c2ab5a636480aebb8 100644 --- a/cc/layers/surface_layer_impl.h +++ b/cc/layers/surface_layer_impl.h @@ -80,6 +80,13 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl { void AsValueInto(base::trace_event::TracedValue* dict) const override; const char* LayerTypeAsString() const override; +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(gfx::Rect visible_quad_rect); +#endif // OHOS_VIDEO_ASSISTANT +#if defined(OHOS_CUSTOM_VIDEO_PLAYER) + void OnLayerRectUpdate(gfx::Rect visible_quad_rect); +#endif // OHOS_CUSTOM_VIDEO_PLAYER + UpdateSubmissionStateCB update_submission_state_callback_; viz::SurfaceRange surface_range_; absl::optional deadline_in_frames_; @@ -89,6 +96,10 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl { bool has_pointer_events_none_ = false; bool is_reflection_ = false; bool will_draw_ = false; + +#ifdef OHOS_VIDEO_ASSISTANT + gfx::Rect layer_bounds_; +#endif // OHOS_VIDEO_ASSISTANT }; } // namespace cc diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index e78ab72f561f95fe596a18ae72e496cde2f2112b..fc348b59b2e0f63b33f0ad25a6a415970ac1d2d4 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -2077,4 +2077,13 @@ void LayerTreeHost::IncrementVisualUpdateDuration( pending_commit_state()->visual_update_duration += visual_update_duration; } +#ifdef OHOS_VIDEO_ASSISTANT +void LayerTreeHost::OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) { + DCHECK(IsMainThread()); + if (auto* layer = LayerById(id)) { + layer->OnLayerBoundsUpdate(bounds); + } +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace cc diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index d008ef953b1da04f066b4e81286bfeeb4ab3a5e7..706575515705ef2b64b0937b708f6fb5ca9cc24d 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -908,6 +908,10 @@ void RegisterClippedVisualViewportSelectionBounds( void IncrementVisualUpdateDuration(base::TimeDelta visual_update_duration); +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds); +#endif // OHOS_VIDEO_ASSISTANT + protected: LayerTreeHost(InitParams params, CompositorMode mode); diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index cc15ce7f80ac1bed878f268f726abf3e3394cc61..3682b74c4df206978726928b3a0990c79ba7bd65 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -5329,6 +5329,12 @@ std::string LayerTreeHostImpl::GetHungCommitDebugInfo() const { tile_manager_.GetHungCommitDebugInfo(); } +#ifdef OHOS_VIDEO_ASSISTANT +void LayerTreeHostImpl::OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) { + client_->OnLayerBoundsUpdate(id, bounds); +} +#endif // OHOS_VIDEO_ASSISTANT + #ifdef OHOS_NWEB_EX void LayerTreeHostImpl::SetupScrollBy() { if (!input_delegate_) { diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index 36ff754c0999ab100653c53a6290ed40c356443f..ebb37efe0822de32f3276408a7bf277f539530ac 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -184,6 +184,10 @@ class LayerTreeHostImplClient { virtual size_t CommitDurationSampleCountForTesting() const = 0; +#ifdef OHOS_VIDEO_ASSISTANT + virtual void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) {} +#endif // OHOS_VIDEO_ASSISTANT + protected: virtual ~LayerTreeHostImplClient() = default; }; @@ -920,6 +924,10 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient, void RequestImplSideInvalidationForRerasterTiling(); +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds); +#endif // OHOS_VIDEO_ASSISTANT + void SetDownsampleMetricsForTesting(bool value) { downsample_metrics_ = value; } diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index 9b7a0091d9e55f7636560ad7a4ec69b3680a7213..58644d97abe7ffa375ec47ef5de974bf873dafb8 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -2999,4 +2999,10 @@ void LayerTreeImpl::RequestImplSideInvalidationForRerasterTiling() { host_impl_->RequestImplSideInvalidationForRerasterTiling(); } +#ifdef OHOS_VIDEO_ASSISTANT +void LayerTreeImpl::OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) { + host_impl_->OnLayerBoundsUpdate(id, bounds); +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace cc diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h index adc3601a017a4dd7a09ffe108bdcbaffaae0852a..05a03bc65b723c5f5628e99b63e96c8bba296bd4 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -169,6 +169,10 @@ class CC_EXPORT LayerTreeImpl { bool IsReadyToActivate() const; void RequestImplSideInvalidationForRerasterTiling(); +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds); +#endif // OHOS_VIDEO_ASSISTANT + // Tree specific methods exposed to layer-impl tree. // --------------------------------------------------------------------------- void SetNeedsRedraw(); diff --git a/cc/trees/proxy_impl.cc b/cc/trees/proxy_impl.cc index 3a11373d592eaf1bf1d3b8e14a092678667b9a00..da5e5a37dbf7b52faddd37a247f694f27db53f84 100644 --- a/cc/trees/proxy_impl.cc +++ b/cc/trees/proxy_impl.cc @@ -1049,4 +1049,13 @@ bool ProxyImpl::DataForCommit::IsValid() const { commit_timestamps); } +#ifdef OHOS_VIDEO_ASSISTANT +void ProxyImpl::OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) { + DCHECK(IsImplThread()); + MainThreadTaskRunner()->PostTask( + FROM_HERE, base::BindOnce(&ProxyMain::OnLayerBoundsUpdate, + proxy_main_weak_ptr_, id, bounds)); +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace cc diff --git a/cc/trees/proxy_impl.h b/cc/trees/proxy_impl.h index b24ad86f5813abd2c8e0bcaab0da6ad32089dced..4e6bd644c3c2e4e6dbe0cbd90cfea4dc1d5bb5f7 100644 --- a/cc/trees/proxy_impl.h +++ b/cc/trees/proxy_impl.h @@ -95,6 +95,10 @@ class CC_EXPORT ProxyImpl : public LayerTreeHostImplClient, void ClearHistory() override; size_t CommitDurationSampleCountForTesting() const override; +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) override; +#endif // OHOS_VIDEO_ASSISTANT + private: // LayerTreeHostImplClient implementation void DidLoseLayerTreeFrameSinkOnImplThread() override; diff --git a/cc/trees/proxy_main.cc b/cc/trees/proxy_main.cc index 345a83262c3ac1de1dbf6d8ad804afc0f4b3010d..6769770e71de9d3a081c51e0363b6a0c9705513a 100644 --- a/cc/trees/proxy_main.cc +++ b/cc/trees/proxy_main.cc @@ -873,4 +873,10 @@ double ProxyMain::GetPercentDroppedFrames() const { return 0.0; } +#ifdef OHOS_VIDEO_ASSISTANT +void ProxyMain::OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) { + layer_tree_host_->OnLayerBoundsUpdate(id, bounds); +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace cc diff --git a/cc/trees/proxy_main.h b/cc/trees/proxy_main.h index 006fd7ec2191d6c72f7b638944e92aea88872e33..d02e11c7f741d9d1c86e2535e965c4a829b950e5 100644 --- a/cc/trees/proxy_main.h +++ b/cc/trees/proxy_main.h @@ -87,6 +87,10 @@ class CC_EXPORT ProxyMain : public Proxy { return final_pipeline_stage_; } +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds); +#endif // OHOS_VIDEO_ASSISTANT + private: // Proxy implementation. bool IsStarted() const override; diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index 9b6d4e8ae5288d151a3f746173511535e67c418e..8fa75a244414917b1a0ce94edb3c19e357001572 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -2519,6 +2519,17 @@ source_set("browser") { ] } + #ifdef OHOS_VIDEO_ASSISTANT + if (defined(ohos_video_assistant) && ohos_video_assistant) { + sources += [ + "media/video_assistant/video_assistant.cc", + "media/video_assistant/video_assistant.h", + ] + deps += [ + "//ohos_nweb_ex/overrides/ui/strings", + ] + } #endif OHOS_VIDEO_ASSISTANT + if (is_mac) { sources += [ "../app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm", diff --git a/content/browser/media/media_web_contents_observer.cc b/content/browser/media/media_web_contents_observer.cc index 1402164ff0cb4af7106e90e3385aeed8a2fe7269..c1280033d19dcb5135a9aeb542f754f5b1010f50 100644 --- a/content/browser/media/media_web_contents_observer.cc +++ b/content/browser/media/media_web_contents_observer.cc @@ -602,6 +602,10 @@ void MediaWebContentsObserver::OnMediaPlayerObserverDisconnected( const MediaPlayerId& player_id) { DCHECK(media_player_observer_hosts_.contains(player_id)); media_player_observer_hosts_.erase(player_id); + +#ifdef OHOS_VIDEO_ASSISTANT + web_contents_impl()->OnVideoDestroyed(player_id); +#endif // OHOS_VIDEO_ASSISTANT } device::mojom::WakeLock* MediaWebContentsObserver::GetAudioWakeLock() { @@ -711,5 +715,78 @@ MediaWebContentsObserver::GetWeakPtrForFrame( std::make_unique>(this))); return result.first->second->GetWeakPtr(); } + +#ifdef OHOS_VIDEO_ASSISTANT +bool MediaWebContentsObserver::IsMediaPlaying(const MediaPlayerId& player_id) { + auto player_info = GetPlayerInfo(player_id); + return player_info && player_info->is_playing(); +} + +void MediaWebContentsObserver::SetPlaybackRate(double playback_rate, + const MediaPlayerId& player_id) { + const auto iter = media_player_remotes_.find(player_id); + if (iter == media_player_remotes_.end()) { + return; + } + + iter->second->SetPlaybackRate(playback_rate); +} + +void MediaWebContentsObserver::RequestFullScreen( + bool enable, + const MediaPlayerId& player_id) { + const auto iter = media_player_remotes_.find(player_id); + if (iter == media_player_remotes_.end()) { + return; + } + + if (enable) { + iter->second->RequestEnterFullscreen(); + } else { + iter->second->RequestExitFullscreen(); + } + + +void MediaWebContentsObserver::RequestDownloadUrl( + const MediaPlayerId& player_id) { + const auto iter = media_player_remotes_.find(player_id); + if (iter == media_player_remotes_.end()) { + return; + } + + iter->second->RequestDownloadUrl(); +} + +void MediaWebContentsObserver::MediaPlayerHostImpl:: + RequestVideoAssistantConfig( + RequestVideoAssistantConfigCallback callback) { + LOG(INFO) << "RequestVideoAssistantConfig"; + auto config = media::mojom::VideoAssistantConfig::New(true, true, + media::mojom::VideoAssistantDownloadButton::kDownloadPerPage); + auto* web_contents_impl = media_web_contents_observer_->web_contents_impl(); + web_contents_impl->PopluateVideoAssistantConfig(config); + std::move(callback).Run(std::move(config)); +} +void MediaWebContentsObserver::MediaPlayerObserverHostImpl:: + OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes) { + LOG(INFO) << "OnVideoPlaying"; + media_web_contents_observer_->web_contents_impl()->OnVideoPlaying( + std::move(video_attributes), media_player_id_); + +void MediaWebContentsObserver::MediaPlayerObserverHostImpl:: + OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes) { + LOG(INFO) << "OnUpdateVideoAttributes"; + media_web_contents_observer_->web_contents_impl()->OnUpdateVideoAttributes( + std::move(video_attributes), media_player_id_); +} +void MediaWebContentsObserver::MediaPlayerObserverHostImpl:: + OnVideoDestroyed() { + LOG(INFO) << "OnVideoDestroyed"; + media_web_contents_observer_->web_contents_impl()->OnVideoDestroyed( + media_player_id_); +} +#endif // OHOS_VIDEO_ASSISTANT } // namespace content diff --git a/content/browser/media/media_web_contents_observer.h b/content/browser/media/media_web_contents_observer.h index d3e1a85d5c5fdb92c88681656d8354242e23470f..a3674b6cf85972025f0446f65f4fdc98e56b623d 100644 --- a/content/browser/media/media_web_contents_observer.h +++ b/content/browser/media/media_web_contents_observer.h @@ -142,6 +142,13 @@ class CONTENT_EXPORT MediaWebContentsObserver // be suspended. void SuspendAllMediaPlayers(); +#if defined(OHOS_VIDEO_ASSISTANT) + bool IsMediaPlaying(const MediaPlayerId& player_id); + void SetPlaybackRate(double playback_rate, const MediaPlayerId& player_id); + void RequestFullScreen(bool enable, const MediaPlayerId& player_id); + void RequestDownloadUrl(const MediaPlayerId& player_id); +#endif // defined(OHOS_VIDEO_ASSISTANT) + protected: MediaSessionControllersManager* session_controllers_manager() { return session_controllers_manager_.get(); @@ -173,6 +180,10 @@ class CONTENT_EXPORT MediaWebContentsObserver mojo::PendingAssociatedReceiver media_player_observer, int32_t player_id) override; +#ifdef OHOS_VIDEO_ASSISTANT + void RequestVideoAssistantConfig( + RequestVideoAssistantConfigCallback callback) override; +#endif // OHOS_VIDEO_ASSISTANT private: GlobalRenderFrameHostId frame_routing_id_; @@ -215,6 +226,14 @@ class CONTENT_EXPORT MediaWebContentsObserver media_session::mojom::RemotePlaybackMetadataPtr remote_playback_metadata) override; +#ifdef OHOS_VIDEO_ASSISTANT + void OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes) override; + void OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes) override; + void OnVideoDestroyed() override; +#endif // OHOS_VIDEO_ASSISTANT + private: PlayerInfo* GetPlayerInfo(); void NotifyAudioStreamMonitorIfNeeded(); diff --git a/content/browser/media/video_assistant/video_assistant.cc b/content/browser/media/video_assistant/video_assistant.cc new file mode 100644 index 0000000000000000000000000000000000000000..4ce4c38bc239cd504c0daa4f9a54b8044256c3f0 --- /dev/null +++ b/content/browser/media/video_assistant/video_assistant.cc @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "content/browser/media/video_assistant/video_assistant.h" + +#include "media/mojo/mojom/media_player.mojom.h" + +namespace content { + +VideoAssistant::VideoAssistant() = default; +VideoAssistant::~VideoAssistant() = default; + +void VideoAssistant::EnableVideoAssistant(bool enable) {} +void VideoAssistant::ExecuteVideoAssistantFunction(const std::string& cmd_id) {} + +bool VideoAssistant::Enabled() { return false; } +void VideoAssistant::DidFinishNavigation() {} +void VideoAssistant::UpdateVideoAssistantConfig( + const media::mojom::VideoAssistantConfigPtr& config) {} + +void VideoAssistant::OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id) {} +void VideoAssistant::OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id) {} +void VideoAssistant::OnVideoDestroyed(const MediaPlayerId& id) {} + +} // namespace diff --git a/content/browser/media/video_assistant/video_assistant.h b/content/browser/media/video_assistant/video_assistant.h new file mode 100644 index 0000000000000000000000000000000000000000..aa2cecbcedcbc30d4ab43bfc608a96c95b42917e --- /dev/null +++ b/content/browser/media/video_assistant/video_assistant.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 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 CONTENT_BROWSER_MEDIA_VIDEO_ASSISTANT_VIDEO_ASSISTANT_H_ +#define CONTENT_BROWSER_MEDIA_VIDEO_ASSISTANT_VIDEO_ASSISTANT_H_ + +#include + +#include "content/public/browser/media_player_id.h" +#include "media/mojo/mojom/media_player.mojom-forward.h" + +namespace content { + +class VideoAssistant { + public: + VideoAssistant(); + virtual ~VideoAssistant(); + + virtual void EnableVideoAssistant(bool enable); + virtual void ExecuteVideoAssistantFunction(const std::string& cmd_id); + + virtual bool Enabled(); + virtual void DidFinishNavigation(); + virtual void UpdateVideoAssistantConfig( + const media::mojom::VideoAssistantConfigPtr& config); + + virtual void OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id); + virtual void OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id); + virtual void OnVideoDestroyed(const MediaPlayerId& id); +}; + +} // namespace + +#endif // CONTENT_BROWSER_MEDIA_VIDEO_ASSISTANT_VIDEO_ASSISTANT_H_ diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index bf3803ebf90cb1c77a416960167cb9eb1132fc07..8cb806889a27b9d65375a35b15500424b7fef09d 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -1413,6 +1413,15 @@ void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { // Re-read values from the new delegate and apply them. if (view_) view_->SetOverscrollControllerEnabled(CanOverscrollContent()); + +#ifdef OHOS_VIDEO_ASSISTANT + if (delegate_) { + video_assistant_ = delegate_->CreateVideoAssistant(); + } + if (!video_assistant_) { + video_assistant_ = std::make_unique(); + } +#endif // OHOS_VIDEO_ASSISTANT } RenderFrameHostImpl* WebContentsImpl::GetPrimaryMainFrame() { @@ -6112,6 +6121,11 @@ void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { if (navigation_handle->IsInPrimaryMainFrame() && !navigation_handle->IsSameDocument()) { was_ever_audible_ = false; +#ifdef OHOS_VIDEO_ASSISTANT + if (video_assistant_) { + video_assistant_->DidFinishNavigation(); + } +#endif // OHOS_VIDEO_ASSISTANT } // Clear the stored prerender activation result if this is not a prerender @@ -9372,6 +9386,12 @@ void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) { void WebContentsImpl::MediaDestroyed(const MediaPlayerId& id) { OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MediaDestroyed"); observers_.NotifyObservers(&WebContentsObserver::MediaDestroyed, id); + +#ifdef OHOS_VIDEO_ASSISTANT + if (video_assistant_) { + video_assistant_->OnVideoDestroyed(id); + } +#endif // OHOS_VIDEO_ASSISTANT } int WebContentsImpl::GetCurrentlyPlayingVideoCount() { @@ -10112,4 +10132,19 @@ void WebContentsImpl::SetTabletMode(bool is_tablet) { GetContentClient()->browser()->SetTabletMode(is_tablet); } #endif + +#if BUILDFLAG(IS_OHOS) +void WebContentsImpl::EnableSafeBrowsingDetection(bool enable, + bool strictMode) { + if (is_safe_browsing_enabled_ != enable) { + LOG(INFO) << "EnableSafeBrowsingDetection enable " << enable; + is_safe_browsing_enabled_ = enable; + } + if (safe_browsing_strict_mode_ != strictMode) { + LOG(INFO) << "EnableSafeBrowsingDetection strictMode " << strictMode; + safe_browsing_strict_mode_ = strictMode; + } +} +#endif + } // namespace content diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index b6ebad3a40e6973979d31de8a7356a85429c807b..d31d676600328f8b7b49a9bb4565fedbc6cf9b6a 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -405,6 +405,13 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, return touch_insert_handle_menu_show_; } #endif // #ifdef OHOS_CLIPBOARD +#if BUILDFLAG(IS_OHOS) + void EnableSafeBrowsingDetection(bool enable, bool strictMode) override; + + bool IsSafeBrowsingDetectionEnabled() override { + return is_safe_browsing_enabled_; + } +#endif #if defined(OHOS_EX_PASSWORD) void SetSavePasswordAutomatically(bool enable) override { LOG(INFO) << "set save password automatically: " << enable; @@ -2300,6 +2307,8 @@ void SetTabletMode(bool is_tablet) override; #if BUILDFLAG(IS_OHOS) std::unique_ptr native_web_contents_observer_; + bool is_safe_browsing_enabled_ = true; + bool safe_browsing_strict_mode_ = false; #endif #if BUILDFLAG(ENABLE_PPAPI) diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 0aa5c7e862d4942393d57070b31ca11da487ff23..7ca983fc8dc6178d1ef03b09cb292664d22f0f03 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -636,6 +636,11 @@ class WebContents : public PageNavigator, virtual bool GetTouchInsertHandleMenuShow() = 0; #endif +#if BUILDFLAG(IS_OHOS) + virtual void EnableSafeBrowsingDetection(bool enable, bool strictMode) = 0; + virtual bool IsSafeBrowsingDetectionEnabled() = 0; +#endif + #if defined(OHOS_EX_PASSWORD) virtual void SetSavePasswordAutomatically(bool enable) = 0; virtual bool GetSavePasswordAutomatically() = 0; diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc index 7b7871f0c0815acda5f757ce61e25083e57c754b..c347d71e12a701d4e1274fdde5a8536f978fde7d 100644 --- a/content/public/browser/web_contents_delegate.cc +++ b/content/public/browser/web_contents_delegate.cc @@ -23,6 +23,10 @@ #include "third_party/blink/public/common/security/protocol_handler_security_level.h" #include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h" #include "ui/gfx/geometry/rect.h" +#ifdef OHOS_VIDEO_ASSISTANT +#include "content/browser/media/video_assistant/video_assistant.h" +#include "media/mojo/mojom/media_player.mojom.h" +#endif // OHOS_VIDEO_ASSISTANT namespace content { @@ -402,4 +406,25 @@ bool WebContentsDelegate::IsPrivileged() { return false; } +#if defined(OHOS_VIDEO_ASSISTANT) +void WebContentsDelegate::OnShowToast(double duration, + const std::string& toast) {} + +void WebContentsDelegate::OnShowVideoAssistant( + const std::string& videoAssistantItems) {} + +void WebContentsDelegate::OnReportStatisticLog(const std::string& content) {} + +std::unique_ptr WebContentsDelegate::CreateVideoAssistant() { + return std::make_unique(); +} +void WebContentsDelegate::PopluateVideoAssistantConfig( + const std::string& url, + media::mojom::VideoAssistantConfigPtr& config) {} +void WebContentsDelegate::OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes) {} +void WebContentsDelegate::OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes) {} +#endif // defined(OHOS_VIDEO_ASSISTANT) + } // namespace content diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index 6a221d9fd4cd67c68d2264846662e2a83236d327..d8d08a7b26b34b0421d3aea981e46c76b02816cf 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -46,6 +46,10 @@ #include "content/public/browser/native_embed_info.h" #endif +#ifdef OHOS_VIDEO_ASSISTANT +#include "media/mojo/mojom/media_player.mojom-forward.h" +#endif // OHOS_VIDEO_ASSISTANT + class GURL; namespace base { @@ -77,6 +81,10 @@ struct DropData; struct MediaPlayerWatchTime; struct NativeWebKeyboardEvent; struct Referrer; + +#ifdef OHOS_VIDEO_ASSISTANT +class VideoAssistant; +#endif // OHOS_VIDEO_ASSISTANT } // namespace content namespace device { @@ -784,6 +792,21 @@ class CONTENT_EXPORT WebContentsDelegate { NativeEmbedInfo::TagState state) {} #endif +#if defined(OHOS_VIDEO_ASSISTANT) + virtual std::unique_ptr CreateVideoAssistant(); + virtual void PopluateVideoAssistantConfig( + const std::string& url, + media::mojom::VideoAssistantConfigPtr& config); + virtual void OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes); + virtual void OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes); + + virtual void OnShowToast(double duration, const std::string& toast); + virtual void OnShowVideoAssistant(const std::string& videoAssistantItems); + virtual void OnReportStatisticLog(const std::string& content); +#endif // defined(OHOS_VIDEO_ASSISTANT) + protected: virtual ~WebContentsDelegate(); diff --git a/media/mojo/mojom/media_player.mojom b/media/mojo/mojom/media_player.mojom index ad54237467757a11ad5353711fbb8d21a28bc6d3..f98d40f64c3e460dcb3d1b761cd64e3c85856809 100644 --- a/media/mojo/mojom/media_player.mojom +++ b/media/mojo/mojom/media_player.mojom @@ -9,6 +9,33 @@ import "mojo/public/mojom/base/time.mojom"; import "services/media_session/public/mojom/media_session.mojom"; import "ui/gfx/geometry/mojom/geometry.mojom"; +[EnableIf=ohos_video_assistant] +enum VideoAssistantDownloadButton { + kDownloadPerPage, + kDownloadForceShow, + kDownloadForceHide, +}; + +[EnableIf=ohos_video_assistant] +struct VideoAssistantConfig { + bool video_assistant; + bool playback_rate; + VideoAssistantDownloadButton download_button; +}; + +[EnableIf=ohos_video_assistant] +struct VideoAttributesForVAST { + bool show_fullscreen_button; + bool show_download_button; + bool show_playback_rate_menu; + double current_playback_rate; + gfx.mojom.RectF rect; + + bool supports_save; + double duration; + bool visible; +}; + // Implemented by HTMLMediaElement in the renderer process to allow the // browser to control media playback. interface MediaPlayer { @@ -58,6 +85,12 @@ interface MediaPlayer { // Request the media player to start Media Remoting when there are available // sinks. RequestMediaRemoting(); + + [EnableIf=ohos_video_assistant] + SetPlaybackRate(double playback_rate); + + [EnableIf=ohos_video_assistant] + RequestDownloadUrl(); }; // Implemented by the MediaWebContentsObserver. The remote lives in the renderer @@ -114,6 +147,15 @@ interface MediaPlayerObserver { // Notifies that the RemotePlayback metadata of the media player has changed. OnRemotePlaybackMetadataChange(media_session.mojom.RemotePlaybackMetadata remote_playback_metadata); + + [EnableIf=ohos_video_assistant] + OnVideoPlaying(VideoAttributesForVAST video_attributes); + + [EnableIf=ohos_video_assistant] + OnUpdateVideoAttributes(VideoAttributesForVAST video_attributes); + + [EnableIf=ohos_video_assistant] + OnVideoDestroyed(); }; // Implemented by MediaWebContentsObserver::MediaPlayerHostImpl in the browser @@ -128,4 +170,8 @@ interface MediaPlayerHost { OnMediaPlayerAdded(pending_associated_remote player_remote, pending_associated_receiver observer, int32 player_id); + + [EnableIf=ohos_video_assistant] + RequestVideoAssistantConfig() => (VideoAssistantConfig config); + }; diff --git a/ohos_build/build/config/ohos.json b/ohos_build/build/config/ohos.json index 0814d94a57aa6e87e9fff63aa7f14af1d47f122a..15b11b36538b7812a6a2c43619dce9a37d3f7395 100755 --- a/ohos_build/build/config/ohos.json +++ b/ohos_build/build/config/ohos.json @@ -598,6 +598,14 @@ "dependence": "", "default": "true" }, +{ "name": "OHOS_VIDEO_ASSISTANT", +"owner": "", +"desc": "video assistant", +"effect": "main gn blink_core other", +"genCommandline": "default", +"dependence": "", +"default": "true" +}, { "name": "OHOS_VIEWPORT", "owner": "", "desc": "adapt viewport", diff --git a/ohos_nweb/BUILD.gn b/ohos_nweb/BUILD.gn index 3efe672b2d8d27e1a8d074ce1d2e49385c53cb16..641b96551b955d01cec3255dbab9fa2f39cd9daf 100644 --- a/ohos_nweb/BUILD.gn +++ b/ohos_nweb/BUILD.gn @@ -284,6 +284,7 @@ component("nweb_sources") { "include/nweb_value.h", "include/nweb_value_callback.h", "src/capi/nweb_app_client_extension_callback.h", + "src/capi/nweb_statistic_callback.h", "src/capi/nweb_storage_extension_callback.h", "src/nweb_cookie_manager_delegate_interface.h", "src/nweb_cookie_manager_impl.cc", diff --git a/ohos_nweb/src/capi/nweb_app_client_extension_callback.h b/ohos_nweb/src/capi/nweb_app_client_extension_callback.h index daf50a316d1ef7d5553b8a1c7c49678adbadb286..ce9b68ddb05f549faa0bd36623be4e9f84e74144 100644 --- a/ohos_nweb/src/capi/nweb_app_client_extension_callback.h +++ b/ohos_nweb/src/capi/nweb_app_client_extension_callback.h @@ -48,6 +48,11 @@ struct NWebAppClientExtensionCallback { void (*ContentsBrowserZoomChange)(double zoom_factor, bool can_show_bubble, int nweb_id); + + void (*OnShowToast)(int32_t nweb_id, double duration, const char* toast); + + void (*OnShowVideoAssistant)(int32_t nweb_id, + const char* video_assistant_items); }; #endif // OHOS_NWEB_SRC_NWEB_APP_CLIENT_EXTENSION_CALLBACK_H_ diff --git a/ohos_nweb/src/capi/nweb_statistic_callback.h b/ohos_nweb/src/capi/nweb_statistic_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..bfd013dc2e88603527f6e3ee592c62ff2f76bb30 --- /dev/null +++ b/ohos_nweb/src/capi/nweb_statistic_callback.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 OHOS_NWEB_SRC_NWEB_STATISTIC_CALLBACK_H_ +#define OHOS_NWEB_SRC_NWEB_STATISTIC_CALLBACK_H_ + +typedef void (*OnReportStatisticLogFunc)(const char*); + +#endif // OHOS_NWEB_SRC_NWEB_STATISTIC_CALLBACK_H_ diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 9b7dd142896b80cf5e1e6a0dddff69fe872ee74b..a72bc366fe5a3c5acb45af16e3f9cebd1ea038d4 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -2606,6 +2606,17 @@ void NWebDelegate::EnableSafeBrowsing(bool enable) { GetBrowser()->EnableSafeBrowsing(enable); } + +void NWebDelegate::EnableSafeBrowsingDetection(bool enable, bool strictMode) { + LOG(DEBUG) << "NWebDelegate::EnableSafeBrowsingDetection. enable is " + << enable << ", strictMode is " << strictMode; + if (GetBrowser() == nullptr) { + LOG(ERROR) << "NWebDelegate::EnableSafeBrowsingDetection failed."; + return; + } + + GetBrowser()->EnableSafeBrowsingDetection(enable, strictMode); +} #endif void NWebDelegate::RegisterAccessibilityEventListener( diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index 9f37921e044d15b2da1b016d8352ba6e371ed319..5f310d386cb99e5e7119738d04e7f99c814cdcbd 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -299,6 +299,7 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { #ifdef BUILDFLAG(IS_OHOS) bool IsSafeBrowsingEnabled() override; void EnableSafeBrowsing(bool enable) override; +void EnableSafeBrowsingDetection(bool enable, bool strictMode) override; #endif #ifdef OHOS_PAGE_UP_DOWN diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc index 0bafcdacad4f97c71bc6604b9ed1958143f68ce6..5e2145a1804139516a707db3a81ca634d7fa0055 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc @@ -584,6 +584,14 @@ void NWebHandlerDelegate::OnAfterCreated(CefRefPtr browser) { } } } +#if defined(OHOS_VIDEO_ASSISTANT) + if (video_assistant_enabled_) { + if (main_browser_ && main_browser_->GetHost()) { + main_browser_->GetHost()->EnableVideoAssistant( + *video_assistant_enabled_); + } + } +#endif // OHOS_VIDEO_ASSISTANT return; } #endif // defined(OHOS_MULTI_WINDOW) @@ -603,6 +611,15 @@ void NWebHandlerDelegate::OnAfterCreated(CefRefPtr browser) { } else { LOG(ERROR) << "Failed to set browser to settings delegate"; } + +#if defined(OHOS_VIDEO_ASSISTANT) + if (video_assistant_enabled_) { + if (main_browser_ && main_browser_->GetHost()) { + main_browser_->GetHost()->EnableVideoAssistant( + *video_assistant_enabled_); + } + } +#endif // OHOS_VIDEO_ASSISTANT } bool NWebHandlerDelegate::DoClose(CefRefPtr browser) { @@ -2550,4 +2567,54 @@ void NWebHandlerDelegate::SetFocusState(bool focusState) { #endif // defined(OHOS_INPUT_EVENTS) } #endif // #ifdef OHOS_FOCUS + +void NWebHandlerDelegate::OnShowToast(double duration, const CefString& toast) { +#if defined(OHOS_VIDEO_ASSISTANT) + if (!web_app_client_extension_listener_) { + LOG(WARNING) << "application extension listener is nullptr"; + return; + } + + if (!web_app_client_extension_listener_->OnShowToast) { + LOG(WARNING) << "show toast callback is nullptr"; + return; + } + + web_app_client_extension_listener_->OnShowToast( + web_app_client_extension_listener_->nweb_id, duration, + toast.ToString().c_str()); +#endif // defined(OHOS_VIDEO_ASSISTANT) +} + +void NWebHandlerDelegate::OnShowVideoAssistant( + const CefString& videoAssistantItems) { +#if defined(OHOS_VIDEO_ASSISTANT) + if (!web_app_client_extension_listener_) { + LOG(WARNING) << "application extension listener is nullptr"; + return; + } + + if (!web_app_client_extension_listener_->OnShowVideoAssistant) { + LOG(WARNING) << "show video assistant callback is nullptr"; + return; + } + + web_app_client_extension_listener_->OnShowVideoAssistant( + web_app_client_extension_listener_->nweb_id, + videoAssistantItems.ToString().c_str()); +#endif // defined(OHOS_VIDEO_ASSISTANT) +} + +void NWebHandlerDelegate::OnReportStatisticLog(const CefString& content) { +#if defined(OHOS_VIDEO_ASSISTANT) + NWebImpl::OnReportStatisticLog(content.ToString()); +#endif // defined(OHOS_VIDEO_ASSISTANT) +} + +#if defined(OHOS_VIDEO_ASSISTANT) +void NWebHandlerDelegate::EnableVideoAssistant(bool enable) { + video_assistant_enabled_ = enable; +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h index d55504256e9b327823ad3ed735d0338b571738b2..93d07518a249805247614cb4d4f4c9d6c672e2d1 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include "capi/nweb_app_client_extension_callback.h" @@ -594,6 +595,15 @@ class NWebHandlerDelegate : public CefClient, bool IsDragEnter() const { return is_drag_enter_; } void SetDragEnter(bool enter) { is_drag_enter_ = enter; } #endif // #ifdef OHOS_DRAG_DROP + + void OnShowToast(double duration, const CefString& toast) override; + void OnShowVideoAssistant(const CefString& videoAssistantItems) override; + void OnReportStatisticLog(const CefString& content) override; + +#if defined(OHOS_VIDEO_ASSISTANT) + void EnableVideoAssistant(bool enable); +#endif // OHOS_VIDEO_ASSISTANT + private: void CopyImageToClipboard(CefRefPtr image); // List of existing browser windows. Only accessed on the CEF UI thread. @@ -676,6 +686,10 @@ class NWebHandlerDelegate : public CefClient, ObjectMethodMap javascript_method_map_; std::function onLoadStartCallback_ = nullptr; std::function onLoadEndCallback_ = nullptr; + +#if defined(OHOS_VIDEO_ASSISTANT) + std::optional video_assistant_enabled_; +#endif // OHOS_VIDEO_ASSISTANT }; } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 7f5fbcc138436daa13e37569e158fd2375b35757..0fbc321dafda6ceebe4e75ba904914860ff7045d 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -367,6 +367,7 @@ class NWebDelegateInterface #if BUILDFLAG(IS_OHOS) virtual bool IsSafeBrowsingEnabled() = 0; virtual void EnableSafeBrowsing(bool enable) = 0; + virtual void EnableSafeBrowsingDetection(bool enable, bool strictMode) = 0; #endif #if defined(OHOS_SECURITY_STATE) diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index dfb658565f0d67d9452aa27ca64fb5a8d8f2e01e..0067017b92b29fe16195a751bff40d7b3203f702 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -91,6 +91,10 @@ #include "ohos_nweb_ex/overrides/cef/libcef/browser/alloy/alloy_browser_ua_config.h" #endif +#if defined(OHOS_VIDEO_ASSISTANT) +#include "ohos_nweb_ex/overrides/cef/libcef/browser/alloy/alloy_browser_engine_cloud_config.h" +#endif + #ifdef OHOS_EX_GET_ZOOM_LEVEL #include "third_party/blink/public/common/page/page_zoom.h" #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" @@ -2107,6 +2111,13 @@ void NWebImpl::EnableSafeBrowsing(bool enable) { return nweb_delegate_->EnableSafeBrowsing(enable); } +void NWebImpl::EnableSafeBrowsingDetection(bool enable, bool strictMode) const { + if (nweb_delegate_ == nullptr) { + return; + } + nweb_delegate_->EnableSafeBrowsingDetection(enable, strictMode); +} + } // namespace OHOS::NWeb using namespace OHOS::NWeb; diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index 9f0dc3cfde987b70794ef5f2caeb7b9d44b0bfd5..5eb056c0201029faf8351ab8638d83e3fbde2701 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -252,6 +252,7 @@ class NWebImpl : public NWeb { bool GetPrintBackground() override; bool IsSafeBrowsingEnabled() override; void EnableSafeBrowsing(bool enable) override; + void EnableSafeBrowsingDetection(bool enable, bool strictMode) const; #endif #if defined(OHOS_INPUT_EVENTS) @@ -307,6 +308,10 @@ class NWebImpl : public NWeb { static void SetBrowserUA(const std::string& ua_name); #endif // OHOS_EX_UA +#if defined(OHOS_VIDEO_ASSISTANT) + static void UpdateBrowserEngineConfig(const std::string& file_path, const std::string& version); +#endif + #if defined(OHOS_EX_FORCE_ZOOM) void SetForceEnableZoom(bool forceEnableZoom) const; bool GetForceEnableZoom() const;