mirror of
https://github.com/electron/electron.git
synced 2026-01-25 07:18:18 -05:00
Don't clear until render view is deleted for process id
This commit is contained in:
@@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user