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/devtools_client.h"
7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/common/devtools_messages.h"
11 #include "content/public/common/content_switches.h"
12 #include "content/public/common/url_constants.h"
13 #include "content/renderer/render_thread_impl.h"
14 #include "content/renderer/render_view_impl.h"
15 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
16 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/web/WebDevToolsFrontend.h"
18 #include "ui/base/ui_base_switches.h"
20 using blink::WebDevToolsFrontend
;
21 using blink::WebString
;
25 DevToolsClient::DevToolsClient(
26 RenderFrame
* main_render_frame
,
27 const std::string
& compatibility_script
)
28 : RenderFrameObserver(main_render_frame
),
29 compatibility_script_(compatibility_script
) {
30 const base::CommandLine
& command_line
=
31 *base::CommandLine::ForCurrentProcess();
32 web_tools_frontend_
.reset(WebDevToolsFrontend::create(
33 main_render_frame
->GetRenderView()->GetWebView(), this,
34 base::ASCIIToUTF16(command_line
.GetSwitchValueASCII(switches::kLang
))));
37 DevToolsClient::~DevToolsClient() {
40 void DevToolsClient::DidClearWindowObject() {
41 if (!compatibility_script_
.empty())
42 render_frame()->ExecuteJavaScript(base::UTF8ToUTF16(compatibility_script_
));
45 void DevToolsClient::sendMessageToBackend(const WebString
& message
) {
46 Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(routing_id(),
50 void DevToolsClient::sendMessageToEmbedder(const WebString
& message
) {
51 Send(new DevToolsHostMsg_DispatchOnEmbedder(routing_id(),
55 bool DevToolsClient::isUnderTest() {
56 return RenderThreadImpl::current()->layout_test_mode();
59 } // namespace content