Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lindexi_gd
Uno
提交
0a8d32b4
U
Uno
项目概览
lindexi_gd
/
Uno
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Uno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0a8d32b4
编写于
4月 09, 2023
作者:
M
Martin Zikmund
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: Provide separate implementation of legacy InvokeScriptAsync behavior
上级
151754ff
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
69 addition
and
34 deletion
+69
-34
src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2.cs
src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2.cs
+10
-0
src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/NativeWebViewWrapper.Android.cs
...ls/WebView/Native/Android/NativeWebViewWrapper.Android.cs
+14
-2
src/Uno.UI/UI/Xaml/Controls/WebView/Native/INativeWebView.cs
src/Uno.UI/UI/Xaml/Controls/WebView/Native/INativeWebView.cs
+2
-0
src/Uno.UI/UI/Xaml/Controls/WebView/Native/iOSmacOS/UnoWKWebView.iOSmacOS.cs
...Controls/WebView/Native/iOSmacOS/UnoWKWebView.iOSmacOS.cs
+30
-0
src/Uno.UI/UI/Xaml/Controls/WebView/WebView1/WebView.cs
src/Uno.UI/UI/Xaml/Controls/WebView/WebView1/WebView.cs
+13
-32
未找到文件。
src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2.cs
浏览文件 @
0a8d32b4
...
...
@@ -99,6 +99,16 @@ public partial class CoreWebView2
return
_nativeWebView
.
ExecuteScriptAsync
(
javaScript
,
ct
);
});
internal
async
Task
<
string
?>
InvokeScriptAsync
(
string
script
,
string
[]?
arguments
,
CancellationToken
ct
)
{
if
(
_nativeWebView
is
null
)
{
return
null
;
}
return
await
_nativeWebView
.
InvokeScriptAsync
(
script
,
arguments
,
ct
);
}
internal
void
OnOwnerApplyTemplate
()
{
_nativeWebView
=
GetNativeWebViewFromTemplate
();
...
...
src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/NativeWebViewWrapper.Android.cs
浏览文件 @
0a8d32b4
...
...
@@ -160,8 +160,6 @@ internal class NativeWebViewWrapper : INativeWebView
_webView
.
LoadDataWithBaseURL
(
null
,
html
,
"text/html; charset=utf-8"
,
"utf-8"
,
null
);
}
//_owner should be IAsyncOperation<string> instead of Task<string> but we use an extension method to enable the same signature in Win.
//IAsyncOperation is not available in Xamarin.
async
Task
<
string
>
INativeWebView
.
ExecuteScriptAsync
(
string
script
,
CancellationToken
token
)
{
TaskCompletionSource
<
string
>
tcs
=
new
TaskCompletionSource
<
string
>();
...
...
@@ -175,6 +173,20 @@ internal class NativeWebViewWrapper : INativeWebView
return
await
tcs
.
Task
;
}
async
Task
<
string
>
INativeWebView
.
InvokeScriptAsync
(
string
script
,
string
[]
arguments
,
CancellationToken
ct
)
{
var
argumentString
=
Windows
.
UI
.
Xaml
.
Controls
.
WebView
.
ConcatenateJavascriptArguments
(
arguments
);
TaskCompletionSource
<
string
>
tcs
=
new
TaskCompletionSource
<
string
>();
ct
.
Register
(()
=>
tcs
.
TrySetCanceled
());
_webView
.
EvaluateJavascript
(
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"javascript:{0}(\"{1}\");"
,
script
,
argumentString
),
new
ScriptResponse
(
value
=>
tcs
.
SetResult
(
value
)));
return
await
tcs
.
Task
;
}
// On Windows, the WebView ignores "about:blank" entries from its navigation history.
// Because Android doesn't let you modify the navigation history,
// we need CanGoBack, CanGoForward, GoBack and GoForward to take the above condition into consideration.
...
...
src/Uno.UI/UI/Xaml/Controls/WebView/Native/INativeWebView.cs
浏览文件 @
0a8d32b4
...
...
@@ -25,5 +25,7 @@ internal partial interface INativeWebView
Task
<
string
?>
ExecuteScriptAsync
(
string
script
,
CancellationToken
token
);
Task
<
string
?>
InvokeScriptAsync
(
string
script
,
string
[]?
arguments
,
CancellationToken
token
);
void
SetScrollingEnabled
(
bool
isScrollingEnabled
);
}
src/Uno.UI/UI/Xaml/Controls/WebView/Native/iOSmacOS/UnoWKWebView.iOSmacOS.cs
浏览文件 @
0a8d32b4
...
...
@@ -644,6 +644,36 @@ public partial class UnoWKWebView : WKWebView, INativeWebView, IWKScriptMessageH
return
await
tcs
.
Task
;
}
async
Task
<
string
>
INativeWebView
.
InvokeScriptAsync
(
string
script
,
string
[]
arguments
,
CancellationToken
ct
)
{
var
argumentString
=
Windows
.
UI
.
Xaml
.
Controls
.
WebView
.
ConcatenateJavascriptArguments
(
arguments
);
var
javascript
=
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"javascript:{0}(\"{1}\")"
,
script
,
argumentString
);
if
(
this
.
Log
().
IsEnabled
(
Uno
.
Foundation
.
Logging
.
LogLevel
.
Debug
))
{
this
.
Log
().
Debug
(
$"EvaluateJavascriptAsync:
{
javascript
}
"
);
}
var
tcs
=
new
TaskCompletionSource
<
string
>();
using
(
ct
.
Register
(()
=>
tcs
.
TrySetCanceled
()))
{
EvaluateJavaScript
(
javascript
,
(
result
,
error
)
=>
{
if
(
error
!=
null
)
{
tcs
.
TrySetException
(
new
InvalidOperationException
(
$"Failed to execute javascript
{
error
.
LocalizedDescription
}
,
{
error
.
LocalizedFailureReason
}
,
{
error
.
LocalizedRecoverySuggestion
}
"
));
}
else
{
tcs
.
TrySetResult
(
result
as
NSString
);
}
});
return
await
tcs
.
Task
;
}
}
private
void
ProcessNSUrlRequest
(
NSUrlRequest
request
)
{
if
(
request
==
null
)
...
...
src/Uno.UI/UI/Xaml/Controls/WebView/WebView1/WebView.cs
浏览文件 @
0a8d32b4
...
...
@@ -59,16 +59,23 @@ public partial class WebView : Control, IWebView
public
IAsyncOperation
<
string
?>
InvokeScriptAsync
(
string
scriptName
,
IEnumerable
<
string
>
arguments
)
=>
AsyncOperation
.
FromTask
(
ct
=>
InvokeScriptAsync
(
ct
,
scriptName
,
arguments
?.
ToArray
()));
public
async
Task
<
string
?>
InvokeScriptAsync
(
CancellationToken
ct
,
string
script
,
string
[]?
arguments
)
{
var
argumentString
=
ConcatenateJavascriptArguments
(
arguments
);
var
javaScript
=
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"{0}(\"{1}\")"
,
script
,
argumentString
);
return
AdjustInvokeScriptResult
(
await
CoreWebView2
.
ExecuteScriptAsync
(
javaScript
));
}
public
async
Task
<
string
?>
InvokeScriptAsync
(
CancellationToken
ct
,
string
script
,
string
[]?
arguments
)
=>
await
CoreWebView2
.
InvokeScriptAsync
(
script
,
arguments
,
ct
);
public
void
NavigateWithHttpRequestMessage
(
global
::
System
.
Net
.
Http
.
HttpRequestMessage
requestMessage
)
=>
CoreWebView2
.
NavigateWithHttpRequestMessage
(
requestMessage
);
internal
static
string
ConcatenateJavascriptArguments
(
string
[]?
arguments
)
{
var
argument
=
string
.
Empty
;
if
(
arguments
!=
null
&&
arguments
.
Length
>
0
)
{
argument
=
string
.
Join
(
","
,
arguments
);
}
return
argument
;
}
private
void
CoreWebView2_DocumentTitleChanged
(
CoreWebView2
sender
,
object
args
)
=>
DocumentTitle
=
sender
.
DocumentTitle
;
...
...
@@ -114,30 +121,4 @@ public partial class WebView : Control, IWebView
private
void
CoreWebView2_UnsupportedUriSchemeIdentified
(
CoreWebView2
sender
,
WebViewUnsupportedUriSchemeIdentifiedEventArgs
args
)
=>
UnsupportedUriSchemeIdentified
?.
Invoke
(
this
,
args
);
private
static
string
?
AdjustInvokeScriptResult
(
string
result
)
{
if
(
result
is
null
)
{
return
null
;
}
if
(
result
.
StartsWith
(
"\""
,
StringComparison
.
Ordinal
)
&&
result
.
EndsWith
(
"\""
,
StringComparison
.
Ordinal
))
{
return
result
.
Substring
(
1
,
result
.
Length
-
2
);
}
return
""
;
}
private
static
string
ConcatenateJavascriptArguments
(
string
[]?
arguments
)
{
var
argument
=
string
.
Empty
;
if
(
arguments
!=
null
&&
arguments
.
Length
>
0
)
{
argument
=
string
.
Join
(
","
,
arguments
);
}
return
argument
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录