1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/devtools_client.h"
7 #include "base/command_line.h"
8 #include "base/message_loop.h"
9 #include "base/utf_string_conversions.h"
10 #include "content/common/devtools_messages.h"
11 #include "content/public/common/content_switches.h"
12 #include "content/renderer/render_thread_impl.h"
13 #include "content/renderer/render_view_impl.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontend.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
17 #include "ui/base/ui_base_switches.h"
19 using WebKit::WebDevToolsFrontend
;
20 using WebKit::WebString
;
24 DevToolsClient::DevToolsClient(RenderViewImpl
* render_view
)
25 : RenderViewObserver(render_view
) {
26 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
27 web_tools_frontend_
.reset(
28 WebDevToolsFrontend::create(
29 render_view
->webview(),
31 ASCIIToUTF16(command_line
.GetSwitchValueASCII(switches::kLang
))));
34 DevToolsClient::~DevToolsClient() {
37 bool DevToolsClient::OnMessageReceived(const IPC::Message
& message
) {
38 DCHECK(RenderThreadImpl::current());
41 IPC_BEGIN_MESSAGE_MAP(DevToolsClient
, message
)
42 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend
,
43 OnDispatchOnInspectorFrontend
)
44 IPC_MESSAGE_UNHANDLED(handled
= false);
50 void DevToolsClient::sendMessageToBackend(const WebString
& message
) {
51 Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(routing_id(),
55 void DevToolsClient::activateWindow() {
56 Send(new DevToolsHostMsg_ActivateWindow(routing_id()));
59 void DevToolsClient::closeWindow() {
60 Send(new DevToolsHostMsg_CloseWindow(routing_id()));
63 void DevToolsClient::moveWindowBy(const WebKit::WebFloatPoint
& offset
) {
64 Send(new DevToolsHostMsg_MoveWindow(routing_id(), offset
.x
, offset
.y
));
67 void DevToolsClient::requestSetDockSide(const WebKit::WebString
& side
) {
68 Send(new DevToolsHostMsg_RequestSetDockSide(routing_id(), side
.utf8()));
71 void DevToolsClient::openInNewTab(const WebKit::WebString
& url
) {
72 Send(new DevToolsHostMsg_OpenInNewTab(routing_id(),
76 void DevToolsClient::save(const WebKit::WebString
& url
,
77 const WebKit::WebString
& content
,
79 Send(new DevToolsHostMsg_Save(routing_id(),
85 void DevToolsClient::append(const WebKit::WebString
& url
,
86 const WebKit::WebString
& content
) {
87 Send(new DevToolsHostMsg_Append(routing_id(),
92 void DevToolsClient::OnDispatchOnInspectorFrontend(const std::string
& message
) {
93 web_tools_frontend_
->dispatchOnInspectorFrontend(
94 WebString::fromUTF8(message
));
97 } // namespace content