diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index de85c17b772cb03e4fcb6e2ae72bd1d5f57310db..8a31f50afa7a6138be4fd25c284c0851730508ce 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -4613,18 +4613,22 @@ void MediaStreamManager::SetScreenCaptureDelegateCallback( screen_capture_callback_ = std::move(callback); } -void MediaStreamManager::StopScreenCapture(const std::string& session_id) { +void MediaStreamManager::StopScreenCapture(int32_t nweb_id, const std::string& session_id) { if (!video_capture_manager_) { LOG(ERROR) << "videoCaptureManager null"; return; } - media::VideoCaptureError ret = video_capture_manager_->StopScreenCapture(session_id); - if (ret == media::VideoCaptureError::kNone) { - SendScreenCaptureState(session_id, SCREEN_CAPTURE_STOP_SUCCESS); + std::lock_guard lock(nweb_id_mutex_); + auto nweb_id_it = nweb_id_maps_.find(session_id); + if (nweb_id_it == nweb_id_maps_.end()) { + return; } else { - SendScreenCaptureState(session_id, SCREEN_CAPTURE_STOP_FAILURE); + if (nweb_id_it->second != nweb_id) { + return; + } } + video_capture_manager_->StopScreenCapture(session_id); } void MediaStreamManager::SendScreenCaptureState(const std::string& session_id, diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h index 93834a7753c9552d5feff3c01091cafe787e6605..7e57ebd7c070171b7c8c9d131b7fe3e49513e821 100644 --- a/content/browser/renderer_host/media/media_stream_manager.h +++ b/content/browser/renderer_host/media/media_stream_manager.h @@ -74,8 +74,6 @@ enum ScreenCaptureState { SCREEN_CAPTURE_OPENED = 0, SCREEN_CAPTURE_STOPED, SCREEN_CAPTURE_ABORTED, - SCREEN_CAPTURE_STOP_SUCCESS, - SCREEN_CAPTURE_STOP_FAILURE }; #endif // defined(OHOS_EX_SCREEN_CAPTURE) @@ -467,7 +465,7 @@ class CONTENT_EXPORT MediaStreamManager static void SetScreenCaptureDelegateCallback(ScreenCaptureCallback callback); static void SendScreenCaptureStateToNative(int32_t nweb_id, const std::string& session_id, int32_t state); static ScreenCaptureCallback screen_capture_callback_; - void StopScreenCapture(const std::string& session_id); + void StopScreenCapture(int32_t nweb_id, const std::string& session_id); void SendScreenCaptureState(const std::string& session_id, int32_t state); #endif // defined(OHOS_EX_SCREEN_CAPTURE) diff --git a/content/browser/renderer_host/media/video_capture_controller.cc b/content/browser/renderer_host/media/video_capture_controller.cc index 76675afbc6c4b44b66d8f61e56f5f77246bb6de2..4cb03c90f9f9fd0ba7cbfcee0ca57421fb2698ee 100644 --- a/content/browser/renderer_host/media/video_capture_controller.cc +++ b/content/browser/renderer_host/media/video_capture_controller.cc @@ -473,27 +473,6 @@ void VideoCaptureController::StopSession( } } -#if defined(OHOS_EX_SCREEN_CAPTURE) -media::VideoCaptureError VideoCaptureController::StopScreenCapture( - const base::UnguessableToken& session_id) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - std::ostringstream string_stream; - string_stream << "VideoCaptureController::StopScreenCapture: session_id = " - << session_id; - EmitLogMessage(string_stream.str(), 1); - - ControllerClient *client = FindClient(session_id, controller_clients_); - - if (client) { - client->session_closed = true; - client->event_handler->OnEnded(client->controller_id); - return media::VideoCaptureError::kNone; - } else { - return media::VideoCaptureError::kScreenCaptureKitFailedStopCapture; - } -} -#endif // defined(OHOS_EX_SCREEN_CAPTURE) - void VideoCaptureController::ReturnBuffer( const VideoCaptureControllerID& id, VideoCaptureControllerEventHandler* event_handler, diff --git a/content/browser/renderer_host/media/video_capture_controller.h b/content/browser/renderer_host/media/video_capture_controller.h index f06282adb6a4121e380d4da9e731d320eb841c7d..7bf5c02a25c59f03ebb2e4883228e8a46e2ce33c 100644 --- a/content/browser/renderer_host/media/video_capture_controller.h +++ b/content/browser/renderer_host/media/video_capture_controller.h @@ -105,10 +105,6 @@ class CONTENT_EXPORT VideoCaptureController // prematurely closed. void StopSession(const base::UnguessableToken& session_id); -#if defined(OHOS_EX_SCREEN_CAPTURE) - media::VideoCaptureError StopScreenCapture(const base::UnguessableToken& session_id); -#endif // defined(OHOS_EX_SCREEN_CAPTURE) - // Return a buffer with id |buffer_id| previously given in // VideoCaptureControllerEventHandler::OnBufferReady. // If the consumer provided resource utilization diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc index 59ffa366d11623890d8b42033c3d3f318704c151..8212d6545ee650ff345a315c301729d96bf86e6b 100644 --- a/content/browser/renderer_host/media/video_capture_manager.cc +++ b/content/browser/renderer_host/media/video_capture_manager.cc @@ -1103,27 +1103,24 @@ void VideoCaptureManager::BindSessionIdToNWebId( #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) -media::VideoCaptureError VideoCaptureManager::StopScreenCapture(const std::string& session_id) { +void VideoCaptureManager::StopScreenCapture(const std::string& session_id) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - std::lock_guard lock(NWebIdMutex_); absl::optional token = base::Token::FromString(session_id); if (!token.has_value()) { - return media::VideoCaptureError::kScreenCaptureKitFailedStopCapture; + return; } absl::optional unguessable_token = base::UnguessableToken::Deserialize(token->high(), token->low()); auto session_it = sessions_.find(unguessable_token.value()); if (session_it == sessions_.end()) { - return media::VideoCaptureError::kScreenCaptureKitFailedStopCapture; + return; } auto videoCaptureController = LookupControllerBySessionId(unguessable_token.value()); - if (videoCaptureController == nullptr) { - return media::VideoCaptureError::kScreenCaptureKitFailedStopCapture; - } else { - return videoCaptureController->StopScreenCapture(unguessable_token.value()); + if (videoCaptureController != nullptr) { + videoCaptureController->StopSession(unguessable_token.value()); } } #endif // defined(OHOS_EX_SCREEN_CAPTURE) diff --git a/content/browser/renderer_host/media/video_capture_manager.h b/content/browser/renderer_host/media/video_capture_manager.h index 5144dd802a0bbd03c2c0f9f937e62faf7abe4521..b485d0c1fabd5ae0b52ebafbd6a4d7b6f9a7571e 100644 --- a/content/browser/renderer_host/media/video_capture_manager.h +++ b/content/browser/renderer_host/media/video_capture_manager.h @@ -242,10 +242,9 @@ class CONTENT_EXPORT VideoCaptureManager #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) - media::VideoCaptureError StopScreenCapture(const std::string& session_id); + void StopScreenCapture(const std::string& session_id); #endif // defined(OHOS_EX_SCREEN_CAPTURE) - private: class CaptureDeviceStartRequest; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index f1ef3d1f6db5d3e205579675118ce06e3159fa94..c54ac6da10258d842d7682b015b5a556baaf552a 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -10527,7 +10527,7 @@ void WebContentsImpl::SetNWebId(int nWebID) { #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) -void WebContentsImpl::StopScreenCapture(const std::string& session_id) { +void WebContentsImpl::StopScreenCapture(int32_t nweb_id, const std::string& session_id) { if(!BrowserMainLoop::GetInstance()){ LOG(ERROR) << "BrowserMainLoop null"; return; @@ -10538,7 +10538,7 @@ void WebContentsImpl::StopScreenCapture(const std::string& session_id) { LOG(ERROR) << "media_stream_manager null"; return; } - media_stream_manager->StopScreenCapture(session_id); + media_stream_manager->StopScreenCapture(nweb_id, session_id); } #endif // defined(OHOS_EX_SCREEN_CAPTURE) diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 29446f6d37a47bc05bc9ddd7a813e293c0ed0ace..870e6d6e8c8fc236b62da3b0f4635a58cb7abbd9 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -377,7 +377,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) - void StopScreenCapture(const std::string &session_id) override; + void StopScreenCapture(int32_t nweb_id, const std::string &session_id) override; #endif // defined(OHOS_EX_SCREEN_CAPTURE) // WebContents ------------------------------------------------------ diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 73bde00df790da5a55423ad711ee245ed363ba9d..d79e55e7ead238f8149f12d76cd1f1bfe3fec94f 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -712,7 +712,7 @@ class WebContents : public PageNavigator, #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) - virtual void StopScreenCapture(const std::string& session_id) = 0; + virtual void StopScreenCapture(int32_t nweb_id, const std::string& session_id) = 0; #endif // defined(OHOS_EX_SCREEN_CAPTURE) // Saves the given title to the navigation entry and does associated work. It diff --git a/ohos_nweb/src/capi/nweb_c_api.h b/ohos_nweb/src/capi/nweb_c_api.h index 445cbbe3d0960c70acd0c64a17c4f27956e278ae..1a9c290439a6c22402c9c6734bf624422c097c9c 100644 --- a/ohos_nweb/src/capi/nweb_c_api.h +++ b/ohos_nweb/src/capi/nweb_c_api.h @@ -41,8 +41,6 @@ enum NWebSrceenCaptureState { OPENED = 0, STOPED, ABORTED, - STOPED_SUCCESS, - STOPED_FAILURE, }; typedef struct NWebDownloadDelegateCallback WebDownloadDelegateCallback; diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 1bd43cac6faa3c74ec05d698aa2bfbcfb344690d..ce21841849b69b55b5106a1317147b8283b0387f 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -3001,7 +3001,7 @@ void NWebDelegate::CloseCamera() { #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) -void NWebDelegate::StopScreenCapture(const char *session_id) { +void NWebDelegate::StopScreenCapture(int32_t nweb_id, const char *session_id) { if (GetBrowser() == nullptr || GetBrowser()->GetHost() == nullptr) { LOG(ERROR) << "StopScreenCapture can not get browser"; return; diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index ff9c29722e5ca0f6c2bdf7dd02c7089294e50fea..d421710ae27954bf1d6e3342c06d12bab4e0801a 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -503,7 +503,7 @@ void SetTransformHint(uint32_t rotation) override; #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) - void StopScreenCapture(const char* session_id) override; + void StopScreenCapture(int32_t nweb_id, const char* session_id) override; void RegisterScreenCaptureDelegateListener( std::shared_ptr listener) override; #endif // defined(OHOS_EX_SCREEN_CAPTURE) diff --git a/ohos_nweb/src/download/web_downloader.cc b/ohos_nweb/src/download/web_downloader.cc index 03c4ca932e9e9de07adfb7a0a6deffdee5792fc8..d5fbec3cfd8488183d8b27241f8457c0eded71db 100644 --- a/ohos_nweb/src/download/web_downloader.cc +++ b/ohos_nweb/src/download/web_downloader.cc @@ -497,7 +497,7 @@ void WebScreenCapture_StopScreenCapture(int32_t nweb_id, const char* session_id) WVLOG_E("session_id is null"); return; } - nweb->StopScreenCapture(session_id); + nweb->StopScreenCapture(nweb_id, session_id); #endif // defined(OHOS_EX_SCREEN_CAPTURE) } diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 7aae1dbec86a6cc9892498b57ffc435a75f8851d..b825674032e736e3c48dee5a4ebe2900a2c0b79d 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -354,7 +354,7 @@ class NWebDelegateInterface #endif // defined(OHOS_WEBRTC) #if defined(OHOS_EX_SCREEN_CAPTURE) - virtual void StopScreenCapture(const char* session_id) = 0; + virtual void StopScreenCapture(int32_t nweb_id, const char* session_id) = 0; virtual void RegisterScreenCaptureDelegateListener( std::shared_ptr screenCaptureDelegateListener) = 0; diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index ee828cc5518153e9fc207a79231195d5c2812292..a09ccb5310db98ffc42dfc1930d93d87075765b6 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -3218,7 +3218,7 @@ void NWebImpl::CloseCamera() { } #if defined(OHOS_EX_SCREEN_CAPTURE) -void NWebImpl::StopScreenCapture(const char* session_id) { +void NWebImpl::StopScreenCapture(int32_t nweb_id, const char* session_id) { if (session_id == nullptr) { WVLOG_E("StopScreenCapture session_id is null"); return; @@ -3227,7 +3227,7 @@ void NWebImpl::StopScreenCapture(const char* session_id) { WVLOG_E("StopScreenCapture nweb_delegate_ is null"); return; } - nweb_delegate_->StopScreenCapture(session_id); + nweb_delegate_->StopScreenCapture(nweb_id, session_id); } void NWebImpl::PutWebScreenCaptureDelegateCallback( diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index 88d1e8e8ff4211197a3205d35d9c89bdf77bef35..c8e8094494cbd58a80fb4656927071b9d90d4052 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -343,7 +343,7 @@ class NWebImpl : public NWeb { void CloseCamera() override; #if defined(OHOS_EX_SCREEN_CAPTURE) - void StopScreenCapture(const char* session_id); + void StopScreenCapture(int32_t nweb_id, const char* session_id); void PutWebScreenCaptureDelegateCallback( std::shared_ptr callback); #endif // defined(OHOS_EX_SCREEN_CAPTURE) diff --git a/ohos_nweb/src/nweb_impl_unittest.cc b/ohos_nweb/src/nweb_impl_unittest.cc index 205e6205eb9b0605bc32a934bd68ac74ccd2f0f8..7171056e158efaa75a0e535ddc39f8c3bf3abdb2 100644 --- a/ohos_nweb/src/nweb_impl_unittest.cc +++ b/ohos_nweb/src/nweb_impl_unittest.cc @@ -775,7 +775,7 @@ class MockNWebDelegate : public NWebDelegateInterface { MOCK_METHOD(void, RefreshAccessibilityManagerClickEvent, (), (override)); #ifdef OHOS_EX_SCREEN_CAPTURE - MOCK_METHOD(void, StopScreenCapture, (const char* session_id), (override)); + MOCK_METHOD(void, StopScreenCapture, (int32_t nweb_id, const char* session_id), (override)); #endif #ifdef OHOS_EX_REFRESH_IFRAME diff --git a/ohos_nweb/src/nweb_input_handler_unittest.cc b/ohos_nweb/src/nweb_input_handler_unittest.cc index 7dfda82ad51c3a90dd8c558fac5fca3cb523775b..9606fb9a039b6cfc288d006e260fd6d278cb5ac3 100644 --- a/ohos_nweb/src/nweb_input_handler_unittest.cc +++ b/ohos_nweb/src/nweb_input_handler_unittest.cc @@ -769,7 +769,7 @@ class MockNWebDelegate : public NWebDelegateInterface { MOCK_METHOD(void, RefreshAccessibilityManagerClickEvent, (), (override)); #ifdef OHOS_EX_SCREEN_CAPTURE - MOCK_METHOD(void, StopScreenCapture, (const char* session_id), (override)); + MOCK_METHOD(void, StopScreenCapture, (int32_t nweb_id, const char* session_id), (override)); #endif #ifdef OHOS_EX_REFRESH_IFRAME