From 391468ece07f0b6a64479e2aa8c364024aa45575 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 17:50:57 +0800 Subject: [PATCH] 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 dc11dd35e12c..0cd9d0198fd4 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 d8a8be529748..be0c1b298e0a 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); };