diff --git a/interfaces/kits/cj/include/webview_controller_impl.h b/interfaces/kits/cj/include/webview_controller_impl.h index ddcb4a51df7351b1d0735bc73e07a9154a0e508d..e0775d54abe254a8dfa587f4d824fa83c8aa4ba0 100644 --- a/interfaces/kits/cj/include/webview_controller_impl.h +++ b/interfaces/kits/cj/include/webview_controller_impl.h @@ -50,6 +50,13 @@ namespace OHOS::Webview { DANGEROUS = 5 }; + enum class MediaPlaybackState : int { + NONE = 0, + PLAYING = 1, + PAUSED = 2, + STOPPED = 3 + }; + class __attribute__((visibility("default"))) WebviewControllerImpl : public OHOS::FFI::FFIData { DECL_TYPE(WebviewControllerImpl, OHOS::FFI::FFIData) public: diff --git a/interfaces/kits/cj/include/webview_ffi.h b/interfaces/kits/cj/include/webview_ffi.h index af456fc2ca2331176ba9f5709797e7c9e75273f4..5e76149dd82521da13fce4ce880718b1052992d4 100644 --- a/interfaces/kits/cj/include/webview_ffi.h +++ b/interfaces/kits/cj/include/webview_ffi.h @@ -69,6 +69,21 @@ extern "C" { FFI_EXPORT int32_t FfiOHOSWebviewCtlRemoveCache(int64_t id, bool clearRom); FFI_EXPORT int64_t FfiOHOSWebviewCtlGetBackForwardEntries(int64_t id, int32_t *errCode); FFI_EXPORT int32_t FfiOHOSWebviewCtlStop(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlStopCamera(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlStartCamera(int64_t id); + FFI_EXPORT bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id); + FFI_EXPORT void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id); + FFI_EXPORT bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable); + // BackForwardList FFI_EXPORT int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode); diff --git a/interfaces/kits/cj/src/webview_controller_impl.cpp b/interfaces/kits/cj/src/webview_controller_impl.cpp index 10b83226cc52c29ad44119ce56fad0f3d468e351..ffe9e921c22457d043d2c7935c1dd76efdf310b5 100644 --- a/interfaces/kits/cj/src/webview_controller_impl.cpp +++ b/interfaces/kits/cj/src/webview_controller_impl.cpp @@ -446,6 +446,9 @@ namespace OHOS::Webview { } ret.code = NWebError::NO_ERROR; ret.data = MallocCString(result); + if (ret.data == nullptr) { + ret.code = NWebError::NEW_OOM; + } cjCallback(ret); }); nweb_ptr->StoreWebArchive(baseName, autoName, callbackImpl); @@ -607,4 +610,139 @@ namespace OHOS::Webview { } return; } + + int32_t WebviewControllerImpl::GetMediaPlaybackState() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return static_cast(MediaPlaybackState::NONE); + } + return nweb_ptr->GetMediaPlaybackState(); + } + + void WebviewControllerImpl::CloseCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->CloseCamera(); + } + return; + } + + void WebviewControllerImpl::StopCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->StopCamera(); + } + return; + } + + void WebviewControllerImpl::StartCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->StartCamera(); + } + return; + } + + bool WebviewControllerImpl::GetPrintBackground() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->GetPrintBackground(); + } + + void WebviewControllerImpl::SetPrintBackground(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->SetPrintBackground(enable); + } + return; + } + + bool WebviewControllerImpl::GetScrollable() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return true; + } + std::shared_ptr setting = nweb_ptr->GetPreference(); + if (!setting) { + return true; + } + return setting->GetScrollable(); + } + + void WebviewControllerImpl::SetScrollable(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return; + } + std::shared_ptr setting = nweb_ptr->GetPreference(); + if (!setting) { + return; + } + return setting->SetScrollable(enable); + } + + bool WebviewControllerImpl::IsAdsBlockEnabledForCurPage() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsAdsBlockEnabledForCurPage(); + } + + void WebviewControllerImpl::EnableAdsBlock(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->EnableAdsBlock(enable); + } + return; + } + + bool WebviewControllerImpl::IsAdsBlockEnabled() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsAdsBlockEnabled(); + } + + bool WebviewControllerImpl::IsIntelligentTrackingPreventionEnabled() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsIntelligentTrackingPreventionEnabled(); + } + + void WebviewControllerImpl::EnableIntelligentTrackingPrevention(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->EnableIntelligentTrackingPrevention(enable); + } + return; + } + + void WebviewControllerImpl::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + WEBVIEWLOGE("WebviewControllerImpl::void SetBackForwardCacheOptions nweb_ptr is null"); + return; + } + nweb_ptr->SetBackForwardCacheOptions(size, timeToLive); + } } diff --git a/interfaces/kits/cj/src/webview_ffi.cpp b/interfaces/kits/cj/src/webview_ffi.cpp index 62028c2aade09bdae76724873a3a861a364e1a4f..2b7109ef4573fe1e45fe86991f4d51913d37c19f 100644 --- a/interfaces/kits/cj/src/webview_ffi.cpp +++ b/interfaces/kits/cj/src/webview_ffi.cpp @@ -643,6 +643,135 @@ extern "C" { return NWebError::NO_ERROR; } + int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + } + return nativeWebviewCtl->GetMediaPlaybackState(); + } + + int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->CloseCamera(); + return NWebError::NO_ERROR; + } + + int32_t FfiOHOSWebviewCtlStopCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->StopCamera(); + return NWebError::NO_ERROR; + } + + int32_t FfiOHOSWebviewCtlStartCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->StartCamera(); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool printBackground = nativeWebviewCtl->GetPrintBackground(); + *errCode = NWebError::NO_ERROR; + return printBackground; + } + + int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->SetPrintBackground(enable); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool scrollable = nativeWebviewCtl->GetScrollable(); + *errCode = NWebError::NO_ERROR; + return scrollable; + } + + int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->SetScrollable(enable); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return false; + } + return nativeWebviewCtl->IsAdsBlockEnabledForCurPage(); + } + + void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + nativeWebviewCtl->EnableAdsBlock(enable); + } + + bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return false; + } + return nativeWebviewCtl->IsAdsBlockEnabled(); + } + + bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool intelligentTrackingPreventionEnabled = nativeWebviewCtl->IsIntelligentTrackingPreventionEnabled(); + *errCode = NWebError::NO_ERROR; + return intelligentTrackingPreventionEnabled; + } + + int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->EnableIntelligentTrackingPrevention(enable); + return NWebError::NO_ERROR; + } + // BackForwardList int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode) {