summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/devtools_client.cc
blob: 8083288aa4bcfec58a9697766b4b4994f6fbf6be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2009 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 file.

#include "chrome/renderer/devtools_client.h"

#include "app/app_switches.h"
#include "base/command_line.h"
#include "chrome/common/devtools_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/render_view.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontend.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"

using WebKit::WebDevToolsFrontend;
using WebKit::WebString;

DevToolsClient::DevToolsClient(RenderView* view)
    : render_view_(view) {
  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
  web_tools_frontend_.reset(
      WebDevToolsFrontend::create(
          view->webview(),
          this,
          WideToUTF16Hack(command_line.GetSwitchValue(switches::kLang))));
}

DevToolsClient::~DevToolsClient() {
}

void DevToolsClient::Send(const IPC::Message& tools_agent_message) {
  render_view_->Send(new ViewHostMsg_ForwardToDevToolsAgent(
      render_view_->routing_id(),
      tools_agent_message));
}

bool DevToolsClient::OnMessageReceived(const IPC::Message& message) {
  DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());

  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(DevToolsClient, message)
    IPC_MESSAGE_HANDLER(DevToolsClientMsg_RpcMessage, OnRpcMessage)
    IPC_MESSAGE_UNHANDLED(handled = false);
  IPC_END_MESSAGE_MAP()

  return handled;
}

void DevToolsClient::sendMessageToAgent(const WebString& class_name,
                                        const WebString& method_name,
                                        const WebString& param1,
                                        const WebString& param2,
                                        const WebString& param3) {
  Send(DevToolsAgentMsg_RpcMessage(
      class_name.utf8(),
      method_name.utf8(),
      param1.utf8(),
      param2.utf8(),
      param3.utf8()));
}

void DevToolsClient::sendDebuggerCommandToAgent(const WebString& command) {
  Send(DevToolsAgentMsg_DebuggerCommand(command.utf8()));
}

void DevToolsClient::sendDebuggerPauseScript() {
  Send(DevToolsAgentMsg_DebuggerPauseScript());
}

void DevToolsClient::activateWindow() {
  render_view_->Send(new ViewHostMsg_ActivateDevToolsWindow(
      render_view_->routing_id()));
}

void DevToolsClient::closeWindow() {
  render_view_->Send(new ViewHostMsg_CloseDevToolsWindow(
      render_view_->routing_id()));
}

void DevToolsClient::dockWindow() {
  render_view_->Send(new ViewHostMsg_DockDevToolsWindow(
      render_view_->routing_id()));
}

void DevToolsClient::undockWindow() {
  render_view_->Send(new ViewHostMsg_UndockDevToolsWindow(
      render_view_->routing_id()));
}

void DevToolsClient::OnRpcMessage(const std::string& class_name,
                                  const std::string& method_name,
                                  const std::string& param1,
                                  const std::string& param2,
                                  const std::string& param3) {
  web_tools_frontend_->dispatchMessageFromAgent(
      WebString::fromUTF8(class_name),
      WebString::fromUTF8(method_name),
      WebString::fromUTF8(param1),
      WebString::fromUTF8(param2),
      WebString::fromUTF8(param3));
}