| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  | import { EventEmitter } from 'events' | 
					
						
							|  |  |  | import { deprecate } from 'electron' | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  | const binding = process.atomBinding('web_frame') | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  | class WebFrame extends EventEmitter { | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   constructor (public context: Window) { | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |     super() | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |     // Lots of webview would subscribe to webFrame's events.
 | 
					
						
							|  |  |  |     this.setMaxListeners(0) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   findFrameByRoutingId (...args: Array<any>) { | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |     return getWebFrame(binding._findFrameByRoutingId(this.context, ...args)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   getFrameForSelector (...args: Array<any>) { | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |     return getWebFrame(binding._getFrameForSelector(this.context, ...args)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   findFrameByName (...args: Array<any>) { | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |     return getWebFrame(binding._findFrameByName(this.context, ...args)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get opener () { | 
					
						
							|  |  |  |     return getWebFrame(binding._getOpener(this.context)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get parent () { | 
					
						
							|  |  |  |     return getWebFrame(binding._getParent(this.context)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get top () { | 
					
						
							|  |  |  |     return getWebFrame(binding._getTop(this.context)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get firstChild () { | 
					
						
							|  |  |  |     return getWebFrame(binding._getFirstChild(this.context)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get nextSibling () { | 
					
						
							|  |  |  |     return getWebFrame(binding._getNextSibling(this.context)) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get routingId () { | 
					
						
							|  |  |  |     return binding._getRoutingId(this.context) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Deprecations
 | 
					
						
							|  |  |  |   // TODO(nitsakh): Remove in 6.0
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   setIsolatedWorldSecurityOrigin (worldId: number, securityOrigin: string) { | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  |     deprecate.warn('webFrame.setIsolatedWorldSecurityOrigin', 'webFrame.setIsolatedWorldInfo') | 
					
						
							| 
									
										
										
										
											2019-01-22 02:15:15 +05:30
										 |  |  |     binding.setIsolatedWorldInfo(this.context, worldId, { securityOrigin }) | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   setIsolatedWorldContentSecurityPolicy (worldId: number, csp: string) { | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  |     deprecate.warn('webFrame.setIsolatedWorldContentSecurityPolicy', 'webFrame.setIsolatedWorldInfo') | 
					
						
							| 
									
										
										
										
											2019-01-22 02:15:15 +05:30
										 |  |  |     binding.setIsolatedWorldInfo(this.context, worldId, { | 
					
						
							|  |  |  |       securityOrigin: window.location.origin, | 
					
						
							|  |  |  |       csp | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   setIsolatedWorldHumanReadableName (worldId: number, name: string) { | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  |     deprecate.warn('webFrame.setIsolatedWorldHumanReadableName', 'webFrame.setIsolatedWorldInfo') | 
					
						
							| 
									
										
										
										
											2019-01-22 02:15:15 +05:30
										 |  |  |     binding.setIsolatedWorldInfo(this.context, worldId, { name }) | 
					
						
							| 
									
										
										
										
											2019-02-13 10:05:28 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Populate the methods.
 | 
					
						
							|  |  |  | for (const name in binding) { | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  |   if (!name.startsWith('_')) { // some methods are manually populated above
 | 
					
						
							|  |  |  |     // TODO(felixrieseberg): Once we can type web_frame natives, we could
 | 
					
						
							|  |  |  |     // use a neat `keyof` here
 | 
					
						
							|  |  |  |     (WebFrame as any).prototype[name] = function (...args: Array<any>) { | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |       return binding[name](this.context, ...args) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Helper to return WebFrame or null depending on context.
 | 
					
						
							|  |  |  | // TODO(zcbenz): Consider returning same WebFrame for the same frame.
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  | function getWebFrame (context: Window) { | 
					
						
							| 
									
										
										
										
											2019-02-09 06:38:31 +09:00
										 |  |  |   return context ? new WebFrame(context) : null | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:39:04 -08:00
										 |  |  | const _webFrame = new WebFrame(window) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default _webFrame |