Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / devtools / devtools_frontend_host_impl.cc
blob67981c594ed077abb8aef04bf7ce80c7955eea16
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 namespace {
18 const char kCompatibilityScript[] = "devtools.js";
21 // static
22 DevToolsFrontendHost* DevToolsFrontendHost::Create(
23 RenderFrameHost* frontend_main_frame,
24 DevToolsFrontendHost::Delegate* delegate) {
25 return new DevToolsFrontendHostImpl(frontend_main_frame, delegate);
28 // static
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);
37 return std::string();
40 DevToolsFrontendHostImpl::DevToolsFrontendHostImpl(
41 RenderFrameHost* frontend_main_frame,
42 DevToolsFrontendHost::Delegate* delegate)
43 : WebContentsObserver(
44 WebContents::FromRenderFrameHost(frontend_main_frame)),
45 delegate_(delegate) {
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())
64 return false;
65 bool handled = true;
66 IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHostImpl, message)
67 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
68 OnDispatchOnInspectorBackend)
69 IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder,
70 OnDispatchOnEmbedder)
71 IPC_MESSAGE_UNHANDLED(handled = false)
72 IPC_END_MESSAGE_MAP()
73 return handled;
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