1 Star 0 Fork 1

defeng2020/wdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ace.diff 9.61 KB
一键复制 编辑 原始数据 按行查看 历史
defeng2020 提交于 2022-11-01 11:02 +08:00 . dd
diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp
index b247e0d..54e8f7f 100644
--- a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp
+++ b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp
@@ -1264,6 +1264,7 @@ void JSWeb::JSBind(BindingTarget globalObj)
JSClass<JSWeb>::StaticMethod("password", &JSWeb::Password);
JSClass<JSWeb>::StaticMethod("tableData", &JSWeb::TableData);
JSClass<JSWeb>::StaticMethod("onFileSelectorShow", &JSWeb::OnFileSelectorShowAbandoned);
+ JSClass<JSWeb>::StaticMethod("privilegedSchemes", &JSWeb::OnPrivilegedSchemes);
JSClass<JSWeb>::StaticMethod("onHttpAuthRequest", &JSWeb::OnHttpAuthRequest);
JSClass<JSWeb>::StaticMethod("onSslErrorEventReceive", &JSWeb::OnSslErrorRequest);
JSClass<JSWeb>::StaticMethod("onClientAuthenticationRequest", &JSWeb::OnSslSelectCertRequest);
@@ -2552,6 +2553,78 @@ void JSWeb::OnFileSelectorShow(const JSCallbackInfo& args)
webComponent->SetOnFileSelectorShow(std::move(jsCallback));
}
+bool WebcustomSchemeCheckName(std::string scheme)
+{
+ #define MAX_NAME_SIZE 32
+ if (scheme.size() > MAX_NAME_SIZE || scheme.empty()) {
+ LOGE("wdf invalid size %{public}d", scheme.size());
+ return false;
+ }
+
+ for(auto it = scheme.begin(); it != scheme.end(); it++) {
+ char chr = *it;
+ if ((chr >= 'a' && chr <= 'z') || (chr >= '0' && chr <= '9') || (chr == '.') || (chr == '+') || (chr == '-')) {
+ continue;
+ } else {
+ LOGE("wdf invalid character %{public}c", chr);
+ return false;
+ }
+ }
+ return true;
+}
+
+void JSWeb::OnPrivilegedSchemes(const JSCallbackInfo& args)
+{
+ if ((args.Length() <= 0) || !(args[0]->IsArray())) {
+ LOGE("arg is invalid");
+ return;
+ }
+ JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
+ if (array->Length() > 3) {
+ LOGE("arg len invalid");
+ return;
+ }
+ std::string cmdLine;
+ for (size_t i = 0; i < array->Length(); i++) {
+ auto obj = JSRef<JSObject>::Cast(array->GetValueAt(i));
+ auto schemeName = obj->GetProperty("schemeName");
+ auto isCors = obj->GetProperty("isSupportCors");
+ auto isFetch = obj->GetProperty("isSupportFetch");
+ if (!schemeName->IsString() || !isCors->IsBoolean() || !isFetch->IsBoolean()) {
+ LOGE("scheme value is undefined");
+ return;
+ }
+ auto schemeNamestr = schemeName->ToString();
+ if (!WebcustomSchemeCheckName(schemeNamestr)) {
+ LOGE("scheme name is invalid");
+ return;
+ }
+ auto isCorsBool = isCors->ToBoolean();
+ auto isFetchBool = isFetch->ToBoolean();
+ LOGI("reg scheme info %{public}s:%{public}d:%{public}d", schemeNamestr.c_str(), isCorsBool, isFetchBool);
+ cmdLine.append(schemeNamestr + ",");
+ if (isCorsBool) {
+ cmdLine.append("1,");
+ } else {
+ cmdLine.append("0,");
+ }
+
+ if (isFetchBool) {
+ cmdLine.append("1;");
+ } else {
+ cmdLine.append("0;");
+ }
+ }
+ cmdLine.pop_back();
+ LOGI("reg scheme cmdline %{public}s", cmdLine.c_str());
+ if (Container::IsCurrentUseNewPipeline()) {
+ NG::WebView::SetCustomScheme(cmdLine);
+ return;
+ }
+ auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
+ webComponent->SetCustomScheme(cmdLine);
+}
+
JSRef<JSVal> ContextMenuEventToJSValue(const ContextMenuEvent& eventInfo)
{
JSRef<JSObject> obj = JSRef<JSObject>::New();
diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.h b/frameworks/bridge/declarative_frontend/jsview/js_web.h
index 1b147d3..91ae3f0 100644
--- a/frameworks/bridge/declarative_frontend/jsview/js_web.h
+++ b/frameworks/bridge/declarative_frontend/jsview/js_web.h
@@ -55,6 +55,7 @@ public:
static void OnErrorReceive(const JSCallbackInfo& args);
static void OnHttpErrorReceive(const JSCallbackInfo& args);
static void OnFileSelectorShow(const JSCallbackInfo& args);
+ static void OnPrivilegedSchemes(const JSCallbackInfo& args);
static void OnInterceptRequest(const JSCallbackInfo& args);
static void OnUrlLoadIntercept(const JSCallbackInfo& args);
static void JsEnabled(bool isJsEnabled);
diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp
index bc6c226..a849169 100755
--- a/frameworks/core/components/web/resource/web_delegate.cpp
+++ b/frameworks/core/components/web/resource/web_delegate.cpp
@@ -1988,6 +1988,23 @@ void WebDelegate::InitWebViewWithSurface(sptr<Surface> surface)
initArgs.web_engine_args_to_add.push_back(
std::string("--lang=").append(AceApplicationInfo::GetInstance().GetLanguage() +
"-" + AceApplicationInfo::GetInstance().GetCountryOrRegion()));
+ std::string customScheme;
+ if (Container::IsCurrentUseNewPipeline()) {
+ auto webPattern = delegate->webPattern_.Upgrade();
+ CHECK_NULL_VOID(webPattern);
+ auto webData = webPattern->GetCustomScheme();
+ CHECK_NULL_VOID(webData);
+ customScheme = webData.value();
+ } else {
+ auto webCom = delegate->webComponent_.Upgrade();
+ CHECK_NULL_VOID(webCom);
+ customScheme = webCom->GetCustomScheme();
+ }
+ if (!customScheme.empty()) {
+ LOGI("custome scheme %{public}s", customScheme.c_str());
+ initArgs.web_engine_args_to_add.push_back(
+ std::string("--ohos-custom-scheme=").append(customScheme));
+ }
sptr<Surface> surface = surfaceWeak.promote();
CHECK_NULL_VOID(surface);
delegate->nweb_ = OHOS::NWeb::NWebAdapterHelper::Instance().CreateNWeb(surface, initArgs);
diff --git a/frameworks/core/components/web/web_component.h b/frameworks/core/components/web/web_component.h
index 352c6bd..79ea4fb 100644
--- a/frameworks/core/components/web/web_component.h
+++ b/frameworks/core/components/web/web_component.h
@@ -343,6 +343,16 @@ public:
userAgent_ = std::move(userAgent);
}
+ std::string GetCustomScheme() const
+ {
+ return customScheme_;
+ }
+
+ void SetCustomScheme(std::string cmdLine)
+ {
+ customScheme_ = std::move(cmdLine);
+ }
+
bool GetContentAccessEnabled() const
{
return isContentAccessEnabled_;
@@ -860,6 +870,7 @@ private:
bool isContentAccessEnabled_ = true;
bool isFileAccessEnabled_ = true;
std::string userAgent_;
+ std::string customScheme_;
WeakPtr<FocusNode> focusElement_;
bool isOnLineImageAccessEnabled_ = false;
bool isDomStorageAccessEnabled_ = false;
diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.h b/frameworks/core/components_ng/pattern/web/web_pattern.h
index a2422cc..300bee0 100644
--- a/frameworks/core/components_ng/pattern/web/web_pattern.h
+++ b/frameworks/core/components_ng/pattern/web/web_pattern.h
@@ -115,6 +115,16 @@ public:
return webData_;
}
+ void SetCustomScheme(const std::string& scheme)
+ {
+ customScheme_ = scheme;
+ }
+
+ const std::optional<std::string>& GetCustomScheme() const
+ {
+ return customScheme_;
+ }
+
void SetWebController(const RefPtr<WebController>& webController)
{
// TODO: add web controller diff function.
@@ -263,6 +273,7 @@ private:
std::optional<std::string> webSrc_;
std::optional<std::string> webData_;
+ std::optional<std::string> customScheme_;
RefPtr<WebController> webController_;
SetWebIdCallback setWebIdCallback_ = nullptr;
JsProxyCallback jsProxyCallback_ = nullptr;
diff --git a/frameworks/core/components_ng/pattern/web/web_view.cpp b/frameworks/core/components_ng/pattern/web/web_view.cpp
index 53700f7..fc81be6 100644
--- a/frameworks/core/components_ng/pattern/web/web_view.cpp
+++ b/frameworks/core/components_ng/pattern/web/web_view.cpp
@@ -289,6 +289,13 @@ void WebView::SetUserAgent(const std::string& userAgent)
webPattern->UpdateUserAgent(userAgent);
}
+void WebView::SetCustomScheme(const std::string& customScheme)
+{
+ auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
+ CHECK_NULL_VOID(webPattern);
+ webPattern->SetCustomScheme(customScheme);
+}
+
void WebView::SetRenderExitedId(OnWebAsyncFunc&& renderExitedId)
{
auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
diff --git a/frameworks/core/components_ng/pattern/web/web_view.h b/frameworks/core/components_ng/pattern/web/web_view.h
index 68aa62e..88b5ce1 100644
--- a/frameworks/core/components_ng/pattern/web/web_view.h
+++ b/frameworks/core/components_ng/pattern/web/web_view.h
@@ -67,6 +67,7 @@ public:
static void SetZoomAccessEnabled(bool isZoomAccessEnabled);
static void SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled);
static void SetUserAgent(const std::string& userAgent);
+ static void SetCustomScheme(const std::string& customScheme);
static void SetRenderExitedId(OnWebAsyncFunc&& renderExitedId);
static void SetRefreshAccessedHistoryId(OnWebAsyncFunc&& refreshAccessedHistoryId);
static void SetCacheMode(WebCacheMode mode);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/defeng2020/wdf.git
git@gitee.com:defeng2020/wdf.git
defeng2020
wdf
wdf
master

搜索帮助