summaryrefslogtreecommitdiffstats
path: root/content/renderer/devtools/devtools_client.cc
blob: d0a55b29b6ca5458aaba2dc1d0229aa877feec1b (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// 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 file.

#include "content/renderer/devtools/devtools_client.h"

#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "content/common/devtools_messages.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontend.h"
#include "third_party/WebKit/public/platform/WebFloatPoint.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "ui/base/ui_base_switches.h"
#include "webkit/common/appcache/appcache_interfaces.h"

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

namespace content {

DevToolsClient::DevToolsClient(RenderViewImpl* render_view)
    : RenderViewObserver(render_view) {
  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
  web_tools_frontend_.reset(
      WebDevToolsFrontend::create(
          render_view->webview(),
          this,
          ASCIIToUTF16(command_line.GetSwitchValueASCII(switches::kLang))));
  appcache::AddSupportedScheme(chrome::kChromeDevToolsScheme);
}

DevToolsClient::~DevToolsClient() {
}

bool DevToolsClient::OnMessageReceived(const IPC::Message& message) {
  DCHECK(RenderThreadImpl::current());

  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(DevToolsClient, message)
    IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
                        OnDispatchOnInspectorFrontend)
    IPC_MESSAGE_UNHANDLED(handled = false);
  IPC_END_MESSAGE_MAP()

  return handled;
}

void DevToolsClient::sendMessageToBackend(const WebString& message)  {
  Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(routing_id(),
                                                       message.utf8()));
}

void DevToolsClient::activateWindow() {
  Send(new DevToolsHostMsg_ActivateWindow(routing_id()));
}

void DevToolsClient::changeAttachedWindowHeight(unsigned height) {
  Send(new DevToolsHostMsg_ChangeAttachedWindowHeight(routing_id(), height));
}

void DevToolsClient::closeWindow() {
  Send(new DevToolsHostMsg_CloseWindow(routing_id()));
}

void DevToolsClient::moveWindowBy(const WebKit::WebFloatPoint& offset) {
  Send(new DevToolsHostMsg_MoveWindow(routing_id(), offset.x, offset.y));
}

void DevToolsClient::requestSetDockSide(const WebKit::WebString& side) {
  Send(new DevToolsHostMsg_RequestSetDockSide(routing_id(), side.utf8()));
}

void DevToolsClient::openInNewTab(const WebKit::WebString& url) {
  Send(new DevToolsHostMsg_OpenInNewTab(routing_id(),
                                        url.utf8()));
}

void DevToolsClient::save(const WebKit::WebString& url,
                          const WebKit::WebString& content,
                          bool save_as) {
  Send(new DevToolsHostMsg_Save(routing_id(),
                                url.utf8(),
                                content.utf8(),
                                save_as));
}

void DevToolsClient::append(const WebKit::WebString& url,
                            const WebKit::WebString& content) {
  Send(new DevToolsHostMsg_Append(routing_id(),
                                  url.utf8(),
                                  content.utf8()));
}

void DevToolsClient::requestFileSystems() {
  Send(new DevToolsHostMsg_RequestFileSystems(routing_id()));
}

void DevToolsClient::addFileSystem() {
  Send(new DevToolsHostMsg_AddFileSystem(routing_id()));
}

void DevToolsClient::removeFileSystem(const WebString& fileSystemPath) {
  Send(new DevToolsHostMsg_RemoveFileSystem(routing_id(),
                                            fileSystemPath.utf8()));
}

bool DevToolsClient::isUnderTest() {
  return RenderThreadImpl::current()->layout_test_mode();
}

void DevToolsClient::OnDispatchOnInspectorFrontend(const std::string& message) {
  web_tools_frontend_->dispatchOnInspectorFrontend(
      WebString::fromUTF8(message));
}

}  // namespace content