diff --git a/base/base_switches.cc b/base/base_switches.cc index 8aa19df6589790af97cc8d1afa6b84b4938981c0..17c5004e57d690eeb785dd9326bb0ded022a440a 100644 --- a/base/base_switches.cc +++ b/base/base_switches.cc @@ -195,4 +195,8 @@ const char kBundleName[] = "bundle-name"; const char kArkWebInstallPath[] = "arkwebcore-install-path"; #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 7b576c06ed1e6230f2c3cdc4aac477455a003571..8aa8db3aa7a98d5b2b81ef70d47979bcb947c18b 100644 --- a/base/base_switches.h +++ b/base/base_switches.h @@ -76,6 +76,9 @@ extern const char kBundleInstallationDir[]; extern const char kBundleName[]; extern const char kArkWebInstallPath[]; #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 1bb4398c159c30822a274d36498df4e406135a3c..82809f6521cf4eee40106257f704fc3c86ccbb8c 100644 --- a/cc/layers/layer.h +++ b/cc/layers/layer.h @@ -867,6 +867,9 @@ class CC_EXPORT Layer : public base::RefCounted, virtual void OnLayerRectVisibilityChange(bool visibility) {} #endif +#ifdef OHOS_VIDEO_ASSISTANT + virtual void OnLayerBoundsUpdate(const gfx::Rect& bounds) {} +#endif // OHOS_VIDEO_ASSISTANT void SetShouldInterceptTouchEvent(bool intercept) { should_intercept_touch_event_.Write(*this) = intercept; diff --git a/cc/layers/surface_layer.cc b/cc/layers/surface_layer.cc index ec1b17612dd573075e1146d23ffd52d362aa3a96..07527e288ccbd31efc5f3693f06813bd91b5939c 100644 --- a/cc/layers/surface_layer.cc +++ b/cc/layers/surface_layer.cc @@ -203,5 +203,16 @@ void SurfaceLayer::OnLayerRectUpdate(const gfx::Rect& rect) { } } #endif // OHOS_CUSTOM_VIDEO_PLAYER +#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 3522665821fb091f80bdae35eb4148098da08a2e..e1b7298aac15b853d7a585700e703a94046b5a7c 100644 --- a/cc/layers/surface_layer.h +++ b/cc/layers/surface_layer.h @@ -65,6 +65,11 @@ class CC_EXPORT SurfaceLayer : public Layer { using RectChangeCallback = base::RepeatingCallback; void SetVideoRectChangeCallback(RectChangeCallback callback); #endif // OHOS_CUSTOM_VIDEO_PLAYER +#ifdef OHOS_VIDEO_ASSISTANT + using LayerBoundsChangeCallback = + base::RepeatingCallback; + void SetLayerBoundsChangeCallback(LayerBoundsChangeCallback callback); +#endif // OHOS_VIDEO_ASSISTANT // Layer overrides. std::unique_ptr CreateLayerImpl( @@ -76,6 +81,9 @@ class CC_EXPORT SurfaceLayer : public Layer { #if defined(OHOS_CUSTOM_VIDEO_PLAYER) void OnLayerRectUpdate(const gfx::Rect& rect) override; #endif // OHOS_CUSTOM_VIDEO_PLAYER +#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(); @@ -126,6 +134,9 @@ class CC_EXPORT SurfaceLayer : public Layer { #if defined(OHOS_CUSTOM_VIDEO_PLAYER) RectChangeCallback video_rect_change_callback_; #endif // OHOS_CUSTOM_VIDEO_PLAYER +#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 1a3e4d03bdb823ae088863884d20ae56a4026b7e..ee941fd132274964954e5457d4f4d44fac63bcc7 100644 --- a/cc/layers/surface_layer_impl.cc +++ b/cc/layers/surface_layer_impl.cc @@ -212,6 +212,9 @@ void SurfaceLayerImpl::AppendQuads(viz::CompositorRenderPass* render_pass, // |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) visible_quad_rect.set_origin( ScreenSpaceTransform().MapPoint(visible_quad_rect.origin())); @@ -334,4 +337,14 @@ 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 } // namespace cc diff --git a/cc/layers/surface_layer_impl.h b/cc/layers/surface_layer_impl.h index a701d4d9b7dc26096ee1d23793e8de1104fe09e0..9f81c40a51d1af924add21d25f9c38ab4d861726 100644 --- a/cc/layers/surface_layer_impl.h +++ b/cc/layers/surface_layer_impl.h @@ -80,6 +80,10 @@ 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 + UpdateSubmissionStateCB update_submission_state_callback_; viz::SurfaceRange surface_range_; absl::optional deadline_in_frames_; @@ -93,6 +97,9 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl { #if defined(OHOS_CUSTOM_VIDEO_PLAYER) gfx::Rect visible_quad_rect_; #endif // OHOS_CUSTOM_VIDEO_PLAYER +#ifdef OHOS_VIDEO_ASSISTANT + gfx::Rect layer_bounds_; +#endif // OHOS_VIDEO_ASSISTANT }; } // namespace cc diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index 48bb5eb965a767d1516af9f5a253af5c4063690d..ec047140cec7f969825facee9e62a756ff36df74 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -919,6 +919,10 @@ void RegisterClippedVisualViewportSelectionBounds( void OnLayerRectVisibilityChange(int id, bool visibility); #endif +#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 5efa45b3499e7389f5e4c7892ab2e95a35abf17a..4b385efd9f6ddf97c6bee56712d1f9d7f878a2b2 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -5428,6 +5428,12 @@ void LayerTreeHostImpl::OnLayerRectVisibilityChange(int id, bool visibility) { } #endif +#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 83a0e8835a2953287b98dcc03de56d59cca81383..5fe60aa66e8b774ecb7192c3827ba07739690306 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -194,6 +194,9 @@ class LayerTreeHostImplClient { virtual void OnLayerRectVisibilityChange(int id, bool visibility) {} #endif +#ifdef OHOS_VIDEO_ASSISTANT + virtual void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) {} +#endif // OHOS_VIDEO_ASSISTANT protected: virtual ~LayerTreeHostImplClient() = default; @@ -940,6 +943,9 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient, void OnLayerRectVisibilityChange(int id, bool visibility); #endif +#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 f30a205cc6c66d120a682f3a6d41a135fa9b9854..4a1ad71234706bca39505c7f94ecc5706be50101 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -3031,4 +3031,9 @@ void LayerTreeImpl::OnLayerRectVisibilityChange(int id, bool visibility) { } #endif +#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 f6c6986927de7a136178ad55c921867d4775d29d..ee10e2ab1041d87df6c0a70bbe8f845b6e6636ee 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -177,6 +177,10 @@ class CC_EXPORT LayerTreeImpl { void OnLayerRectVisibilityChange(int id, bool visibility); #endif +#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 5c88a238f42ebf691623480bfa66cf876e8b33ae..6679cf3cda62cf744aaabcc9819ef142338580e3 100644 --- a/cc/trees/proxy_impl.cc +++ b/cc/trees/proxy_impl.cc @@ -1114,4 +1114,13 @@ void ProxyImpl::OnLayerRectVisibilityChange(int id, bool visibility) { proxy_main_weak_ptr_, id, visibility)); } #endif + +#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 a0e894c3a3cf5e1c90bdcd6c48728dd97cead043..5c892cb73f4e60c2472baec93671df73c5b3e9eb 100644 --- a/cc/trees/proxy_impl.h +++ b/cc/trees/proxy_impl.h @@ -100,6 +100,9 @@ class CC_EXPORT ProxyImpl : public LayerTreeHostImplClient, void OnLayerRectVisibilityChange(int id, bool visibility) override; #endif +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds) override; +#endif // OHOS_VIDEO_ASSISTANT private: // LayerTreeHostImplClient implementation diff --git a/cc/trees/proxy_main.cc b/cc/trees/proxy_main.cc index bda4accdc49e836ba5624500a3765a3813c05569..7f48b7524c841a38ff4caf5ce97e94bb8d9efa84 100644 --- a/cc/trees/proxy_main.cc +++ b/cc/trees/proxy_main.cc @@ -906,4 +906,9 @@ void ProxyMain::OnLayerRectVisibilityChange(int id, bool visibility) { } #endif +#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 32a41eda4ea93b4ab972364ec1ed8d3f510648dc..4539ba086a564a33316d4daa18360841ccf1d33d 100644 --- a/cc/trees/proxy_main.h +++ b/cc/trees/proxy_main.h @@ -91,6 +91,9 @@ class CC_EXPORT ProxyMain : public Proxy { void OnLayerRectVisibilityChange(int id, bool visibility); #endif +#ifdef OHOS_VIDEO_ASSISTANT + void OnLayerBoundsUpdate(int id, const gfx::Rect& bounds); +#endif // OHOS_VIDEO_ASSISTANT private: // Proxy implementation. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index b26c54a3c43e1123f8cd84b8f1ea71a48615a143..65465a3809c2639f71c9f650560c31765c339a5d 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -2546,6 +2546,18 @@ source_set("browser") { deps += [ "//third_party:huawei_securec" ] } + #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 0f66810d8c801f2987c17cdb5cc16058cca1b10b..26143976ce8fd9020ee7dde390766c3707630a08 100644 --- a/content/browser/media/media_web_contents_observer.cc +++ b/content/browser/media/media_web_contents_observer.cc @@ -643,6 +643,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() { @@ -790,6 +794,11 @@ void MediaWebContentsObserver::RequestExitFullscreen(const MediaPlayerId& player #endif // OHOS_CUSTOM_VIDEO_PLAYER #if defined(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); @@ -826,4 +835,37 @@ void MediaWebContentsObserver::RequestDownloadUrl( } #endif // defined(OHOS_VIDEO_ASSISTANT) +#ifdef OHOS_VIDEO_ASSISTANT +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 8d222d49b4bb4108eb938c2cfc8463cafe0802c9..3e71bcd072f1dbb84cbfdf4414091b63ac401118 100644 --- a/content/browser/media/media_web_contents_observer.h +++ b/content/browser/media/media_web_contents_observer.h @@ -157,6 +157,7 @@ class CONTENT_EXPORT MediaWebContentsObserver #endif // OHOS_CUSTOM_VIDEO_PLAYER #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); @@ -193,6 +194,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_; @@ -243,6 +248,14 @@ class CONTENT_EXPORT MediaWebContentsObserver void FullscreenChanged(bool is_fullscreen) override; #endif // OHOS_CUSTOM_VIDEO_PLAYER +#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 c5d3e7f5bc5366f2eb54ba814cd1d330d890bc11..7ede4e8b4465f139d2e3a162f29807e669661513 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -247,6 +247,10 @@ #include "base/ohos/locale_utils.h" #endif +#ifdef OHOS_VIDEO_ASSISTANT +#include "content/browser/media/video_assistant/video_assistant.h" +#endif // OHOS_VIDEO_ASSISTANT + namespace content { namespace { @@ -1109,6 +1113,10 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) star_scan_load_observer_ = std::make_unique(this); } #endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && BUILDFLAG(USE_STARSCAN) + +#ifdef OHOS_VIDEO_ASSISTANT + video_assistant_ = std::make_unique(); +#endif // OHOS_VIDEO_ASSISTANT } WebContentsImpl::~WebContentsImpl() { @@ -1444,6 +1452,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() { @@ -1986,7 +2003,6 @@ void WebContentsImpl::SetUserAgentOverride( user_agent_ = ua_override.ua_string_override; UpdateOverridingUserAgent(); - // DTS2023022711784 // 子进程打开新窗口时,会先创建delayed_load_url_params_,等到加载url时直接使用 // delayed_load_url_params_的值创建NavigationRequest。其override_user_agent默认值是 // UA_OVERRIDE_FALSE,故这里也要更新。 @@ -3161,6 +3177,12 @@ const blink::web_pref::WebPreferences WebContentsImpl::ComputeWebPreferences() { #endif GetContentClient()->browser()->OverrideWebkitPrefs(this, &prefs); +#ifdef OHOS_VIDEO_ASSISTANT + prefs.video_assistant_enabled = video_assistant_ + ? video_assistant_->Enabled() + : false; +#endif // OHOS_VIDEO_ASSISTANT + return prefs; } @@ -6284,6 +6306,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 @@ -9616,6 +9643,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() { @@ -10624,9 +10657,17 @@ void WebContentsImpl::RequestExitFullscreen(const MediaPlayerId& player_id) { #endif // OHOS_CUSTOM_VIDEO_PLAYER #if defined(OHOS_VIDEO_ASSISTANT) -void WebContentsImpl::EnableVideoAssistant(bool enable) {} +void WebContentsImpl::EnableVideoAssistant(bool enable) { + if (video_assistant_->Enabled() == enable) { + return; + } + video_assistant_->EnableVideoAssistant(enable); + OnWebPreferencesChanged(); +} -void WebContentsImpl::ExecuteVideoAssistantFunction(const std::string& cmdId) {} +void WebContentsImpl::ExecuteVideoAssistantFunction(const std::string& cmdId) { + video_assistant_->ExecuteVideoAssistantFunction(cmdId); +} void WebContentsImpl::OnShowToast(double duration, const std::string& toast) { if (!delegate_) { @@ -10697,4 +10738,28 @@ void WebContentsImpl::OnBeforeUnloadFired(bool proceed) { } #endif // OHOS_DISPATCH_BEFORE_UNLOAD +#ifdef OHOS_VIDEO_ASSISTANT +void WebContentsImpl::PopluateVideoAssistantConfig( + media::mojom::VideoAssistantConfigPtr& config) { + if (delegate_) { + delegate_->PopluateVideoAssistantConfig( + GetLastCommittedURL().DeprecatedGetOriginAsURL().spec(), config); + video_assistant_->UpdateVideoAssistantConfig(config); + } +} +void WebContentsImpl::OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id) { + video_assistant_->OnVideoPlaying(std::move(video_attributes), id); +} +void WebContentsImpl::OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id) { + video_assistant_->OnUpdateVideoAttributes(std::move(video_attributes), id); +} +void WebContentsImpl::OnVideoDestroyed(const MediaPlayerId& id) { + video_assistant_->OnVideoDestroyed(id); +} +#endif // OHOS_VIDEO_ASSISTANT + } // namespace content diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index ff53c44249bb367eb1494dc71cddea950ee9c33f..edd8b06375bcaf7a7dcab83d9dcf93e5f1b67d85 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -188,6 +188,10 @@ class PepperPlaybackObserver; class CustomMediaPlayerListener; #endif // OHOS_CUSTOM_VIDEO_PLAYER +#ifdef OHOS_VIDEO_ASSISTANT +class VideoAssistant; +#endif // OHOS_VIDEO_ASSISTANT + // CreatedWindow holds the WebContentsImpl and target url between IPC calls to // CreateNewWindow and ShowCreatedWindow. struct CONTENT_EXPORT CreatedWindow { @@ -1588,6 +1592,18 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, void OnBeforeUnloadFired(bool proceed) override; #endif // OHOS_DISPATCH_BEFORE_UNLOAD +#ifdef OHOS_VIDEO_ASSISTANT + void PopluateVideoAssistantConfig( + media::mojom::VideoAssistantConfigPtr& config); + void OnVideoPlaying( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id); + void OnUpdateVideoAttributes( + media::mojom::VideoAttributesForVASTPtr video_attributes, + const MediaPlayerId& id); + void OnVideoDestroyed(const MediaPlayerId& id); +#endif // OHOS_VIDEO_ASSISTANT + private: using FrameTreeIterationCallback = base::RepeatingCallback; using RenderViewHostIterationCallback = @@ -2676,6 +2692,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, #if defined(OHOS_CUSTOM_VIDEO_PLAYER) std::map players_; #endif // OHOS_CUSTOM_VIDEO_PLAYER + +#ifdef OHOS_VIDEO_ASSISTANT + std::unique_ptr video_assistant_; +#endif // OHOS_VIDEO_ASSISTANT }; // Dangerous methods which should never be made part of the public API, so we diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc index 2141c3c40c1a949b091d96d38f11e1045892de59..92890135db10e98258b34fc85e4929cfe93643c8 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 { @@ -420,4 +424,17 @@ void WebContentsDelegate::OnShowVideoAssistant( void WebContentsDelegate::OnReportStatisticLog(const std::string& content) {} #endif // defined(OHOS_VIDEO_ASSISTANT) +#ifdef OHOS_VIDEO_ASSISTANT +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 // OHOS_VIDEO_ASSISTANT + } // namespace content diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index 5d6d6d7f906717b0cd5cb9dda8b5d134b9aea573..0a962a479502ab971c5d0a441c933632ca878d91 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 { @@ -84,6 +88,9 @@ class CustomMediaPlayerListener; struct MediaInfo; #endif // OHOS_CUSTOM_VIDEO_PLAYER +#ifdef OHOS_VIDEO_ASSISTANT +class VideoAssistant; +#endif // OHOS_VIDEO_ASSISTANT } // namespace content namespace device { @@ -844,6 +851,15 @@ class CONTENT_EXPORT WebContentsDelegate { #endif // OHOS_CUSTOM_VIDEO_PLAYER #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); diff --git a/media/mojo/mojom/media_player.mojom b/media/mojo/mojom/media_player.mojom index c240feaa45b4a438c863a35b624b6a659d4ab289..6ea04ec5df19947b73a4057eb3cff08573ca4c8b 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 { @@ -140,6 +167,15 @@ interface MediaPlayerObserver { [EnableIf=ohos_custom_video_player] FullscreenChanged(bool is_fullscreen); + + [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 @@ -154,4 +190,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 db00b87debef814f98e0ae6c57c016a4196ebb2c..f2fa7c4d1118d8977449539f2f3894f1c4deb817 100644 --- a/ohos_build/build/config/ohos.json +++ b/ohos_build/build/config/ohos.json @@ -950,7 +950,7 @@ "effect": "main gn blink_core other", "genCommandline": "default", "dependence": "", - "default": "true" + "default": "false" }, { "name": "OHOS_VIEWPORT", diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 29a6e45890dfa052e81f64744dcece3faaf9d728..f65c66b9e63fe1f1659b50ccae151c1dd346c8f9 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -4494,6 +4494,31 @@ void NWebDelegate::CloseDevtools() { } GetBrowser()->GetHost()->CloseDevTools(); } + +#if defined(OHOS_VIDEO_ASSISTANT) +void NWebDelegate::EnableVideoAssistant(bool enable) { + if (GetBrowser() == nullptr || GetBrowser()->GetHost() == nullptr) { + if (!handler_delegate_) { + LOG(ERROR) << "failed to enable video assistant, handler delegate is null"; + return; + } + handler_delegate_->EnableVideoAssistant(enable); + return; + } + + GetBrowser()->GetHost()->EnableVideoAssistant(enable); +} + +void NWebDelegate::ExecuteVideoAssistantFunction(const std::string& cmd_id) { + if (GetBrowser() == nullptr || GetBrowser()->GetHost() == nullptr) { + LOG(ERROR) << "failed to get host when execute video assistant function"; + return; + } + + GetBrowser()->GetHost()->ExecuteVideoAssistantFunction(cmd_id); +} +#endif // defined(OHOS_VIDEO_ASSISTANT) + #if defined(OHOS_DISPATCH_BEFORE_UNLOAD) bool NWebDelegate::NeedToFireBeforeUnloadOrUnloadEvents() { if (GetBrowser().get()) { diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc index 3f31c43ce1120341a032ed99077ed31d530f6b39..09cd7b2e075813e61368919a866a6ed0ccdae51e 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc @@ -891,6 +891,14 @@ void NWebHandlerDelegate::OnAfterCreated(CefRefPtr browser) { } } #endif +#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) @@ -910,6 +918,14 @@ 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) { @@ -3974,6 +3990,12 @@ void NWebHandlerDelegate::OnActivateContent() { } #endif +#if defined(OHOS_VIDEO_ASSISTANT) +void NWebHandlerDelegate::EnableVideoAssistant(bool enable) { + video_assistant_enabled_ = enable; +} +#endif // OHOS_VIDEO_ASSISTANT + #if defined(OHOS_DISPATCH_BEFORE_UNLOAD) void NWebHandlerDelegate::OnBeforeUnloadFired(CefRefPtr browser, bool proceed) { diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h index a890e0f02f2fcc77a337b0189a95bbe02b0a4cb5..5bbe512c2e129f83e1c54705f6e8f2b772d5bbf5 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h @@ -788,6 +788,10 @@ void OnTouchIconUrlWithSizesReceived( void OnRequestOpenDevTools(); +#if defined(OHOS_VIDEO_ASSISTANT) + void EnableVideoAssistant(bool enable); +#endif // OHOS_VIDEO_ASSISTANT + #if defined(OHOS_DISPATCH_BEFORE_UNLOAD) void OnBeforeUnloadFired(CefRefPtr browser, bool proceed) override; @@ -921,6 +925,9 @@ void OnTouchIconUrlWithSizesReceived( #ifdef OHOS_ARKWEB_ADBLOCK bool is_global_adblock_enabled_ = false; #endif +#if defined(OHOS_VIDEO_ASSISTANT) + std::optional video_assistant_enabled_; +#endif // OHOS_VIDEO_ASSISTANT base::WeakPtrFactory weak_factory_{this}; }; diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index 8d087449241eaae38ca87a26ac57a952c47623f1..b38c8400f6891ca116d3c0c806e0eb105a14c5b9 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -96,6 +96,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" @@ -2640,6 +2644,13 @@ void NWebImpl::SetBrowserUA(const std::string& ua_name) { } #endif // OHOS_EX_UA +#if defined(OHOS_VIDEO_ASSISTANT) +// static +void NWebImpl::UpdateBrowserEngineConfig(const std::string& file_path, const std::string& version) { + nweb_ex::AlloyBrowserEngineCloudConfig::GetInstance()->UpdateBrowserEngineCloudConfig(file_path, version); +} +#endif + #if defined(OHOS_I18N) void NWebImpl::UpdateAcceptLanguageInternal() { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index ed2e42c775220299f55dfc931a0b470a1fda5b72..603a808872fde4fae6cfa729001cdc3c4afb6823 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -463,6 +463,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;