Merge InspectableWebContentsImpl and DevToolsFrontend
While this prevents clients from easily implementing their own devtools windows, it gives us much easier control over the devtools experience.
This commit is contained in:
parent
881a203b57
commit
d20ecc0e2b
5 changed files with 124 additions and 160 deletions
|
@ -28,8 +28,6 @@
|
|||
'browser/default_web_contents_delegate_mac.mm',
|
||||
'browser/devtools_delegate.cc',
|
||||
'browser/devtools_delegate.h',
|
||||
'browser/devtools_frontend.cc',
|
||||
'browser/devtools_frontend.h',
|
||||
'browser/inspectable_web_contents.cc',
|
||||
'browser/inspectable_web_contents.h',
|
||||
'browser/inspectable_web_contents_impl.cc',
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#include "devtools_frontend.h"
|
||||
|
||||
#include "browser/browser_client.h"
|
||||
#include "browser/browser_main_parts.h"
|
||||
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/devtools_client_host.h"
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "content/public/browser/devtools_manager.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
content::WebContents* DevToolsFrontend::Show(content::WebContents* inspected_contents) {
|
||||
// frontend will delete itself when the WebContents closes.
|
||||
auto frontend = new DevToolsFrontend(inspected_contents);
|
||||
|
||||
return frontend->web_contents();
|
||||
}
|
||||
|
||||
DevToolsFrontend::DevToolsFrontend(content::WebContents* inspected_contents)
|
||||
: WebContentsObserver(content::WebContents::Create(content::WebContents::CreateParams(inspected_contents->GetBrowserContext()))),
|
||||
inspected_web_contents_(inspected_contents),
|
||||
agent_host_(content::DevToolsAgentHost::GetOrCreateFor(inspected_contents->GetRenderViewHost())),
|
||||
frontend_host_(content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this)) {
|
||||
web_contents()->SetDelegate(this);
|
||||
auto client = static_cast<BrowserClient*>(content::GetContentClient()->browser());
|
||||
auto handler = client->browser_main_parts()->devtools_http_handler();
|
||||
auto url = handler->GetFrontendURL(nullptr);
|
||||
web_contents()->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
||||
}
|
||||
|
||||
DevToolsFrontend::~DevToolsFrontend() {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::ActivateWindow() {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::ChangeAttachedWindowHeight(unsigned height) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::CloseWindow() {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::MoveWindow(int x, int y) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::SetDockSide(const std::string& side) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::OpenInNewTab(const std::string& url) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::SaveToFile(const std::string& url, const std::string& content, bool save_as) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::AppendToFile(const std::string& url, const std::string& content) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::RequestFileSystems() {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::AddFileSystem() {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::RemoveFileSystem(const std::string& file_system_path) {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::InspectedContentsClosing() {
|
||||
}
|
||||
|
||||
void DevToolsFrontend::RenderViewCreated(content::RenderViewHost* render_view_host) {
|
||||
content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost());
|
||||
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get());
|
||||
}
|
||||
|
||||
void DevToolsFrontend::WebContentsDestroyed(content::WebContents*) {
|
||||
content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get());
|
||||
delete this;
|
||||
}
|
||||
|
||||
void DevToolsFrontend::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) {
|
||||
auto delegate = inspected_web_contents_->GetDelegate();
|
||||
if (delegate)
|
||||
delegate->HandleKeyboardEvent(source, event);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_FRONTEND_H_
|
||||
#define BRIGHTRAY_BROWSER_DEVTOOLS_FRONTEND_H_
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "content/public/browser/devtools_frontend_host_delegate.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
||||
namespace content {
|
||||
class DevToolsAgentHost;
|
||||
class DevToolsClientHost;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class DevToolsFrontend : content::DevToolsFrontendHostDelegate, content::WebContentsObserver, content::WebContentsDelegate {
|
||||
public:
|
||||
static content::WebContents* Show(content::WebContents* inspected_contents);
|
||||
|
||||
private:
|
||||
DevToolsFrontend(content::WebContents* inspected_contents);
|
||||
~DevToolsFrontend();
|
||||
|
||||
// content::DevToolsFrontendHostDelegate
|
||||
|
||||
virtual void ActivateWindow() OVERRIDE;
|
||||
virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE;
|
||||
virtual void CloseWindow() OVERRIDE;
|
||||
virtual void MoveWindow(int x, int y) OVERRIDE;
|
||||
virtual void SetDockSide(const std::string& 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 InspectedContentsClosing() OVERRIDE;
|
||||
|
||||
// content::WebContentsObserver
|
||||
|
||||
virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE;
|
||||
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
|
||||
|
||||
// content::WebContentsDelegate
|
||||
|
||||
virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE;
|
||||
|
||||
content::WebContents* inspected_web_contents_;
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||
scoped_ptr<content::DevToolsClientHost> frontend_host_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,8 +1,19 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#include "browser/inspectable_web_contents_impl.h"
|
||||
|
||||
#include "browser/devtools_frontend.h"
|
||||
#include "browser/browser_client.h"
|
||||
#include "browser/browser_main_parts.h"
|
||||
#include "browser/inspectable_web_contents_view.h"
|
||||
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/devtools_client_host.h"
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "content/public/browser/devtools_manager.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
// Implemented separately on each platform.
|
||||
|
@ -25,9 +36,76 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
|
|||
}
|
||||
|
||||
void InspectableWebContentsImpl::ShowDevTools() {
|
||||
if (!devtools_web_contents_)
|
||||
devtools_web_contents_.reset(DevToolsFrontend::Show(web_contents_.get()));
|
||||
if (!devtools_web_contents_) {
|
||||
devtools_web_contents_.reset(content::WebContents::Create(content::WebContents::CreateParams(web_contents_->GetBrowserContext())));
|
||||
Observe(devtools_web_contents_.get());
|
||||
devtools_web_contents_->SetDelegate(this);
|
||||
|
||||
agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost());
|
||||
frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this));
|
||||
|
||||
auto client = static_cast<BrowserClient*>(content::GetContentClient()->browser());
|
||||
auto handler = client->browser_main_parts()->devtools_http_handler();
|
||||
auto url = handler->GetFrontendURL(nullptr);
|
||||
devtools_web_contents_->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
||||
}
|
||||
|
||||
view_->ShowDevTools();
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::ActivateWindow() {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::ChangeAttachedWindowHeight(unsigned height) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::CloseWindow() {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::MoveWindow(int x, int y) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::SetDockSide(const std::string& side) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::SaveToFile(const std::string& url, const std::string& content, bool save_as) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::AppendToFile(const std::string& url, const std::string& content) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::RequestFileSystems() {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::AddFileSystem() {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::RemoveFileSystem(const std::string& file_system_path) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::InspectedContentsClosing() {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* render_view_host) {
|
||||
content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost());
|
||||
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get());
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) {
|
||||
content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get());
|
||||
Observe(nullptr);
|
||||
agent_host_ = nullptr;
|
||||
frontend_host_.reset();
|
||||
devtools_web_contents_.reset();
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) {
|
||||
auto delegate = web_contents_->GetDelegate();
|
||||
if (delegate)
|
||||
delegate->HandleKeyboardEvent(source, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,11 +3,24 @@
|
|||
|
||||
#include "browser/inspectable_web_contents.h"
|
||||
|
||||
#include "content/public/browser/devtools_frontend_host_delegate.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
||||
namespace content {
|
||||
class DevToolsAgentHost;
|
||||
class DevToolsClientHost;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class InspectableWebContentsView;
|
||||
|
||||
class InspectableWebContentsImpl : public InspectableWebContents {
|
||||
class InspectableWebContentsImpl :
|
||||
public InspectableWebContents,
|
||||
content::DevToolsFrontendHostDelegate,
|
||||
content::WebContentsObserver,
|
||||
content::WebContentsDelegate {
|
||||
public:
|
||||
InspectableWebContentsImpl(const content::WebContents::CreateParams&);
|
||||
virtual ~InspectableWebContentsImpl() OVERRIDE;
|
||||
|
@ -20,9 +33,38 @@ public:
|
|||
content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); }
|
||||
|
||||
private:
|
||||
// content::DevToolsFrontendHostDelegate
|
||||
|
||||
virtual void ActivateWindow() OVERRIDE;
|
||||
virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE;
|
||||
virtual void CloseWindow() OVERRIDE;
|
||||
virtual void MoveWindow(int x, int y) OVERRIDE;
|
||||
virtual void SetDockSide(const std::string& 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 InspectedContentsClosing() OVERRIDE;
|
||||
|
||||
// content::WebContentsObserver
|
||||
|
||||
virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE;
|
||||
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
|
||||
|
||||
// content::WebContentsDelegate
|
||||
|
||||
virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE;
|
||||
|
||||
scoped_ptr<content::WebContents> web_contents_;
|
||||
scoped_ptr<content::WebContents> devtools_web_contents_;
|
||||
scoped_ptr<InspectableWebContentsView> view_;
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||
scoped_ptr<content::DevToolsClientHost> frontend_host_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue