1 // Copyright 2014 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/browser/devtools/devtools_frontend_host_impl.h"
7 #include "content/browser/bad_message.h"
8 #include "content/common/devtools_messages.h"
9 #include "content/public/browser/navigation_entry.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/content_client.h"
13 #include "grit/devtools_resources_map.h"
18 const char kCompatibilityScript
[] = "devtools.js";
22 DevToolsFrontendHost
* DevToolsFrontendHost::Create(
23 RenderFrameHost
* frontend_main_frame
,
24 DevToolsFrontendHost::Delegate
* delegate
) {
25 return new DevToolsFrontendHostImpl(frontend_main_frame
, delegate
);
29 base::StringPiece
DevToolsFrontendHost::GetFrontendResource(
30 const std::string
& path
) {
31 for (size_t i
= 0; i
< kDevtoolsResourcesSize
; ++i
) {
32 if (path
== kDevtoolsResources
[i
].name
) {
33 return GetContentClient()->GetDataResource(
34 kDevtoolsResources
[i
].value
, ui::SCALE_FACTOR_NONE
);
40 DevToolsFrontendHostImpl::DevToolsFrontendHostImpl(
41 RenderFrameHost
* frontend_main_frame
,
42 DevToolsFrontendHost::Delegate
* delegate
)
43 : WebContentsObserver(
44 WebContents::FromRenderFrameHost(frontend_main_frame
)),
46 frontend_main_frame
->Send(new DevToolsMsg_SetupDevToolsClient(
47 frontend_main_frame
->GetRoutingID(),
48 DevToolsFrontendHost::GetFrontendResource(
49 kCompatibilityScript
).as_string()));
52 DevToolsFrontendHostImpl::~DevToolsFrontendHostImpl() {
55 void DevToolsFrontendHostImpl::BadMessageRecieved() {
56 bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(),
57 bad_message::DFH_BAD_EMBEDDER_MESSAGE
);
60 bool DevToolsFrontendHostImpl::OnMessageReceived(
61 const IPC::Message
& message
,
62 RenderFrameHost
* render_frame_host
) {
63 if (render_frame_host
!= web_contents()->GetMainFrame())
66 IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHostImpl
, message
)
67 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend
,
68 OnDispatchOnInspectorBackend
)
69 IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder
,
71 IPC_MESSAGE_UNHANDLED(handled
= false)
76 void DevToolsFrontendHostImpl::OnDispatchOnInspectorBackend(
77 const std::string
& message
) {
78 delegate_
->HandleMessageFromDevToolsFrontendToBackend(message
);
81 void DevToolsFrontendHostImpl::OnDispatchOnEmbedder(
82 const std::string
& message
) {
83 delegate_
->HandleMessageFromDevToolsFrontend(message
);
86 } // namespace content