The DevTools window should manage lifetime itself.

This commit is contained in:
Cheng Zhao 2014-02-24 12:17:10 +08:00
parent eaedac2536
commit f65f95e95c
4 changed files with 19 additions and 12 deletions

View file

@ -47,7 +47,7 @@ void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) {
} }
void DevToolsDelegate::InspectedContentsClosing() { void DevToolsDelegate::InspectedContentsClosing() {
owner_window_->CloseImmediately(); delete owner_window_;
} }
void DevToolsDelegate::AboutToNavigateRenderView( void DevToolsDelegate::AboutToNavigateRenderView(
@ -56,4 +56,8 @@ void DevToolsDelegate::AboutToNavigateRenderView(
owner_window_->GetWebContents()->GetRenderViewHost()); owner_window_->GetWebContents()->GetRenderViewHost());
} }
void DevToolsDelegate::OnWindowClosed() {
delete owner_window_;
}
} // namespace atom } // namespace atom

View file

@ -6,6 +6,7 @@
#define ATOM_BROWSER_DEVTOOLS_DELEGATE_H_ #define ATOM_BROWSER_DEVTOOLS_DELEGATE_H_
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "browser/native_window_observer.h"
#include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/devtools_frontend_host_delegate.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
@ -19,7 +20,8 @@ namespace atom {
class NativeWindow; class NativeWindow;
class DevToolsDelegate : public content::DevToolsFrontendHostDelegate, class DevToolsDelegate : public content::DevToolsFrontendHostDelegate,
public content::WebContentsObserver { public content::WebContentsObserver,
public NativeWindowObserver {
public: public:
DevToolsDelegate(NativeWindow* window, DevToolsDelegate(NativeWindow* window,
content::WebContents* target_web_contents); content::WebContents* target_web_contents);
@ -34,6 +36,9 @@ class DevToolsDelegate : public content::DevToolsFrontendHostDelegate,
virtual void AboutToNavigateRenderView( virtual void AboutToNavigateRenderView(
content::RenderViewHost* render_view_host) OVERRIDE; content::RenderViewHost* render_view_host) OVERRIDE;
// Implementations of NativeWindowObserver.
virtual void OnWindowClosed() OVERRIDE;
private: private:
NativeWindow* owner_window_; NativeWindow* owner_window_;

View file

@ -185,16 +185,14 @@ void NativeWindow::InspectElement(int x, int y) {
agent->InspectElement(x, y); agent->InspectElement(x, y);
} }
scoped_ptr<NativeWindow> NativeWindow::DebugDevTools() { void NativeWindow::DebugDevTools() {
scoped_ptr<NativeWindow> window; if (!IsDevToolsOpened())
if (IsDevToolsOpened()) { return;
base::DictionaryValue options;
window.reset(NativeWindow::Create(&options));
window->devtools_delegate_.reset(new DevToolsDelegate(
window.get(), GetDevToolsWebContents()));
}
return window.Pass(); base::DictionaryValue options;
NativeWindow* window = NativeWindow::Create(&options);
window->devtools_delegate_.reset(new DevToolsDelegate(
window, GetDevToolsWebContents()));
} }
void NativeWindow::FocusOnWebView() { void NativeWindow::FocusOnWebView() {

View file

@ -130,7 +130,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void InspectElement(int x, int y); virtual void InspectElement(int x, int y);
// Creates a new window to debug the devtools. // Creates a new window to debug the devtools.
virtual scoped_ptr<NativeWindow> DebugDevTools(); virtual void DebugDevTools();
virtual void FocusOnWebView(); virtual void FocusOnWebView();
virtual void BlurWebView(); virtual void BlurWebView();