fixup! [M120 Migration][MM] Suspend/Resume according to webview visibility 74/320374/5
authorzhishun.zhou <zhishun.zhou@samsung.com>
Thu, 14 Nov 2024 03:39:33 +0000 (11:39 +0800)
committerBot Blink <blinkbot@samsung.com>
Fri, 15 Nov 2024 05:22:32 +0000 (05:22 +0000)
1. In wrt case, the hide event is from WRTNativeWindow::SetPageVisibility, that
is from ecore window visibility change callback, see wrt_native_window.cc;
and the suspend event is from UiRuntime::OnPause, and OnPause event is
later than hide event. there is no backgroud running APP, that means hide
will definitely lead to suspend, In order to release platform player as soon
as possible, we can trigger media player suspend process by hide event, which
is in the flow of WRTNativeWindow::SetPageVisibility in UI side and
RenderFrameImpl::WasHidden in render side.

2. In EWK case [such as webbrowser], the hide event is from evas hide callback
see ewk_view_private.cc, the suspend event is from ewk_view_suspend;
When switch tab in browser, there are both hide event and suspend event,
but when exit webbrowser suspend event occur earlier than hide event, and there
is no hide event sometimes, in this case we can only use suspend event to
trigger media player suspend. For the sake of uniformity, for none-wrt case,
let's response ewk_view_suspend to suspend meida player, which is in
WebViewImpl::PauseScheduledTasks in renderer side.

3. Resources requested by the player must be released before process exit,
while current suspend event is asynchronous and unreliable, we need a
mechanism to ensure all platform player are released. when destory web
content instance, let's release all platform player.

Change-Id: I08dff1ffc5f04226740a3da82512a50893a49242
Signed-off-by: zhishun.zhou <zhishun.zhou@samsung.com>
16 files changed:
content/browser/renderer_host/render_widget_host_impl.cc
content/renderer/render_frame_impl.cc
content/renderer/render_frame_impl.h
third_party/blink/public/web/web_document.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_document.cc
third_party/blink/renderer/core/exported/web_view_impl.cc
third_party/blink/renderer/core/html/media/html_media_element.cc
third_party/blink/renderer/core/html/media/html_media_element.h
third_party/blink/renderer/platform/widget/widget_base.cc
tizen_src/chromium_impl/content/browser/media/tizen_renderer_impl.cc
tizen_src/ewk/efl_integration/eweb_view.cc

index 9256fe564b4f7668415e1bb6206409a97a9a0ab6..63f75fd8f1bf27dfc8591e11d67456b29b2edb88 100644 (file)
@@ -603,10 +603,12 @@ void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) {
 
 #if BUILDFLAG(IS_TIZEN)
 void RenderWidgetHostImpl::PauseScheduledTasks() {
+  LOG(INFO) << __FUNCTION__;
   blink_widget_->PauseScheduledTasks();
 }
 
 void RenderWidgetHostImpl::UnPauseScheduledTasks() {
+  LOG(INFO) << __FUNCTION__;
   blink_widget_->UnPauseScheduledTasks();
 }
 #endif
index ac5b8847c4bd1c0ac111fbbac28820abc81a6c8a..af8096e3d8560be314dc7b75dbd6f0b5b07ecaab 100644 (file)
 #include "wrt/public/browser/wrt.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "third_party/blink/public/platform/web_application_type.h"
+#endif
+
 using base::Time;
 using blink::ContextMenuData;
 using blink::WebContentDecryptionModule;
@@ -4128,14 +4132,14 @@ void RenderFrameImpl::ScrollbarThumbPartFocusChanged(
     observer.ScrollbarThumbPartFocusChanged(orientation, focused);
 }
 
-void RenderFrameImpl::WRTMediaSuspend(bool suspend) {
-  LOG(INFO) << "WRTMediaSuspend:" << suspend << ", this:" << (void*)this;
+void RenderFrameImpl::SuspendMediaByHost(bool suspend) {
+  LOG(INFO) << "SuspendMediaByHost: " << suspend << ", this:" << (void*)this;
   if (!IsMainFrame()) {
     LOG(INFO) << "Not main frame, ignore.";
     return;
   }
 
-  frame_->GetDocument().WRTMediaSuspend(suspend);
+  frame_->GetDocument().SuspendMediaByHost(suspend);
 }
 #endif
 
@@ -4778,8 +4782,12 @@ void RenderFrameImpl::OnDroppedNavigation() {
 }
 
 void RenderFrameImpl::WasHidden() {
+  LOG(INFO) << __FUNCTION__ << "[" << (void*)this << "]";
 #if BUILDFLAG(IS_TIZEN_TV)
-  WRTMediaSuspend(true);
+  if (blink::IsTIZENWRT()) {
+    LOG(INFO) << __func__ << ", WRT case trigger media player suspend";
+    SuspendMediaByHost(true);
+  }
 #endif
 
   frame_->WasHidden();
@@ -4793,8 +4801,12 @@ void RenderFrameImpl::WasHidden() {
 }
 
 void RenderFrameImpl::WasShown() {
+  LOG(INFO) << __FUNCTION__ << "[" << (void*)this << "]";
 #if BUILDFLAG(IS_TIZEN_TV)
-  WRTMediaSuspend(false);
+  if (blink::IsTIZENWRT()) {
+    LOG(INFO) << __func__ << ", WRT case trigger media player resume";
+    SuspendMediaByHost(false);
+  }
 #endif
 
   frame_->WasShown();
index fa2127d6a497faf7c52ba77b26196ee85b5aecac..c3b5f809f42c105d7f1228b141a68d02faab04fa 100644 (file)
@@ -572,7 +572,7 @@ class CONTENT_EXPORT RenderFrameImpl
 #if BUILDFLAG(IS_TIZEN_TV)
   void RunArrowScroll() override;
   void ScrollbarThumbPartFocusChanged(cc::ScrollbarOrientation, bool) override;
-  void WRTMediaSuspend(bool suspend);
+  void SuspendMediaByHost(bool suspend);
 #endif
 
   void RunScriptsAtDocumentElementAvailable() override;
index 081d943f47db2d11c444d103edd5627ab64780fc..bafd822348bae6f873bf5dbc2e7bc1d7a75c6890 100644 (file)
@@ -92,7 +92,7 @@ class BLINK_EXPORT WebDocument : public WebNode {
 
 #if BUILDFLAG(IS_TIZEN_TV)
   void GrantLoadLocalResources();
-  void WRTMediaSuspend(bool suspend);
+  void SuspendMediaByHost(bool suspend);
 #endif
 
   WebString Encoding() const;
index 78abb50607c7f10e83da3dc2339323aea02a8cfe..000b836f114d144efa55fd77c6156915324daaec 100644 (file)
@@ -1076,9 +1076,9 @@ bool Document::IsVideoPlaying() const {
   return false;
 }
 
-void Document::WRTMediaSuspend(bool suspend) {
+void Document::SuspendMediaByHost(bool suspend) {
   if (GetExecutionContext())
-    GetExecutionContext()->WRTMediaSuspend(suspend);
+    GetExecutionContext()->SuspendMediaByHost(suspend);
   else
     LOG(INFO) << "GetExecutionContext() is null";
 }
index b5c37baa87f6b34c76298232627af1cffdddf44d..3fd63dcdf5987dd9b0649e2459717050e8fd37cd 100644 (file)
@@ -1691,7 +1691,7 @@ class CORE_EXPORT Document : public ContainerNode,
 
 #if BUILDFLAG(IS_TIZEN_TV)
   bool IsVideoPlaying() const;
-  void WRTMediaSuspend(bool suspend);
+  void SuspendMediaByHost(bool suspend);
 #endif
 
   // Returns true if this document has a frame and is an outermost main frame.
index 4b9e6684a426b9978129f34371f9b340f74ce1f8..b31e5da42910d50fd9b25d3f03191446a60f7866 100644 (file)
@@ -348,7 +348,7 @@ void ExecutionContext::SetPreferTextLang(const String& lang) {
       });
 }
 
-void ExecutionContext::WRTMediaSuspend(bool suspend) {
+void ExecutionContext::SuspendMediaByHost(bool suspend) {
   ContextLifecycleNotifier::observers().ForEachObserver(
       [&](ContextLifecycleObserver* observer) {
         if (!observer->IsExecutionContextLifecycleObserver())
@@ -363,7 +363,7 @@ void ExecutionContext::WRTMediaSuspend(bool suspend) {
         DCHECK_EQ(state_observer->GetExecutionContext(), Context());
         DCHECK(state_observer->UpdateStateIfNeededCalled());
 #endif
-        state_observer->WRTMediaSuspend(suspend);
+        state_observer->SuspendMediaByHost(suspend);
       });
 }
 #endif
index d13b5f6b50d74ddedf84f827730ee4a6fe202034..1197bd3be52f476a4c3bdfd9d3d0866ef732dc6e 100644 (file)
@@ -481,7 +481,7 @@ class CORE_EXPORT ExecutionContext : public Supplementable<ExecutionContext>,
   void SetTranslatedURL(const String&);
   void SetParentalRatingResult(const String& url, bool is_pass);
   void SetPreferTextLang(const String&);
-  void WRTMediaSuspend(bool suspend);
+  void SuspendMediaByHost(bool suspend);
 #endif
 
  protected:
index 0bce86047a2704693cb95a708ee1d2a717156c64..8cc8c3a894ef30eaba635936f7b09fb38e36ca8d 100644 (file)
@@ -78,8 +78,8 @@ class CORE_EXPORT ExecutionContextLifecycleStateObserver
   virtual void SetParentalRatingResult(bool) {}
   virtual void SetTranslatedURL(const String&) {}
   virtual void SetPreferTextLang(const String&) {}
-  virtual void WRTMediaSuspend(bool suspend) {}
 #endif
+  virtual void SuspendMediaByHost(bool suspend) {}
 
   void SetExecutionContext(ExecutionContext*) override;
 
index 44a04f9b95cd172e878f173fabfa958d0117cd90..6b2c50ca89e73ed4d019b65f86824ccf17c974f7 100644 (file)
@@ -148,13 +148,13 @@ void WebDocument::GrantLoadLocalResources() {
     document->domWindow()->GetMutableSecurityOrigin()->GrantLoadLocalResources();
 }
 
-void WebDocument::WRTMediaSuspend(bool suspend) {
+void WebDocument::SuspendMediaByHost(bool suspend) {
   Document* document = Unwrap<Document>();
   if (!document) {
     LOG(ERROR) << "document is null";
     return;
   }
-  document->WRTMediaSuspend(suspend);
+  document->SuspendMediaByHost(suspend);
 }
 #endif
 
index 2795801418d75e52552575bf9cc3a9ab9b701385..6dc643ea8652a072b78ae482cda017041fec5a47 100644 (file)
@@ -1319,6 +1319,8 @@ void WebViewImpl::DidUpdateBrowserControls() {
 
 #if BUILDFLAG(IS_TIZEN)
 void WebViewImpl::PauseScheduledTasks() {
+  LOG(INFO) << __FUNCTION__ << "[" << (void*)this << "]";
+
   if (!MainFrameImpl())
     return;
 
@@ -1336,6 +1338,8 @@ void WebViewImpl::PauseScheduledTasks() {
 }
 
 void WebViewImpl::UnpauseScheduledTasks() {
+  LOG(INFO) << __FUNCTION__ << "[" << (void*)this << "]";
+
   if (!MainFrameImpl())
     return;
   Page* page = GetPage();
index a2e9c81645cb084f44620fcede66dffb13c2de9a..c9f2bbc122dd642d4026ad4b5de1403f8ba09455 100644 (file)
@@ -519,8 +519,8 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tag_name,
       is_video_visibility_set_(false),
       is_translated_url_(false),
       text_track_menu_on_(false),
-      suspend_media_by_wrt_(false),
-      resume_media_by_wrt_(false),
+      suspended_by_host_(false),
+      resumed_by_host_(false),
 #endif
 #if defined(TIZEN_MULTIMEDIA)
       live_playback_complete_(false),
@@ -4523,64 +4523,9 @@ void HTMLMediaElement::ContextLifecycleStateChanged(
   }
 #if defined(TIZEN_MULTIMEDIA)
   else if (state == mojom::FrameLifecycleState::kPaused) {
-#if BUILDFLAG(IS_TIZEN_TV)
-    resume_media_by_wrt_ = false;
-    if (suspend_media_by_wrt_) {
-      LOG(INFO) << "Already suspend by WRT, return directly.";
-      return;
-    }
-    suspend_media_by_wrt_ = true;
-#endif
-#if defined(SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE)
-    if (media_source_attachment_) {
-      // Send suspend event to the source before WebMediaPlayer suspends
-      // backend.
-      media_source_attachment_->OnSuspend(media_source_tracer_);
-    }
-#endif  // SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE
-    // Suspend if a browser tab is switched.
-    if (GetWebMediaPlayer())
-      GetWebMediaPlayer()->Suspend();
-    else
-      LOG(INFO) << "no WebMediaPlayer, ignore.";
-
-    if (playing_) {
-      paused_by_context_paused_ = true;
-      pause();
-    }
+    SuspendMediaByHost(true);
   } else if (state == mojom::FrameLifecycleState::kRunning) {
-#if BUILDFLAG(IS_TIZEN_TV)
-    suspend_media_by_wrt_ = false;
-    if (resume_media_by_wrt_) {
-      LOG(INFO) << "Already resume by WRT, return directly.";
-      return;
-    }
-    resume_media_by_wrt_ = false;
-#endif
-
-    // Do not resume if suspended by player except the resource conflict case.
-    if (GetWebMediaPlayer() && GetWebMediaPlayer()->SuspendedByPlayer()) {
-      LOG(INFO) << "suspended by player except the resource conflict case, do "
-                   "not resume.";
-      return;
-    }
-
-    if (GetWebMediaPlayer())
-      GetWebMediaPlayer()->Resume();
-    else
-      LOG(INFO) << "no WebMediaPlayer, ignore.";
-
-#if defined(SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE)
-    if (media_source_attachment_) {
-      // Send suspend event to the source after WebMediaPlayer resumes backend.
-      media_source_attachment_->OnResume(media_source_tracer_);
-    }
-#endif  // SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE
-
-    if (paused_by_context_paused_) {
-      paused_by_context_paused_ = false;
-      Play();
-    }
+    SuspendMediaByHost(false);
   }
 #else
   else if (state == mojom::FrameLifecycleState::kRunning &&
@@ -5020,15 +4965,22 @@ void HTMLMediaElement::SetPreferTextLang(const String& lang) {
     GetWebMediaPlayer()->SetPreferTextLanguage(prefer_text_lang_);
 }
 
-void HTMLMediaElement::WRTMediaSuspend(bool suspend) {
-  LOG(INFO) << "WRTMediaSuspend:" << suspend << ",this:" << (void*)this;
+bool HTMLMediaElement::HasEncryptedListener() const {
+  return HasEventListeners(event_type_names::kEncrypted);
+}
+#endif
+
+void HTMLMediaElement::SuspendMediaByHost(bool suspend) {
+  LOG(INFO) << "SuspendMediaByHost: " << suspend << ", this:" << (void*)this;
   if (suspend) {
-    resume_media_by_wrt_ = false;
-    if (suspend_media_by_wrt_) {
+#if BUILDFLAG(IS_TIZEN_TV)
+    resumed_by_host_ = false;
+    if (suspended_by_host_) {
       LOG(INFO) << "Already suspend, return directly.";
       return;
     }
-    suspend_media_by_wrt_ = true;
+    suspended_by_host_ = true;
+#endif
 
 #if defined(SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE)
     if (media_source_attachment_) {
@@ -5041,30 +4993,33 @@ void HTMLMediaElement::WRTMediaSuspend(bool suspend) {
     if (GetWebMediaPlayer())
       GetWebMediaPlayer()->Suspend();
     else
-      LOG(INFO) << "WebMediaPlayer is null";
+      LOG(INFO) << __func__ << ", WebMediaPlayer is null";
 
     if (playing_) {
       paused_by_context_paused_ = true;
       pause();
     }
   } else {
-    suspend_media_by_wrt_ = false;
-    if (resume_media_by_wrt_) {
-      LOG(INFO) << "Already resume, return directly.";
+#if BUILDFLAG(IS_TIZEN_TV)
+    suspended_by_host_ = false;
+    if (resumed_by_host_) {
+      LOG(INFO) << __func__ << ", Already resume, return directly.";
       return;
     }
-    resume_media_by_wrt_ = true;
-
-#if defined(SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE)
-    if (media_source_attachment_) {
-      media_source_attachment_->OnResume(media_source_tracer_);
-    }
+    resumed_by_host_ = true;
 #endif
 
     if (GetWebMediaPlayer())
       GetWebMediaPlayer()->Resume();
     else
-      LOG(INFO) << "WebMediaPlayer is null";
+      LOG(INFO) << __func__ << ", WebMediaPlayer is null";
+
+#if defined(SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE)
+    if (media_source_attachment_) {
+      // Send suspend event to the source after WebMediaPlayer resumes backend.
+      media_source_attachment_->OnResume(media_source_tracer_);
+    }
+#endif  // SAMSUNG_ELEMENTARY_MEDIA_STREAM_SOURCE
 
     if (paused_by_context_paused_) {
       paused_by_context_paused_ = false;
@@ -5073,10 +5028,6 @@ void HTMLMediaElement::WRTMediaSuspend(bool suspend) {
   }
 }
 
-bool HTMLMediaElement::HasEncryptedListener() const {
-  return HasEventListeners(event_type_names::kEncrypted);
-}
-#endif
 double HTMLMediaElement::getStartDate() const {
 #if BUILDFLAG(IS_TIZEN_TV)
   if (!IsHbbTV() || !GetWebMediaPlayer()) {
index 689a6e11816b6a877f0324d4c8630d74fba783d8..61252d0b7565a3afef3eea672c3fb65cd4819c9b 100644 (file)
@@ -443,9 +443,9 @@ class CORE_EXPORT HTMLMediaElement
       media::register_timeline_cb_info_s info) override;
   void OnMrsUrlChange(const std::string& url) override;
   void OnContentIdChange(const std::string& id) override;
-  void WRTMediaSuspend(bool suspend) override;
   bool HasEncryptedListener() const override;
 #endif
+  void SuspendMediaByHost(bool suspend) override;
 
 #if defined(TIZEN_MULTIMEDIA)
   void OnLivePlaybackComplete() override;
@@ -993,8 +993,8 @@ class CORE_EXPORT HTMLMediaElement
 
 #if BUILDFLAG(IS_TIZEN_TV)
   bool text_track_menu_on_ : 1;
-  bool suspend_media_by_wrt_ : 1;
-  bool resume_media_by_wrt_ : 1;
+  bool suspended_by_host_ : 1;
+  bool resumed_by_host_ : 1;
   int active_text_track_id_{-1};
   String content_mime_type_;
   bool is_translated_url_ : 1;
index a71d5c122192fdcb60b4016e7a98adf423f8721c..dbbe347831cff9045700b19566c67fb2cb56912d 100644 (file)
@@ -644,10 +644,12 @@ void WidgetBase::WasHidden() {
 
 #if BUILDFLAG(IS_TIZEN)
 void WidgetBase::PauseScheduledTasks() {
+  LOG(INFO) << __FUNCTION__;
   client_->PauseScheduledTasks();
 }
 
 void WidgetBase::UnPauseScheduledTasks() {
+  LOG(INFO) << __FUNCTION__;
   client_->UnPauseScheduledTasks();
 }
 #endif
index bb9e833344b10a8a1a623e352be3c1a17cfbb44d..32a79daa4d0bc01b119382c8396fd728c6becc18 100644 (file)
@@ -745,12 +745,20 @@ void TizenRendererImpl::OnEnabledAudioTracksChanged(
 }
 
 void TizenRendererImpl::OnWebContentsDestroyed() {
+  LOG_ID(INFO, player_id_) << ", OnWebContentsDestroyed";
+  if (media_player_) {
+    LOG_ID(INFO, player_id_)
+        << ", OnWebContentsDestroyed release platform player";
+    media_player_->Release();
+  }
+
   web_contents_observer_ = nullptr;
 }
 
 void TizenRendererImpl::OnReleaseAll() {
-  LOG_ID(INFO, player_id_) << "OnReleaseAll";
+  LOG_ID(INFO, player_id_) << "OnReleaseAll";
   if (media_player_) {
+    LOG_ID(INFO, player_id_) << ", OnReleaseAll release platform player";
     media_player_->Release();
   }
 }
index d5470a18b47ed7385da594999e0745879102b09e..2fb031f671a08bcd04435c32a1ecb7afcfb1da11 100644 (file)
@@ -770,6 +770,7 @@ void EWebView::Stop() {
 }
 
 void EWebView::Suspend() {
+  LOG(INFO) << __FUNCTION__ << "[" << (void*)this << "]";
 #if BUILDFLAG(IS_TIZEN)
   CHECK(web_contents_);
   if (IsMobileProfile() && web_contents_->IsFullscreen())
@@ -787,6 +788,7 @@ void EWebView::Suspend() {
 }
 
 void EWebView::Resume() {
+  LOG(INFO) << __FUNCTION__ << "[" << (void*)this << "]";
 #if BUILDFLAG(IS_TIZEN)
   CHECK(web_contents_);
   RenderViewHost* rvh = web_contents_->GetRenderViewHost();