Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
714192fd
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
714192fd
编写于
2月 14, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleaning up reviver handling for webviews
上级
f7bfa34a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
73 deletion
+68
-73
src/vs/workbench/api/electron-browser/mainThreadWebview.ts
src/vs/workbench/api/electron-browser/mainThreadWebview.ts
+56
-53
src/vs/workbench/contrib/webview/electron-browser/webviewEditorService.ts
.../contrib/webview/electron-browser/webviewEditorService.ts
+12
-20
未找到文件。
src/vs/workbench/api/electron-browser/mainThreadWebview.ts
浏览文件 @
714192fd
...
...
@@ -2,35 +2,33 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
dispose
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
map
from
'
vs/base/common/map
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/browser/services/codeEditorService
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ILifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
import
{
ExtHostContext
,
ExtHostWebviewsShape
,
IExtHostContext
,
MainContext
,
MainThreadWebviewsShape
,
WebviewPanelHandle
,
WebviewPanelShowOptions
,
WebviewInsetHandle
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
ExtHostContext
,
ExtHostWebviewsShape
,
IExtHostContext
,
MainContext
,
MainThreadWebviewsShape
,
WebviewInsetHandle
,
WebviewPanelHandle
,
WebviewPanelShowOptions
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
editorGroupToViewColumn
,
EditorViewColumn
,
viewColumnToEditorGroup
}
from
'
vs/workbench/api/shared/editor
'
;
import
{
CodeInsetController
}
from
'
vs/workbench/contrib/codeinset/electron-browser/codeInset.contribution
'
;
import
{
WebviewEditor
}
from
'
vs/workbench/contrib/webview/electron-browser/webviewEditor
'
;
import
{
WebviewEditorInput
}
from
'
vs/workbench/contrib/webview/electron-browser/webviewEditorInput
'
;
import
{
ICreateWebViewShowOptions
,
IWebviewEditorService
,
WebviewInputOptions
,
WebviewReviver
}
from
'
vs/workbench/contrib/webview/electron-browser/webviewEditorService
'
;
import
{
ICreateWebViewShowOptions
,
IWebviewEditorService
,
WebviewInputOptions
}
from
'
vs/workbench/contrib/webview/electron-browser/webviewEditorService
'
;
import
{
WebviewElement
}
from
'
vs/workbench/contrib/webview/electron-browser/webviewElement
'
;
import
{
IEditorGroupsService
}
from
'
vs/workbench/services/editor/common/editorGroupsService
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IExtensionService
}
from
'
vs/workbench/services/extensions/common/extensions
'
;
import
{
I
EditorGroupsService
}
from
'
vs/workbench/services/editor/common/editorGroups
Service
'
;
import
{
I
PartService
,
Parts
}
from
'
vs/workbench/services/part/common/part
Service
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
extHostNamedCustomer
}
from
'
./extHostCustomers
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
WebviewElement
}
from
'
vs/workbench/contrib/webview/electron-browser/webviewElement
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/browser/services/codeEditorService
'
;
import
{
CodeInsetController
}
from
'
vs/workbench/contrib/codeinset/electron-browser/codeInset.contribution
'
;
import
{
IPartService
,
Parts
}
from
'
vs/workbench/services/part/common/partService
'
;
@
extHostNamedCustomer
(
MainContext
.
MainThreadWebviews
)
export
class
MainThreadWebviews
implements
MainThreadWebviewsShape
,
WebviewReviver
{
private
static
readonly
viewType
=
'
mainThreadWebview
'
;
export
class
MainThreadWebviews
implements
MainThreadWebviewsShape
{
private
static
readonly
standardSupportedLinkSchemes
=
[
'
http
'
,
'
https
'
,
'
mailto
'
];
...
...
@@ -41,7 +39,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
private
readonly
_proxy
:
ExtHostWebviewsShape
;
private
readonly
_webviews
=
new
Map
<
WebviewPanelHandle
,
WebviewEditorInput
>
();
private
readonly
_webviewsElements
=
new
Map
<
WebviewInsetHandle
,
WebviewElement
>
();
private
readonly
_revivers
=
new
Set
<
string
>
();
private
readonly
_revivers
=
new
Map
<
string
,
IDisposable
>
();
private
_activeWebview
:
WebviewPanelHandle
|
undefined
=
undefined
;
...
...
@@ -62,8 +60,6 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
_editorService
.
onDidActiveEditorChange
(
this
.
onActiveEditorChanged
,
this
,
this
.
_toDispose
);
_editorService
.
onDidVisibleEditorsChange
(
this
.
onVisibleEditorsChanged
,
this
,
this
.
_toDispose
);
this
.
_toDispose
.
push
(
_webviewService
.
registerReviver
(
MainThreadWebviews
.
viewType
,
this
));
lifecycleService
.
onBeforeShutdown
(
e
=>
{
e
.
veto
(
this
.
_onBeforeShutdown
());
},
this
,
this
.
_toDispose
);
...
...
@@ -88,7 +84,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
mainThreadShowOptions
.
group
=
viewColumnToEditorGroup
(
this
.
_editorGroupService
,
showOptions
.
viewColumn
);
}
const
webview
=
this
.
_webviewService
.
createWebview
(
MainThreadWebviews
.
viewType
,
title
,
mainThreadShowOptions
,
reviveWebviewOptions
(
options
),
URI
.
revive
(
extensionLocation
),
this
.
createWebviewEventDelegate
(
handle
));
const
webview
=
this
.
_webviewService
.
createWebview
(
this
.
getInternalWebviewId
(
viewType
)
,
title
,
mainThreadShowOptions
,
reviveWebviewOptions
(
options
),
URI
.
revive
(
extensionLocation
),
this
.
createWebviewEventDelegate
(
handle
));
webview
.
state
=
{
viewType
:
viewType
,
state
:
undefined
...
...
@@ -208,50 +204,57 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
}
public
$registerSerializer
(
viewType
:
string
):
void
{
this
.
_revivers
.
add
(
viewType
);
}
public
$unregisterSerializer
(
viewType
:
string
):
void
{
this
.
_revivers
.
delete
(
viewType
);
}
public
reviveWebview
(
webview
:
WebviewEditorInput
):
Promise
<
void
>
{
const
viewType
=
webview
.
state
.
viewType
;
return
Promise
.
resolve
(
this
.
_extensionService
.
activateByEvent
(
`onWebviewPanel:
${
viewType
}
`
).
then
(()
=>
{
const
handle
=
'
revival-
'
+
MainThreadWebviews
.
revivalPool
++
;
this
.
_webviews
.
set
(
handle
,
webview
);
webview
.
_events
=
this
.
createWebviewEventDelegate
(
handle
);
let
state
=
undefined
;
if
(
webview
.
state
.
state
)
{
try
{
state
=
JSON
.
parse
(
webview
.
state
.
state
);
}
catch
{
// noop
}
if
(
this
.
_revivers
.
has
(
viewType
))
{
throw
new
Error
(
`Reviver for
${
viewType
}
already registered`
);
}
this
.
_revivers
.
set
(
viewType
,
this
.
_webviewService
.
registerReviver
(
this
.
getInternalWebviewId
(
viewType
),
{
canRevive
:
(
webview
)
=>
{
return
!
webview
.
isDisposed
()
&&
webview
.
state
;
},
reviveWebview
:
(
webview
):
Promise
<
void
>
=>
{
const
viewType
=
webview
.
state
.
viewType
;
return
Promise
.
resolve
(
this
.
_extensionService
.
activateByEvent
(
`onWebviewPanel:
${
viewType
}
`
).
then
(()
=>
{
const
handle
=
'
revival-
'
+
MainThreadWebviews
.
revivalPool
++
;
this
.
_webviews
.
set
(
handle
,
webview
);
webview
.
_events
=
this
.
createWebviewEventDelegate
(
handle
);
let
state
=
undefined
;
if
(
webview
.
state
.
state
)
{
try
{
state
=
JSON
.
parse
(
webview
.
state
.
state
);
}
catch
{
// noop
}
}
return
this
.
_proxy
.
$deserializeWebviewPanel
(
handle
,
webview
.
state
.
viewType
,
webview
.
getTitle
(),
state
,
editorGroupToViewColumn
(
this
.
_editorGroupService
,
webview
.
group
),
webview
.
options
)
.
then
(
undefined
,
error
=>
{
onUnexpectedError
(
error
);
webview
.
html
=
MainThreadWebviews
.
getDeserializationFailedContents
(
viewType
);
});
}));
}
return
this
.
_proxy
.
$deserializeWebviewPanel
(
handle
,
webview
.
state
.
viewType
,
webview
.
getTitle
(),
state
,
editorGroupToViewColumn
(
this
.
_editorGroupService
,
webview
.
group
),
webview
.
options
)
.
then
(
undefined
,
error
=>
{
onUnexpectedError
(
error
);
webview
.
html
=
MainThreadWebviews
.
getDeserializationFailedContents
(
viewType
);
});
}));
}
public
canRevive
(
webview
:
WebviewEditorInput
):
boolean
{
if
(
webview
.
isDisposed
()
||
!
webview
.
state
)
{
return
false
;
public
$unregisterSerializer
(
viewType
:
string
):
void
{
const
reviver
=
this
.
_revivers
.
get
(
viewType
);
if
(
!
reviver
)
{
throw
new
Error
(
`No reviver for
${
viewType
}
registered`
);
}
return
this
.
_revivers
.
has
(
webview
.
state
.
viewType
)
||
!!
webview
.
reviver
;
reviver
.
dispose
();
this
.
_revivers
.
delete
(
viewType
);
}
private
getInternalWebviewId
(
viewType
:
string
):
string
{
return
`mainThreadWebview-
${
viewType
}
`
;
}
private
_onBeforeShutdown
():
boolean
{
this
.
_webviews
.
forEach
((
view
)
=>
{
if
(
this
.
canRevive
(
view
))
{
view
.
state
.
state
=
view
.
webviewState
;
this
.
_webviews
.
forEach
((
web
view
)
=>
{
if
(
!
webview
.
isDisposed
()
&&
webview
.
state
&&
this
.
_revivers
.
has
(
webview
.
state
.
viewType
))
{
webview
.
state
.
state
=
web
view
.
webviewState
;
}
});
return
false
;
// Don't veto shutdown
...
...
src/vs/workbench/contrib/webview/electron-browser/webviewEditorService.ts
浏览文件 @
714192fd
...
...
@@ -90,7 +90,7 @@ export function areWebviewInputOptionsEqual(a: WebviewInputOptions, b: WebviewIn
export
class
WebviewEditorService
implements
IWebviewEditorService
{
_serviceBrand
:
any
;
private
readonly
_revivers
=
new
Map
<
string
,
WebviewReviver
[]
>
();
private
readonly
_revivers
=
new
Map
<
string
,
WebviewReviver
>
();
private
_awaitingRevival
:
{
input
:
WebviewEditorInput
,
resolve
:
(
x
:
any
)
=>
void
}[]
=
[];
constructor
(
...
...
@@ -159,17 +159,14 @@ export class WebviewEditorService implements IWebviewEditorService {
viewType
:
string
,
reviver
:
WebviewReviver
):
IDisposable
{
const
currentRevivers
=
this
.
_revivers
.
get
(
viewType
);
if
(
currentRevivers
)
{
currentRevivers
.
push
(
reviver
);
}
else
{
this
.
_revivers
.
set
(
viewType
,
[
reviver
]);
if
(
this
.
_revivers
.
has
(
viewType
))
{
throw
new
Error
(
`Reviver for
${
viewType
}
already registered`
);
}
this
.
_revivers
.
set
(
viewType
,
reviver
);
// Resolve any pending views
const
toRevive
=
this
.
_awaitingRevival
.
filter
(
x
=>
x
.
input
.
viewType
===
viewType
);
this
.
_awaitingRevival
=
this
.
_awaitingRevival
.
filter
(
x
=>
x
.
input
.
viewType
!==
viewType
);
const
toRevive
=
this
.
_awaitingRevival
.
filter
(
x
=>
reviver
.
canRevive
(
x
.
input
)
);
this
.
_awaitingRevival
=
this
.
_awaitingRevival
.
filter
(
x
=>
!
reviver
.
canRevive
(
x
.
input
)
);
for
(
const
input
of
toRevive
)
{
reviver
.
reviveWebview
(
input
.
input
).
then
(()
=>
input
.
resolve
(
undefined
));
...
...
@@ -184,24 +181,19 @@ export class WebviewEditorService implements IWebviewEditorService {
webview
:
WebviewEditorInput
):
boolean
{
const
viewType
=
webview
.
viewType
;
const
reviver
s
=
this
.
_revivers
.
get
(
viewType
);
return
!!
reviver
s
&&
revivers
.
some
(
reviver
=>
reviver
.
canRevive
(
webview
)
);
const
reviver
=
this
.
_revivers
.
get
(
viewType
);
return
!!
reviver
&&
reviver
.
canRevive
(
webview
);
}
private
async
tryRevive
(
webview
:
WebviewEditorInput
):
Promise
<
boolean
>
{
const
reviver
s
=
this
.
_revivers
.
get
(
webview
.
viewType
);
if
(
!
reviver
s
)
{
const
reviver
=
this
.
_revivers
.
get
(
webview
.
viewType
);
if
(
!
reviver
||
!
reviver
.
canRevive
(
webview
)
)
{
return
false
;
}
for
(
const
reviver
of
revivers
)
{
if
(
reviver
.
canRevive
(
webview
))
{
await
reviver
.
reviveWebview
(
webview
);
return
true
;
}
}
return
false
;
await
reviver
.
reviveWebview
(
webview
);
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录