1+ const BrowserView = electron . BrowserView
2+
13var viewMap = { } // id: view
24var viewStateMap = { } // id: view state
35
4- const BrowserView = electron . BrowserView
6+ var temporaryPopupViews = { } // id: view
7+
8+ const defaultViewWebPreferences = {
9+ nodeIntegration : false ,
10+ nodeIntegrationInSubFrames : true ,
11+ scrollBounce : true ,
12+ safeDialogs : true ,
13+ safeDialogsMessage : 'Prevent this page from creating additional dialogs' ,
14+ preload : __dirname + '/dist/preload.js' ,
15+ contextIsolation : true ,
16+ sandbox : true ,
17+ enableRemoteModule : false ,
18+ allowPopups : false ,
19+ // partition: partition || 'persist:webcontent',
20+ enableWebSQL : false ,
21+ autoplayPolicy : ( settings . get ( 'enableAutoplay' ) ? 'no-user-gesture-required' : 'user-gesture-required' )
22+ }
523
6- function createView ( id , webPreferencesString , boundsString , events ) {
7- const view = new BrowserView ( JSON . parse ( webPreferencesString ) )
24+ function createView ( existingViewId , id , webPreferencesString , boundsString , events ) {
25+ console . log ( existingViewId )
26+ let view
27+ if ( existingViewId ) {
28+ view = temporaryPopupViews [ existingViewId ]
29+ } else {
30+ view = new BrowserView ( { webPreferences : Object . assign ( { } , defaultViewWebPreferences , JSON . parse ( webPreferencesString ) ) } )
31+ }
832
933 events . forEach ( function ( event ) {
1034 view . webContents . on ( event , function ( e ) {
@@ -29,6 +53,7 @@ function createView (id, webPreferencesString, boundsString, events) {
2953 Workaround for crashes when calling preventDefault() on the new-window event (https://github.com/electron/electron/issues/23859#issuecomment-650270680)
3054 Calling preventDefault also prevents the new-window event from occurring, so create a new event here instead
3155 */
56+ /*
3257 view.webContents.on('-will-add-new-contents', function (e, url) {
3358 e.preventDefault()
3459 mainWindow.webContents.send('view-event', {
@@ -37,6 +62,30 @@ function createView (id, webPreferencesString, boundsString, events) {
3762 args: [url, '', 'new-window']
3863 })
3964 })
65+ */
66+
67+ view . webContents . removeAllListeners ( '-add-new-contents' )
68+
69+ view . webContents . on ( '-add-new-contents' , function ( e , webContents , disposition , _userGesture , _left , _top , _width , _height , url , frameName , referrer , rawFeatures , postData ) {
70+ console . log ( arguments )
71+ var view = new BrowserView ( { webPreferences : defaultViewWebPreferences , webContents : webContents } )
72+
73+ view . setBounds ( {
74+ x : 0 ,
75+ y : 0 ,
76+ width : 500 ,
77+ height : 500
78+ } )
79+
80+ var popupId = Math . random ( ) . toString ( )
81+ temporaryPopupViews [ popupId ] = view
82+
83+ mainWindow . webContents . send ( 'view-event' , {
84+ viewId : id ,
85+ event : 'did-create-popup' ,
86+ args : [ popupId ]
87+ } )
88+ } )
4089
4190 view . webContents . on ( 'ipc-message' , function ( e , channel , data ) {
4291 mainWindow . webContents . send ( 'view-ipc' , {
@@ -161,7 +210,7 @@ function getViewIDFromWebContents (contents) {
161210}
162211
163212ipc . on ( 'createView' , function ( e , args ) {
164- createView ( args . id , args . webPreferencesString , args . boundsString , args . events )
213+ createView ( args . existingViewId , args . id , args . webPreferencesString , args . boundsString , args . events )
165214} )
166215
167216ipc . on ( 'destroyView' , function ( e , id ) {
0 commit comments