Use the "chrome-devtools://" scheme to open devtools.
This commit is contained in:
parent
c949fd931c
commit
9d29c8eb7c
10 changed files with 246 additions and 101 deletions
|
@ -35,8 +35,8 @@
|
|||
'browser/default_web_contents_delegate.cc',
|
||||
'browser/default_web_contents_delegate.h',
|
||||
'browser/default_web_contents_delegate_mac.mm',
|
||||
'browser/devtools_delegate.cc',
|
||||
'browser/devtools_delegate.h',
|
||||
'browser/devtools_ui.cc',
|
||||
'browser/devtools_ui.h',
|
||||
'browser/download_manager_delegate.cc',
|
||||
'browser/download_manager_delegate.h',
|
||||
'browser/inspectable_web_contents.cc',
|
||||
|
@ -66,6 +66,8 @@
|
|||
'browser/win/devtools_window.h',
|
||||
'browser/win/inspectable_web_contents_view_win.cc',
|
||||
'browser/win/inspectable_web_contents_view_win.h',
|
||||
'browser/web_ui_controller_factory.cc',
|
||||
'browser/web_ui_controller_factory.h',
|
||||
'common/application_info.h',
|
||||
'common/application_info_mac.mm',
|
||||
'common/application_info_win.cc',
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
#include "browser/browser_main_parts.h"
|
||||
|
||||
#include "browser/browser_context.h"
|
||||
#include "browser/devtools_delegate.h"
|
||||
#include "browser/web_ui_controller_factory.h"
|
||||
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "net/socket/tcp_listen_socket.h"
|
||||
|
||||
namespace brightray {
|
||||
|
@ -16,19 +15,14 @@ BrowserMainParts::BrowserMainParts() {
|
|||
}
|
||||
|
||||
BrowserMainParts::~BrowserMainParts() {
|
||||
devtools_http_handler_->Stop();
|
||||
devtools_http_handler_ = nullptr;
|
||||
}
|
||||
|
||||
void BrowserMainParts::PreMainMessageLoopRun() {
|
||||
browser_context_.reset(CreateBrowserContext());
|
||||
browser_context_->Initialize();
|
||||
|
||||
// These two objects are owned by devtools_http_handler_.
|
||||
auto delegate = new DevToolsDelegate;
|
||||
auto factory = new net::TCPListenSocketFactory("127.0.0.1", 0);
|
||||
|
||||
devtools_http_handler_ = content::DevToolsHttpHandler::Start(factory, std::string(), delegate);
|
||||
web_ui_controller_factory_.reset(new WebUIControllerFactory(browser_context_.get()));
|
||||
content::WebUIControllerFactory::RegisterFactory(web_ui_controller_factory_.get());
|
||||
}
|
||||
|
||||
BrowserContext* BrowserMainParts::CreateBrowserContext() {
|
||||
|
|
|
@ -9,13 +9,10 @@
|
|||
#include "base/memory/scoped_ptr.h"
|
||||
#include "content/public/browser/browser_main_parts.h"
|
||||
|
||||
namespace content {
|
||||
class DevToolsHttpHandler;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class BrowserContext;
|
||||
class WebUIControllerFactory;
|
||||
|
||||
class BrowserMainParts : public content::BrowserMainParts {
|
||||
public:
|
||||
|
@ -23,7 +20,6 @@ public:
|
|||
~BrowserMainParts();
|
||||
|
||||
BrowserContext* browser_context() { return browser_context_.get(); }
|
||||
content::DevToolsHttpHandler* devtools_http_handler() { return devtools_http_handler_; }
|
||||
|
||||
protected:
|
||||
// Subclasses should override this to provide their own BrowserContxt implementation. The caller
|
||||
|
@ -38,7 +34,7 @@ protected:
|
|||
|
||||
private:
|
||||
scoped_ptr<BrowserContext> browser_context_;
|
||||
content::DevToolsHttpHandler* devtools_http_handler_;
|
||||
scoped_ptr<WebUIControllerFactory> web_ui_controller_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
|
||||
};
|
||||
|
|
|
@ -1,49 +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_delegate.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
DevToolsDelegate::DevToolsDelegate() {
|
||||
}
|
||||
|
||||
DevToolsDelegate::~DevToolsDelegate() {
|
||||
}
|
||||
|
||||
std::string DevToolsDelegate::GetDiscoveryPageHTML() {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
bool DevToolsDelegate::BundlesFrontendResources() {
|
||||
return true;
|
||||
}
|
||||
|
||||
base::FilePath DevToolsDelegate::GetDebugFrontendDir() {
|
||||
return base::FilePath();
|
||||
}
|
||||
|
||||
std::string DevToolsDelegate::GetPageThumbnailData(const GURL&) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
content::RenderViewHost* DevToolsDelegate::CreateNewTarget() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::DevToolsHttpHandlerDelegate::TargetType DevToolsDelegate::GetTargetType(content::RenderViewHost*) {
|
||||
return kTargetTypeTab;
|
||||
}
|
||||
|
||||
std::string DevToolsDelegate::GetViewDescription(content::RenderViewHost*) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
scoped_refptr<net::StreamListenSocket> DevToolsDelegate::CreateSocketForTethering(
|
||||
net::StreamListenSocket::Delegate*,
|
||||
std::string* name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +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_DELEGATE_H_
|
||||
#define BRIGHTRAY_BROWSER_DEVTOOLS_DELEGATE_H_
|
||||
|
||||
#include "content/public/browser/devtools_http_handler_delegate.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
|
||||
public:
|
||||
DevToolsDelegate();
|
||||
~DevToolsDelegate();
|
||||
|
||||
private:
|
||||
virtual std::string GetDiscoveryPageHTML() OVERRIDE;
|
||||
virtual bool BundlesFrontendResources() OVERRIDE;
|
||||
virtual base::FilePath GetDebugFrontendDir() OVERRIDE;
|
||||
virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE;
|
||||
virtual content::RenderViewHost* CreateNewTarget() OVERRIDE;
|
||||
virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE;
|
||||
virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE;
|
||||
virtual scoped_refptr<net::StreamListenSocket> CreateSocketForTethering(
|
||||
net::StreamListenSocket::Delegate*,
|
||||
std::string* name) OVERRIDE;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
102
brightray/browser/devtools_ui.cc
Normal file
102
brightray/browser/devtools_ui.cc
Normal file
|
@ -0,0 +1,102 @@
|
|||
// 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 "browser/devtools_ui.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "browser/browser_context.h"
|
||||
|
||||
#include "base/memory/ref_counted_memory.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "content/public/browser/url_data_source.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_ui.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
using content::WebContents;
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kChromeUIDevToolsBundledHost[] = "devtools";
|
||||
|
||||
std::string PathWithoutParams(const std::string& path) {
|
||||
return GURL(std::string("chrome-devtools://devtools/") + path)
|
||||
.path().substr(1);
|
||||
}
|
||||
|
||||
std::string GetMimeTypeForPath(const std::string& path) {
|
||||
std::string filename = PathWithoutParams(path);
|
||||
if (EndsWith(filename, ".html", false)) {
|
||||
return "text/html";
|
||||
} else if (EndsWith(filename, ".css", false)) {
|
||||
return "text/css";
|
||||
} else if (EndsWith(filename, ".js", false)) {
|
||||
return "application/javascript";
|
||||
} else if (EndsWith(filename, ".png", false)) {
|
||||
return "image/png";
|
||||
} else if (EndsWith(filename, ".gif", false)) {
|
||||
return "image/gif";
|
||||
} else if (EndsWith(filename, ".manifest", false)) {
|
||||
return "text/cache-manifest";
|
||||
}
|
||||
NOTREACHED();
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
class BundledDataSource : public content::URLDataSource {
|
||||
public:
|
||||
explicit BundledDataSource() {
|
||||
}
|
||||
|
||||
// content::URLDataSource implementation.
|
||||
virtual std::string GetSource() const OVERRIDE {
|
||||
return kChromeUIDevToolsBundledHost;
|
||||
}
|
||||
|
||||
virtual void StartDataRequest(const std::string& path,
|
||||
int render_process_id,
|
||||
int render_view_id,
|
||||
const GotDataCallback& callback) OVERRIDE {
|
||||
std::string filename = PathWithoutParams(path);
|
||||
|
||||
int resource_id =
|
||||
content::DevToolsHttpHandler::GetFrontendResourceId(filename);
|
||||
|
||||
DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: "
|
||||
<< filename << ". If you compiled with debug_devtools=1, try running"
|
||||
" with --debug-devtools.";
|
||||
const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
||||
scoped_refptr<base::RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(
|
||||
resource_id));
|
||||
callback.Run(bytes);
|
||||
}
|
||||
|
||||
virtual std::string GetMimeType(const std::string& path) const OVERRIDE {
|
||||
return GetMimeTypeForPath(path);
|
||||
}
|
||||
|
||||
virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE {
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~BundledDataSource() {}
|
||||
DISALLOW_COPY_AND_ASSIGN(BundledDataSource);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
DevToolsUI::DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui)
|
||||
: WebUIController(web_ui),
|
||||
browser_context_(browser_context) {
|
||||
web_ui->SetBindings(0);
|
||||
content::URLDataSource::Add(browser_context_, new BundledDataSource());
|
||||
}
|
||||
|
||||
}
|
28
brightray/browser/devtools_ui.h
Normal file
28
brightray/browser/devtools_ui.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2011 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_UI_H_
|
||||
#define BRIGHTRAY_BROWSER_DEVTOOLS_UI_H_
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/browser/web_ui_controller.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class BrowserContext;
|
||||
|
||||
class DevToolsUI : public content::WebUIController {
|
||||
public:
|
||||
explicit DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui);
|
||||
|
||||
private:
|
||||
// Weak reference to the browser context.
|
||||
BrowserContext* browser_context_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DevToolsUI);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,8 +25,13 @@ namespace brightray {
|
|||
|
||||
namespace {
|
||||
|
||||
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html";
|
||||
const char kDockSidePref[] = "brightray.devtools.dockside";
|
||||
|
||||
GURL GetDevToolsURL() {
|
||||
return GURL(kChromeUIDevToolsURL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Implemented separately on each platform.
|
||||
|
@ -70,9 +75,7 @@ void InspectableWebContentsImpl::ShowDevTools() {
|
|||
agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost());
|
||||
frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this));
|
||||
|
||||
auto handler = BrowserClient::Get()->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());
|
||||
devtools_web_contents_->GetController().LoadURL(GetDevToolsURL(), content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
||||
}
|
||||
|
||||
view_->SetDockSide(dock_side_);
|
||||
|
|
59
brightray/browser/web_ui_controller_factory.cc
Normal file
59
brightray/browser/web_ui_controller_factory.cc
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright (c) 2013 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 "browser/web_ui_controller_factory.h"
|
||||
|
||||
#include "browser/browser_context.h"
|
||||
#include "browser/devtools_ui.h"
|
||||
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_ui.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kChromeUIDevToolsBundledHost[] = "devtools";
|
||||
|
||||
}
|
||||
|
||||
WebUIControllerFactory::WebUIControllerFactory(BrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
DCHECK(browser_context_);
|
||||
}
|
||||
|
||||
WebUIControllerFactory::~WebUIControllerFactory() {
|
||||
}
|
||||
|
||||
content::WebUI::TypeID WebUIControllerFactory::GetWebUIType(
|
||||
content::BrowserContext* browser_context, const GURL& url) const {
|
||||
if (url.host() == kChromeUIDevToolsBundledHost) {
|
||||
return const_cast<WebUIControllerFactory*>(this);
|
||||
}
|
||||
|
||||
return content::WebUI::kNoWebUI;
|
||||
}
|
||||
|
||||
bool WebUIControllerFactory::UseWebUIForURL(
|
||||
content::BrowserContext* browser_context, const GURL& url) const {
|
||||
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
|
||||
}
|
||||
|
||||
bool WebUIControllerFactory::UseWebUIBindingsForURL(
|
||||
content::BrowserContext* browser_context, const GURL& url) const {
|
||||
return UseWebUIForURL(browser_context, url);
|
||||
}
|
||||
|
||||
content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL(
|
||||
content::WebUI* web_ui, const GURL& url) const {
|
||||
DCHECK(browser_context_);
|
||||
|
||||
if (url.host() == kChromeUIDevToolsBundledHost)
|
||||
return new DevToolsUI(browser_context_, web_ui);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
42
brightray/browser/web_ui_controller_factory.h
Normal file
42
brightray/browser/web_ui_controller_factory.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) 2013 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_WEB_UI_CONTROLLER_FACTORY_H_
|
||||
#define BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "content/public/browser/web_ui.h"
|
||||
#include "content/public/browser/web_ui_controller_factory.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class BrowserContext;
|
||||
|
||||
class WebUIControllerFactory : public content::WebUIControllerFactory {
|
||||
public:
|
||||
WebUIControllerFactory(BrowserContext* browser_context);
|
||||
virtual ~WebUIControllerFactory();
|
||||
|
||||
virtual content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
|
||||
const GURL& url) const OVERRIDE;
|
||||
virtual bool UseWebUIForURL(content::BrowserContext* browser_context,
|
||||
const GURL& url) const OVERRIDE;
|
||||
virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context,
|
||||
const GURL& url) const OVERRIDE;
|
||||
virtual content::WebUIController* CreateWebUIControllerForURL(
|
||||
content::WebUI* web_ui,
|
||||
const GURL& url) const OVERRIDE;
|
||||
|
||||
static WebUIControllerFactory* GetInstance();
|
||||
|
||||
private:
|
||||
// Weak reference to the browser context.
|
||||
BrowserContext* browser_context_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebUIControllerFactory);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue