Merge pull request #4069 from atom/destroyed-webcontents-methods
Destroy the native class when webContents is destroyed
This commit is contained in:
commit
c2f6f64e6a
2 changed files with 15 additions and 1 deletions
|
@ -635,8 +635,16 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||||
void WebContents::WebContentsDestroyed() {
|
void WebContents::WebContentsDestroyed() {
|
||||||
// The RenderViewDeleted was not called when the WebContents is destroyed.
|
// The RenderViewDeleted was not called when the WebContents is destroyed.
|
||||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
||||||
Emit("destroyed");
|
|
||||||
RemoveFromWeakMap();
|
RemoveFromWeakMap();
|
||||||
|
|
||||||
|
// We can not call Destroy here because we need to call Emit first, but we
|
||||||
|
// also do not want any method to be used, so just mark as destroyed here.
|
||||||
|
MarkDestroyed();
|
||||||
|
|
||||||
|
Emit("destroyed");
|
||||||
|
|
||||||
|
// Destroy the native class in next tick.
|
||||||
|
base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::NavigationEntryCommitted(
|
void WebContents::NavigationEntryCommitted(
|
||||||
|
|
|
@ -55,6 +55,12 @@ describe 'browser-window module', ->
|
||||||
done()
|
done()
|
||||||
w.loadURL 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')
|
w.loadURL 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')
|
||||||
|
|
||||||
|
describe 'BrowserWindow.destroy()', ->
|
||||||
|
it 'prevents users to access methods of webContents', ->
|
||||||
|
webContents = w.webContents
|
||||||
|
w.destroy()
|
||||||
|
assert.throws (-> webContents.getId()), /Object has been destroyed/
|
||||||
|
|
||||||
describe 'BrowserWindow.loadURL(url)', ->
|
describe 'BrowserWindow.loadURL(url)', ->
|
||||||
it 'should emit did-start-loading event', (done) ->
|
it 'should emit did-start-loading event', (done) ->
|
||||||
w.webContents.on 'did-start-loading', ->
|
w.webContents.on 'did-start-loading', ->
|
||||||
|
|
Loading…
Reference in a new issue