WebContents::~WebContents() {
}
+void WebContents::RenderViewDeleted(content::RenderViewHost*) {
+ base::ListValue args;
+ args.AppendInteger(GetProcessID());
+ args.AppendInteger(GetRoutingID());
+ Emit("render-view-deleted", args);
+}
+
+void WebContents::RenderProcessGone(base::TerminationStatus status) {
+ Emit("crashed");
+}
+
void WebContents::WebContentsDestroyed(content::WebContents*) {
+ // The RenderViewDeleted is not called when the WebContents is destroyed
+ // directly.
+ RenderViewDeleted(web_contents_->GetRenderViewHost());
+
web_contents_ = NULL;
}
v8::Isolate* isolate) OVERRIDE;
// content::WebContentsObserver implementations:
+ virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
+ virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
private:
Emit("responsive");
}
-void Window::OnRenderViewDeleted(int process_id, int routing_id) {
- base::ListValue args;
- args.AppendInteger(process_id);
- args.AppendInteger(routing_id);
- Emit("render-view-deleted", args);
-}
-
-void Window::OnRendererCrashed() {
- Emit("crashed");
-}
-
// static
mate::Wrappable* Window::New(mate::Arguments* args,
const base::DictionaryValue& options) {
.SetMethod("blurWebView", &Window::BlurWebView)
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
.SetMethod("capturePage", &Window::CapturePage)
- .SetMethod("getWebContents", &Window::GetWebContents)
- .SetMethod("getDevToolsWebContents", &Window::GetDevToolsWebContents)
+ .SetMethod("_getWebContents", &Window::GetWebContents)
+ .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents)
.SetMethod("loadUrl", &Window::LoadURL)
.SetMethod("canGoBack", &Window::CanGoBack)
.SetMethod("canGoForward", &Window::CanGoForward)
virtual void OnWindowBlur() OVERRIDE;
virtual void OnRendererUnresponsive() OVERRIDE;
virtual void OnRendererResponsive() OVERRIDE;
- virtual void OnRenderViewDeleted(int process_id, int routing_id) OVERRIDE;
- virtual void OnRendererCrashed() OVERRIDE;
private:
// APIs for NativeWindow.
menu = app.getApplicationMenu()
@setMenu menu if menu?
- # Define getter for webContents.
- webContents = null
- @__defineGetter__ 'webContents', ->
- webContents ?= @getWebContents()
- # Return null if webContents is destroyed.
- webContents = null unless webContents?.isAlive()
- webContents
-
- # And devToolsWebContents.
+ @webContents = @getWebContents()
+
+ # Define getter for devToolsWebContents.
devToolsWebContents = null
@__defineGetter__ 'devToolsWebContents', ->
if @isDevToolsOpened()
- # Get the new devToolsWebContents if previous one has been destroyed, it
+ # Get a new devToolsWebContents if previous one has been destroyed, it
# could happen when the devtools has been closed and then reopened.
devToolsWebContents = null unless devToolsWebContents?.isAlive()
devToolsWebContents ?= @getDevToolsWebContents()
# Tell the rpc server that a render view has been deleted and we need to
# release all objects owned by it.
- @on 'render-view-deleted', (event, processId, routingId) ->
+ @webContents.on 'render-view-deleted', (event, processId, routingId) ->
process.emit 'ATOM_BROWSER_RELEASE_RENDER_VIEW', processId, routingId
BrowserWindow::toggleDevTools = ->
if @isDevToolsOpened() then @closeDevTools() else @openDevTools()
+BrowserWindow::getWebContents = ->
+ webContents = @_getWebContents()
+ webContents.__proto__ = EventEmitter.prototype
+ webContents
+
+BrowserWindow::getDevToolsWebContents = ->
+ webContents = @_getDevToolsWebContents()
+ webContents.__proto__ = EventEmitter.prototype
+ webContents = null unless webContents.isAlive()
+ webContents
+
BrowserWindow::restart = ->
@loadUrl(@getUrl())
if (!inspectable_web_contents_)
return;
- // The OnRenderViewDeleted is not called when the WebContents is destroyed
- // directly (e.g. when closing the window), so we make sure it's always
- // emitted to users by sending it before window is closed..
- FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
- OnRenderViewDeleted(
- GetWebContents()->GetRenderProcessHost()->GetID(),
- GetWebContents()->GetRoutingID()));
-
inspectable_web_contents_.reset();
}
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
}
-void NativeWindow::RenderViewDeleted(content::RenderViewHost* rvh) {
- FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
- OnRenderViewDeleted(rvh->GetProcess()->GetID(),
- rvh->GetRoutingID()));
-}
-
-void NativeWindow::RenderProcessGone(base::TerminationStatus status) {
- FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererCrashed());
-}
-
void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
// Do nothing, we override this method just to avoid compilation error since
// there are two virtual functions named BeforeUnloadFired.
virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
// Implementations of content::WebContentsObserver.
- virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
- virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// Called when renderer recovers.
virtual void OnRendererResponsive() {}
-
- // Called when a render view has been deleted.
- virtual void OnRenderViewDeleted(int process_id, int routing_id) {}
-
- // Called when renderer has crashed.
- virtual void OnRendererCrashed() {}
};
} // namespace atom