Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
89aa8bf1
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,发现更多精彩内容 >>
提交
89aa8bf1
编写于
6月 28, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moving some electron specific webview js back into electron
上级
c9c29f3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
51 deletion
+57
-51
src/vs/workbench/contrib/webview/browser/pre/main.js
src/vs/workbench/contrib/webview/browser/pre/main.js
+13
-49
src/vs/workbench/contrib/webview/electron-browser/pre/electron-index.js
...ch/contrib/webview/electron-browser/pre/electron-index.js
+44
-2
未找到文件。
src/vs/workbench/contrib/webview/browser/pre/main.js
浏览文件 @
89aa8bf1
...
...
@@ -3,6 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
/**
* @typedef {{
* postMessage: (channel: string, data?: any) => void,
* onMessage: (channel: string, handler: any) => void,
* focusIframeOnCreate?: boolean,
* ready?: Promise<void>,
* onIframeLoaded: (iframe: HTMLIFrameElement) => void
* }} WebviewHost
*/
(
function
()
{
'
use strict
'
;
...
...
@@ -134,23 +145,13 @@
}
/**
* @typedef {{
* postMessage: (channel: string, data?: any) => void,
* onMessage: (channel: string, handler: any) => void,
* focusIframeOnCreate?: boolean,
* ready?: Promise<void>
* }} HostCommunications
*/
/**
* @param {HostCommunications} host
* @param {WebviewHost} host
*/
function
createWebviewManager
(
host
)
{
// state
let
firstLoad
=
true
;
let
loadTimeout
;
let
pendingMessages
=
[];
let
isInDevelopmentMode
=
false
;
const
initData
=
{
initialScrollProgress
:
undefined
...
...
@@ -442,44 +443,10 @@
}
});
if
(
!
FAKE_LOAD
)
{
newFrame
.
contentWindow
.
onbeforeunload
=
()
=>
{
if
(
isInDevelopmentMode
)
{
// Allow reloads while developing a webview
host
.
postMessage
(
'
do-reload
'
);
return
false
;
}
// Block navigation when not in development mode
console
.
log
(
'
prevented webview navigation
'
);
return
false
;
};
}
// Bubble out link clicks
newFrame
.
contentWindow
.
addEventListener
(
'
click
'
,
handleInnerClick
);
// Electron 4 eats mouseup events from inside webviews
// https://github.com/microsoft/vscode/issues/75090
// Try to fix this by rebroadcasting mouse moves and mouseups so that we can
// emulate these on the main window
if
(
!
FAKE_LOAD
)
{
let
isMouseDown
=
false
;
newFrame
.
contentWindow
.
addEventListener
(
'
mousedown
'
,
()
=>
{
isMouseDown
=
true
;
});
const
tryDispatchSyntheticMouseEvent
=
(
e
)
=>
{
if
(
!
isMouseDown
)
{
host
.
postMessage
(
'
synthetic-mouse-event
'
,
{
type
:
e
.
type
,
screenX
:
e
.
screenX
,
screenY
:
e
.
screenY
,
clientX
:
e
.
clientX
,
clientY
:
e
.
clientY
});
}
};
newFrame
.
contentWindow
.
addEventListener
(
'
mouseup
'
,
e
=>
{
tryDispatchSyntheticMouseEvent
(
e
);
isMouseDown
=
false
;
});
newFrame
.
contentWindow
.
addEventListener
(
'
mousemove
'
,
tryDispatchSyntheticMouseEvent
);
}
host
.
onIframeLoaded
(
newFrame
);
}
if
(
!
FAKE_LOAD
)
{
...
...
@@ -511,9 +478,6 @@
initData
.
initialScrollProgress
=
progress
;
});
host
.
onMessage
(
'
devtools-opened
'
,
()
=>
{
isInDevelopmentMode
=
true
;
});
trackFocus
({
onFocus
:
()
=>
host
.
postMessage
(
'
did-focus
'
),
...
...
src/vs/workbench/contrib/webview/electron-browser/pre/electron-index.js
浏览文件 @
89aa8bf1
...
...
@@ -28,14 +28,54 @@
// @ts-ignore
const
ipcRenderer
=
require
(
'
electron
'
).
ipcRenderer
;
require
(
'
../../browser/pre/main
'
)({
let
isInDevelopmentMode
=
false
;
/**
* @type {import('../../browser/pre/main').WebviewHost}
*/
const
host
=
{
postMessage
:
(
channel
,
data
)
=>
{
ipcRenderer
.
sendToHost
(
channel
,
data
);
},
onMessage
:
(
channel
,
handler
)
=>
{
ipcRenderer
.
on
(
channel
,
handler
);
},
focusIframeOnCreate
:
true
focusIframeOnCreate
:
true
,
onIframeLoaded
:
(
newFrame
)
=>
{
newFrame
.
contentWindow
.
onbeforeunload
=
()
=>
{
if
(
isInDevelopmentMode
)
{
// Allow reloads while developing a webview
host
.
postMessage
(
'
do-reload
'
);
return
false
;
}
// Block navigation when not in development mode
console
.
log
(
'
prevented webview navigation
'
);
return
false
;
};
// Electron 4 eats mouseup events from inside webviews
// https://github.com/microsoft/vscode/issues/75090
// Try to fix this by rebroadcasting mouse moves and mouseups so that we can
// emulate these on the main window
let
isMouseDown
=
false
;
newFrame
.
contentWindow
.
addEventListener
(
'
mousedown
'
,
()
=>
{
isMouseDown
=
true
;
});
const
tryDispatchSyntheticMouseEvent
=
(
e
)
=>
{
if
(
!
isMouseDown
)
{
host
.
postMessage
(
'
synthetic-mouse-event
'
,
{
type
:
e
.
type
,
screenX
:
e
.
screenX
,
screenY
:
e
.
screenY
,
clientX
:
e
.
clientX
,
clientY
:
e
.
clientY
});
}
};
newFrame
.
contentWindow
.
addEventListener
(
'
mouseup
'
,
e
=>
{
tryDispatchSyntheticMouseEvent
(
e
);
isMouseDown
=
false
;
});
newFrame
.
contentWindow
.
addEventListener
(
'
mousemove
'
,
tryDispatchSyntheticMouseEvent
);
}
};
host
.
onMessage
(
'
devtools-opened
'
,
()
=>
{
isInDevelopmentMode
=
true
;
});
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
...
...
@@ -46,4 +86,6 @@
ipcRenderer
.
sendToHost
(
message
.
data
.
command
,
message
.
data
.
data
);
};
});
require
(
'
../../browser/pre/main
'
)(
host
);
}());
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录