Don't clear until render view is deleted for process id
This commit is contained in:
parent
851f490168
commit
f3d391e3f2
1 changed files with 16 additions and 7 deletions
|
@ -19,17 +19,14 @@ class ObjectsRegistry {
|
|||
// registered then the already assigned ID would be returned.
|
||||
add (webContents, obj) {
|
||||
// Get or assign an ID to the object.
|
||||
let id = this.saveToStorage(obj)
|
||||
const id = this.saveToStorage(obj)
|
||||
|
||||
// Add object to the set of referenced objects.
|
||||
let webContentsId = webContents.getId()
|
||||
const webContentsId = webContents.getId()
|
||||
let owner = this.owners[webContentsId]
|
||||
if (!owner) {
|
||||
owner = this.owners[webContentsId] = new Set()
|
||||
// Clear the storage when webContents is reloaded/navigated.
|
||||
webContents.once('render-view-deleted', () => {
|
||||
this.clear(webContentsId)
|
||||
})
|
||||
this.registerDeleteListener(webContents, webContentsId)
|
||||
}
|
||||
if (!owner.has(id)) {
|
||||
owner.add(id)
|
||||
|
@ -39,6 +36,18 @@ class ObjectsRegistry {
|
|||
return id
|
||||
}
|
||||
|
||||
// Clear the storage when webContents is reloaded/navigated.
|
||||
registerDeleteListener (webContents, webContentsId) {
|
||||
const processId = webContents.getProcessId()
|
||||
const listener = (event, deletedProcessId) => {
|
||||
if (deletedProcessId === processId) {
|
||||
webContents.removeListener('render-view-deleted', listener)
|
||||
this.clear(webContentsId)
|
||||
}
|
||||
}
|
||||
webContents.on('render-view-deleted', listener)
|
||||
}
|
||||
|
||||
// Get an object according to its ID.
|
||||
get (id) {
|
||||
const pointer = this.storage[id]
|
||||
|
@ -90,7 +99,7 @@ class ObjectsRegistry {
|
|||
pointer.count -= 1
|
||||
if (pointer.count === 0) {
|
||||
v8Util.deleteHiddenValue(pointer.object, 'atomId')
|
||||
return delete this.storage[id]
|
||||
delete this.storage[id]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue