2016-03-25 19:57:17 +00:00
|
|
|
'use strict'
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { EventEmitter } = require('events')
|
2019-02-08 21:38:31 +00:00
|
|
|
const binding = process.atomBinding('web_frame')
|
2019-02-13 18:05:28 +00:00
|
|
|
const { deprecate } = require('electron')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-02-08 21:38:31 +00:00
|
|
|
class WebFrame extends EventEmitter {
|
|
|
|
constructor (context) {
|
|
|
|
super()
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-02-08 21:38:31 +00:00
|
|
|
this.context = context
|
|
|
|
// Lots of webview would subscribe to webFrame's events.
|
|
|
|
this.setMaxListeners(0)
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-02-08 21:38:31 +00:00
|
|
|
findFrameByRoutingId (...args) {
|
|
|
|
return getWebFrame(binding._findFrameByRoutingId(this.context, ...args))
|
|
|
|
}
|
|
|
|
|
|
|
|
getFrameForSelector (...args) {
|
|
|
|
return getWebFrame(binding._getFrameForSelector(this.context, ...args))
|
|
|
|
}
|
|
|
|
|
|
|
|
findFrameByName (...args) {
|
|
|
|
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 18:05:28 +00:00
|
|
|
|
|
|
|
// Deprecations
|
|
|
|
// TODO(nitsakh): Remove in 6.0
|
|
|
|
setIsolatedWorldSecurityOrigin (worldId, securityOrigin) {
|
|
|
|
deprecate.warn('webFrame.setIsolatedWorldSecurityOrigin', 'webFrame.setIsolatedWorldInfo')
|
2019-01-21 20:45:15 +00:00
|
|
|
binding.setIsolatedWorldInfo(this.context, worldId, { securityOrigin })
|
2019-02-13 18:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setIsolatedWorldContentSecurityPolicy (worldId, csp) {
|
|
|
|
deprecate.warn('webFrame.setIsolatedWorldContentSecurityPolicy', 'webFrame.setIsolatedWorldInfo')
|
2019-01-21 20:45:15 +00:00
|
|
|
binding.setIsolatedWorldInfo(this.context, worldId, {
|
|
|
|
securityOrigin: window.location.origin,
|
|
|
|
csp
|
|
|
|
})
|
2019-02-13 18:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setIsolatedWorldHumanReadableName (worldId, name) {
|
|
|
|
deprecate.warn('webFrame.setIsolatedWorldHumanReadableName', 'webFrame.setIsolatedWorldInfo')
|
2019-01-21 20:45:15 +00:00
|
|
|
binding.setIsolatedWorldInfo(this.context, worldId, { name })
|
2019-02-13 18:05:28 +00:00
|
|
|
}
|
2019-02-08 21:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the methods.
|
|
|
|
for (const name in binding) {
|
|
|
|
if (!name.startsWith('_')) { // some methods are manully populated above
|
|
|
|
WebFrame.prototype[name] = function (...args) {
|
|
|
|
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.
|
|
|
|
function getWebFrame (context) {
|
|
|
|
return context ? new WebFrame(context) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new WebFrame(window)
|