Get rid of the ATOM_BROWSER_RELEASE_RENDER_VIEW event

This commit is contained in:
Cheng Zhao 2016-02-22 14:54:55 +08:00
parent 593a79ce20
commit 6753fcc1b4
3 changed files with 10 additions and 19 deletions

View file

@ -485,17 +485,7 @@ void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
} }
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) { void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
int process_id = render_view_host->GetProcess()->GetID(); Emit("render-view-deleted", render_view_host->GetProcess()->GetID());
Emit("render-view-deleted", process_id);
// process.emit('ATOM_BROWSER_RELEASE_RENDER_VIEW', processId);
// Tell the rpc server that a render view has been deleted and we need to
// release all objects owned by it.
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
node::Environment* env = node::Environment::GetCurrent(isolate());
mate::EmitEvent(isolate(), env->process_object(),
"ATOM_BROWSER_RELEASE_RENDER_VIEW", process_id);
} }
void WebContents::RenderProcessGone(base::TerminationStatus status) { void WebContents::RenderProcessGone(base::TerminationStatus status) {

View file

@ -17,14 +17,20 @@ class ObjectsRegistry {
// Register a new object and return its assigned ID. If the object is already // Register a new object and return its assigned ID. If the object is already
// registered then the already assigned ID would be returned. // registered then the already assigned ID would be returned.
add(webContentsId, obj) { add(webContents, obj) {
// Get or assign an ID to the object. // Get or assign an ID to the object.
let id = this.saveToStorage(obj); let id = this.saveToStorage(obj);
// Add object to the set of referenced objects. // Add object to the set of referenced objects.
let webContentsId = webContents.getId();
let owner = this.owners[webContentsId]; let owner = this.owners[webContentsId];
if (!owner) if (!owner) {
owner = this.owners[webContentsId] = new Set(); owner = this.owners[webContentsId] = new Set();
// Clear the storage when webContents is reloaded/navigated.
webContents.once('render-view-deleted', (event, id) => {
this.clear(id);
});
}
if (!owner.has(id)) { if (!owner.has(id)) {
owner.add(id); owner.add(id);
// Increase reference count if not referenced before. // Increase reference count if not referenced before.

View file

@ -100,7 +100,7 @@ var valueToMeta = function(sender, value, optimizeSimpleObject) {
// Reference the original value if it's an object, because when it's // Reference the original value if it's an object, because when it's
// passed to renderer we would assume the renderer keeps a reference of // passed to renderer we would assume the renderer keeps a reference of
// it. // it.
meta.id = objectsRegistry.add(sender.getId(), value); meta.id = objectsRegistry.add(sender, value);
meta.members = getObjectMemebers(value); meta.members = getObjectMemebers(value);
meta.proto = getObjectPrototype(value); meta.proto = getObjectPrototype(value);
} else if (meta.type === 'buffer') { } else if (meta.type === 'buffer') {
@ -239,11 +239,6 @@ var callFunction = function(event, func, caller, args) {
} }
}; };
// Send by BrowserWindow when its render view is deleted.
process.on('ATOM_BROWSER_RELEASE_RENDER_VIEW', function(id) {
return objectsRegistry.clear(id);
});
ipcMain.on('ATOM_BROWSER_REQUIRE', function(event, module) { ipcMain.on('ATOM_BROWSER_REQUIRE', function(event, module) {
try { try {
return event.returnValue = valueToMeta(event.sender, process.mainModule.require(module)); return event.returnValue = valueToMeta(event.sender, process.mainModule.require(module));