Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e5d36bb1
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,发现更多精彩内容 >>
提交
e5d36bb1
编写于
10月 16, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move onMissingCsp onto base
上级
7f55f73e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
53 deletion
+59
-53
src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts
...s/workbench/contrib/webview/browser/baseWebviewElement.ts
+50
-7
src/vs/workbench/contrib/webview/browser/webviewElement.ts
src/vs/workbench/contrib/webview/browser/webviewElement.ts
+6
-9
src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts
...kbench/contrib/webview/electron-browser/webviewElement.ts
+3
-37
未找到文件。
src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts
浏览文件 @
e5d36bb1
...
...
@@ -4,8 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import
{
addClass
}
from
'
vs/base/browser/dom
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
WebviewOptions
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
WebviewExtensionDescription
,
WebviewOptions
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
export
const
enum
WebviewMessageChannels
{
onmessage
=
'
onmessage
'
,
...
...
@@ -27,7 +31,13 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
private
readonly
_ready
:
Promise
<
void
>
;
constructor
(
options
:
WebviewOptions
)
{
public
extension
:
WebviewExtensionDescription
|
undefined
;
constructor
(
options
:
WebviewOptions
,
@
ITelemetryService
private
readonly
_telemetryService
:
ITelemetryService
,
@
IEnvironmentService
private
readonly
_environementService
:
IEnvironmentService
,
)
{
super
();
this
.
_element
=
this
.
createElement
(
options
);
...
...
@@ -41,12 +51,11 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
resolve
();
}));
});
}
protected
abstract
createElement
(
options
:
WebviewOptions
):
T
;
protected
abstract
on
<
T
=
unknown
>
(
channel
:
WebviewMessageChannels
,
handler
:
(
data
:
T
)
=>
void
):
IDisposable
;
protected
abstract
postMessage
(
channel
:
string
,
data
?:
any
):
void
;
this
.
_register
(
this
.
on
(
'
no-csp-found
'
,
()
=>
{
this
.
handleNoCspFound
();
}))
;
}
dispose
():
void
{
if
(
this
.
element
)
{
...
...
@@ -57,9 +66,43 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
super
.
dispose
();
}
private
readonly
_onMissingCsp
=
this
.
_register
(
new
Emitter
<
ExtensionIdentifier
>
());
public
readonly
onMissingCsp
=
this
.
_onMissingCsp
.
event
;
protected
_send
(
channel
:
string
,
data
?:
any
):
void
{
this
.
_ready
.
then
(()
=>
this
.
postMessage
(
channel
,
data
))
.
catch
(
err
=>
console
.
error
(
err
));
}
protected
abstract
createElement
(
options
:
WebviewOptions
):
T
;
protected
abstract
on
<
T
=
unknown
>
(
channel
:
string
,
handler
:
(
data
:
T
)
=>
void
):
IDisposable
;
protected
abstract
postMessage
(
channel
:
string
,
data
?:
any
):
void
;
private
_hasAlertedAboutMissingCsp
=
false
;
private
handleNoCspFound
():
void
{
if
(
this
.
_hasAlertedAboutMissingCsp
)
{
return
;
}
this
.
_hasAlertedAboutMissingCsp
=
true
;
if
(
this
.
extension
&&
this
.
extension
.
id
)
{
if
(
this
.
_environementService
.
isExtensionDevelopment
)
{
this
.
_onMissingCsp
.
fire
(
this
.
extension
.
id
);
}
type
TelemetryClassification
=
{
extension
?:
{
classification
:
'
SystemMetaData
'
,
purpose
:
'
FeatureInsight
'
;
};
};
type
TelemetryData
=
{
extension
?:
string
,
};
this
.
_telemetryService
.
publicLog2
<
TelemetryData
,
TelemetryClassification
>
(
'
webviewMissingCsp
'
,
{
extension
:
this
.
extension
.
id
.
value
});
}
}
}
src/vs/workbench/contrib/webview/browser/webviewElement.ts
浏览文件 @
e5d36bb1
...
...
@@ -9,16 +9,17 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
isWeb
}
from
'
vs/base/common/platform
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
ITunnelService
}
from
'
vs/platform/remote/common/tunnel
'
;
import
{
Webview
,
WebviewContentOptions
,
WebviewOptions
,
WebviewExtensionDescription
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
Webview
,
WebviewContentOptions
,
WebviewOptions
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
areWebviewInputOptionsEqual
}
from
'
vs/workbench/contrib/webview/browser/webviewWorkbenchService
'
;
import
{
WebviewPortMappingManager
}
from
'
vs/workbench/contrib/webview/common/portMapping
'
;
import
{
loadLocalResource
}
from
'
vs/workbench/contrib/webview/common/resourceLoader
'
;
import
{
WebviewThemeDataProvider
}
from
'
vs/workbench/contrib/webview/common/themeing
'
;
import
{
IWorkbenchEnvironmentService
}
from
'
vs/workbench/services/environment/common/environmentService
'
;
import
{
BaseWebview
,
WebviewMessageChannels
}
from
'
vs/workbench/contrib/webview/browser/baseWebviewElement
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
interface
WebviewContent
{
readonly
html
:
string
;
...
...
@@ -32,8 +33,6 @@ export class IFrameWebview extends BaseWebview<HTMLIFrameElement> implements Web
private
readonly
_portMappingManager
:
WebviewPortMappingManager
;
public
extension
:
WebviewExtensionDescription
|
undefined
;
constructor
(
private
readonly
id
:
string
,
options
:
WebviewOptions
,
...
...
@@ -43,8 +42,10 @@ export class IFrameWebview extends BaseWebview<HTMLIFrameElement> implements Web
@
IWorkbenchEnvironmentService
private
readonly
environmentService
:
IWorkbenchEnvironmentService
,
@
IFileService
private
readonly
fileService
:
IFileService
,
@
IConfigurationService
private
readonly
_configurationService
:
IConfigurationService
,
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IEnvironmentService
environementService
:
IEnvironmentService
,
)
{
super
(
options
);
super
(
options
,
telemetryService
,
environementService
);
if
(
!
this
.
useExternalEndpoint
&&
(
!
environmentService
.
options
||
typeof
environmentService
.
webviewExternalEndpoint
!==
'
string
'
))
{
throw
new
Error
(
'
To use iframe based webviews, you must configure `environmentService.webviewExternalEndpoint`
'
);
}
...
...
@@ -197,10 +198,6 @@ export class IFrameWebview extends BaseWebview<HTMLIFrameElement> implements Web
private
readonly
_onMessage
=
this
.
_register
(
new
Emitter
<
any
>
());
public
readonly
onMessage
=
this
.
_onMessage
.
event
;
private
readonly
_onMissingCsp
=
this
.
_register
(
new
Emitter
<
ExtensionIdentifier
>
());
public
readonly
onMissingCsp
=
this
.
_onMissingCsp
.
event
;
sendMessage
(
data
:
any
):
void
{
this
.
_send
(
'
message
'
,
data
);
}
...
...
src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts
浏览文件 @
e5d36bb1
...
...
@@ -12,7 +12,6 @@ import { isMacintosh } from 'vs/base/common/platform';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ITunnelService
}
from
'
vs/platform/remote/common/tunnel
'
;
...
...
@@ -253,10 +252,10 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IFileService
fileService
:
IFileService
,
@
ITunnelService
tunnelService
:
ITunnelService
,
@
ITelemetryService
private
readonly
_
telemetryService
:
ITelemetryService
,
@
IEnvironmentService
private
readonly
_
environementService
:
IEnvironmentService
,
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IEnvironmentService
environementService
:
IEnvironmentService
,
)
{
super
(
options
);
super
(
options
,
telemetryService
,
environementService
);
this
.
content
=
{
html
:
''
,
...
...
@@ -351,10 +350,6 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
this
.
handleFocusChange
(
false
);
}));
this
.
_register
(
this
.
on
(
'
no-csp-found
'
,
()
=>
{
this
.
handleNoCspFound
();
}));
this
.
_register
(
addDisposableListener
(
this
.
element
!
,
'
devtools-opened
'
,
()
=>
{
this
.
_send
(
'
devtools-opened
'
);
}));
...
...
@@ -411,9 +406,6 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
private
readonly
_onMessage
=
this
.
_register
(
new
Emitter
<
any
>
());
public
readonly
onMessage
=
this
.
_onMessage
.
event
;
private
readonly
_onMissingCsp
=
this
.
_register
(
new
Emitter
<
ExtensionIdentifier
>
());
public
readonly
onMissingCsp
=
this
.
_onMissingCsp
.
event
;
protected
postMessage
(
channel
:
string
,
data
?:
any
):
void
{
if
(
this
.
element
)
{
this
.
element
.
send
(
channel
,
data
);
...
...
@@ -484,32 +476,6 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
}
}
private
_hasAlertedAboutMissingCsp
=
false
;
private
handleNoCspFound
():
void
{
if
(
this
.
_hasAlertedAboutMissingCsp
)
{
return
;
}
this
.
_hasAlertedAboutMissingCsp
=
true
;
if
(
this
.
extension
&&
this
.
extension
.
id
)
{
if
(
this
.
_environementService
.
isExtensionDevelopment
)
{
this
.
_onMissingCsp
.
fire
(
this
.
extension
.
id
);
}
type
TelemetryClassification
=
{
extension
?:
{
classification
:
'
SystemMetaData
'
,
purpose
:
'
FeatureInsight
'
;
};
};
type
TelemetryData
=
{
extension
?:
string
,
};
this
.
_telemetryService
.
publicLog2
<
TelemetryData
,
TelemetryClassification
>
(
'
webviewMissingCsp
'
,
{
extension
:
this
.
extension
.
id
.
value
});
}
}
public
sendMessage
(
data
:
any
):
void
{
this
.
_send
(
'
message
'
,
data
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录