@@ -5,6 +5,7 @@ import { parseWebViewWebPreferences } from '@electron/internal/common/parse-feat
5
5
import { syncMethods , asyncMethods , properties } from '@electron/internal/common/web-view-methods' ;
6
6
import { webViewEvents } from '@electron/internal/common/web-view-events' ;
7
7
import { serialize } from '@electron/internal/common/type-utils' ;
8
+ import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages' ;
8
9
9
10
interface GuestInstance {
10
11
elementInstanceId ?: number ;
@@ -83,7 +84,7 @@ const createGuest = function (embedder: Electron.WebContents, params: Record<str
83
84
// Dispatch events to embedder.
84
85
const fn = function ( event : string ) {
85
86
guest . on ( event as any , function ( _ , ...args : any [ ] ) {
86
- sendToEmbedder ( 'ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT' , event , ...args ) ;
87
+ sendToEmbedder ( IPC_MESSAGES . GUEST_VIEW_INTERNAL_DISPATCH_EVENT , event , ...args ) ;
87
88
} ) ;
88
89
} ;
89
90
for ( const event of supportedWebViewEvents ) {
@@ -93,22 +94,22 @@ const createGuest = function (embedder: Electron.WebContents, params: Record<str
93
94
}
94
95
95
96
guest . on ( 'new-window' , function ( event , url , frameName , disposition , options , additionalFeatures , referrer ) {
96
- sendToEmbedder ( 'ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT' , 'new-window' , url ,
97
+ sendToEmbedder ( IPC_MESSAGES . GUEST_VIEW_INTERNAL_DISPATCH_EVENT , 'new-window' , url ,
97
98
frameName , disposition , sanitizeOptionsForGuest ( options ) ,
98
99
additionalFeatures , referrer ) ;
99
100
} ) ;
100
101
101
102
// Dispatch guest's IPC messages to embedder.
102
103
guest . on ( 'ipc-message-host' as any , function ( _ : Electron . Event , channel : string , args : any [ ] ) {
103
- sendToEmbedder ( 'ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE' , channel , ...args ) ;
104
+ sendToEmbedder ( IPC_MESSAGES . GUEST_VIEW_INTERNAL_IPC_MESSAGE , channel , ...args ) ;
104
105
} ) ;
105
106
106
107
// Notify guest of embedder window visibility when it is ready
107
108
// FIXME Remove once https://github.com/electron/electron/issues/6828 is fixed
108
109
guest . on ( 'dom-ready' , function ( ) {
109
110
const guestInstance = guestInstances [ guestInstanceId ] ;
110
111
if ( guestInstance != null && guestInstance . visibilityState != null ) {
111
- guest . _sendInternal ( 'ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE' , guestInstance . visibilityState ) ;
112
+ guest . _sendInternal ( IPC_MESSAGES . GUEST_INSTANCE_VISIBILITY_CHANGE , guestInstance . visibilityState ) ;
112
113
}
113
114
} ) ;
114
115
@@ -152,7 +153,7 @@ const attachGuest = function (event: Electron.IpcMainInvokeEvent,
152
153
// Remove guest from embedder if moving across web views
153
154
if ( guest . viewInstanceId !== params . instanceId ) {
154
155
webViewManager . removeGuest ( guestInstance . embedder , guestInstanceId ) ;
155
- guestInstance . embedder . _sendInternal ( `ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST -${ guest . viewInstanceId } ` ) ;
156
+ guestInstance . embedder . _sendInternal ( `${ IPC_MESSAGES . GUEST_VIEW_INTERNAL_DESTROY_GUEST } -${ guest . viewInstanceId } ` ) ;
156
157
}
157
158
}
158
159
@@ -253,7 +254,7 @@ const watchEmbedder = function (embedder: Electron.WebContents) {
253
254
const guestInstance = guestInstances [ guestInstanceId ] ;
254
255
guestInstance . visibilityState = visibilityState ;
255
256
if ( guestInstance . embedder === embedder ) {
256
- guestInstance . guest . _sendInternal ( 'ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE' , visibilityState ) ;
257
+ guestInstance . guest . _sendInternal ( IPC_MESSAGES . GUEST_INSTANCE_VISIBILITY_CHANGE , visibilityState ) ;
257
258
}
258
259
}
259
260
} ;
@@ -305,24 +306,24 @@ const handleMessageSync = function (channel: string, handler: (event: ElectronIn
305
306
ipcMainUtils . handleSync ( channel , makeSafeHandler ( channel , handler ) ) ;
306
307
} ;
307
308
308
- handleMessage ( 'ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST' , function ( event , params ) {
309
+ handleMessage ( IPC_MESSAGES . GUEST_VIEW_MANAGER_CREATE_GUEST , function ( event , params ) {
309
310
return createGuest ( event . sender , params ) ;
310
311
} ) ;
311
312
312
- handleMessage ( 'ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST' , function ( event , embedderFrameId : number , elementInstanceId : number , guestInstanceId : number , params ) {
313
+ handleMessage ( IPC_MESSAGES . GUEST_VIEW_MANAGER_ATTACH_GUEST , function ( event , embedderFrameId : number , elementInstanceId : number , guestInstanceId : number , params ) {
313
314
try {
314
315
attachGuest ( event , embedderFrameId , elementInstanceId , guestInstanceId , params ) ;
315
316
} catch ( error ) {
316
317
console . error ( `Guest attach failed: ${ error } ` ) ;
317
318
}
318
319
} ) ;
319
320
320
- handleMessageSync ( 'ELECTRON_GUEST_VIEW_MANAGER_DETACH_GUEST' , function ( event , guestInstanceId : number ) {
321
+ handleMessageSync ( IPC_MESSAGES . GUEST_VIEW_MANAGER_DETACH_GUEST , function ( event , guestInstanceId : number ) {
321
322
return detachGuest ( event . sender , guestInstanceId ) ;
322
323
} ) ;
323
324
324
325
// this message is sent by the actual <webview>
325
- ipcMainInternal . on ( 'ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE' , function ( event : ElectronInternal . IpcMainInternalEvent , focus : boolean , guestInstanceId : number ) {
326
+ ipcMainInternal . on ( IPC_MESSAGES . GUEST_VIEW_MANAGER_FOCUS_CHANGE , function ( event : ElectronInternal . IpcMainInternalEvent , focus : boolean , guestInstanceId : number ) {
326
327
const guest = getGuest ( guestInstanceId ) ;
327
328
if ( guest === event . sender ) {
328
329
event . sender . emit ( 'focus-change' , { } , focus , guestInstanceId ) ;
@@ -331,7 +332,7 @@ ipcMainInternal.on('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', function (event:
331
332
}
332
333
} ) ;
333
334
334
- handleMessage ( 'ELECTRON_GUEST_VIEW_MANAGER_CALL' , function ( event , guestInstanceId : number , method : string , args : any [ ] ) {
335
+ handleMessage ( IPC_MESSAGES . GUEST_VIEW_MANAGER_CALL , function ( event , guestInstanceId : number , method : string , args : any [ ] ) {
335
336
const guest = getGuestForWebContents ( guestInstanceId , event . sender ) ;
336
337
if ( ! asyncMethods . has ( method ) ) {
337
338
throw new Error ( `Invalid method: ${ method } ` ) ;
@@ -340,7 +341,7 @@ handleMessage('ELECTRON_GUEST_VIEW_MANAGER_CALL', function (event, guestInstance
340
341
return ( guest as any ) [ method ] ( ...args ) ;
341
342
} ) ;
342
343
343
- handleMessageSync ( 'ELECTRON_GUEST_VIEW_MANAGER_CALL' , function ( event , guestInstanceId : number , method : string , args : any [ ] ) {
344
+ handleMessageSync ( IPC_MESSAGES . GUEST_VIEW_MANAGER_CALL , function ( event , guestInstanceId : number , method : string , args : any [ ] ) {
344
345
const guest = getGuestForWebContents ( guestInstanceId , event . sender ) ;
345
346
if ( ! syncMethods . has ( method ) ) {
346
347
throw new Error ( `Invalid method: ${ method } ` ) ;
@@ -349,7 +350,7 @@ handleMessageSync('ELECTRON_GUEST_VIEW_MANAGER_CALL', function (event, guestInst
349
350
return ( guest as any ) [ method ] ( ...args ) ;
350
351
} ) ;
351
352
352
- handleMessageSync ( 'ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_GET' , function ( event , guestInstanceId : number , property : string ) {
353
+ handleMessageSync ( IPC_MESSAGES . GUEST_VIEW_MANAGER_PROPERTY_GET , function ( event , guestInstanceId : number , property : string ) {
353
354
const guest = getGuestForWebContents ( guestInstanceId , event . sender ) ;
354
355
if ( ! properties . has ( property ) ) {
355
356
throw new Error ( `Invalid property: ${ property } ` ) ;
@@ -358,7 +359,7 @@ handleMessageSync('ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_GET', function (event, g
358
359
return ( guest as any ) [ property ] ;
359
360
} ) ;
360
361
361
- handleMessageSync ( 'ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_SET' , function ( event , guestInstanceId : number , property : string , val : any ) {
362
+ handleMessageSync ( IPC_MESSAGES . GUEST_VIEW_MANAGER_PROPERTY_SET , function ( event , guestInstanceId : number , property : string , val : any ) {
362
363
const guest = getGuestForWebContents ( guestInstanceId , event . sender ) ;
363
364
if ( ! properties . has ( property ) ) {
364
365
throw new Error ( `Invalid property: ${ property } ` ) ;
@@ -367,7 +368,7 @@ handleMessageSync('ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_SET', function (event, g
367
368
( guest as any ) [ property ] = val ;
368
369
} ) ;
369
370
370
- handleMessage ( 'ELECTRON_GUEST_VIEW_MANAGER_CAPTURE_PAGE' , async function ( event , guestInstanceId : number , args : any [ ] ) {
371
+ handleMessage ( IPC_MESSAGES . GUEST_VIEW_MANAGER_CAPTURE_PAGE , async function ( event , guestInstanceId : number , args : any [ ] ) {
371
372
const guest = getGuestForWebContents ( guestInstanceId , event . sender ) ;
372
373
373
374
return serialize ( await guest . capturePage ( ...args ) ) ;
0 commit comments