mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-19 14:43:36 -04:00
@@ -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) {
|
||||
|
||||
Regular → Executable
+342
-1
@@ -73,7 +73,6 @@ private:
|
||||
RefPtr<Result> result_;
|
||||
};
|
||||
|
||||
|
||||
class JSWebConsoleLog : public Referenced {
|
||||
public:
|
||||
static void JSBind(BindingTarget globalObj)
|
||||
@@ -410,6 +409,136 @@ private:
|
||||
RefPtr<WebRequest> request_;
|
||||
};
|
||||
|
||||
class JSFileSelectorParam : public Referenced {
|
||||
public:
|
||||
static void JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSFileSelectorParam>::Declare("FileSelectorParam");
|
||||
JSClass<JSFileSelectorParam>::CustomMethod("title", &JSFileSelectorParam::GetTitle);
|
||||
JSClass<JSFileSelectorParam>::CustomMethod("mode", &JSFileSelectorParam::GetMode);
|
||||
JSClass<JSFileSelectorParam>::CustomMethod("acceptType", &JSFileSelectorParam::GetAcceptType);
|
||||
JSClass<JSFileSelectorParam>::CustomMethod("isCapture", &JSFileSelectorParam::IsCapture);
|
||||
JSClass<JSFileSelectorParam>::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<JSVal>::Make(title);
|
||||
args.SetReturnValue(descriptionRef);
|
||||
}
|
||||
|
||||
void GetMode(const JSCallbackInfo& args)
|
||||
{
|
||||
auto mode = JSVal(ToJSValue(param_->GetMode()));
|
||||
auto descriptionRef = JSRef<JSVal>::Make(mode);
|
||||
args.SetReturnValue(descriptionRef);
|
||||
}
|
||||
|
||||
void IsCapture(const JSCallbackInfo& args)
|
||||
{
|
||||
auto isCapture = JSVal(ToJSValue(param_->IsCapture()));
|
||||
auto descriptionRef = JSRef<JSVal>::Make(isCapture);
|
||||
args.SetReturnValue(descriptionRef);
|
||||
}
|
||||
|
||||
void GetAcceptType(const JSCallbackInfo& args)
|
||||
{
|
||||
auto acceptTypes = param_->GetAcceptType();
|
||||
JSRef<JSArray> result = JSRef<JSArray>::New();
|
||||
std::vector<std::string>::iterator iterator;
|
||||
uint32_t index = 0;
|
||||
for (iterator = acceptTypes.begin(); iterator != acceptTypes.end(); ++iterator) {
|
||||
auto valueStr = JSVal(ToJSValue(*iterator));
|
||||
auto value = JSRef<JSVal>::Make(valueStr);
|
||||
result->SetValueAt(index++, value);
|
||||
}
|
||||
args.SetReturnValue(result);
|
||||
}
|
||||
|
||||
private:
|
||||
static void Constructor(const JSCallbackInfo& args)
|
||||
{
|
||||
auto jSFilerSelectorParam = Referenced::MakeRefPtr<JSFileSelectorParam>();
|
||||
jSFilerSelectorParam->IncRefCount();
|
||||
args.SetReturnValue(Referenced::RawPtr(jSFilerSelectorParam));
|
||||
}
|
||||
|
||||
static void Destructor(JSFileSelectorParam* jSFilerSelectorParam)
|
||||
{
|
||||
if (jSFilerSelectorParam != nullptr) {
|
||||
jSFilerSelectorParam->DecRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<WebFileSelectorParam> param_;
|
||||
};
|
||||
|
||||
class JSFileSelectorResult : public Referenced {
|
||||
public:
|
||||
static void JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSFileSelectorResult>::Declare("FileSelectorResult");
|
||||
JSClass<JSFileSelectorResult>::CustomMethod("handleFileList",
|
||||
&JSFileSelectorResult::HandleFileList);
|
||||
JSClass<JSFileSelectorResult>::Bind(globalObj, &JSFileSelectorResult::Constructor,
|
||||
&JSFileSelectorResult::Destructor);
|
||||
}
|
||||
|
||||
void SetResult(const FileSelectorEvent& eventInfo)
|
||||
{
|
||||
result_ = eventInfo.GetFileSelectorResult();
|
||||
}
|
||||
|
||||
void HandleFileList(const JSCallbackInfo& args)
|
||||
{
|
||||
std::vector<std::string> fileList;
|
||||
if (args[0]->IsArray()) {
|
||||
JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
|
||||
for (size_t i = 0; i < array->Length(); i++) {
|
||||
JSRef<JSVal> 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>();
|
||||
jsFileSelectorResult->IncRefCount();
|
||||
args.SetReturnValue(Referenced::RawPtr(jsFileSelectorResult));
|
||||
}
|
||||
|
||||
static void Destructor(JSFileSelectorResult* jsFileSelectorResult)
|
||||
{
|
||||
if (jsFileSelectorResult != nullptr) {
|
||||
jsFileSelectorResult->DecRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<FileSelectorResult> result_;
|
||||
};
|
||||
|
||||
void JSWeb::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSWeb>::Declare("Web");
|
||||
@@ -425,6 +554,7 @@ void JSWeb::JSBind(BindingTarget globalObj)
|
||||
JSClass<JSWeb>::StaticMethod("onGeolocationHide", &JSWeb::OnGeolocationHide);
|
||||
JSClass<JSWeb>::StaticMethod("onGeolocationShow", &JSWeb::OnGeolocationShow);
|
||||
JSClass<JSWeb>::StaticMethod("onRequestSelected", &JSWeb::OnRequestFocus);
|
||||
JSClass<JSWeb>::StaticMethod("onFileSelectorShow", &JSWeb::OnFileSelectorShow);
|
||||
JSClass<JSWeb>::StaticMethod("javaScriptAccess", &JSWeb::JsEnabled);
|
||||
JSClass<JSWeb>::StaticMethod("fileExtendAccess", &JSWeb::ContentAccessEnabled);
|
||||
JSClass<JSWeb>::StaticMethod("fileAccess", &JSWeb::FileAccessEnabled);
|
||||
@@ -432,6 +562,7 @@ void JSWeb::JSBind(BindingTarget globalObj)
|
||||
JSClass<JSWeb>::StaticMethod("onDownloadStart", &JSWeb::OnDownloadStart);
|
||||
JSClass<JSWeb>::StaticMethod("onErrorReceive", &JSWeb::OnErrorReceive);
|
||||
JSClass<JSWeb>::StaticMethod("onHttpErrorReceive", &JSWeb::OnHttpErrorReceive);
|
||||
JSClass<JSWeb>::StaticMethod("onUrlLoadIntercept", &JSWeb::OnUrlLoadIntercept);
|
||||
JSClass<JSWeb>::StaticMethod("onlineImageAccess", &JSWeb::OnLineImageAccessEnabled);
|
||||
JSClass<JSWeb>::StaticMethod("domStorageAccess", &JSWeb::DomStorageAccessEnabled);
|
||||
JSClass<JSWeb>::StaticMethod("imageAccess", &JSWeb::ImageAccessEnabled);
|
||||
@@ -440,6 +571,13 @@ void JSWeb::JSBind(BindingTarget globalObj)
|
||||
JSClass<JSWeb>::StaticMethod("geolocationAccess", &JSWeb::GeolocationAccessEnabled);
|
||||
JSClass<JSWeb>::StaticMethod("javaScriptProxy", &JSWeb::JavaScriptProxy);
|
||||
JSClass<JSWeb>::StaticMethod("userAgent", &JSWeb::UserAgent);
|
||||
JSClass<JSWeb>::StaticMethod("onRenderExited", &JSWeb::OnRenderExited);
|
||||
JSClass<JSWeb>::StaticMethod("onRefreshAccessedHistory", &JSWeb::OnRefreshAccessedHistory);
|
||||
JSClass<JSWeb>::StaticMethod("cacheMode", &JSWeb::CacheMode);
|
||||
JSClass<JSWeb>::StaticMethod("overviewModeAccess", &JSWeb::OverviewModeAccess);
|
||||
JSClass<JSWeb>::StaticMethod("fileFromUrlAccess", &JSWeb::FileFromUrlAccess);
|
||||
JSClass<JSWeb>::StaticMethod("databaseAccess", &JSWeb::DatabaseAccess);
|
||||
JSClass<JSWeb>::StaticMethod("textZoomAtio", &JSWeb::TextZoomAtio);
|
||||
JSClass<JSWeb>::Inherit<JSViewAbstract>();
|
||||
JSClass<JSWeb>::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<JSVal> LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent& eventInfo)
|
||||
@@ -506,6 +646,13 @@ JSRef<JSVal> LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent& e
|
||||
return JSRef<JSVal>::Cast(obj);
|
||||
}
|
||||
|
||||
JSRef<JSVal> UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent& eventInfo)
|
||||
{
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::New();
|
||||
obj->SetProperty("data", eventInfo.GetData());
|
||||
return JSRef<JSVal>::Cast(obj);
|
||||
}
|
||||
|
||||
JSRef<JSVal> LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent& eventInfo)
|
||||
{
|
||||
return JSRef<JSVal>::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<JsEventFunction<UrlLoadInterceptEvent, 1>>(
|
||||
JSRef<JSFunc>::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<UrlLoadInterceptEvent>(info);
|
||||
JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
|
||||
if (message->IsBoolean()) {
|
||||
return message->ToBoolean();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto webComponent = AceType::DynamicCast<WebComponent>(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<JSVal> FileSelectorEventToJSValue(const FileSelectorEvent& eventInfo)
|
||||
{
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::New();
|
||||
|
||||
JSRef<JSObject> paramObj = JSClass<JSFileSelectorParam>::NewInstance();
|
||||
auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap<JSFileSelectorParam>());
|
||||
fileSelectorParam->SetParam(eventInfo);
|
||||
|
||||
JSRef<JSObject> resultObj = JSClass<JSFileSelectorResult>::NewInstance();
|
||||
auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap<JSFileSelectorResult>());
|
||||
fileSelectorResult->SetResult(eventInfo);
|
||||
|
||||
obj->SetPropertyObject("result", resultObj);
|
||||
obj->SetPropertyObject("fileSelector", paramObj);
|
||||
return JSRef<JSVal>::Cast(obj);
|
||||
}
|
||||
|
||||
void JSWeb::OnFileSelectorShow(const JSCallbackInfo& args)
|
||||
{
|
||||
LOGI("OnFileSelectorShow");
|
||||
if (!args[0]->IsFunction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FileSelectorEvent, 1>>(
|
||||
JSRef<JSFunc>::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<FileSelectorEvent>(info);
|
||||
JSRef<JSVal> result = func->ExecuteWithValue(*eventInfo);
|
||||
if (result->IsBoolean()) {
|
||||
return result->ToBoolean();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto webComponent = AceType::DynamicCast<WebComponent>(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<JSVal> RenderExitedEventToJSValue(const RenderExitedEvent& eventInfo)
|
||||
{
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::New();
|
||||
obj->SetProperty("renderExitReason", eventInfo.GetExitedReason());
|
||||
return JSRef<JSVal>::Cast(obj);
|
||||
}
|
||||
|
||||
JSRef<JSVal> RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent& eventInfo)
|
||||
{
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::New();
|
||||
obj->SetProperty("url", eventInfo.GetVisitedUrl());
|
||||
obj->SetProperty("isRefreshed", eventInfo.IsRefreshed());
|
||||
return JSRef<JSVal>::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<JsEventFunction<RenderExitedEvent, 1>>(
|
||||
JSRef<JSFunc>::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<RenderExitedEvent>(info);
|
||||
func->Execute(*eventInfo);
|
||||
});
|
||||
auto webComponent = AceType::DynamicCast<WebComponent>(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<JsEventFunction<RefreshAccessedHistoryEvent, 1>>(
|
||||
JSRef<JSFunc>::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<RefreshAccessedHistoryEvent>(info);
|
||||
func->Execute(*eventInfo);
|
||||
});
|
||||
auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
|
||||
webComponent->SetRefreshAccessedHistoryId(eventMarker);
|
||||
}
|
||||
|
||||
void JSWeb::CacheMode(int32_t cacheMode)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto webComponent = AceType::DynamicCast<WebComponent>(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<WebComponent>(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<WebComponent>(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<WebComponent>(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<WebComponent>(stack->GetMainComponent());
|
||||
if (!webComponent) {
|
||||
LOGE("JSWeb: MainComponent is null.");
|
||||
return;
|
||||
}
|
||||
webComponent->SetTextZoomAtio(textZoomAtioNum);
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
Regular → Executable
+9
@@ -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);
|
||||
|
||||
@@ -71,6 +71,72 @@ std::shared_ptr<WebJSValue> ParseValue(
|
||||
}
|
||||
}
|
||||
|
||||
class JSWebCookie : public Referenced {
|
||||
public:
|
||||
static void JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSWebCookie>::Declare("WebCookie");
|
||||
JSClass<JSWebCookie>::CustomMethod("setCookie", &JSWebCookie::SetCookie);
|
||||
JSClass<JSWebCookie>::CustomMethod("saveCookieSync", &JSWebCookie::SaveCookieSync);
|
||||
JSClass<JSWebCookie>::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<JSVal>::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<JSVal>::Make(jsVal);
|
||||
args.SetReturnValue(returnValue);
|
||||
}
|
||||
|
||||
private:
|
||||
static void Constructor(const JSCallbackInfo& args)
|
||||
{
|
||||
auto jsWebCookie = Referenced::MakeRefPtr<JSWebCookie>();
|
||||
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<JSWebController>::CustomMethod("accessStep", &JSWebController::AccessStep);
|
||||
JSClass<JSWebController>::CustomMethod("accessForward", &JSWebController::AccessForward);
|
||||
JSClass<JSWebController>::CustomMethod("accessBackward", &JSWebController::AccessBackward);
|
||||
JSClass<JSWebController>::CustomMethod("clearHistory", &JSWebController::ClearHistory);
|
||||
JSClass<JSWebController>::CustomMethod("getCookieManager", &JSWebController::GetCookieManager);
|
||||
JSClass<JSWebController>::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<JSWebCookie>::NewInstance();
|
||||
auto jsWebCookieVal = Referenced::Claim(jsWebCookie_->Unwrap<JSWebCookie>());
|
||||
jsWebCookieVal->SetWebCookie(webController_->GetCookieManager());
|
||||
jsWebCookieInit_ = true;
|
||||
}
|
||||
args.SetReturnValue(jsWebCookie_);
|
||||
}
|
||||
}
|
||||
|
||||
void JSWebController::SetJavascriptCallBackImpl()
|
||||
{
|
||||
if (!webController_ || jsRegisterCallBackInit_) {
|
||||
|
||||
@@ -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<WebController>& GetController() const
|
||||
{
|
||||
@@ -80,6 +82,8 @@ private:
|
||||
std::unordered_map<std::string, std::vector<std::string>> methods_;
|
||||
RefPtr<WebController> webController_;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(JSWebController);
|
||||
JSRef<JSObject> jsWebCookie_;
|
||||
bool jsWebCookieInit_ = false;
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_CONTROLLER_H
|
||||
Regular → Executable
+27
-1
@@ -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<WebAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
|
||||
return attribute.src;
|
||||
}
|
||||
|
||||
|
||||
void SetWebData(const std::string& data)
|
||||
{
|
||||
auto& attribute = MaybeResetAttribute<WebAttribute>(AttributeTag::SPECIALIZED_ATTR);
|
||||
@@ -225,6 +227,30 @@ public:
|
||||
return event.messageEventId;
|
||||
}
|
||||
|
||||
void SetRenderExitedId(const EventMarker& renderExitedEventId)
|
||||
{
|
||||
auto& event = MaybeResetEvent<WebEvent>(EventTag::SPECIALIZED_EVENT);
|
||||
event.renderExitedEventId = renderExitedEventId;
|
||||
}
|
||||
|
||||
const EventMarker& GetRenderExitedId() const
|
||||
{
|
||||
auto& event = static_cast<WebEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT));
|
||||
return event.renderExitedEventId;
|
||||
}
|
||||
|
||||
void SetRefreshAccessedHistoryId(const EventMarker& refreshAccessedHistoryId)
|
||||
{
|
||||
auto& event = MaybeResetEvent<WebEvent>(EventTag::SPECIALIZED_EVENT);
|
||||
event.refreshAccessedHistoryId = refreshAccessedHistoryId;
|
||||
}
|
||||
|
||||
const EventMarker& GetRefreshAccessedHistoryId() const
|
||||
{
|
||||
auto& event = static_cast<WebEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT));
|
||||
return event.refreshAccessedHistoryId;
|
||||
}
|
||||
|
||||
protected:
|
||||
void InitSpecialized() override;
|
||||
bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
|
||||
|
||||
@@ -68,6 +68,11 @@ void RenderWeb::Update(const RefPtr<Component>& 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);
|
||||
|
||||
@@ -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<NWeb::NWebJSDialogResult> 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<NWeb::FileSelectorCallback> callback,
|
||||
std::shared_ptr<NWeb::NWebFileSelectorParams> params)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
bool jsResult = false;
|
||||
auto param = std::make_shared<FileSelectorEvent>(AceType::MakeRefPtr<FileSelectorParamOhos>(params),
|
||||
AceType::MakeRefPtr<FileSelectorResultOhos>(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
|
||||
|
||||
@@ -72,16 +72,17 @@ public:
|
||||
bool OnConfirmDialogByJS(const std::string &url,
|
||||
const std::string &message,
|
||||
std::shared_ptr<NWeb::NWebJSDialogResult> result) override;
|
||||
bool OnFileSelectorShow(std::shared_ptr<NWeb::FileSelectorCallback> callback,
|
||||
std::shared_ptr<NWeb::NWebFileSelectorParams> params) override;
|
||||
|
||||
void OnFocus() override;
|
||||
void OnResourceLoadError(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,
|
||||
std::shared_ptr<OHOS::NWeb::NWebUrlResourceError> error) override;
|
||||
void OnHttpError(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,
|
||||
std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> 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<WebDelegate>& delegate)
|
||||
{
|
||||
webDelegate_ = delegate;
|
||||
|
||||
@@ -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<std::string> FileSelectorParamOhos::GetAcceptType()
|
||||
{
|
||||
if (param_) {
|
||||
return param_->AcceptType();
|
||||
}
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
bool FileSelectorParamOhos::IsCapture()
|
||||
{
|
||||
if (param_) {
|
||||
return param_->IsCapture();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileSelectorResultOhos::HandleFileList(std::vector<std::string> 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<int>(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<PipelineContext>& context)
|
||||
{
|
||||
@@ -751,6 +835,10 @@ void WebDelegate::InitOHOSWeb(const WeakPtr<PipelineContext>& context, sptr<Surf
|
||||
webComponent_->GetHttpErrorEventId(), pipelineContext);
|
||||
onDownloadStartV2_ = AceAsyncEvent<void(const std::shared_ptr<BaseEventInfo>&)>::Create(
|
||||
webComponent_->GetDownloadStartEventId(), pipelineContext);
|
||||
onRenderExitedV2_ = AceAsyncEvent<void(const std::shared_ptr<BaseEventInfo>&)>::Create(
|
||||
webComponent_->GetRenderExitedId(), pipelineContext);
|
||||
onRefreshAccessedHistoryV2_ = AceAsyncEvent<void(const std::shared_ptr<BaseEventInfo>&)>::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> 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> surface)
|
||||
delegate->nweb_->SetNWebHandler(nweb_handler);
|
||||
delegate->nweb_->PutDownloadCallback(downloadListenerImpl);
|
||||
|
||||
std::shared_ptr<OHOS::NWeb::NWebPreference> 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<OHOS::NWeb::NWebPreference::AccessMode>(component->GetMixedMode()));
|
||||
std::shared_ptr<OHOS::NWeb::NWebPreference> 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<OHOS::NWeb::NWebPreference::AccessMode>(component->GetMixedMode()));
|
||||
setting->PutZoomingFunctionEnabled(component->GetZoomAccessEnabled());
|
||||
setting->PutGeolocationAllowed(component->GetGeolocationAccessEnabled());
|
||||
setting->PutCacheMode(
|
||||
static_cast<OHOS::NWeb::NWebPreference::CacheModeFlag>(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<OHOS::NWeb::NWebPreference> setting = delegate->nweb_->GetPreference();
|
||||
setting->PutCacheMode(static_cast<OHOS::NWeb::NWebPreference::CacheModeFlag>(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<OHOS::NWeb::NWebPreference> 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<OHOS::NWeb::NWebPreference> 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<OHOS::NWeb::NWebPreference> 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<OHOS::NWeb::NWebPreference> 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<DownloadStartEvent>(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<RenderExitedEvent>(static_cast<int32_t>(reason)));
|
||||
}
|
||||
}
|
||||
|
||||
void WebDelegate::OnRefreshAccessedHistory(const std::string& url, bool isRefreshed)
|
||||
{
|
||||
if (onRefreshAccessedHistoryV2_) {
|
||||
onRefreshAccessedHistoryV2_(std::make_shared<RefreshAccessedHistoryEvent>(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<UrlLoadInterceptEvent>(data);
|
||||
return webComponent_->OnUrlLoadIntercept(param.get());
|
||||
}
|
||||
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
void WebDelegate::HandleTouchDown(const int32_t& id, const double& x, const double& y)
|
||||
{
|
||||
|
||||
@@ -67,12 +67,40 @@ private:
|
||||
std::shared_ptr<OHOS::NWeb::NWebJSDialogResult> result_;
|
||||
};
|
||||
|
||||
class FileSelectorParamOhos : public WebFileSelectorParam {
|
||||
DECLARE_ACE_TYPE(FileSelectorParamOhos, WebFileSelectorParam)
|
||||
|
||||
public:
|
||||
FileSelectorParamOhos(std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param)
|
||||
: param_(param) {}
|
||||
|
||||
std::string GetTitle() override;
|
||||
int GetMode() override;
|
||||
std::string GetDefaultFileName() override;
|
||||
std::vector<std::string> GetAcceptType() override;
|
||||
bool IsCapture() override;
|
||||
private:
|
||||
std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param_;
|
||||
};
|
||||
|
||||
class FileSelectorResultOhos : public FileSelectorResult {
|
||||
DECLARE_ACE_TYPE(FileSelectorResultOhos, FileSelectorResult)
|
||||
|
||||
public:
|
||||
FileSelectorResultOhos(std::shared_ptr<OHOS::NWeb::FileSelectorCallback> callback)
|
||||
: callback_(callback) {}
|
||||
|
||||
void HandleFileList(std::vector<std::string> result) override;
|
||||
private:
|
||||
std::shared_ptr<OHOS::NWeb::FileSelectorCallback> 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<OHOS::NWeb::NWebGeolocationCallbackInterface> 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<OHOS::NWeb::NWebConsoleLog> 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<OHOS::NWeb::NWeb> nweb_;
|
||||
OHOS::NWeb::NWebCookieManager* cookieManager_ = nullptr;
|
||||
sptr<Rosen::Window> 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_;
|
||||
|
||||
@@ -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<bool(const std::string, const std::string)>;
|
||||
using SaveCookieSyncImpl = std::function<bool()>;
|
||||
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<bool(int32_t)>;
|
||||
using BackwardImpl = std::function<void()>;
|
||||
using ForwardImpl = std::function<void()>;
|
||||
using ClearHistoryImpl = std::function<void()>;
|
||||
void LoadUrl(std::string url, std::map<std::string, std::string>& 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(std::string, std::function<void(std::string)>&&)>;
|
||||
void ExecuteTypeScript(std::string jscode, std::function<void(std::string)>&& 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(const std::string, const std::string)>;
|
||||
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()>;
|
||||
bool SaveCookieSync()
|
||||
{
|
||||
if (saveCookieSyncImpl_) {
|
||||
return saveCookieSyncImpl_();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl)
|
||||
{
|
||||
saveCookieSyncImpl = saveCookieSyncImpl_;
|
||||
}
|
||||
|
||||
using AddJavascriptInterfaceImpl = std::function<void(
|
||||
const std::string&,
|
||||
const std::vector<std::string>&)>;
|
||||
@@ -324,14 +424,16 @@ public:
|
||||
|
||||
private:
|
||||
RefPtr<WebDeclaration> 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<WebDeclaration>& 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(const BaseEventInfo* info)>;
|
||||
bool OnCommonDialog(const BaseEventInfo* info, DialogEventType dialogEventType) const
|
||||
{
|
||||
@@ -688,6 +860,40 @@ public:
|
||||
focusElement_ = focusElement;
|
||||
}
|
||||
|
||||
using OnFileSelectorShowImpl = std::function<bool(const BaseEventInfo* info)>;
|
||||
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(const BaseEventInfo* info)>;
|
||||
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<WebDeclaration> 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
|
||||
|
||||
@@ -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<std::string> 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<std::string> 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<WebConsoleLog> 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<WebFileSelectorParam>& param,
|
||||
const RefPtr<FileSelectorResult>& result)
|
||||
: BaseEventInfo("FileSelectorEvent"), param_(param), result_(result)
|
||||
{
|
||||
LOGI("FileSelectorEvent constructor");
|
||||
}
|
||||
~FileSelectorEvent() = default;
|
||||
|
||||
const RefPtr<WebFileSelectorParam>& GetParam() const
|
||||
{
|
||||
return param_;
|
||||
}
|
||||
|
||||
const RefPtr<FileSelectorResult>& GetFileSelectorResult() const
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WebFileSelectorParam> param_;
|
||||
RefPtr<FileSelectorResult> result_;
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H
|
||||
|
||||
Reference in New Issue
Block a user