From 1c072351212d745e4cfc9670d6aac809be18101d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 14:25:15 +0800 Subject: [PATCH] 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 3ef5bc7d1b68..7bd45ee0b63d 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 b1eb6e695b46..6d97c3aabbe8 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 569ea3f1e14b..90ea5b1d3b91 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 569ea3f1e14b9214528be09dfc2117e387c0a03f +Subproject commit 90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2