From 1c072351212d745e4cfc9670d6aac809be18101d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 14:25:15 +0800 Subject: [PATCH 1/9] Disable the undocked devtools. --- browser/native_window.cc | 41 +++++++++++++++++++++++++++++++++++----- browser/native_window.h | 14 +++++++------- vendor/brightray | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index 3ef5bc7d1b..7bd45ee0b6 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -7,6 +7,7 @@ #include #include "base/file_util.h" +#include "base/prefs/pref_service.h" #include "base/message_loop/message_loop.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -38,13 +39,18 @@ #include "ui/gfx/point.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" -#include "vendor/brightray/browser/inspectable_web_contents_impl.h" #include "webkit/common/user_agent/user_agent_util.h" using content::NavigationEntry; namespace atom { +namespace { + +const char kDockSidePref[] = "brightray.devtools.dockside"; + +} // namespace + NativeWindow::NativeWindow(content::WebContents* web_contents, base::DictionaryValue* options) : content::WebContentsObserver(web_contents), @@ -166,7 +172,19 @@ bool NativeWindow::HasModalDialog() { } void NativeWindow::OpenDevTools() { + // Check if the devtools is docked. + AtomBrowserContext* browser_context = AtomBrowserContext::Get(); + std::string dock_side = browser_context->prefs()->GetString(kDockSidePref); + if (dock_side == "undocked") + browser_context->prefs()->SetString(kDockSidePref, "bottom"); + inspectable_web_contents()->ShowDevTools(); + + // Intercept the requestSetDockSide message of devtools. + inspectable_web_contents()->embedder_message_dispatcher()-> + RegisterHandler("requestSetDockSide", + base::Bind(&NativeWindow::OnRequestSetDockSide, + base::Unretained(this))); } void NativeWindow::CloseDevTools() { @@ -283,10 +301,7 @@ content::WebContents* NativeWindow::GetWebContents() const { } content::WebContents* NativeWindow::GetDevToolsWebContents() const { - brightray::InspectableWebContentsImpl* inspectable_web_contents_impl = - static_cast( - inspectable_web_contents()); - return inspectable_web_contents_impl->devtools_web_contents(); + return inspectable_web_contents()->devtools_web_contents(); } void NativeWindow::NotifyWindowClosed() { @@ -476,6 +491,22 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, callback.Run(data); } +bool NativeWindow::OnRequestSetDockSide(const base::ListValue& args) { + brightray::DevToolsEmbedderMessageDispatcher::Delegate* delegate = + static_cast( + inspectable_web_contents()); + + // Do not allow the "undocked" state. + std::string dock_side; + if (args.GetString(0, &dock_side) && dock_side == "undocked") { + delegate->CloseWindow(); + return true; + } + + delegate->SetDockSide(dock_side); + return true; +} + void NativeWindow::OnRendererMessage(const string16& channel, const base::ListValue& args) { AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage( diff --git a/browser/native_window.h b/browser/native_window.h index b1eb6e695b..6d97c3aabb 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -14,19 +14,15 @@ #include "browser/native_window_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_observer.h" -#include "content/public/browser/web_contents_observer.h" #include "ui/gfx/image/image.h" #include "vendor/brightray/browser/default_web_contents_delegate.h" +#include "vendor/brightray/browser/inspectable_web_contents_impl.h" namespace base { class DictionaryValue; class ListValue; } -namespace brightray { -class InspectableWebContents; -} - namespace content { class BrowserContext; class WebContents; @@ -174,8 +170,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, explicit NativeWindow(content::WebContents* web_contents, base::DictionaryValue* options); - brightray::InspectableWebContents* inspectable_web_contents() const { - return inspectable_web_contents_.get(); + brightray::InspectableWebContentsImpl* inspectable_web_contents() const { + return static_cast( + inspectable_web_contents_.get()); } void NotifyWindowClosed(); @@ -232,6 +229,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, bool succeed, const SkBitmap& bitmap); + // Handler for the requestSetDockSide message from devtools. + bool OnRequestSetDockSide(const base::ListValue&); + void OnRendererMessage(const string16& channel, const base::ListValue& args); diff --git a/vendor/brightray b/vendor/brightray index 569ea3f1e1..90ea5b1d3b 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 569ea3f1e14b9214528be09dfc2117e387c0a03f +Subproject commit 90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2 From d37bf06b5a9d8160df5d85233f9b6762b5a03209 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 14:35:35 +0800 Subject: [PATCH 2/9] Make the DebugDevTools API more generic. --- browser/api/atom_api_window.cc | 3 ++- browser/native_window.cc | 18 ++++++++---------- browser/native_window.h | 13 ++++++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index f502425749..7486f4f5b6 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -417,7 +417,8 @@ void Window::InspectElement(const v8::FunctionCallbackInfo& args) { // static void Window::DebugDevTools(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->DebugDevTools(); + if (self->window_->IsDevToolsOpened()) + NativeWindow::Debug(self->window_->GetDevToolsWebContents()); } // static diff --git a/browser/native_window.cc b/browser/native_window.cc index 7bd45ee0b6..3d3d38474c 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -101,6 +101,14 @@ NativeWindow* NativeWindow::Create(base::DictionaryValue* options) { return Create(content::WebContents::Create(create_params), options); } +// static +NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) { + base::DictionaryValue options; + NativeWindow* window = NativeWindow::Create(&options); + window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents)); + return window; +} + // static NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) { // Stupid iterating. @@ -203,16 +211,6 @@ void NativeWindow::InspectElement(int x, int y) { agent->InspectElement(x, y); } -void NativeWindow::DebugDevTools() { - if (!IsDevToolsOpened()) - return; - - base::DictionaryValue options; - NativeWindow* window = NativeWindow::Create(&options); - window->devtools_delegate_.reset(new DevToolsDelegate( - window, GetDevToolsWebContents())); -} - void NativeWindow::FocusOnWebView() { GetWebContents()->GetRenderViewHost()->Focus(); } diff --git a/browser/native_window.h b/browser/native_window.h index 6d97c3aabb..1e02dee817 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -72,13 +72,19 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual ~NativeWindow(); - // Create window with existing WebContents. + // Create window with existing WebContents, the caller is responsible for + // managing the window's live. static NativeWindow* Create(content::WebContents* web_contents, base::DictionaryValue* options); - // Create window with new WebContents. + // Create window with new WebContents, the caller is responsible for + // managing the window's live. static NativeWindow* Create(base::DictionaryValue* options); + // Creates a devtools window to debug the WebContents, the returned window + // will manage its own life. + static NativeWindow* Debug(content::WebContents* web_contents); + // Find a window from its process id and routing id. static NativeWindow* FromRenderView(int process_id, int routing_id); @@ -125,9 +131,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual bool IsDevToolsOpened(); virtual void InspectElement(int x, int y); - // Creates a new window to debug the devtools. - virtual void DebugDevTools(); - virtual void FocusOnWebView(); virtual void BlurWebView(); virtual bool IsWebViewFocused(); From c2996d4fd16195a58810177753ca33468afe1739 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 15:46:12 +0800 Subject: [PATCH 3/9] Take control if devtools is undocked. --- browser/native_window.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index 3d3d38474c..72db7ef77a 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -180,12 +180,15 @@ bool NativeWindow::HasModalDialog() { } void NativeWindow::OpenDevTools() { - // Check if the devtools is docked. + // Check if the devtools is undocked. AtomBrowserContext* browser_context = AtomBrowserContext::Get(); std::string dock_side = browser_context->prefs()->GetString(kDockSidePref); - if (dock_side == "undocked") - browser_context->prefs()->SetString(kDockSidePref, "bottom"); + if (dock_side == "undocked") { + Debug(GetWebContents()); + return; + } + // For docked devtools we give it to brightray. inspectable_web_contents()->ShowDevTools(); // Intercept the requestSetDockSide message of devtools. @@ -494,14 +497,14 @@ bool NativeWindow::OnRequestSetDockSide(const base::ListValue& args) { static_cast( inspectable_web_contents()); - // Do not allow the "undocked" state. + // Takeover when devtools is undocked. std::string dock_side; if (args.GetString(0, &dock_side) && dock_side == "undocked") { delegate->CloseWindow(); - return true; + Debug(GetWebContents()); + } else { + delegate->SetDockSide(dock_side); } - - delegate->SetDockSide(dock_side); return true; } From 5e05a3045c78757877c5fa836b47d07bb14cbe10 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 17:08:30 +0800 Subject: [PATCH 4/9] Use InspectableWebContentsDelegate. --- browser/native_window.cc | 49 ++++++++++++++++------------------------ browser/native_window.h | 10 +++++--- vendor/brightray | 2 +- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index 72db7ef77a..e16c45f1eb 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -72,6 +72,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, options->GetString(switches::kNodeIntegration, &node_integration_); web_contents->SetDelegate(this); + inspectable_web_contents()->SetDelegate(this); WindowList::AddWindow(this); @@ -180,22 +181,8 @@ bool NativeWindow::HasModalDialog() { } void NativeWindow::OpenDevTools() { - // Check if the devtools is undocked. - AtomBrowserContext* browser_context = AtomBrowserContext::Get(); - std::string dock_side = browser_context->prefs()->GetString(kDockSidePref); - if (dock_side == "undocked") { - Debug(GetWebContents()); - return; - } - // For docked devtools we give it to brightray. inspectable_web_contents()->ShowDevTools(); - - // Intercept the requestSetDockSide message of devtools. - inspectable_web_contents()->embedder_message_dispatcher()-> - RegisterHandler("requestSetDockSide", - base::Bind(&NativeWindow::OnRequestSetDockSide, - base::Unretained(this))); } void NativeWindow::CloseDevTools() { @@ -483,6 +470,24 @@ void NativeWindow::Observe(int type, } } +bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side, + bool* succeed) { + if (dock_side != "undocked") + return false; + + CloseDevTools(); + Debug(GetWebContents()); + return true; +} + +bool NativeWindow::DevToolsShow(const std::string& dock_side) { + if (dock_side != "undocked") + return false; + + Debug(GetWebContents()); + return true; +} + void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, bool succeed, const SkBitmap& bitmap) { @@ -492,22 +497,6 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, callback.Run(data); } -bool NativeWindow::OnRequestSetDockSide(const base::ListValue& args) { - brightray::DevToolsEmbedderMessageDispatcher::Delegate* delegate = - static_cast( - inspectable_web_contents()); - - // Takeover when devtools is undocked. - std::string dock_side; - if (args.GetString(0, &dock_side) && dock_side == "undocked") { - delegate->CloseWindow(); - Debug(GetWebContents()); - } else { - delegate->SetDockSide(dock_side); - } - return true; -} - void NativeWindow::OnRendererMessage(const string16& channel, const base::ListValue& args) { AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage( diff --git a/browser/native_window.h b/browser/native_window.h index 1e02dee817..1b3b38df70 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -16,6 +16,7 @@ #include "content/public/browser/notification_observer.h" #include "ui/gfx/image/image.h" #include "vendor/brightray/browser/default_web_contents_delegate.h" +#include "vendor/brightray/browser/inspectable_web_contents_delegate.h" #include "vendor/brightray/browser/inspectable_web_contents_impl.h" namespace base { @@ -45,6 +46,7 @@ class DevToolsDelegate; struct DraggableRegion; class NativeWindow : public brightray::DefaultWebContentsDelegate, + public brightray::InspectableWebContentsDelegate, public content::WebContentsObserver, public content::NotificationObserver { public: @@ -220,6 +222,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Implementations of brightray::InspectableWebContentsDelegate. + virtual bool DevToolsSetDockSide(const std::string& dock_side, + bool* succeed) OVERRIDE; + virtual bool DevToolsShow(const std::string& side) OVERRIDE; + // Whether window has standard frame. bool has_frame_; @@ -232,9 +239,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, bool succeed, const SkBitmap& bitmap); - // Handler for the requestSetDockSide message from devtools. - bool OnRequestSetDockSide(const base::ListValue&); - void OnRendererMessage(const string16& channel, const base::ListValue& args); diff --git a/vendor/brightray b/vendor/brightray index 90ea5b1d3b..8111949e34 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2 +Subproject commit 8111949e34a17bbeba9246494326bb891f55df34 From 391468ece07f0b6a64479e2aa8c364024aa45575 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 17:50:57 +0800 Subject: [PATCH 5/9] Make DevToolsDelegate respond to messages. --- browser/devtools_delegate.cc | 57 ++++++++++++++++++++++++++++++++++-- browser/devtools_delegate.h | 28 +++++++++++++++++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/browser/devtools_delegate.cc b/browser/devtools_delegate.cc index dc11dd35e1..0cd9d0198f 100644 --- a/browser/devtools_delegate.cc +++ b/browser/devtools_delegate.cc @@ -11,13 +11,16 @@ #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/web_contents.h" +#include "ui/gfx/point.h" namespace atom { DevToolsDelegate::DevToolsDelegate(NativeWindow* window, content::WebContents* target_web_contents) : content::WebContentsObserver(window->GetWebContents()), - owner_window_(window) { + owner_window_(window), + embedder_message_dispatcher_( + new DevToolsEmbedderMessageDispatcher(this)) { content::WebContents* web_contents = window->GetWebContents(); // Setup devtools. @@ -34,7 +37,7 @@ DevToolsDelegate::DevToolsDelegate(NativeWindow* window, options.SetString("title", "DevTools Debugger"); window->InitFromOptions(&options); web_contents->GetController().LoadURL( - GURL("chrome-devtools://devtools/devtools.html"), + GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"), content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); @@ -44,6 +47,7 @@ DevToolsDelegate::~DevToolsDelegate() { } void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) { + embedder_message_dispatcher_->Dispatch(message); } void DevToolsDelegate::InspectedContentsClosing() { @@ -60,4 +64,53 @@ void DevToolsDelegate::OnWindowClosed() { delete owner_window_; } +void DevToolsDelegate::ActivateWindow() { +} + +void DevToolsDelegate::CloseWindow() { + owner_window_->Close(); +} + +void DevToolsDelegate::MoveWindow(int x, int y) { + owner_window_->SetPosition(gfx::Point(x, y)); +} + +void DevToolsDelegate::SetDockSide(const std::string& dock_side) { + if (dock_side != "undocked") + owner_window_->Close(); +} + +void DevToolsDelegate::OpenInNewTab(const std::string& url) { +} + +void DevToolsDelegate::SaveToFile( + const std::string& url, const std::string& content, bool save_as) { +} + +void DevToolsDelegate::AppendToFile( + const std::string& url, const std::string& content) { +} + +void DevToolsDelegate::RequestFileSystems() { +} + +void DevToolsDelegate::AddFileSystem() { +} + +void DevToolsDelegate::RemoveFileSystem(const std::string& file_system_path) { +} + +void DevToolsDelegate::IndexPath( + int request_id, const std::string& file_system_path) { +} + +void DevToolsDelegate::StopIndexing(int request_id) { +} + +void DevToolsDelegate::SearchInPath( + int request_id, + const std::string& file_system_path, + const std::string& query) { +} + } // namespace atom diff --git a/browser/devtools_delegate.h b/browser/devtools_delegate.h index d8a8be5297..be0c1b298e 100644 --- a/browser/devtools_delegate.h +++ b/browser/devtools_delegate.h @@ -9,19 +9,23 @@ #include "browser/native_window_observer.h" #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_observer.h" +#include "vendor/brightray/browser/devtools_embedder_message_dispatcher.h" namespace content { class DevToolsAgentHost; class DevToolsClientHost; } +using brightray::DevToolsEmbedderMessageDispatcher; + namespace atom { class NativeWindow; class DevToolsDelegate : public content::DevToolsFrontendHostDelegate, public content::WebContentsObserver, - public NativeWindowObserver { + public NativeWindowObserver, + public DevToolsEmbedderMessageDispatcher::Delegate { public: DevToolsDelegate(NativeWindow* window, content::WebContents* target_web_contents); @@ -39,11 +43,33 @@ class DevToolsDelegate : public content::DevToolsFrontendHostDelegate, // Implementations of NativeWindowObserver. virtual void OnWindowClosed() OVERRIDE; + // Implementations of DevToolsEmbedderMessageDispatcher::Delegate. + virtual void ActivateWindow() OVERRIDE; + virtual void CloseWindow() OVERRIDE; + virtual void MoveWindow(int x, int y) OVERRIDE; + virtual void SetDockSide(const std::string& dock_side) OVERRIDE; + virtual void OpenInNewTab(const std::string& url) OVERRIDE; + virtual void SaveToFile(const std::string& url, + const std::string& content, + bool save_as) OVERRIDE; + virtual void AppendToFile(const std::string& url, + const std::string& content) OVERRIDE; + virtual void RequestFileSystems() OVERRIDE; + virtual void AddFileSystem() OVERRIDE; + virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; + virtual void IndexPath(int request_id, + const std::string& file_system_path) OVERRIDE; + virtual void StopIndexing(int request_id) OVERRIDE; + virtual void SearchInPath(int request_id, + const std::string& file_system_path, + const std::string& query) OVERRIDE; + private: NativeWindow* owner_window_; scoped_refptr devtools_agent_host_; scoped_ptr devtools_client_host_; + scoped_ptr embedder_message_dispatcher_; DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); }; From 6bd0b82b2e20279702283dc507f71833af71fa21 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 18:42:37 +0800 Subject: [PATCH 6/9] Store the devtools window in weak pointer. --- browser/native_window.cc | 18 +++++++++++++----- browser/native_window.h | 6 ++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index e16c45f1eb..b3e492dae9 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -181,8 +181,10 @@ bool NativeWindow::HasModalDialog() { } void NativeWindow::OpenDevTools() { - // For docked devtools we give it to brightray. - inspectable_web_contents()->ShowDevTools(); + if (devtools_window_) + devtools_window_->Focus(true); + else + inspectable_web_contents()->ShowDevTools(); } void NativeWindow::CloseDevTools() { @@ -472,11 +474,17 @@ void NativeWindow::Observe(int type, bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side, bool* succeed) { - if (dock_side != "undocked") + if (dock_side != "undocked") { + // Switch to docked mode. + if (devtools_window_) { + devtools_window_->Close(); + devtools_window_.reset(); + } return false; + } CloseDevTools(); - Debug(GetWebContents()); + devtools_window_ = Debug(GetWebContents())->GetWeakPtr(); return true; } @@ -484,7 +492,7 @@ bool NativeWindow::DevToolsShow(const std::string& dock_side) { if (dock_side != "undocked") return false; - Debug(GetWebContents()); + devtools_window_ = Debug(GetWebContents())->GetWeakPtr(); return true; } diff --git a/browser/native_window.h b/browser/native_window.h index 1b3b38df70..8a0c1ccfe4 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -153,6 +153,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Should be called by platform code when user want to close the window. virtual void CloseWebContents(); + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } + content::WebContents* GetWebContents() const; content::WebContents* GetDevToolsWebContents() const; @@ -267,6 +271,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, base::WeakPtrFactory weak_factory_; + base::WeakPtr devtools_window_; + scoped_ptr devtools_delegate_; scoped_ptr dialog_manager_; scoped_ptr inspectable_web_contents_; From 01b42c9e5989c5555b34c32d997fc4d7be849e10 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 18:45:36 +0800 Subject: [PATCH 7/9] Make devtools API aware of devtools window. --- browser/native_window.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index b3e492dae9..177cab7f56 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -188,11 +188,15 @@ void NativeWindow::OpenDevTools() { } void NativeWindow::CloseDevTools() { - inspectable_web_contents()->GetView()->CloseDevTools(); + if (devtools_window_) + devtools_window_->Close(); + else + inspectable_web_contents()->GetView()->CloseDevTools(); } bool NativeWindow::IsDevToolsOpened() { - return inspectable_web_contents()->IsDevToolsViewShowing(); + return (devtools_window_ && devtools_window_->IsFocused()) || + inspectable_web_contents()->IsDevToolsViewShowing(); } void NativeWindow::InspectElement(int x, int y) { From 9f86fa1893dfc24b50672229ab07cbab6dafeff8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 19:02:48 +0800 Subject: [PATCH 8/9] Correctly free devtools window. --- browser/devtools_delegate.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/browser/devtools_delegate.cc b/browser/devtools_delegate.cc index 0cd9d0198f..37bba54bc1 100644 --- a/browser/devtools_delegate.cc +++ b/browser/devtools_delegate.cc @@ -4,6 +4,7 @@ #include "browser/devtools_delegate.h" +#include "base/message_loop/message_loop.h" #include "base/values.h" #include "browser/native_window.h" #include "content/public/browser/devtools_agent_host.h" @@ -36,6 +37,7 @@ DevToolsDelegate::DevToolsDelegate(NativeWindow* window, base::DictionaryValue options; options.SetString("title", "DevTools Debugger"); window->InitFromOptions(&options); + window->AddObserver(this); web_contents->GetController().LoadURL( GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"), content::Referrer(), @@ -51,7 +53,7 @@ void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) { } void DevToolsDelegate::InspectedContentsClosing() { - delete owner_window_; + owner_window_->Close(); } void DevToolsDelegate::AboutToNavigateRenderView( @@ -61,7 +63,7 @@ void DevToolsDelegate::AboutToNavigateRenderView( } void DevToolsDelegate::OnWindowClosed() { - delete owner_window_; + base::MessageLoop::current()->DeleteSoon(FROM_HERE, owner_window_); } void DevToolsDelegate::ActivateWindow() { @@ -76,8 +78,7 @@ void DevToolsDelegate::MoveWindow(int x, int y) { } void DevToolsDelegate::SetDockSide(const std::string& dock_side) { - if (dock_side != "undocked") - owner_window_->Close(); + owner_window_->Close(); } void DevToolsDelegate::OpenInNewTab(const std::string& url) { From dc154f39070353ea8853bc3430fe1d7231080199 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 19:59:25 +0800 Subject: [PATCH 9/9] Disable the detachment of devtools. --- browser/devtools_delegate.cc | 7 ++++++- browser/devtools_delegate.h | 6 ++++++ browser/native_window.cc | 24 ++++++++---------------- browser/native_window.h | 2 +- vendor/brightray | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/browser/devtools_delegate.cc b/browser/devtools_delegate.cc index 37bba54bc1..3886bfe222 100644 --- a/browser/devtools_delegate.cc +++ b/browser/devtools_delegate.cc @@ -20,6 +20,7 @@ DevToolsDelegate::DevToolsDelegate(NativeWindow* window, content::WebContents* target_web_contents) : content::WebContentsObserver(window->GetWebContents()), owner_window_(window), + delegate_(NULL), embedder_message_dispatcher_( new DevToolsEmbedderMessageDispatcher(this)) { content::WebContents* web_contents = window->GetWebContents(); @@ -78,7 +79,11 @@ void DevToolsDelegate::MoveWindow(int x, int y) { } void DevToolsDelegate::SetDockSide(const std::string& dock_side) { - owner_window_->Close(); + bool succeed = true; + if (delegate_ && + delegate_->DevToolsSetDockSide("attach-back", &succeed) && + succeed) + owner_window_->Close(); } void DevToolsDelegate::OpenInNewTab(const std::string& url) { diff --git a/browser/devtools_delegate.h b/browser/devtools_delegate.h index be0c1b298e..54e05a25b5 100644 --- a/browser/devtools_delegate.h +++ b/browser/devtools_delegate.h @@ -10,6 +10,7 @@ #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_observer.h" #include "vendor/brightray/browser/devtools_embedder_message_dispatcher.h" +#include "vendor/brightray/browser/inspectable_web_contents_delegate.h" namespace content { class DevToolsAgentHost; @@ -31,6 +32,10 @@ class DevToolsDelegate : public content::DevToolsFrontendHostDelegate, content::WebContents* target_web_contents); virtual ~DevToolsDelegate(); + void SetDelegate(brightray::InspectableWebContentsDelegate* delegate) { + delegate_ = delegate; + } + protected: // Implementations of content::DevToolsFrontendHostDelegate. virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; @@ -66,6 +71,7 @@ class DevToolsDelegate : public content::DevToolsFrontendHostDelegate, private: NativeWindow* owner_window_; + brightray::InspectableWebContentsDelegate* delegate_; scoped_refptr devtools_agent_host_; scoped_ptr devtools_client_host_; diff --git a/browser/native_window.cc b/browser/native_window.cc index 177cab7f56..85396ab7a5 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -478,26 +478,18 @@ void NativeWindow::Observe(int type, bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side, bool* succeed) { - if (dock_side != "undocked") { - // Switch to docked mode. - if (devtools_window_) { - devtools_window_->Close(); - devtools_window_.reset(); - } + if (dock_side == "undocked") { + *succeed = false; + return true; + } else { return false; } - - CloseDevTools(); - devtools_window_ = Debug(GetWebContents())->GetWeakPtr(); - return true; } -bool NativeWindow::DevToolsShow(const std::string& dock_side) { - if (dock_side != "undocked") - return false; - - devtools_window_ = Debug(GetWebContents())->GetWeakPtr(); - return true; +bool NativeWindow::DevToolsShow(std::string* dock_side) { + if (*dock_side == "undocked") + *dock_side = "bottom"; + return false; } void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, diff --git a/browser/native_window.h b/browser/native_window.h index 8a0c1ccfe4..af763ddb51 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -229,7 +229,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Implementations of brightray::InspectableWebContentsDelegate. virtual bool DevToolsSetDockSide(const std::string& dock_side, bool* succeed) OVERRIDE; - virtual bool DevToolsShow(const std::string& side) OVERRIDE; + virtual bool DevToolsShow(std::string* dock_side) OVERRIDE; // Whether window has standard frame. bool has_frame_; diff --git a/vendor/brightray b/vendor/brightray index 8111949e34..1a8afaa871 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 8111949e34a17bbeba9246494326bb891f55df34 +Subproject commit 1a8afaa87129527f2c41570ee563abb507f2337a