electron/atom/browser/devtools_delegate.cc

125 lines
3.6 KiB
C++
Raw Normal View History

2014-02-24 03:53:13 +00:00
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
2014-02-24 03:53:13 +00:00
// found in the LICENSE file.
2014-03-16 00:30:26 +00:00
#include "atom/browser/devtools_delegate.h"
2014-02-24 03:53:13 +00:00
#include <string>
2014-03-04 11:02:48 +00:00
#include "base/message_loop/message_loop.h"
2014-02-24 03:53:13 +00:00
#include "base/values.h"
2014-03-16 00:30:26 +00:00
#include "atom/browser/native_window.h"
2014-02-24 03:53:13 +00:00
#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"
#include "ui/gfx/point.h"
2014-02-24 03:53:13 +00:00
namespace atom {
DevToolsDelegate::DevToolsDelegate(NativeWindow* window,
content::WebContents* target_web_contents)
: content::WebContentsObserver(window->GetWebContents()),
owner_window_(window),
2014-03-04 11:59:25 +00:00
delegate_(NULL),
embedder_message_dispatcher_(
new DevToolsEmbedderMessageDispatcher(this)) {
2014-02-24 03:53:13 +00:00
content::WebContents* web_contents = window->GetWebContents();
// Setup devtools.
devtools_agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(
target_web_contents->GetRenderViewHost());
devtools_client_host_.reset(
content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents,
this));
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
devtools_agent_host_.get(), devtools_client_host_.get());
// Go!
base::DictionaryValue options;
options.SetString("title", "DevTools Debugger");
window->InitFromOptions(&options);
2014-03-04 11:02:48 +00:00
window->AddObserver(this);
2014-02-24 03:53:13 +00:00
web_contents->GetController().LoadURL(
GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"),
2014-02-24 03:53:13 +00:00
content::Referrer(),
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
}
DevToolsDelegate::~DevToolsDelegate() {
}
void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) {
embedder_message_dispatcher_->Dispatch(message);
2014-02-24 03:53:13 +00:00
}
void DevToolsDelegate::InspectedContentsClosing() {
2014-03-04 11:02:48 +00:00
owner_window_->Close();
2014-02-24 03:53:13 +00:00
}
void DevToolsDelegate::AboutToNavigateRenderView(
content::RenderViewHost* render_view_host) {
content::DevToolsClientHost::SetupDevToolsFrontendClient(
owner_window_->GetWebContents()->GetRenderViewHost());
}
void DevToolsDelegate::OnWindowClosed() {
2014-03-04 11:02:48 +00:00
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) {
2014-03-04 11:59:25 +00:00
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) {
}
2014-02-24 03:53:13 +00:00
} // namespace atom