зеркало из https://github.com/electron/electron.git
Merge pull request #13 from brightray/devtools-scheme
Use "chrome-devtools://" scheme for devtools
This commit is contained in:
Коммит
8ff43b034c
|
@ -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,10 +5,7 @@
|
|||
#include "browser/browser_main_parts.h"
|
||||
|
||||
#include "browser/browser_context.h"
|
||||
#include "browser/devtools_delegate.h"
|
||||
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "net/socket/tcp_listen_socket.h"
|
||||
#include "browser/web_ui_controller_factory.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
|
@ -16,19 +13,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
|
|
@ -0,0 +1,101 @@
|
|||
// 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) {
|
||||
web_ui->SetBindings(0);
|
||||
content::URLDataSource::Add(browser_context, new BundledDataSource());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// 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:
|
||||
DISALLOW_COPY_AND_ASSIGN(DevToolsUI);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,6 +25,7 @@ namespace brightray {
|
|||
|
||||
namespace {
|
||||
|
||||
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html";
|
||||
const char kDockSidePref[] = "brightray.devtools.dockside";
|
||||
|
||||
}
|
||||
|
@ -69,10 +70,10 @@ void InspectableWebContentsImpl::ShowDevTools() {
|
|||
|
||||
agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost());
|
||||
frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this));
|
||||
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get());
|
||||
|
||||
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());
|
||||
GURL devtools_url(kChromeUIDevToolsURL);
|
||||
devtools_web_contents_->GetController().LoadURL(devtools_url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
||||
}
|
||||
|
||||
view_->SetDockSide(dock_side_);
|
||||
|
@ -141,9 +142,8 @@ void InspectableWebContentsImpl::SearchInPath(int request_id, const std::string&
|
|||
void InspectableWebContentsImpl::InspectedContentsClosing() {
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* render_view_host) {
|
||||
void InspectableWebContentsImpl::AboutToNavigateRenderView(content::RenderViewHost* render_view_host) {
|
||||
content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost());
|
||||
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get());
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::DidFinishLoad(int64, const GURL&, bool is_main_frame, content::RenderViewHost*) {
|
||||
|
|
|
@ -69,7 +69,7 @@ private:
|
|||
|
||||
// content::WebContentsObserver
|
||||
|
||||
virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE;
|
||||
virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) OVERRIDE;
|
||||
virtual void DidFinishLoad(int64 frame_id,
|
||||
const GURL& validated_url,
|
||||
bool is_main_frame,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче