[M120 Migration] Implement ewk_view_is_video_playing api 35/307835/4
authoryangzhiwen <zw714.yang@samsung.com>
Wed, 13 Mar 2024 12:22:15 +0000 (20:22 +0800)
committeryangzhiwen <zw714.yang@samsung.com>
Fri, 15 Mar 2024 01:33:18 +0000 (09:33 +0800)
The api used to set video to auto fullscreen on timeout
during idle situation(Timeout of 120sec or 2 hours).

If video is found to be in playing state, then video
is turned into fullscreen.

refs:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/290475/

Change-Id: I644ec19401648a3efeba23b6802cca2cd16d31a8
Signed-off-by: yangzhiwen <zw714.yang@samsung.com>
28 files changed:
content/browser/renderer_host/render_widget_host_impl.cc
content/browser/renderer_host/render_widget_host_impl.h
content/browser/renderer_host/render_widget_host_view_aura.cc
content/browser/renderer_host/render_widget_host_view_aura.h
content/browser/renderer_host/render_widget_host_view_base.h
content/public/browser/web_contents_delegate.h
third_party/blink/public/mojom/widget/platform_widget.mojom
third_party/blink/public/web/web_view.h
third_party/blink/renderer/core/dom/document.cc
third_party/blink/renderer/core/dom/document.h
third_party/blink/renderer/core/execution_context/execution_context.cc
third_party/blink/renderer/core/execution_context/execution_context.h
third_party/blink/renderer/core/execution_context/execution_context_lifecycle_state_observer.h
third_party/blink/renderer/core/exported/web_view_impl.cc
third_party/blink/renderer/core/exported/web_view_impl.h
third_party/blink/renderer/core/frame/web_frame_widget_impl.cc
third_party/blink/renderer/core/frame/web_frame_widget_impl.h
third_party/blink/renderer/core/html/media/html_media_element.h
third_party/blink/renderer/platform/widget/widget_base.cc
third_party/blink/renderer/platform/widget/widget_base.h
third_party/blink/renderer/platform/widget/widget_base_client.h
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_common_helper_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_common_helper_efl.h
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/public/ewk_view.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h

index a1d7a8e..89be0f9 100644 (file)
@@ -612,6 +612,25 @@ void RenderWidgetHostImpl::UnPauseScheduledTasks() {
 #endif
 
 #if BUILDFLAG(IS_TIZEN_TV)
+void RenderWidgetHostImpl::RequestVideoPlaying(int callback_id) {
+  if (!blink_widget_){
+    LOG(ERROR) << "blink_widget_ is null";
+    return;
+  }
+  blink_widget_->IsVideoPlaying(
+      base::BindOnce(&RenderWidgetHostImpl::OnGetVideoPlayingStatus,
+                     weak_factory_.GetWeakPtr(), callback_id));
+}
+
+void RenderWidgetHostImpl::OnGetVideoPlayingStatus(int callback_id,
+                                                   bool is_playing) {
+  if (!view_){
+    LOG(ERROR) << "view_ is null";
+    return;
+  }
+  view_->VideoPlayingStatusReceived(is_playing, callback_id);
+}
+
 void RenderWidgetHostImpl::SetParentalRatingResult(const std::string& url,
                                                    bool is_pass) {
   if (!blink_widget_){
index c1e2ec6..733f395 100644 (file)
@@ -380,6 +380,8 @@ class CONTENT_EXPORT RenderWidgetHostImpl
   void SetView(RenderWidgetHostViewBase* view);
 
 #if BUILDFLAG(IS_TIZEN_TV)
+  void RequestVideoPlaying(int callback_id);
+  void OnGetVideoPlayingStatus(int callback_id, bool is_playing);
   void SetTranslatedURL(const std::string& url);
   void SetParentalRatingResult(const std::string& url, bool is_pass);
 #endif
index 2a443c9..c6efa4f 100644 (file)
@@ -425,6 +425,16 @@ void RenderWidgetHostViewAura::InitAsPopup(
 #endif
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void RenderWidgetHostViewAura::VideoPlayingStatusReceived(bool is_playing,
+                                                          int callback_id) {
+  if (aura_efl_helper())
+    aura_efl_helper()->VideoPlayingStatusReceived(is_playing, callback_id);
+  else
+    LOG(ERROR) << "aura_efl_helper() is false";
+}
+#endif
+
 void RenderWidgetHostViewAura::Hide() {
   window_->Hide();
   visibility_ = Visibility::HIDDEN;
index 97c1d6a..d18e39a 100644 (file)
@@ -188,6 +188,10 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
   bool GetIsMouseLockedUnadjustedMovementForTesting() override;
   bool LockKeyboard(absl::optional<base::flat_set<ui::DomCode>> codes) override;
   void UnlockKeyboard() override;
+#if BUILDFLAG(IS_TIZEN_TV)
+  // notify web browser video playing status
+  void VideoPlayingStatusReceived(bool is_playing, int callback_id) override;
+#endif
   bool IsKeyboardLocked() override;
   base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
   void InvalidateLocalSurfaceIdAndAllocationGroup() override;
index 112417b..a47162f 100644 (file)
@@ -507,6 +507,8 @@ class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView {
 #if BUILDFLAG(IS_TIZEN_TV)
   //Browser edge scroll
   virtual void DidEdgeScrollBy(const gfx::Point& offset, bool handled) {}
+  // notify web browser video playing status
+  virtual void VideoPlayingStatusReceived(bool is_playing, int callback_id) {}
 #endif
 
   // Calls UpdateTooltip if the view is under the cursor.
index d3be49b..1ad242e 100644 (file)
@@ -735,6 +735,7 @@ class CONTENT_EXPORT WebContentsDelegate {
   virtual void ExitPictureInPicture() {}
 
 #if BUILDFLAG(IS_TIZEN_TV)
+  virtual void VideoPlayingStatusReceived(bool is_playing, int callback_id) {}
   virtual void NotifyPlaybackState(int state,
                                    int player_id,
                                    const std::string& url,
index 78dabfb..ed57605 100644 (file)
@@ -140,6 +140,9 @@ interface Widget {
   ResetLastInteractedElements();
 
   [EnableIf=is_tizen_tv]
+  IsVideoPlaying() => (bool is_video_playing);
+
+  [EnableIf=is_tizen_tv]
   SetTranslatedURL(string url);
 
   [EnableIf=is_tizen_tv]
index de07ce2..be84a15 100644 (file)
@@ -545,6 +545,8 @@ class BLINK_EXPORT WebView {
 
 #if BUILDFLAG(IS_TIZEN_TV)
   virtual void SetFloatVideoWindowState(bool enable) = 0;
+  // Return if there is any active video in the view
+  virtual bool IsVideoPlaying() const = 0;
   virtual void SetParentalRatingResult(const WebString&, bool) = 0;
 #endif
 
index 0bd12e6..f1a0a8a 100644 (file)
@@ -1098,6 +1098,16 @@ bool Document::IsInMainFrame() const {
   return GetFrame() && GetFrame()->IsMainFrame();
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+bool Document::IsVideoPlaying() const {
+  if (GetExecutionContext())
+    return GetExecutionContext()->CheckVideoPlaying();
+
+  LOG(INFO) << "GetExecutionContext() is null";
+  return false;
+}
+#endif
+
 bool Document::IsInOutermostMainFrame() const {
   return GetFrame() && GetFrame()->IsOutermostMainFrame();
 }
@@ -7303,7 +7313,10 @@ Document& Document::TopDocument() const {
 }
 
 ExecutionContext* Document::GetExecutionContext() const {
-  return execution_context_.Get();
+  if (execution_context_)
+    return execution_context_.Get();
+  else
+    return nullptr;
 }
 
 Agent& Document::GetAgent() const {
index ee3af84..c64ad1f 100644 (file)
@@ -1689,6 +1689,10 @@ class CORE_EXPORT Document : public ContainerNode,
   // See `Frame::IsMainFrame`.
   bool IsInMainFrame() const;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool IsVideoPlaying() const;
+#endif
+
   // Returns true if this document has a frame and is an outermost main frame.
   // See `Frame::IsOutermostMainFrame`.
   bool IsInOutermostMainFrame() const;
index fc386a1..c0382ee 100644 (file)
@@ -303,6 +303,31 @@ void ExecutionContext::SetParentalRatingResult(const String& url,
           state_observer->SetParentalRatingResult(is_pass);
       });
 }
+
+bool ExecutionContext::CheckVideoPlaying() const {
+  bool result = false;
+  ContextLifecycleNotifier::observers().ForEachObserver(
+      [&](ContextLifecycleObserver* observer) {
+        if (!observer->IsExecutionContextLifecycleObserver())
+          return;
+        if (static_cast<ExecutionContextLifecycleObserver*>(observer)
+                ->ObserverType() !=
+            ExecutionContextLifecycleObserver::kStateObjectType)
+          return;
+        ExecutionContextLifecycleStateObserver* state_observer =
+            static_cast<ExecutionContextLifecycleStateObserver*>(observer);
+        if (state_observer->HasVideo()) {
+#if DCHECK_IS_ON()
+          DCHECK_EQ(state_observer->GetExecutionContext(), Context());
+          DCHECK(state_observer->UpdateStateIfNeededCalled());
+#endif
+          if (state_observer->IsPlaying())
+            result = true;
+        }
+      });
+
+  return result;
+}
 #endif
 
 void ExecutionContext::AddConsoleMessageImpl(
index 131cc60..bfac902 100644 (file)
@@ -477,6 +477,7 @@ class CORE_EXPORT ExecutionContext : public Supplementable<ExecutionContext>,
   virtual bool HasStorageAccess() const { return false; }
 
 #if BUILDFLAG(IS_TIZEN_TV)
+  bool CheckVideoPlaying() const;
   void SetTranslatedURL(const String&);
   void SetParentalRatingResult(const String& url, bool is_pass);
 #endif
index 0a5c90d..45b9b86 100644 (file)
@@ -70,16 +70,16 @@ class CORE_EXPORT ExecutionContextLifecycleStateObserver
   virtual void ContextLifecycleStateChanged(
       mojom::blink::FrameLifecycleState state) {}
 
+  virtual bool HasVideo() const { return false; }
 #if BUILDFLAG(IS_TIZEN_TV)
+  virtual bool IsPlaying() const { return false; }
   virtual bool IsHTMLMediaElement() const { return false; }
   virtual String GetUrl() const { return ""; }
   virtual void SetParentalRatingResult(bool) {}
+  virtual void SetTranslatedURL(const String&) {}
 #endif
 
   void SetExecutionContext(ExecutionContext*) override;
-#if BUILDFLAG(IS_TIZEN_TV)
-  virtual void SetTranslatedURL(const String&) {}
-#endif
 
  protected:
   ~ExecutionContextLifecycleStateObserver() override;
index c71372a..7c8d517 100644 (file)
@@ -4632,6 +4632,22 @@ void WebViewImpl::SetParentalRatingResult(const WebString& url, bool is_pass) {
     document->SetParentalRatingResult(url, is_pass);
   }
 }
+
+bool WebViewImpl::IsVideoPlaying() const {
+  if (!MainFrameImpl()){
+    LOG(ERROR) << "no main frame.";
+    return false;
+  }
+
+  for (const Frame* frame = MainFrameImpl()->GetFrame(); frame;
+       frame = frame->Tree().TraverseNext()) {
+    Document* document = To<LocalFrame>(frame)->GetDocument();
+    DCHECK(document);
+    if (document->IsVideoPlaying())
+      return true;
+  }
+  return false;
+}
 #endif
 
 }  // namespace blink
index 9de841d..6e6051c 100644 (file)
@@ -568,6 +568,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
   gfx::Size MainFrameSize();
 
 #if BUILDFLAG(IS_TIZEN_TV)
+  bool IsVideoPlaying() const override;
   void SetParentalRatingResult(const WebString&, bool) override;
 #endif
 
index ad83c18..73a1f43 100644 (file)
@@ -1452,6 +1452,15 @@ void WebFrameWidgetImpl::SetParentalRatingResult(const WTF::String& url,
   webview->SetParentalRatingResult(blink::WebString::FromUTF8(url.Ascii()),
                                    is_pass);
 }
+
+bool WebFrameWidgetImpl::IsVideoPlaying() {
+  WebViewImpl* webview = View();
+  if (!webview){
+    LOG(ERROR) << "no webview.";
+    return false;
+  }
+  return webview->IsVideoPlaying();
+}
 #endif
 
 void WebFrameWidgetImpl::SetNeedsRecalculateRasterScales() {
index 7249331..ff61471 100644 (file)
@@ -868,6 +868,8 @@ class CORE_EXPORT WebFrameWidgetImpl
 #if BUILDFLAG(IS_TIZEN_TV)
   //Browser edge scroll
   void EdgeScrollBy(const gfx::Point& offset, const gfx::Point& mouse_position) override;
+  // notify web browser video playing status
+  bool IsVideoPlaying() override;
   void SetTranslatedURL(const WTF::String& url) override;
   void SetParentalRatingResult(const WTF::String& url, bool is_pass) override;
 #endif
index da0d0ab..d61c516 100644 (file)
@@ -154,11 +154,15 @@ class CORE_EXPORT HTMLMediaElement
   // Returns true if the loaded media has a video track.
   // Note that even an audio element can have video track in cases such as
   // <audio src="video.webm">, in which case this function will return true.
-  bool HasVideo() const;
+  bool HasVideo() const override;
 
   // Returns true if loaded media has an audio track.
   bool HasAudio() const;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool IsPlaying() const override { return playing_; }
+#endif
+
   // Whether the media element has encrypted audio or video streams.
   bool IsEncrypted() const;
 
index 92cf4f2..0c15209 100644 (file)
@@ -588,6 +588,10 @@ void WidgetBase::SetTranslatedURL(const WTF::String& url) {
 void WidgetBase::SetParentalRatingResult(const WTF::String& url, bool is_pass) {
   client_->SetParentalRatingResult(url, is_pass);
 }
+
+void WidgetBase::IsVideoPlaying(IsVideoPlayingCallback callback) {
+  std::move(callback).Run(client_->IsVideoPlaying());
+}
 #endif // IS_TIZEN_TV
 
 void WidgetBase::WasHidden() {
index a416c0c..286da27 100644 (file)
@@ -173,6 +173,7 @@ class PLATFORM_EXPORT WidgetBase : public mojom::blink::Widget,
 
 #if BUILDFLAG(IS_TIZEN_TV)
   void SetTranslatedURL(const WTF::String& url) override;
+  void IsVideoPlaying(IsVideoPlayingCallback callback) override;
   void SetParentalRatingResult(const WTF::String& url, bool is_pass) override;
 #endif
 
index 0aa127e..1486406 100644 (file)
@@ -205,6 +205,7 @@ class WidgetBaseClient {
 #endif
 
 #if BUILDFLAG(IS_TIZEN_TV)
+  virtual bool IsVideoPlaying() {}
   virtual void SetTranslatedURL(const WTF::String& url) {}
   virtual void SetParentalRatingResult(const WTF::String& url, bool is_pass) {}
 #endif
index d530c7c..7c0b7d1 100644 (file)
@@ -452,6 +452,22 @@ void RWHVAuraCommonHelperEfl::SetParentalRatingResult(const std::string& url,
     LOG(ERROR) << "rwhv_aura_ is null";
 }
 
+void RWHVAuraCommonHelperEfl::VideoPlayingStatusReceived(bool is_playing,
+                                                         int callback_id) {
+  if (web_contents_ && web_contents_->GetDelegate())
+    web_contents_->GetDelegate()->VideoPlayingStatusReceived(is_playing,
+                                                             callback_id);
+  else
+    LOG(ERROR) << "web_contents_ or web_contents_->GetDelegate() is null";
+}
+
+void RWHVAuraCommonHelperEfl::RequestVideoPlaying(int callback_id) {
+  if (rwhv_aura_)
+    rwhv_aura_->host()->RequestVideoPlaying(callback_id);
+  else
+    LOG(ERROR) << "rwhv_aura_ is null";
+}
+
 void RWHVAuraCommonHelperEfl::SetPopupMenuVisible(const bool visible) {
   NOTIMPLEMENTED();
 }
index ba6dd9b..b578d75 100644 (file)
@@ -143,6 +143,9 @@ class CONTENT_EXPORT RWHVAuraCommonHelperEfl {
   void SetMouseEventsEnabled(bool enabled);
   void SetTranslatedURL(const std::string& url);
   void SetParentalRatingResult(const std::string& url, bool is_pass);
+  // notify web browser video playing status
+  void RequestVideoPlaying(int callback_id);
+  void VideoPlayingStatusReceived(bool is_playing, int callback_id);
 #endif
 
   void OnGestureEvent(ui::GestureEvent* event);
index 103ed09..dbff94f 100644 (file)
@@ -495,6 +495,9 @@ EWebView::~EWebView() {
   select_picker_.reset();
   context_menu_.reset();
   mhtml_callback_map_.Clear();
+#if BUILDFLAG(IS_TIZEN_TV)
+  is_video_playing_callback_map_.Clear();
+#endif
 
   compositor_observer_.reset();
 
@@ -3197,6 +3200,32 @@ void EWebView::SetTranslatedURL(const char* url) {
   rwhva()->aura_efl_helper()->SetTranslatedURL(std::string(url));
   LOG(INFO) << "translate_url:" << url;
 }
+
+bool EWebView::IsVideoPlaying(Ewk_Is_Video_Playing_Callback callback,
+                              void* user_data) {
+  IsVideoPlayingCallback* cb = new IsVideoPlayingCallback(callback, user_data);
+  int callback_id = is_video_playing_callback_map_.Add(cb);
+
+  if (!rwhva() || !rwhva()->aura_efl_helper()) {
+    LOG(ERROR) << "rwhva() or rwhva()->aura_efl_helper() is false";
+    return false;
+  }
+  rwhva()->aura_efl_helper()->RequestVideoPlaying(callback_id);
+  return true;
+}
+
+void EWebView::InvokeIsVideoPlayingCallback(bool is_playing, int callback_id) {
+  IsVideoPlayingCallback* callback =
+      is_video_playing_callback_map_.Lookup(callback_id);
+  if (!callback) {
+    LOG(INFO) << "callback is null";
+    return;
+  }
+
+  LOG(INFO) << __func__ << " ; is_playing : " << is_playing;
+  callback->Run(ewk_view(), is_playing);
+  is_video_playing_callback_map_.Remove(callback_id);
+}
 #endif
 
 void EWebView::RequestManifest(Ewk_View_Request_Manifest_Callback callback,
index 4e52d21..bd41e79 100644 (file)
@@ -316,6 +316,23 @@ class GetMediaDeviceCallback {
 };
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+class IsVideoPlayingCallback {
+ public:
+  IsVideoPlayingCallback(Ewk_Is_Video_Playing_Callback func, void* user_data)
+      : func_(func), user_data_(user_data) {}
+  void Run(Evas_Object* obj, bool isplaying) {
+    if (func_) {
+      (func_)(obj, isplaying ? EINA_TRUE : EINA_FALSE, user_data_);
+    }
+  }
+
+ private:
+  Ewk_Is_Video_Playing_Callback func_;
+  void* user_data_;
+};
+#endif
+
 class WebViewAsyncRequestHitTestDataCallback;
 class JavaScriptDialogManagerEfl;
 class PermissionPopupManager;
@@ -738,6 +755,9 @@ class EWebView {
   bool EdgeScrollBy(int delta_x, int delta_y);
   void GetMousePosition(gfx::Point&);
   void InvokeEdgeScrollByCallback(const gfx::Point&, bool);
+  // notify web browser video playing status
+  bool IsVideoPlaying(Ewk_Is_Video_Playing_Callback callback, void* user_data);
+  void InvokeIsVideoPlayingCallback(bool is_playing, int callback_id);
 #endif
 
   void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
@@ -901,6 +921,10 @@ class EWebView {
       MHTMLCallbackDetails;
   base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  base::IDMap<IsVideoPlayingCallback*> is_video_playing_callback_map_;
+#endif
+
   typedef WebViewCallback<Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback,
                           bool>
       MainFrameScrollbarVisibleGetCallback;
index 4302dd4..cac6d2a 100644 (file)
@@ -1715,8 +1715,15 @@ Eina_Bool ewk_view_key_system_whitelist_set(Evas_Object* ewkView, const char** l
 
 Eina_Bool ewk_view_is_video_playing(Evas_Object* o, Ewk_Is_Video_Playing_Callback callback, void* user_data)
 {
-  LOG_EWK_API_MOCKUP();
+#if BUILDFLAG(IS_TIZEN_TV)
+  EWK_VIEW_IMPL_GET_OR_RETURN(o, impl, EINA_FALSE);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
+  LOG(INFO) << __func__;
+  return impl->IsVideoPlaying(callback, user_data) ? EINA_TRUE : EINA_FALSE;
+#else
+  LOG_EWK_API_MOCKUP("Only for Tizen TV.");
   return EINA_FALSE;
+#endif
 }
 
 Eina_Bool ewk_view_stop_video(Evas_Object* o, Ewk_Stop_Video_Callback callback, void* user_data)
index 9178c52..54d16b7 100644 (file)
@@ -827,5 +827,21 @@ void WebContentsDelegateEfl::NotifyPlaybackState(int state,
       *drm_info = data.at(2);
   }
 }
+
+void WebContentsDelegateEfl::OnIsVideoPlayingGet(bool is_playing,
+                                                 int callback_id) {
+  if (web_view_)
+    web_view_->InvokeIsVideoPlayingCallback(is_playing, callback_id);
+  else
+    LOG(INFO) << "web_view_ is null";
+}
+
+void WebContentsDelegateEfl::VideoPlayingStatusReceived(bool is_playing,
+                                                        int callback_id) {
+  if (web_view_)
+    web_view_->InvokeIsVideoPlayingCallback(is_playing, callback_id);
+  else
+    LOG(INFO) << "web_view_ is null";
+}
 #endif
 }  // namespace content
index eda5506..4e57012 100644 (file)
@@ -164,6 +164,7 @@ class WebContentsDelegateEfl : public WebContentsDelegate {
   using EnumerationCallback =
       base::OnceCallback<void(const MediaDeviceEnumeration&)>;
   void GetMediaDeviceList(EnumerationCallback cb);
+  void VideoPlayingStatusReceived(bool is_playing, int callback_id) override;
 #endif
 
 #if defined(TIZEN_AUTOFILL)
@@ -179,6 +180,9 @@ class WebContentsDelegateEfl : public WebContentsDelegate {
                         void* user_data,
                         const GURL& manifest_url,
                         blink::mojom::ManifestPtr manifest);
+#if BUILDFLAG(IS_TIZEN_TV)
+  void OnIsVideoPlayingGet(bool is_playing, int callback_id);
+#endif
   void OnDidChangeFocusedNodeBounds(const gfx::RectF& focused_node_bounds);
   EWebView* web_view_;
   bool is_fullscreen_ = false;