Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
51e1b13e
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51e1b13e
编写于
4月 02, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split webview's pre for electron and browser
上级
53349426
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
160 addition
and
150 deletion
+160
-150
build/gulpfile.vscode.js
build/gulpfile.vscode.js
+2
-1
src/vs/workbench/contrib/webview/browser/pre/main.js
src/vs/workbench/contrib/webview/browser/pre/main.js
+114
-148
src/vs/workbench/contrib/webview/electron-browser/pre/electron-index.js
...ch/contrib/webview/electron-browser/pre/electron-index.js
+43
-0
src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts
...kbench/contrib/webview/electron-browser/webviewElement.ts
+1
-1
未找到文件。
build/gulpfile.vscode.js
浏览文件 @
51e1b13e
...
...
@@ -70,7 +70,8 @@ const vscodeResources = [
'
out-build/vs/workbench/browser/media/*-theme.css
'
,
'
out-build/vs/workbench/contrib/debug/**/*.json
'
,
'
out-build/vs/workbench/contrib/externalTerminal/**/*.scpt
'
,
'
out-build/vs/workbench/contrib/webview/electron-browser/webview-pre.js
'
,
'
out-build/vs/workbench/contrib/webview/browser/pre/*.js
'
,
'
out-build/vs/workbench/contrib/webview/electron-browser/pre/*.js
'
,
'
out-build/vs/**/markdown.css
'
,
'
out-build/vs/workbench/contrib/tasks/**/*.json
'
,
'
out-build/vs/workbench/contrib/welcome/walkThrough/**/*.md
'
,
...
...
src/vs/workbench/contrib/webview/
electron-browser/webview-pre
.js
→
src/vs/workbench/contrib/webview/
browser/pre/main
.js
浏览文件 @
51e1b13e
...
...
@@ -3,72 +3,104 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
(
function
()
{
'
use strict
'
;
// @ts-ignore
const
ipcRenderer
=
require
(
'
electron
'
).
ipcRenderer
;
/**
* @param {string} channel
* @param {*} data
*/
const
postMessageToHost
=
(
channel
,
data
)
=>
{
ipcRenderer
.
sendToHost
(
channel
,
data
);
};
/**
* @param {string} channel
* @param {*} handler
*/
const
onHostMessage
=
(
channel
,
handler
)
=>
{
ipcRenderer
.
on
(
channel
,
handler
);
};
const
registerVscodeResourceScheme
=
(
function
()
{
let
hasRegistered
=
false
;
return
()
=>
{
if
(
hasRegistered
)
{
return
;
}
hasRegistered
=
true
;
// @ts-ignore
require
(
'
electron
'
).
webFrame
.
registerURLSchemeAsPrivileged
(
'
vscode-resource
'
,
{
secure
:
true
,
bypassCSP
:
false
,
allowServiceWorkers
:
false
,
supportFetchAPI
:
true
,
corsEnabled
:
true
});
};
}());
/**
* Use polling to track focus of main webview and iframes within the webview
*
* @param {Object} handlers
* @param {() => void} handlers.onFocus
* @param {() => void} handlers.onBlur
*/
const
trackFocus
=
({
onFocus
,
onBlur
})
=>
{
const
interval
=
50
;
let
isFocused
=
document
.
hasFocus
();
setInterval
(()
=>
{
const
isCurrentlyFocused
=
document
.
hasFocus
();
if
(
isCurrentlyFocused
===
isFocused
)
{
return
;
}
isFocused
=
isCurrentlyFocused
;
if
(
isCurrentlyFocused
)
{
onFocus
();
}
else
{
onBlur
();
}
},
interval
);
};
'
use strict
'
;
/**
* Use polling to track focus of main webview and iframes within the webview
*
* @param {Object} handlers
* @param {() => void} handlers.onFocus
* @param {() => void} handlers.onBlur
*/
const
trackFocus
=
({
onFocus
,
onBlur
})
=>
{
const
interval
=
50
;
let
isFocused
=
document
.
hasFocus
();
setInterval
(()
=>
{
const
isCurrentlyFocused
=
document
.
hasFocus
();
if
(
isCurrentlyFocused
===
isFocused
)
{
return
;
}
isFocused
=
isCurrentlyFocused
;
if
(
isCurrentlyFocused
)
{
onFocus
();
}
else
{
onBlur
();
}
},
interval
);
};
const
getActiveFrame
=
()
=>
{
return
/** @type {HTMLIFrameElement} */
(
document
.
getElementById
(
'
active-frame
'
));
};
const
getPendingFrame
=
()
=>
{
return
/** @type {HTMLIFrameElement} */
(
document
.
getElementById
(
'
pending-frame
'
));
};
const
defaultCssRules
=
`
body {
background-color: var(--vscode-editor-background);
color: var(--vscode-editor-foreground);
font-family: var(--vscode-editor-font-family);
font-weight: var(--vscode-editor-font-weight);
font-size: var(--vscode-editor-font-size);
margin: 0;
padding: 0 20px;
}
img {
max-width: 100%;
max-height: 100%;
}
a {
color: var(--vscode-textLink-foreground);
}
a:hover {
color: var(--vscode-textLink-activeForeground);
}
a:focus,
input:focus,
select:focus,
textarea:focus {
outline: 1px solid -webkit-focus-ring-color;
outline-offset: -1px;
}
code {
color: var(--vscode-textPreformat-foreground);
}
blockquote {
background: var(--vscode-textBlockQuote-background);
border-color: var(--vscode-textBlockQuote-border);
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-thumb {
background-color: var(--vscode-scrollbarSlider-background);
}
::-webkit-scrollbar-thumb:hover {
background-color: var(--vscode-scrollbarSlider-hoverBackground);
}
::-webkit-scrollbar-thumb:active {
background-color: var(--vscode-scrollbarSlider-activeBackground);
}`
;
/**
* @typedef {{ postMessage: (channel: string, data?: any) => void, onMessage: (channel: string, handler: any) => void }} HostCommunications
*/
/**
* @param {HostCommunications} host
*/
module
.
exports
=
function
createWebviewManager
(
host
)
{
// state
let
firstLoad
=
true
;
let
loadTimeout
;
...
...
@@ -98,14 +130,6 @@
}
};
const
getActiveFrame
=
()
=>
{
return
/** @type {HTMLIFrameElement} */
(
document
.
getElementById
(
'
active-frame
'
));
};
const
getPendingFrame
=
()
=>
{
return
/** @type {HTMLIFrameElement} */
(
document
.
getElementById
(
'
pending-frame
'
));
};
/**
* @param {MouseEvent} event
*/
...
...
@@ -127,7 +151,7 @@
scrollTarget
.
scrollIntoView
();
}
}
else
{
postMessageToHost
(
'
did-click-link
'
,
node
.
href
);
host
.
postMessage
(
'
did-click-link
'
,
node
.
href
);
}
event
.
preventDefault
();
break
;
...
...
@@ -140,7 +164,7 @@
* @param {KeyboardEvent} e
*/
const
handleInnerKeydown
=
(
e
)
=>
{
postMessageToHost
(
'
did-keydown
'
,
{
host
.
postMessage
(
'
did-keydown
'
,
{
key
:
e
.
key
,
keyCode
:
e
.
keyCode
,
code
:
e
.
code
,
...
...
@@ -153,7 +177,7 @@
};
const
onMessage
=
(
message
)
=>
{
postMessageToHost
(
message
.
data
.
command
,
message
.
data
.
data
);
host
.
postMessage
(
message
.
data
.
command
,
message
.
data
.
data
);
};
let
isHandlingScroll
=
false
;
...
...
@@ -170,7 +194,7 @@
isHandlingScroll
=
true
;
window
.
requestAnimationFrame
(()
=>
{
try
{
postMessageToHost
(
'
did-scroll
'
,
progress
);
host
.
postMessage
(
'
did-scroll
'
,
progress
);
}
catch
(
e
)
{
// noop
}
...
...
@@ -179,7 +203,7 @@
};
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
onHost
Message
(
'
styles
'
,
(
_event
,
variables
,
activeTheme
)
=>
{
host
.
on
Message
(
'
styles
'
,
(
_event
,
variables
,
activeTheme
)
=>
{
initData
.
styles
=
variables
;
initData
.
activeTheme
=
activeTheme
;
...
...
@@ -192,7 +216,7 @@
});
// propagate focus
onHost
Message
(
'
focus
'
,
()
=>
{
host
.
on
Message
(
'
focus
'
,
()
=>
{
const
target
=
getActiveFrame
();
if
(
target
)
{
target
.
contentWindow
.
focus
();
...
...
@@ -200,11 +224,9 @@
});
// update iframe-contents
onHost
Message
(
'
content
'
,
(
_event
,
data
)
=>
{
host
.
on
Message
(
'
content
'
,
(
_event
,
data
)
=>
{
const
options
=
data
.
options
;
registerVscodeResourceScheme
();
const
text
=
data
.
contents
;
const
newDocument
=
new
DOMParser
().
parseFromString
(
text
,
'
text/html
'
);
...
...
@@ -304,7 +326,7 @@
newFrame
.
contentWindow
.
addEventListener
(
'
keydown
'
,
handleInnerKeydown
);
newFrame
.
contentWindow
.
onbeforeunload
=
()
=>
{
if
(
isInDevelopmentMode
)
{
// Allow reloads while developing a webview
postMessageToHost
(
'
do-reload
'
);
host
.
postMessage
(
'
do-reload
'
);
return
false
;
}
...
...
@@ -366,11 +388,11 @@
newFrame
.
contentDocument
.
write
(
newDocument
.
documentElement
.
innerHTML
);
newFrame
.
contentDocument
.
close
();
postMessageToHost
(
'
did-set-content
'
);
host
.
postMessage
(
'
did-set-content
'
,
undefined
);
});
// Forward message to the embedded iframe
onHost
Message
(
'
message
'
,
(
_event
,
data
)
=>
{
host
.
on
Message
(
'
message
'
,
(
_event
,
data
)
=>
{
const
pending
=
getPendingFrame
();
if
(
!
pending
)
{
const
target
=
getActiveFrame
();
...
...
@@ -382,79 +404,23 @@
pendingMessages
.
push
(
data
);
});
onHost
Message
(
'
initial-scroll-position
'
,
(
_event
,
progress
)
=>
{
host
.
on
Message
(
'
initial-scroll-position
'
,
(
_event
,
progress
)
=>
{
initData
.
initialScrollProgress
=
progress
;
});
onHost
Message
(
'
devtools-opened
'
,
()
=>
{
host
.
on
Message
(
'
devtools-opened
'
,
()
=>
{
isInDevelopmentMode
=
true
;
});
trackFocus
({
onFocus
:
()
=>
postMessageToHost
(
'
did-focus
'
),
onBlur
:
()
=>
postMessageToHost
(
'
did-blur
'
)
onFocus
:
()
=>
host
.
postMessage
(
'
did-focus
'
),
onBlur
:
()
=>
host
.
postMessage
(
'
did-blur
'
)
});
// Forward messages from the embedded iframe
window
.
onmessage
=
onMessage
;
// signal ready
postMessageToHost
(
'
webview-ready
'
,
process
.
pid
);
host
.
postMessage
(
'
webview-ready
'
,
process
.
pid
);
});
const
defaultCssRules
=
`
body {
background-color: var(--vscode-editor-background);
color: var(--vscode-editor-foreground);
font-family: var(--vscode-editor-font-family);
font-weight: var(--vscode-editor-font-weight);
font-size: var(--vscode-editor-font-size);
margin: 0;
padding: 0 20px;
}
img {
max-width: 100%;
max-height: 100%;
}
a {
color: var(--vscode-textLink-foreground);
}
a:hover {
color: var(--vscode-textLink-activeForeground);
}
a:focus,
input:focus,
select:focus,
textarea:focus {
outline: 1px solid -webkit-focus-ring-color;
outline-offset: -1px;
}
code {
color: var(--vscode-textPreformat-foreground);
}
blockquote {
background: var(--vscode-textBlockQuote-background);
border-color: var(--vscode-textBlockQuote-border);
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-thumb {
background-color: var(--vscode-scrollbarSlider-background);
}
::-webkit-scrollbar-thumb:hover {
background-color: var(--vscode-scrollbarSlider-hoverBackground);
}
::-webkit-scrollbar-thumb:active {
background-color: var(--vscode-scrollbarSlider-activeBackground);
}`
;
}());
\ No newline at end of file
};
src/vs/workbench/contrib/webview/electron-browser/pre/electron-index.js
0 → 100644
浏览文件 @
51e1b13e
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
(
function
()
{
'
use strict
'
;
const
registerVscodeResourceScheme
=
(
function
()
{
let
hasRegistered
=
false
;
return
()
=>
{
if
(
hasRegistered
)
{
return
;
}
hasRegistered
=
true
;
// @ts-ignore
require
(
'
electron
'
).
webFrame
.
registerURLSchemeAsPrivileged
(
'
vscode-resource
'
,
{
secure
:
true
,
bypassCSP
:
false
,
allowServiceWorkers
:
false
,
supportFetchAPI
:
true
,
corsEnabled
:
true
});
};
}());
// @ts-ignore
const
ipcRenderer
=
require
(
'
electron
'
).
ipcRenderer
;
require
(
'
../../browser/pre/main
'
)({
postMessage
:
(
channel
,
data
)
=>
{
ipcRenderer
.
sendToHost
(
channel
,
data
);
},
onMessage
:
(
channel
,
handler
)
=>
{
ipcRenderer
.
on
(
channel
,
handler
);
}
});
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
registerVscodeResourceScheme
();
});
}());
\ No newline at end of file
src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts
浏览文件 @
51e1b13e
...
...
@@ -326,7 +326,7 @@ export class WebviewElement extends Disposable implements Webview {
this
.
_webview
.
style
.
height
=
'
0
'
;
this
.
_webview
.
style
.
outline
=
'
0
'
;
this
.
_webview
.
preload
=
require
.
toUrl
(
'
./
webview-pre
.js
'
);
this
.
_webview
.
preload
=
require
.
toUrl
(
'
./
pre/electron-index
.js
'
);
this
.
_webview
.
src
=
'
data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%0D%0A%3Chtml%20lang%3D%22en%22%20style%3D%22width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3Chead%3E%0D%0A%09%3Ctitle%3EVirtual%20Document%3C%2Ftitle%3E%0D%0A%3C%2Fhead%3E%0D%0A%3Cbody%20style%3D%22margin%3A%200%3B%20overflow%3A%20hidden%3B%20width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E
'
;
this
.
_ready
=
new
Promise
(
resolve
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录