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/browser/devtools/devtools_frontend_host.h"
7 #include "content/browser/devtools/devtools_manager_impl.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/common/devtools_messages.h"
11 #include "content/public/browser/devtools_client_host.h"
12 #include "content/public/browser/devtools_frontend_host_delegate.h"
17 DevToolsClientHost
* DevToolsClientHost::CreateDevToolsFrontendHost(
18 WebContents
* client_web_contents
,
19 DevToolsFrontendHostDelegate
* delegate
) {
20 return new DevToolsFrontendHost(
21 static_cast<WebContentsImpl
*>(client_web_contents
), delegate
);
25 void DevToolsClientHost::SetupDevToolsFrontendClient(
26 RenderViewHost
* frontend_rvh
) {
27 frontend_rvh
->Send(new DevToolsMsg_SetupDevToolsClient(
28 frontend_rvh
->GetRoutingID()));
31 DevToolsFrontendHost::DevToolsFrontendHost(
32 WebContentsImpl
* web_contents
,
33 DevToolsFrontendHostDelegate
* delegate
)
34 : WebContentsObserver(web_contents
),
38 DevToolsFrontendHost::~DevToolsFrontendHost() {
39 DevToolsManager::GetInstance()->ClientHostClosing(this);
42 void DevToolsFrontendHost::DispatchOnInspectorFrontend(
43 const std::string
& message
) {
46 RenderViewHostImpl
* target_host
=
47 static_cast<RenderViewHostImpl
*>(web_contents()->GetRenderViewHost());
48 target_host
->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(
49 target_host
->GetRoutingID(),
53 void DevToolsFrontendHost::InspectedContentsClosing() {
54 delegate_
->InspectedContentsClosing();
57 void DevToolsFrontendHost::ReplacedWithAnotherClient() {
60 bool DevToolsFrontendHost::OnMessageReceived(
61 const IPC::Message
& message
) {
63 IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHost
, message
)
64 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend
,
65 OnDispatchOnInspectorBackend
)
66 IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder
,
68 IPC_MESSAGE_UNHANDLED(handled
= false)
73 void DevToolsFrontendHost::RenderProcessGone(
74 base::TerminationStatus status
) {
76 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION
:
77 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED
:
78 case base::TERMINATION_STATUS_PROCESS_CRASHED
:
79 DevToolsManager::GetInstance()->ClientHostClosing(this);
86 void DevToolsFrontendHost::OnDispatchOnInspectorBackend(
87 const std::string
& message
) {
88 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorBackend(this, message
);
91 void DevToolsFrontendHost::OnDispatchOnEmbedder(
92 const std::string
& message
) {
93 delegate_
->DispatchOnEmbedder(message
);
96 } // namespace content