Merge pull request #195 from atom/undocked-devtools
Disable the detachment of devtools
This commit is contained in:
commit
abc6e1e289
6 changed files with 167 additions and 37 deletions
|
@ -417,7 +417,8 @@ void Window::InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
// static
|
||||
void Window::DebugDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
self->window_->DebugDevTools();
|
||||
if (self->window_->IsDevToolsOpened())
|
||||
NativeWindow::Debug(self->window_->GetDevToolsWebContents());
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -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"
|
||||
|
@ -11,13 +12,17 @@
|
|||
#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),
|
||||
delegate_(NULL),
|
||||
embedder_message_dispatcher_(
|
||||
new DevToolsEmbedderMessageDispatcher(this)) {
|
||||
content::WebContents* web_contents = window->GetWebContents();
|
||||
|
||||
// Setup devtools.
|
||||
|
@ -33,8 +38,9 @@ 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"),
|
||||
GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"),
|
||||
content::Referrer(),
|
||||
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
||||
std::string());
|
||||
|
@ -44,10 +50,11 @@ DevToolsDelegate::~DevToolsDelegate() {
|
|||
}
|
||||
|
||||
void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) {
|
||||
embedder_message_dispatcher_->Dispatch(message);
|
||||
}
|
||||
|
||||
void DevToolsDelegate::InspectedContentsClosing() {
|
||||
delete owner_window_;
|
||||
owner_window_->Close();
|
||||
}
|
||||
|
||||
void DevToolsDelegate::AboutToNavigateRenderView(
|
||||
|
@ -57,7 +64,59 @@ void DevToolsDelegate::AboutToNavigateRenderView(
|
|||
}
|
||||
|
||||
void DevToolsDelegate::OnWindowClosed() {
|
||||
delete owner_window_;
|
||||
base::MessageLoop::current()->DeleteSoon(FROM_HERE, 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) {
|
||||
bool succeed = true;
|
||||
if (delegate_ &&
|
||||
delegate_->DevToolsSetDockSide("attach-back", &succeed) &&
|
||||
succeed)
|
||||
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
|
||||
|
|
|
@ -9,24 +9,33 @@
|
|||
#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"
|
||||
#include "vendor/brightray/browser/inspectable_web_contents_delegate.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);
|
||||
virtual ~DevToolsDelegate();
|
||||
|
||||
void SetDelegate(brightray::InspectableWebContentsDelegate* delegate) {
|
||||
delegate_ = delegate;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Implementations of content::DevToolsFrontendHostDelegate.
|
||||
virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
|
||||
|
@ -39,11 +48,34 @@ 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_;
|
||||
brightray::InspectableWebContentsDelegate* delegate_;
|
||||
|
||||
scoped_refptr<content::DevToolsAgentHost> devtools_agent_host_;
|
||||
scoped_ptr<content::DevToolsClientHost> devtools_client_host_;
|
||||
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate);
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <string>
|
||||
|
||||
#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),
|
||||
|
@ -66,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);
|
||||
|
||||
|
@ -95,6 +102,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.
|
||||
|
@ -166,15 +181,22 @@ bool NativeWindow::HasModalDialog() {
|
|||
}
|
||||
|
||||
void NativeWindow::OpenDevTools() {
|
||||
inspectable_web_contents()->ShowDevTools();
|
||||
if (devtools_window_)
|
||||
devtools_window_->Focus(true);
|
||||
else
|
||||
inspectable_web_contents()->ShowDevTools();
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -185,16 +207,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();
|
||||
}
|
||||
|
@ -283,10 +295,7 @@ content::WebContents* NativeWindow::GetWebContents() const {
|
|||
}
|
||||
|
||||
content::WebContents* NativeWindow::GetDevToolsWebContents() const {
|
||||
brightray::InspectableWebContentsImpl* inspectable_web_contents_impl =
|
||||
static_cast<brightray::InspectableWebContentsImpl*>(
|
||||
inspectable_web_contents());
|
||||
return inspectable_web_contents_impl->devtools_web_contents();
|
||||
return inspectable_web_contents()->devtools_web_contents();
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowClosed() {
|
||||
|
@ -467,6 +476,22 @@ void NativeWindow::Observe(int type,
|
|||
}
|
||||
}
|
||||
|
||||
bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side,
|
||||
bool* succeed) {
|
||||
if (dock_side == "undocked") {
|
||||
*succeed = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeWindow::DevToolsShow(std::string* dock_side) {
|
||||
if (*dock_side == "undocked")
|
||||
*dock_side = "bottom";
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
|
||||
bool succeed,
|
||||
const SkBitmap& bitmap) {
|
||||
|
|
|
@ -14,19 +14,16 @@
|
|||
#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_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;
|
||||
|
@ -49,6 +46,7 @@ class DevToolsDelegate;
|
|||
struct DraggableRegion;
|
||||
|
||||
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||
public brightray::InspectableWebContentsDelegate,
|
||||
public content::WebContentsObserver,
|
||||
public content::NotificationObserver {
|
||||
public:
|
||||
|
@ -76,13 +74,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);
|
||||
|
||||
|
@ -129,9 +133,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();
|
||||
|
@ -152,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<NativeWindow> GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
content::WebContents* GetWebContents() const;
|
||||
content::WebContents* GetDevToolsWebContents() const;
|
||||
|
||||
|
@ -174,8 +179,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<brightray::InspectableWebContentsImpl*>(
|
||||
inspectable_web_contents_.get());
|
||||
}
|
||||
|
||||
void NotifyWindowClosed();
|
||||
|
@ -220,6 +226,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(std::string* dock_side) OVERRIDE;
|
||||
|
||||
// Whether window has standard frame.
|
||||
bool has_frame_;
|
||||
|
||||
|
@ -260,6 +271,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
|
||||
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||
|
||||
base::WeakPtr<NativeWindow> devtools_window_;
|
||||
|
||||
scoped_ptr<DevToolsDelegate> devtools_delegate_;
|
||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 569ea3f1e14b9214528be09dfc2117e387c0a03f
|
||||
Subproject commit 1a8afaa87129527f2c41570ee563abb507f2337a
|
Loading…
Reference in a new issue