|
@@ -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)
|
|
@@ -90,8 +87,20 @@ class ObjectsRegistry {
|
|
|
pointer.count -= 1
|
|
|
if (pointer.count === 0) {
|
|
|
v8Util.deleteHiddenValue(pointer.object, 'atomId')
|
|
|
- return delete this.storage[id]
|
|
|
+ delete this.storage[id]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Private: 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)
|
|
|
}
|
|
|
}
|
|
|
|