Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / devtools / devtools_frontend_host_impl.cc
blob712a9c9329cae2eb3c25f31536b120dafe84caa4
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"
15 namespace content {
17 // static
18 DevToolsFrontendHost* DevToolsFrontendHost::Create(
19 RenderFrameHost* frontend_main_frame,
20 DevToolsFrontendHost::Delegate* delegate) {
21 return new DevToolsFrontendHostImpl(frontend_main_frame, delegate);
24 // static
25 base::StringPiece DevToolsFrontendHost::GetFrontendResource(
26 const std::string& path) {
27 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) {
28 if (path == kDevtoolsResources[i].name) {
29 return GetContentClient()->GetDataResource(
30 kDevtoolsResources[i].value, ui::SCALE_FACTOR_NONE);
33 return std::string();
36 DevToolsFrontendHostImpl::DevToolsFrontendHostImpl(
37 RenderFrameHost* frontend_main_frame,
38 DevToolsFrontendHost::Delegate* delegate)
39 : WebContentsObserver(
40 WebContents::FromRenderFrameHost(frontend_main_frame)),
41 delegate_(delegate) {
42 frontend_main_frame->Send(
43 new DevToolsMsg_SetupDevToolsClient(frontend_main_frame->GetRoutingID()));
46 DevToolsFrontendHostImpl::~DevToolsFrontendHostImpl() {
49 void DevToolsFrontendHostImpl::BadMessageRecieved() {
50 bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(),
51 bad_message::DFH_BAD_EMBEDDER_MESSAGE);
54 bool DevToolsFrontendHostImpl::OnMessageReceived(
55 const IPC::Message& message,
56 RenderFrameHost* render_frame_host) {
57 if (render_frame_host != web_contents()->GetMainFrame())
58 return false;
59 bool handled = true;
60 IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHostImpl, message)
61 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
62 OnDispatchOnInspectorBackend)
63 IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder,
64 OnDispatchOnEmbedder)
65 IPC_MESSAGE_UNHANDLED(handled = false)
66 IPC_END_MESSAGE_MAP()
67 return handled;
70 void DevToolsFrontendHostImpl::OnDispatchOnInspectorBackend(
71 const std::string& message) {
72 delegate_->HandleMessageFromDevToolsFrontendToBackend(message);
75 void DevToolsFrontendHostImpl::OnDispatchOnEmbedder(
76 const std::string& message) {
77 delegate_->HandleMessageFromDevToolsFrontend(message);
80 } // namespace content