diff --git a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js index 5df04796..df43ef44 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js +++ b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js @@ -749,6 +749,13 @@ var HitTestType; HitTestType[HitTestType["Unknown"] = 7] = "Unknown"; })(HitTestType || (HitTestType = {})); +var CacheMode; +(function (CacheMode) { + CacheMode[CacheMode["Default"] = 0] = "Default"; + CacheMode[CacheMode["None"] = 1] = "None"; + CacheMode[CacheMode["Online"] = 2] = "Online"; + CacheMode[CacheMode["Only"] = 3] = "Only"; +})(CacheMode || (CacheMode = {})); var ProgressType; (function (ProgressType) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp old mode 100644 new mode 100755 index 9d4fe014..aad089c7 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp @@ -73,7 +73,6 @@ private: RefPtr result_; }; - class JSWebConsoleLog : public Referenced { public: static void JSBind(BindingTarget globalObj) @@ -410,6 +409,136 @@ private: RefPtr request_; }; +class JSFileSelectorParam : public Referenced { +public: + static void JSBind(BindingTarget globalObj) + { + JSClass::Declare("FileSelectorParam"); + JSClass::CustomMethod("title", &JSFileSelectorParam::GetTitle); + JSClass::CustomMethod("mode", &JSFileSelectorParam::GetMode); + JSClass::CustomMethod("acceptType", &JSFileSelectorParam::GetAcceptType); + JSClass::CustomMethod("isCapture", &JSFileSelectorParam::IsCapture); + JSClass::Bind( + globalObj, &JSFileSelectorParam::Constructor, &JSFileSelectorParam::Destructor); + } + + void SetParam(const FileSelectorEvent& eventInfo) + { + param_ = eventInfo.GetParam(); + } + + void GetTitle(const JSCallbackInfo& args) + { + auto title = JSVal(ToJSValue(param_->GetTitle())); + auto descriptionRef = JSRef::Make(title); + args.SetReturnValue(descriptionRef); + } + + void GetMode(const JSCallbackInfo& args) + { + auto mode = JSVal(ToJSValue(param_->GetMode())); + auto descriptionRef = JSRef::Make(mode); + args.SetReturnValue(descriptionRef); + } + + void IsCapture(const JSCallbackInfo& args) + { + auto isCapture = JSVal(ToJSValue(param_->IsCapture())); + auto descriptionRef = JSRef::Make(isCapture); + args.SetReturnValue(descriptionRef); + } + + void GetAcceptType(const JSCallbackInfo& args) + { + auto acceptTypes = param_->GetAcceptType(); + JSRef result = JSRef::New(); + std::vector::iterator iterator; + uint32_t index = 0; + for (iterator = acceptTypes.begin(); iterator != acceptTypes.end(); ++iterator) { + auto valueStr = JSVal(ToJSValue(*iterator)); + auto value = JSRef::Make(valueStr); + result->SetValueAt(index++, value); + } + args.SetReturnValue(result); + } + +private: + static void Constructor(const JSCallbackInfo& args) + { + auto jSFilerSelectorParam = Referenced::MakeRefPtr(); + jSFilerSelectorParam->IncRefCount(); + args.SetReturnValue(Referenced::RawPtr(jSFilerSelectorParam)); + } + + static void Destructor(JSFileSelectorParam* jSFilerSelectorParam) + { + if (jSFilerSelectorParam != nullptr) { + jSFilerSelectorParam->DecRefCount(); + } + } + + RefPtr param_; +}; + +class JSFileSelectorResult : public Referenced { +public: + static void JSBind(BindingTarget globalObj) + { + JSClass::Declare("FileSelectorResult"); + JSClass::CustomMethod("handleFileList", + &JSFileSelectorResult::HandleFileList); + JSClass::Bind(globalObj, &JSFileSelectorResult::Constructor, + &JSFileSelectorResult::Destructor); + } + + void SetResult(const FileSelectorEvent& eventInfo) + { + result_ = eventInfo.GetFileSelectorResult(); + } + + void HandleFileList(const JSCallbackInfo& args) + { + std::vector fileList; + if (args[0]->IsArray()) { + JSRef array = JSRef::Cast(args[0]); + for (size_t i = 0; i < array->Length(); i++) { + JSRef val = array->GetValueAt(i); + if (!val->IsString()) { + LOGW("file selector list is not string at index %{public}zu", i); + continue; + } + std::string fileName; + if (!ConvertFromJSValue(val, fileName)) { + LOGW("can't convert file name at index %{public}zu of JSFileSelectorResult, so skip it.", i); + continue; + } + fileList.push_back(fileName); + } + } + + if (result_) { + result_->HandleFileList(fileList); + } + } + +private: + static void Constructor(const JSCallbackInfo& args) + { + auto jsFileSelectorResult = Referenced::MakeRefPtr(); + jsFileSelectorResult->IncRefCount(); + args.SetReturnValue(Referenced::RawPtr(jsFileSelectorResult)); + } + + static void Destructor(JSFileSelectorResult* jsFileSelectorResult) + { + if (jsFileSelectorResult != nullptr) { + jsFileSelectorResult->DecRefCount(); + } + } + + RefPtr result_; +}; + void JSWeb::JSBind(BindingTarget globalObj) { JSClass::Declare("Web"); @@ -425,6 +554,7 @@ void JSWeb::JSBind(BindingTarget globalObj) JSClass::StaticMethod("onGeolocationHide", &JSWeb::OnGeolocationHide); JSClass::StaticMethod("onGeolocationShow", &JSWeb::OnGeolocationShow); JSClass::StaticMethod("onRequestSelected", &JSWeb::OnRequestFocus); + JSClass::StaticMethod("onFileSelectorShow", &JSWeb::OnFileSelectorShow); JSClass::StaticMethod("javaScriptAccess", &JSWeb::JsEnabled); JSClass::StaticMethod("fileExtendAccess", &JSWeb::ContentAccessEnabled); JSClass::StaticMethod("fileAccess", &JSWeb::FileAccessEnabled); @@ -432,6 +562,7 @@ void JSWeb::JSBind(BindingTarget globalObj) JSClass::StaticMethod("onDownloadStart", &JSWeb::OnDownloadStart); JSClass::StaticMethod("onErrorReceive", &JSWeb::OnErrorReceive); JSClass::StaticMethod("onHttpErrorReceive", &JSWeb::OnHttpErrorReceive); + JSClass::StaticMethod("onUrlLoadIntercept", &JSWeb::OnUrlLoadIntercept); JSClass::StaticMethod("onlineImageAccess", &JSWeb::OnLineImageAccessEnabled); JSClass::StaticMethod("domStorageAccess", &JSWeb::DomStorageAccessEnabled); JSClass::StaticMethod("imageAccess", &JSWeb::ImageAccessEnabled); @@ -440,6 +571,13 @@ void JSWeb::JSBind(BindingTarget globalObj) JSClass::StaticMethod("geolocationAccess", &JSWeb::GeolocationAccessEnabled); JSClass::StaticMethod("javaScriptProxy", &JSWeb::JavaScriptProxy); JSClass::StaticMethod("userAgent", &JSWeb::UserAgent); + JSClass::StaticMethod("onRenderExited", &JSWeb::OnRenderExited); + JSClass::StaticMethod("onRefreshAccessedHistory", &JSWeb::OnRefreshAccessedHistory); + JSClass::StaticMethod("cacheMode", &JSWeb::CacheMode); + JSClass::StaticMethod("overviewModeAccess", &JSWeb::OverviewModeAccess); + JSClass::StaticMethod("fileFromUrlAccess", &JSWeb::FileFromUrlAccess); + JSClass::StaticMethod("databaseAccess", &JSWeb::DatabaseAccess); + JSClass::StaticMethod("textZoomAtio", &JSWeb::TextZoomAtio); JSClass::Inherit(); JSClass::Bind(globalObj); JSWebDialog::JSBind(globalObj); @@ -448,6 +586,8 @@ void JSWeb::JSBind(BindingTarget globalObj) JSWebResourceError::JSBind(globalObj); JSWebResourceResponse::JSBind(globalObj); JSWebConsoleLog::JSBind(globalObj); + JSFileSelectorParam::JSBind(globalObj); + JSFileSelectorResult::JSBind(globalObj); } JSRef LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent& eventInfo) @@ -506,6 +646,13 @@ JSRef LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent& e return JSRef::Cast(obj); } +JSRef UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent& eventInfo) +{ + JSRef obj = JSRef::New(); + obj->SetProperty("data", eventInfo.GetData()); + return JSRef::Cast(obj); +} + JSRef LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent& eventInfo) { return JSRef::Make(ToJSValue(eventInfo.GetOrigin())); @@ -861,6 +1008,29 @@ void JSWeb::OnHttpErrorReceive(const JSCallbackInfo& args) webComponent->SetHttpErrorEventId(eventMarker); } +void JSWeb::OnUrlLoadIntercept(const JSCallbackInfo& args) +{ + LOGI("JSWeb OnUrlLoadIntercept"); + if (!args[0]->IsFunction()) { + LOGE("Param is invalid, it is not a function"); + return; + } + auto jsFunc = AceType::MakeRefPtr>( + JSRef::Cast(args[0]), UrlLoadInterceptEventToJSValue); + auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc)] + (const BaseEventInfo* info) -> bool { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); + auto eventInfo = TypeInfoHelper::DynamicCast(info); + JSRef message = func->ExecuteWithValue(*eventInfo); + if (message->IsBoolean()) { + return message->ToBoolean(); + } + return false; + }; + auto webComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + webComponent->SetOnUrlLoadIntercept(std::move(jsCallback)); +} + void JSWeb::OnFocus(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { @@ -878,6 +1048,51 @@ void JSWeb::OnFocus(const JSCallbackInfo& args) webComponent->SetOnFocusEventId(eventMarker); } +JSRef FileSelectorEventToJSValue(const FileSelectorEvent& eventInfo) +{ + JSRef obj = JSRef::New(); + + JSRef paramObj = JSClass::NewInstance(); + auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap()); + fileSelectorParam->SetParam(eventInfo); + + JSRef resultObj = JSClass::NewInstance(); + auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap()); + fileSelectorResult->SetResult(eventInfo); + + obj->SetPropertyObject("result", resultObj); + obj->SetPropertyObject("fileSelector", paramObj); + return JSRef::Cast(obj); +} + +void JSWeb::OnFileSelectorShow(const JSCallbackInfo& args) +{ + LOGI("OnFileSelectorShow"); + if (!args[0]->IsFunction()) { + return; + } + + auto jsFunc = AceType::MakeRefPtr>( + JSRef::Cast(args[0]), FileSelectorEventToJSValue); + auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc)] + (const BaseEventInfo* info) -> bool { + ACE_SCORING_EVENT("OnFileSelectorShow CallBack"); + if (func == nullptr) { + LOGW("function is null"); + return false; + } + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); + auto eventInfo = TypeInfoHelper::DynamicCast(info); + JSRef result = func->ExecuteWithValue(*eventInfo); + if (result->IsBoolean()) { + return result->ToBoolean(); + } + return false; + }; + auto webComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + webComponent->SetOnFileSelectorShow(std::move(jsCallback)); +} + void JSWeb::JsEnabled(bool isJsEnabled) { auto stack = ViewStackProcessor::GetInstance(); @@ -1013,4 +1228,130 @@ void JSWeb::UserAgent(const std::string& userAgent) } webComponent->SetUserAgent(userAgent); } + +JSRef RenderExitedEventToJSValue(const RenderExitedEvent& eventInfo) +{ + JSRef obj = JSRef::New(); + obj->SetProperty("renderExitReason", eventInfo.GetExitedReason()); + return JSRef::Cast(obj); +} + +JSRef RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent& eventInfo) +{ + JSRef obj = JSRef::New(); + obj->SetProperty("url", eventInfo.GetVisitedUrl()); + obj->SetProperty("isRefreshed", eventInfo.IsRefreshed()); + return JSRef::Cast(obj); +} + +void JSWeb::OnRenderExited(const JSCallbackInfo& args) +{ + LOGI("JSWeb OnRenderExited"); + if (!args[0]->IsFunction()) { + LOGE("Param is invalid, it is not a function"); + return; + } + auto jsFunc = AceType::MakeRefPtr>( + JSRef::Cast(args[0]), RenderExitedEventToJSValue); + auto eventMarker = + EventMarker([execCtx = args.GetExecutionContext(), func = std::move(jsFunc)](const BaseEventInfo* info) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + auto eventInfo = TypeInfoHelper::DynamicCast(info); + func->Execute(*eventInfo); + }); + auto webComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + webComponent->SetRenderExitedId(eventMarker); +} + +void JSWeb::OnRefreshAccessedHistory(const JSCallbackInfo& args) +{ + LOGI("JSWeb OnRefreshAccessedHistory"); + if (!args[0]->IsFunction()) { + LOGE("Param is invalid, it is not a function"); + return; + } + auto jsFunc = AceType::MakeRefPtr>( + JSRef::Cast(args[0]), RefreshAccessedHistoryEventToJSValue); + auto eventMarker = + EventMarker([execCtx = args.GetExecutionContext(), func = std::move(jsFunc)](const BaseEventInfo* info) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + auto eventInfo = TypeInfoHelper::DynamicCast(info); + func->Execute(*eventInfo); + }); + auto webComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + webComponent->SetRefreshAccessedHistoryId(eventMarker); +} + +void JSWeb::CacheMode(int32_t cacheMode) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!webComponent) { + LOGE("JSWeb: MainComponent is null."); + return; + } + auto mode = WebCacheMode::DEFAULT; + switch (cacheMode) { + case 0: + mode = WebCacheMode::DEFAULT; + break; + case 1: + mode = WebCacheMode::USE_CACHE_ELSE_NETWORK; + break; + case 2: + mode = WebCacheMode::USE_NO_CACHE; + break; + case 3: + mode = WebCacheMode::USE_CACHE_ONLY; + break; + default: + mode = WebCacheMode::DEFAULT; + break; + } + webComponent->SetCacheMode(mode); +} + +void JSWeb::OverviewModeAccess(bool isOverviewModeAccessEnabled) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!webComponent) { + LOGE("JSWeb: MainComponent is null."); + return; + } + webComponent->SetOverviewModeAccessEnabled(isOverviewModeAccessEnabled); +} + +void JSWeb::FileFromUrlAccess(bool isFileFromUrlAccessEnabled) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!webComponent) { + LOGE("JSWeb: MainComponent is null."); + return; + } + webComponent->SetFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled); +} + +void JSWeb::DatabaseAccess(bool isDatabaseAccessEnabled) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!webComponent) { + LOGE("JSWeb: MainComponent is null."); + return; + } + webComponent->SetDatabaseAccessEnabled(isDatabaseAccessEnabled); +} + +void JSWeb::TextZoomAtio(int32_t textZoomAtioNum) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!webComponent) { + LOGE("JSWeb: MainComponent is null."); + return; + } + webComponent->SetTextZoomAtio(textZoomAtioNum); +} } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.h b/frameworks/bridge/declarative_frontend/jsview/js_web.h old mode 100644 new mode 100755 index d4c1ab03..e75231d5 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.h @@ -41,6 +41,8 @@ public: static void OnDownloadStart(const JSCallbackInfo& args); static void OnErrorReceive(const JSCallbackInfo& args); static void OnHttpErrorReceive(const JSCallbackInfo& args); + static void OnFileSelectorShow(const JSCallbackInfo& args); + static void OnUrlLoadIntercept(const JSCallbackInfo& args); static void JsEnabled(bool isJsEnabled); static void ContentAccessEnabled(bool isContentAccessEnabled); static void FileAccessEnabled(bool isFileAccessEnabled); @@ -53,6 +55,13 @@ public: static void GeolocationAccessEnabled(bool isGeolocationAccessEnabled); static void JavaScriptProxy(const JSCallbackInfo& args); static void UserAgent(const std::string& userAgent); + static void OnRenderExited(const JSCallbackInfo& args); + static void OnRefreshAccessedHistory(const JSCallbackInfo& args); + static void CacheMode(int32_t cacheMode); + static void OverviewModeAccess(bool isOverviewModeAccessEnabled); + static void FileFromUrlAccess(bool isFileFromUrlAccessEnabled); + static void DatabaseAccess(bool isDatabaseAccessEnabled); + static void TextZoomAtio(int32_t textZoomAtioNum); protected: static void OnCommonDialog(const JSCallbackInfo& args, int dialogEventType); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp index 2f3dded6..cd9c3331 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp @@ -71,6 +71,72 @@ std::shared_ptr ParseValue( } } +class JSWebCookie : public Referenced { +public: + static void JSBind(BindingTarget globalObj) + { + JSClass::Declare("WebCookie"); + JSClass::CustomMethod("setCookie", &JSWebCookie::SetCookie); + JSClass::CustomMethod("saveCookieSync", &JSWebCookie::SaveCookieSync); + JSClass::Bind(globalObj, JSWebCookie::Constructor, JSWebCookie::Destructor); + } + + void SetWebCookie(WebCookie* manager) + { + if (manager) { + manager_ = manager; + } + } + + void SetCookie(const JSCallbackInfo& args) + { + if (!manager_) { + return; + } + std::string url; + std::string value; + bool result = false; + if (args[0]->IsString()) { + url = args[0]->ToString(); + } + if (args[1]->IsString()) { + value = args[1]->ToString(); + } + result = manager_->SetCookie(url, value); + auto jsVal = JSVal(ToJSValue(result)); + auto returnValue = JSRef::Make(jsVal); + args.SetReturnValue(returnValue); + } + + void SaveCookieSync(const JSCallbackInfo& args) + { + if (!manager_) { + return; + } + bool result = false; + result = manager_->SaveCookieSync(); + auto jsVal = JSVal(ToJSValue(result)); + auto returnValue = JSRef::Make(jsVal); + args.SetReturnValue(returnValue); + } + +private: + static void Constructor(const JSCallbackInfo& args) + { + auto jsWebCookie = Referenced::MakeRefPtr(); + jsWebCookie->IncRefCount(); + args.SetReturnValue(Referenced::RawPtr(jsWebCookie)); + } + + static void Destructor(JSWebCookie* jsWebCookie) + { + if (jsWebCookie != nullptr) { + jsWebCookie->DecRefCount(); + } + } + WebCookie* manager_; +}; + JSWebController::JSWebController() { instanceId_ = Container::CurrentId(); @@ -125,7 +191,10 @@ void JSWebController::JSBind(BindingTarget globalObj) JSClass::CustomMethod("accessStep", &JSWebController::AccessStep); JSClass::CustomMethod("accessForward", &JSWebController::AccessForward); JSClass::CustomMethod("accessBackward", &JSWebController::AccessBackward); + JSClass::CustomMethod("clearHistory", &JSWebController::ClearHistory); + JSClass::CustomMethod("getCookieManager", &JSWebController::GetCookieManager); JSClass::Bind(globalObj, JSWebController::Constructor, JSWebController::Destructor); + JSWebCookie::JSBind(globalObj); } void JSWebController::Constructor(const JSCallbackInfo& args) @@ -327,6 +396,15 @@ void JSWebController::AccessForward(const JSCallbackInfo& args) } } +void JSWebController::ClearHistory(const JSCallbackInfo& args) +{ + LOGI("JSWebController clear navigation history."); + ContainerScope scope(instanceId_); + if (webController_) { + webController_->ClearHistory(); + } +} + void JSWebController::Refresh(const JSCallbackInfo& args) { LOGI("JSWebController Refresh"); @@ -355,6 +433,21 @@ void JSWebController::GetHitTestResult(const JSCallbackInfo& args) } } +void JSWebController::GetCookieManager(const JSCallbackInfo& args) +{ + LOGI("JSWebController Start GetCookieManager"); + ContainerScope scope(instanceId_); + if (webController_) { + if (!jsWebCookieInit_) { + jsWebCookie_ = JSClass::NewInstance(); + auto jsWebCookieVal = Referenced::Claim(jsWebCookie_->Unwrap()); + jsWebCookieVal->SetWebCookie(webController_->GetCookieManager()); + jsWebCookieInit_ = true; + } + args.SetReturnValue(jsWebCookie_); + } +} + void JSWebController::SetJavascriptCallBackImpl() { if (!webController_ || jsRegisterCallBackInit_) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.h b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.h index 3c1e95f2..fcf5d7f5 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.h @@ -39,6 +39,7 @@ public: void Refresh(const JSCallbackInfo& args); void StopLoading(const JSCallbackInfo& args); void GetHitTestResult(const JSCallbackInfo& args); + void GetCookieManager(const JSCallbackInfo& args); void AddJavascriptInterface(const JSCallbackInfo& args); void RemoveJavascriptInterface(const JSCallbackInfo& args); void SetJavascriptInterface(const JSCallbackInfo& args); @@ -53,6 +54,7 @@ public: void AccessStep(const JSCallbackInfo& args); void AccessBackward(const JSCallbackInfo& args); void AccessForward(const JSCallbackInfo& args); + void ClearHistory(const JSCallbackInfo& args); const RefPtr& GetController() const { @@ -80,6 +82,8 @@ private: std::unordered_map> methods_; RefPtr webController_; ACE_DISALLOW_COPY_AND_MOVE(JSWebController); + JSRef jsWebCookie_; + bool jsWebCookieInit_ = false; }; } // namespace OHOS::Ace::Framework #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_CONTROLLER_H \ No newline at end of file diff --git a/frameworks/core/components/declaration/web/web_declaration.h b/frameworks/core/components/declaration/web/web_declaration.h old mode 100644 new mode 100755 index 215d8785..f94b1f40 --- a/frameworks/core/components/declaration/web/web_declaration.h +++ b/frameworks/core/components/declaration/web/web_declaration.h @@ -40,6 +40,8 @@ struct WebEvent : Event { EventMarker httpErrorEventId; EventMarker messageEventId; EventMarker downloadStartEventId; + EventMarker renderExitedEventId; + EventMarker refreshAccessedHistoryId; }; struct WebMethod : Method { @@ -68,7 +70,7 @@ public: auto& attribute = static_cast(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); return attribute.src; } - + void SetWebData(const std::string& data) { auto& attribute = MaybeResetAttribute(AttributeTag::SPECIALIZED_ATTR); @@ -225,6 +227,30 @@ public: return event.messageEventId; } + void SetRenderExitedId(const EventMarker& renderExitedEventId) + { + auto& event = MaybeResetEvent(EventTag::SPECIALIZED_EVENT); + event.renderExitedEventId = renderExitedEventId; + } + + const EventMarker& GetRenderExitedId() const + { + auto& event = static_cast(GetEvent(EventTag::SPECIALIZED_EVENT)); + return event.renderExitedEventId; + } + + void SetRefreshAccessedHistoryId(const EventMarker& refreshAccessedHistoryId) + { + auto& event = MaybeResetEvent(EventTag::SPECIALIZED_EVENT); + event.refreshAccessedHistoryId = refreshAccessedHistoryId; + } + + const EventMarker& GetRefreshAccessedHistoryId() const + { + auto& event = static_cast(GetEvent(EventTag::SPECIALIZED_EVENT)); + return event.refreshAccessedHistoryId; + } + protected: void InitSpecialized() override; bool SetSpecializedAttr(const std::pair& attr) override; diff --git a/frameworks/core/components/web/render_web.cpp b/frameworks/core/components/web/render_web.cpp index fb8e32c1..f6433eec 100755 --- a/frameworks/core/components/web/render_web.cpp +++ b/frameworks/core/components/web/render_web.cpp @@ -68,6 +68,11 @@ void RenderWeb::Update(const RefPtr& component) delegate_->UpdateSupportZoom(web->GetZoomAccessEnabled()); delegate_->UpdateDomStorageEnabled(web->GetDomStorageAccessEnabled()); delegate_->UpdateGeolocationEnabled(web->GetGeolocationAccessEnabled()); + delegate_->UpdateCacheMode(web->GetCacheMode()); + delegate_->UpdateOverviewModeEnabled(web->GetOverviewModeAccessEnabled()); + delegate_->UpdateFileFromUrlEnabled(web->GetFileFromUrlAccessEnabled()); + delegate_->UpdateDatabaseEnabled(web->GetDatabaseAccessEnabled()); + delegate_->UpdateTextZoomAtio(web->GetTextZoomAtio()); auto userAgent = web->GetUserAgent(); if (!userAgent.empty()) { delegate_->UpdateUserAgent(userAgent); diff --git a/frameworks/core/components/web/resource/web_client_impl.cpp b/frameworks/core/components/web/resource/web_client_impl.cpp index 9d4cf5af..bae48ab1 100755 --- a/frameworks/core/components/web/resource/web_client_impl.cpp +++ b/frameworks/core/components/web/resource/web_client_impl.cpp @@ -208,6 +208,16 @@ void WebClientImpl::OnRouterPush(const std::string& param) delegate->OnRouterPush(param); } +bool WebClientImpl::OnHandleInterceptUrlLoading(const std::string& url) +{ + ContainerScope scope(instanceId_); + auto delegate = webDelegate_.Upgrade(); + if (!delegate) { + return false; + } + return delegate->OnHandleInterceptUrlLoading(url); +} + bool WebClientImpl::OnAlertDialogByJS( const std::string &url, const std::string &message, std::shared_ptr result) { @@ -232,4 +242,50 @@ bool WebClientImpl::OnConfirmDialogByJS( return OnJsCommonDialog(url, message, result, DialogEventType::DIALOG_EVENT_CONFIRM, this); } +void WebClientImpl::OnRenderExited(OHOS::NWeb::RenderExitReason reason) +{ + ContainerScope scope(instanceId_); + auto delegate = webDelegate_.Upgrade(); + if (!delegate) { + return; + } + delegate->OnRenderExited(reason); +} + +void WebClientImpl::OnRefreshAccessedHistory(const std::string& url, bool isReload) +{ + ContainerScope scope(instanceId_); + auto delegate = webDelegate_.Upgrade(); + if (!delegate) { + return; + } + delegate->OnRefreshAccessedHistory(url, isReload); +} + +bool WebClientImpl::OnFileSelectorShow( + std::shared_ptr callback, + std::shared_ptr params) +{ + ContainerScope scope(instanceId_); + bool jsResult = false; + auto param = std::make_shared(AceType::MakeRefPtr(params), + AceType::MakeRefPtr(callback)); + auto task = Container::CurrentTaskExecutor(); + if (task == nullptr) { + LOGW("can't get task executor"); + return false; + } + task->PostSyncTask([webClient = this, ¶m, &jsResult] { + if (webClient == nullptr) { + return; + } + auto delegate = webClient->GetWebDelegate(); + if (delegate) { + jsResult = delegate->OnFileSelectorShow(param.get()); + } + }, + OHOS::Ace::TaskExecutor::TaskType::JS); + LOGI("OnFileSelectorShow result:%{public}d", jsResult); + return jsResult; +} } // namespace OHOS::Ace diff --git a/frameworks/core/components/web/resource/web_client_impl.h b/frameworks/core/components/web/resource/web_client_impl.h index 68a5b280..ce2ffd3e 100755 --- a/frameworks/core/components/web/resource/web_client_impl.h +++ b/frameworks/core/components/web/resource/web_client_impl.h @@ -72,16 +72,17 @@ public: bool OnConfirmDialogByJS(const std::string &url, const std::string &message, std::shared_ptr result) override; + bool OnFileSelectorShow(std::shared_ptr callback, + std::shared_ptr params) override; void OnFocus() override; void OnResourceLoadError(std::shared_ptr request, std::shared_ptr error) override; void OnHttpError(std::shared_ptr request, std::shared_ptr response) override; - bool OnHandleInterceptUrlLoading(const std::string& url) override - { - return false; - } + void OnRenderExited(OHOS::NWeb::RenderExitReason reason) override; + void OnRefreshAccessedHistory(const std::string& url, bool isReload) override; + bool OnHandleInterceptUrlLoading(const std::string& url) override; void SetWebDelegate(const WeakPtr& delegate) { webDelegate_ = delegate; diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index e8a28696..d32969df 100755 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -119,6 +119,53 @@ void ResultOhos::Cancel() } } +std::string FileSelectorParamOhos::GetTitle() +{ + if (param_) { + return param_->Title(); + } + return ""; +} + +int FileSelectorParamOhos::GetMode() +{ + if (param_) { + return param_->Mode(); + } + return 0; +} + +std::string FileSelectorParamOhos::GetDefaultFileName() +{ + if (param_) { + return param_->DefaultFilename(); + } + return ""; +} + +std::vector FileSelectorParamOhos::GetAcceptType() +{ + if (param_) { + return param_->AcceptType(); + } + return std::vector(); +} + +bool FileSelectorParamOhos::IsCapture() +{ + if (param_) { + return param_->IsCapture(); + } + return false; +} + +void FileSelectorResultOhos::HandleFileList(std::vector result) +{ + if (callback_) { + callback_->OnReceiveValue(result); + } +} + WebDelegate::~WebDelegate() { ReleasePlatformResource(); @@ -270,6 +317,27 @@ void WebDelegate::Forward() TaskExecutor::TaskType::PLATFORM); } +void WebDelegate::ClearHistory() +{ + auto context = context_.Upgrade(); + if (!context) { + LOGE("Get context failed, it is null."); + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this)]() { + auto delegate = weak.Upgrade(); + if (!delegate) { + LOGE("Get delegate failed, it is null."); + return; + } + if (delegate->nweb_) { + delegate->nweb_->DeleteNavigateHistory(); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + bool WebDelegate::AccessStep(int32_t step) { auto delegate = WeakClaim(this).Upgrade(); @@ -551,6 +619,22 @@ int WebDelegate::GetHitTestResult() return static_cast(webHitType); } +bool WebDelegate::SaveCookieSync() +{ + if (cookieManager_) { + return cookieManager_->Store(); + } + return false; +} + +bool WebDelegate::SetCookie(const std::string url, const std::string value) +{ + if (cookieManager_) { + return cookieManager_->SetCookie(url, value); + } + return false; +} + void WebDelegate::CreatePluginResource( const Size& size, const Offset& position, const WeakPtr& context) { @@ -751,6 +835,10 @@ void WebDelegate::InitOHOSWeb(const WeakPtr& context, sptrGetHttpErrorEventId(), pipelineContext); onDownloadStartV2_ = AceAsyncEvent&)>::Create( webComponent_->GetDownloadStartEventId(), pipelineContext); + onRenderExitedV2_ = AceAsyncEvent&)>::Create( + webComponent_->GetRenderExitedId(), pipelineContext); + onRefreshAccessedHistoryV2_ = AceAsyncEvent&)>::Create( + webComponent_->GetRefreshAccessedHistoryId(), pipelineContext); } } @@ -812,6 +900,14 @@ void WebDelegate::SetWebCallBack() } }); }); + webController->SetClearHistoryImpl([weak = WeakClaim(this), uiTaskExecutor]() { + uiTaskExecutor.PostTask([weak]() { + auto delegate = weak.Upgrade(); + if (delegate) { + delegate->ClearHistory(); + } + }); + }); webController->SetAccessStepImpl([weak = WeakClaim(this)](int32_t step) { auto delegate = weak.Upgrade(); if (delegate) { @@ -878,6 +974,22 @@ void WebDelegate::SetWebCallBack() } return 0; }); + webController->SetSaveCookieSyncImpl( + [weak = WeakClaim(this)]() { + auto delegate = weak.Upgrade(); + if (delegate) { + return delegate->SaveCookieSync(); + } + return false; + }); + webController->SetSetCookieImpl( + [weak = WeakClaim(this)](std::string url, std::string value) { + auto delegate = weak.Upgrade(); + if (delegate) { + return delegate->SetCookie(url, value); + } + return false; + }); webController->SetWebViewJavaScriptResultCallBackImpl([weak = WeakClaim(this), uiTaskExecutor]( WebController::JavaScriptCallBackImpl&& javaScriptCallBackImpl) { uiTaskExecutor.PostTask([weak, javaScriptCallBackImpl]() { @@ -984,6 +1096,12 @@ void WebDelegate::InitWebViewWithWindow() LOGE("fail to get webview instance"); return; } + delegate->cookieManager_ = + OHOS::NWeb::NWebHelper::Instance().GetCookieManager(); + if (delegate->cookieManager_ == nullptr) { + LOGE("fail to get webview instance"); + return; + } auto component = delegate->webComponent_; if (!component) { return; @@ -1045,6 +1163,12 @@ void WebDelegate::InitWebViewWithSurface(sptr surface) LOGE("fail to get webview instance"); return; } + delegate->cookieManager_ = + OHOS::NWeb::NWebHelper::Instance().GetCookieManager(); + if (delegate->cookieManager_ == nullptr) { + LOGE("fail to get webview instance"); + return; + } auto component = delegate->webComponent_; if (component == nullptr) { return; @@ -1059,18 +1183,24 @@ void WebDelegate::InitWebViewWithSurface(sptr surface) delegate->nweb_->SetNWebHandler(nweb_handler); delegate->nweb_->PutDownloadCallback(downloadListenerImpl); - std::shared_ptr setting = delegate->nweb_->GetPreference(); - setting->PutDomStorageEnabled(component->GetDomStorageAccessEnabled()); - setting->PutIsCreateWindowsByJavaScriptAllowed(true); - setting->PutJavaScriptEnabled(component->GetJsEnabled()); - setting->PutEnableRawFileAccess(component->GetFileAccessEnabled()); - setting->PutEnableContentAccess(component->GetContentAccessEnabled()); - setting->PutLoadImageFromNetworkDisabled(component->GetOnLineImageAccessEnabled()); - setting->PutImageLoadingAllowed(component->GetImageAccessEnabled()); - setting->PutAccessModeForSecureOriginLoadFromInsecure( - static_cast(component->GetMixedMode())); + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutDomStorageEnabled(component->GetDomStorageAccessEnabled()); + setting->PutIsCreateWindowsByJavaScriptAllowed(true); + setting->PutJavaScriptEnabled(component->GetJsEnabled()); + setting->PutEnableRawFileAccess(component->GetFileAccessEnabled()); + setting->PutEnableContentAccess(component->GetContentAccessEnabled()); + setting->PutLoadImageFromNetworkDisabled(component->GetOnLineImageAccessEnabled()); + setting->PutImageLoadingAllowed(component->GetImageAccessEnabled()); + setting->PutAccessModeForSecureOriginLoadFromInsecure( + static_cast(component->GetMixedMode())); setting->PutZoomingFunctionEnabled(component->GetZoomAccessEnabled()); setting->PutGeolocationAllowed(component->GetGeolocationAccessEnabled()); + setting->PutCacheMode( + static_cast(component->GetCacheMode())); + setting->PutLoadWithOverviewMode(component->GetOverviewModeAccessEnabled()); + setting->PutEnableRawFileAccessFromFileURLs(component->GetFileFromUrlAccessEnabled()); + setting->PutDatabaseAllowed(component->GetDatabaseAccessEnabled()); + setting->PutZoomingForTextFactor(component->GetTextZoomAtio()); }, TaskExecutor::TaskType::PLATFORM); } @@ -1244,6 +1374,91 @@ void WebDelegate::UpdateGeolocationEnabled(const bool& isGeolocationAccessEnable TaskExecutor::TaskType::PLATFORM); } +void WebDelegate::UpdateCacheMode(const WebCacheMode& mode) +{ + auto context = context_.Upgrade(); + if (!context) { + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this), mode]() { + auto delegate = weak.Upgrade(); + if (delegate && delegate->nweb_) { + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutCacheMode(static_cast(mode)); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + +void WebDelegate::UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled) +{ + auto context = context_.Upgrade(); + if (!context) { + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this), isOverviewModeAccessEnabled]() { + auto delegate = weak.Upgrade(); + if (delegate && delegate->nweb_) { + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutLoadWithOverviewMode(isOverviewModeAccessEnabled); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + +void WebDelegate::UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled) +{ + auto context = context_.Upgrade(); + if (!context) { + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this), isFileFromUrlAccessEnabled]() { + auto delegate = weak.Upgrade(); + if (delegate && delegate->nweb_) { + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutEnableRawFileAccessFromFileURLs(isFileFromUrlAccessEnabled); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + +void WebDelegate::UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled) +{ + auto context = context_.Upgrade(); + if (!context) { + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this), isDatabaseAccessEnabled]() { + auto delegate = weak.Upgrade(); + if (delegate && delegate->nweb_) { + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutDatabaseAllowed(isDatabaseAccessEnabled); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + +void WebDelegate::UpdateTextZoomAtio(const int32_t& textZoomAtioNum) +{ + auto context = context_.Upgrade(); + if (!context) { + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this), textZoomAtioNum]() { + auto delegate = weak.Upgrade(); + if (delegate && delegate->nweb_) { + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutZoomingForTextFactor(textZoomAtioNum); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + void WebDelegate::LoadUrl() { auto context = context_.Upgrade(); @@ -1556,7 +1771,7 @@ bool WebDelegate::OnCommonDialog(const BaseEventInfo* info, DialogEventType dial void WebDelegate::OnDownloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, const std::string& mimetype, long contentLength) { -if (onDownloadStartV2_) { + if (onDownloadStartV2_) { onDownloadStartV2_(std::make_shared(url, userAgent, contentDisposition, mimetype, contentLength)); } @@ -1615,6 +1830,20 @@ void WebDelegate::OnRequestFocus() } } +void WebDelegate::OnRenderExited(OHOS::NWeb::RenderExitReason reason) +{ + if (onRenderExitedV2_) { + onRenderExitedV2_(std::make_shared(static_cast(reason))); + } +} + +void WebDelegate::OnRefreshAccessedHistory(const std::string& url, bool isRefreshed) +{ + if (onRefreshAccessedHistoryV2_) { + onRefreshAccessedHistoryV2_(std::make_shared(url, isRefreshed)); + } +} + void WebDelegate::OnPageError(const std::string& param) { if (onPageError_) { @@ -1659,6 +1888,17 @@ void WebDelegate::OnRouterPush(const std::string& param) OHOS::Ace::Framework::DelegateClient::GetInstance().RouterPush(param); } +bool WebDelegate::OnFileSelectorShow(const BaseEventInfo* info) +{ + return webComponent_->OnFileSelectorShow(info); +} + +bool WebDelegate::OnHandleInterceptUrlLoading(const std::string& data) +{ + auto param = std::make_shared(data); + return webComponent_->OnUrlLoadIntercept(param.get()); +} + #ifdef OHOS_STANDARD_SYSTEM void WebDelegate::HandleTouchDown(const int32_t& id, const double& x, const double& y) { diff --git a/frameworks/core/components/web/resource/web_delegate.h b/frameworks/core/components/web/resource/web_delegate.h index a0c43949..e52dfd10 100755 --- a/frameworks/core/components/web/resource/web_delegate.h +++ b/frameworks/core/components/web/resource/web_delegate.h @@ -67,12 +67,40 @@ private: std::shared_ptr result_; }; +class FileSelectorParamOhos : public WebFileSelectorParam { + DECLARE_ACE_TYPE(FileSelectorParamOhos, WebFileSelectorParam) + +public: + FileSelectorParamOhos(std::shared_ptr param) + : param_(param) {} + + std::string GetTitle() override; + int GetMode() override; + std::string GetDefaultFileName() override; + std::vector GetAcceptType() override; + bool IsCapture() override; +private: + std::shared_ptr param_; +}; + +class FileSelectorResultOhos : public FileSelectorResult { + DECLARE_ACE_TYPE(FileSelectorResultOhos, FileSelectorResult) + +public: + FileSelectorResultOhos(std::shared_ptr callback) + : callback_(callback) {} + + void HandleFileList(std::vector result) override; +private: + std::shared_ptr callback_; +}; + class WebGeolocationOhos : public WebGeolocation { DECLARE_ACE_TYPE(WebGeolocationOhos, WebGeolocation) public: WebGeolocationOhos(OHOS::NWeb::NWebGeolocationCallbackInterface* callback) : geolocationCallback_(callback) {} - + void Invoke(const std::string& origin, const bool& allow, const bool& retain) override; private: std::shared_ptr geolocationCallback_; @@ -128,6 +156,11 @@ public: void UpdateSupportZoom(const bool& isZoomAccessEnabled); void UpdateDomStorageEnabled(const bool& isDomStorageAccessEnabled); void UpdateGeolocationEnabled(const bool& isGeolocationAccessEnabled); + void UpdateCacheMode(const WebCacheMode& mode); + void UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled); + void UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled); + void UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled); + void UpdateTextZoomAtio(const int32_t& textZoomAtioNum); void LoadUrl(); void HandleTouchDown(const int32_t& id, const double& x, const double& y); void HandleTouchUp(const int32_t& id, const double& x, const double& y); @@ -153,6 +186,10 @@ public: void OnMessage(const std::string& param); bool OnConsoleLog(std::shared_ptr message); void OnRouterPush(const std::string& param); + void OnRenderExited(OHOS::NWeb::RenderExitReason reason); + void OnRefreshAccessedHistory(const std::string& url, bool isRefreshed); + bool OnFileSelectorShow(const BaseEventInfo* info); + bool OnHandleInterceptUrlLoading(const std::string& url); private: void InitWebEvent(); void RegisterWebEvent(); @@ -186,12 +223,15 @@ private: void OnActive(); void Zoom(float factor); int GetHitTestResult(); + bool SaveCookieSync(); + bool SetCookie(const std::string url, const std::string value); void RegisterOHOSWebEventAndMethord(); void SetWebCallBack(); // Backward and forward void Backward(); void Forward(); + void ClearHistory(); bool AccessStep(int32_t step); bool AccessBackward(); bool AccessForward(); @@ -215,6 +255,7 @@ private: State state_ {State::WAITINGFORSIZE}; #ifdef OHOS_STANDARD_SYSTEM std::shared_ptr nweb_; + OHOS::NWeb::NWebCookieManager* cookieManager_ = nullptr; sptr window_; bool isCreateWebView_ = false; @@ -229,6 +270,8 @@ private: EventCallbackV2 onHttpErrorReceiveV2_; EventCallbackV2 onDownloadStartV2_; EventCallbackV2 onFocusV2_; + EventCallbackV2 onRefreshAccessedHistoryV2_; + EventCallbackV2 onRenderExitedV2_; std::string bundlePath_; std::string bundleDataPath_; diff --git a/frameworks/core/components/web/web_component.h b/frameworks/core/components/web/web_component.h index dee6e4d9..f5b954ab 100755 --- a/frameworks/core/components/web/web_component.h +++ b/frameworks/core/components/web/web_component.h @@ -38,12 +38,58 @@ enum MixedModeContent { MIXED_CONTENT_COMPATIBILITY_MODE = 2 }; +enum WebCacheMode { + DEFAULT = 0, + USE_CACHE_ELSE_NETWORK, + USE_NO_CACHE, + USE_CACHE_ONLY +}; + enum DialogEventType { DIALOG_EVENT_ALERT = 0, DIALOG_EVENT_BEFORE_UNLOAD = 1, DIALOG_EVENT_CONFIRM = 2 }; +constexpr int default_text_zoom_atio = 100; + +class WebCookie : public virtual AceType { + DECLARE_ACE_TYPE(WebCookie, AceType); + +public: + using SetCookieImpl = std::function; + using SaveCookieSyncImpl = std::function; + bool SetCookie(const std::string url, const std::string value) + { + if (setCookieImpl_) { + return setCookieImpl_(url, value); + } + return false; + } + + bool SaveCookieSync() + { + if (saveCookieSyncImpl_) { + return saveCookieSyncImpl_(); + } + return false; + } + + void SetSetCookieImpl(SetCookieImpl && setCookieImpl) + { + setCookieImpl_ = setCookieImpl; + } + + void SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl) + { + saveCookieSyncImpl_ = saveCookieSyncImpl; + } + +private: + SetCookieImpl setCookieImpl_; + SaveCookieSyncImpl saveCookieSyncImpl_; +}; + class WebController : public virtual AceType { DECLARE_ACE_TYPE(WebController, AceType); @@ -54,6 +100,7 @@ public: using AccessStepImpl = std::function; using BackwardImpl = std::function; using ForwardImpl = std::function; + using ClearHistoryImpl = std::function; void LoadUrl(std::string url, std::map& httpHeaders) const { if (loadUrlImpl_) { @@ -101,6 +148,14 @@ public: } } + void ClearHistory() + { + LOGI("Start clear navigation history"); + if (clearHistoryImpl_) { + clearHistoryImpl_(); + } + } + void SetLoadUrlImpl(LoadUrlImpl && loadUrlImpl) { loadUrlImpl_ = std::move(loadUrlImpl); @@ -131,6 +186,11 @@ public: forwardimpl_ = std::move(forwardImpl); } + void SetClearHistoryImpl(ClearHistoryImpl && clearHistoryImpl) + { + clearHistoryImpl_ = std::move(clearHistoryImpl); + } + using ExecuteTypeScriptImpl = std::function&&)>; void ExecuteTypeScript(std::string jscode, std::function&& callback) const { @@ -260,6 +320,46 @@ public: getHitTestResultImpl_ = std::move(getHitTestResultImpl); } + WebCookie* GetCookieManager() + { + if (!saveCookieSyncImpl_ || !setCookieImpl_) { + return nullptr; + } + if (cookieManager_ != nullptr) { + return cookieManager_; + } + cookieManager_ = new WebCookie(); + cookieManager_->SetSaveCookieSyncImpl(std::move(saveCookieSyncImpl_)); + cookieManager_->SetSetCookieImpl(std::move(setCookieImpl_)); + return cookieManager_; + } + + using SetCookieImpl = std::function; + bool SetCookie(const std::string url, const std::string value) + { + if (setCookieImpl_) { + return setCookieImpl_(url, value); + } + return false; + } + void SetSetCookieImpl(SetCookieImpl && setCookieImpl) + { + setCookieImpl_ = setCookieImpl; + } + + using SaveCookieSyncImpl = std::function; + bool SaveCookieSync() + { + if (saveCookieSyncImpl_) { + return saveCookieSyncImpl_(); + } + return false; + } + void SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl) + { + saveCookieSyncImpl = saveCookieSyncImpl_; + } + using AddJavascriptInterfaceImpl = std::function&)>; @@ -324,14 +424,16 @@ public: private: RefPtr declaration_; + WebCookie* cookieManager_ = nullptr; LoadUrlImpl loadUrlImpl_; - + // Forward and Backward AccessBackwardImpl accessBackwardImpl_; AccessForwardImpl accessForwardImpl_; AccessStepImpl accessStepImpl_; BackwardImpl backwardImpl_; ForwardImpl forwardimpl_; + ClearHistoryImpl clearHistoryImpl_; ExecuteTypeScriptImpl executeTypeScriptImpl_; OnInactiveImpl onInactiveImpl_; @@ -343,6 +445,8 @@ private: RefreshImpl refreshImpl_; StopLoadingImpl stopLoadingImpl_; GetHitTestResultImpl getHitTestResultImpl_; + SaveCookieSyncImpl saveCookieSyncImpl_; + SetCookieImpl setCookieImpl_; AddJavascriptInterfaceImpl addJavascriptInterfaceImpl_; RemoveJavascriptInterfaceImpl removeJavascriptInterfaceImpl_; WebViewJavaScriptResultCallBackImpl webViewJavaScriptResultCallBackImpl_; @@ -386,7 +490,7 @@ public: { return declaration_->GetWebSrc(); } - + void SetData(const std::string& data) { declaration_->SetWebData(data); @@ -476,7 +580,7 @@ public: { return declaration_->GetDownloadStartEventId(); } - + void SetOnFocusEventId(const EventMarker& onFocusEventId) { declaration_->SetOnFocusEventId(onFocusEventId); @@ -517,6 +621,26 @@ public: return declaration_->GetMessageEventId(); } + void SetRenderExitedId(const EventMarker& renderExitedId) + { + declaration_->SetRenderExitedId(renderExitedId); + } + + const EventMarker& GetRenderExitedId() const + { + return declaration_->GetRenderExitedId(); + } + + void SetRefreshAccessedHistoryId(const EventMarker& refreshAccessedHistoryId) + { + declaration_->SetRefreshAccessedHistoryId(refreshAccessedHistoryId); + } + + const EventMarker& GetRefreshAccessedHistoryId() const + { + return declaration_->GetRefreshAccessedHistoryId(); + } + void SetDeclaration(const RefPtr& declaration) { if (declaration) { @@ -633,6 +757,54 @@ public: isGeolocationAccessEnabled_ = isEnabled; } + WebCacheMode GetCacheMode() { + return cacheMode_; + } + + void SetCacheMode(WebCacheMode mode) { + cacheMode_ = mode; + } + + bool GetOverviewModeAccessEnabled() const + { + return isOverviewModeAccessEnabled_; + } + + void SetOverviewModeAccessEnabled(bool isEnabled) + { + isOverviewModeAccessEnabled_ = isEnabled; + } + + bool GetFileFromUrlAccessEnabled() + { + return isFileFromUrlAccessEnabled_; + } + + void SetFileFromUrlAccessEnabled(bool isEnabled) + { + isFileFromUrlAccessEnabled_ = isEnabled; + } + + bool GetDatabaseAccessEnabled() + { + return isDatabaseAccessEnabled_; + } + + void SetDatabaseAccessEnabled(bool isEnabled) + { + isDatabaseAccessEnabled_ = isEnabled; + } + + int32_t GetTextZoomAtio() + { + return textZoomAtioNum_; + } + + void SetTextZoomAtio(int32_t atio) + { + textZoomAtioNum_ = atio; + } + using OnCommonDialogImpl = std::function; bool OnCommonDialog(const BaseEventInfo* info, DialogEventType dialogEventType) const { @@ -688,6 +860,40 @@ public: focusElement_ = focusElement; } + using OnFileSelectorShowImpl = std::function; + bool OnFileSelectorShow(const BaseEventInfo* info) const + { + if (onFileSelectorShowImpl_) { + return onFileSelectorShowImpl_(info); + } + return false; + } + void SetOnFileSelectorShow(OnFileSelectorShowImpl && onFileSelectorShowImpl) + { + if (onFileSelectorShowImpl == nullptr) { + return; + } + + onFileSelectorShowImpl_ = onFileSelectorShowImpl; + } + + using OnUrlLoadInterceptImpl = std::function; + bool OnUrlLoadIntercept(const BaseEventInfo* info) const + { + if (onUrlLoadInterceptImpl_) { + return onUrlLoadInterceptImpl_(info); + } + return false; + } + void SetOnUrlLoadIntercept(OnUrlLoadInterceptImpl && onUrlLoadInterceptImpl) + { + if (onUrlLoadInterceptImpl == nullptr) { + return; + } + + onUrlLoadInterceptImpl_ = onUrlLoadInterceptImpl; + } + private: RefPtr declaration_; CreatedCallback createdCallback_ = nullptr; @@ -699,6 +905,8 @@ private: OnCommonDialogImpl onConfirmImpl_; OnCommonDialogImpl onBeforeUnloadImpl_; OnConsoleImpl consoleImpl_; + OnFileSelectorShowImpl onFileSelectorShowImpl_; + OnUrlLoadInterceptImpl onUrlLoadInterceptImpl_; std::string type_; bool isJsEnabled_ = true; @@ -712,7 +920,11 @@ private: MixedModeContent mixedContentMode_ = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW; bool isZoomAccessEnabled_ = true; bool isGeolocationAccessEnabled_ = true; - + bool isOverviewModeAccessEnabled_ = true; + bool isFileFromUrlAccessEnabled_ = false; + bool isDatabaseAccessEnabled_ = false; + int32_t textZoomAtioNum_ = default_text_zoom_atio; + WebCacheMode cacheMode_ = WebCacheMode::DEFAULT; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/web/web_event.h b/frameworks/core/components/web/web_event.h index d48a867d..82ac0139 100755 --- a/frameworks/core/components/web/web_event.h +++ b/frameworks/core/components/web/web_event.h @@ -30,6 +30,19 @@ public: virtual std::string GetSourceId() = 0; }; +class WebFileSelectorParam : public AceType { + DECLARE_ACE_TYPE(WebFileSelectorParam, AceType) +public: + WebFileSelectorParam() = default; + ~WebFileSelectorParam() = default; + + virtual std::string GetTitle() = 0; + virtual int GetMode() = 0; + virtual std::string GetDefaultFileName() = 0; + virtual std::vector GetAcceptType() = 0; + virtual bool IsCapture() = 0; +}; + class ACE_EXPORT WebError : public AceType { DECLARE_ACE_TYPE(WebError, AceType) @@ -164,6 +177,16 @@ public: virtual void Cancel() = 0; }; +class ACE_EXPORT FileSelectorResult : public AceType { + DECLARE_ACE_TYPE(FileSelectorResult, AceType) + +public: + FileSelectorResult() = default; + ~FileSelectorResult() = default; + + virtual void HandleFileList(std::vector fileList) = 0; +}; + class ACE_EXPORT WebDialogEvent : public BaseEventInfo { DECLARE_RELATIONSHIP_OF_CLASSES(WebDialogEvent, BaseEventInfo); @@ -271,6 +294,23 @@ private: std::string title_; }; +class ACE_EXPORT UrlLoadInterceptEvent : public BaseEventInfo { + DECLARE_RELATIONSHIP_OF_CLASSES(UrlLoadInterceptEvent, BaseEventInfo); + +public: + explicit UrlLoadInterceptEvent(const std::string& data) : BaseEventInfo + ("UrlLoadInterceptEvent"), data_(data) {} + ~UrlLoadInterceptEvent() = default; + + const std::string& GetData() const + { + return data_; + } + +private: + std::string data_; +}; + class ACE_EXPORT LoadWebGeolocationHideEvent : public BaseEventInfo { DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebGeolocationHideEvent, BaseEventInfo); @@ -454,6 +494,74 @@ public: private: RefPtr message_; }; + +class ACE_EXPORT RenderExitedEvent : public BaseEventInfo { + DECLARE_RELATIONSHIP_OF_CLASSES(RenderExitedEvent, BaseEventInfo); + +public: + RenderExitedEvent(int32_t exitedReason) : BaseEventInfo("RenderExitedEvent"), exitedReason_(exitedReason) {} + ~RenderExitedEvent() = default; + + int32_t GetExitedReason() const + { + return exitedReason_; + } + +private: + int32_t exitedReason_; +}; + +class ACE_EXPORT RefreshAccessedHistoryEvent : public BaseEventInfo { + DECLARE_RELATIONSHIP_OF_CLASSES(RefreshAccessedHistoryEvent, BaseEventInfo); + +public: + RefreshAccessedHistoryEvent(const std::string& url, bool isRefreshed) : + BaseEventInfo("RefreshAccessedHistoryEvent"), + url_(url), isRefreshed_(isRefreshed) {} + + ~RefreshAccessedHistoryEvent() = default; + + const std::string& GetVisitedUrl() const + { + return url_; + } + + bool IsRefreshed() const + { + return isRefreshed_; + } + +private: + std::string url_; + bool isRefreshed_; +}; + +class ACE_EXPORT FileSelectorEvent : public BaseEventInfo { + DECLARE_RELATIONSHIP_OF_CLASSES(FileSelectorEvent, BaseEventInfo); + +public: + FileSelectorEvent(const RefPtr& param, + const RefPtr& result) + : BaseEventInfo("FileSelectorEvent"), param_(param), result_(result) + { + LOGI("FileSelectorEvent constructor"); + } + ~FileSelectorEvent() = default; + + const RefPtr& GetParam() const + { + return param_; + } + + const RefPtr& GetFileSelectorResult() const + { + return result_; + } + +private: + RefPtr param_; + RefPtr result_; +}; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H