OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/browser/devtools/devtools_frontend_host.h" | |
6 | |
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" | |
13 | |
14 namespace content { | |
15 | |
16 // static | |
17 DevToolsClientHost* DevToolsClientHost::CreateDevToolsFrontendHost( | |
18 WebContents* client_web_contents, | |
19 DevToolsFrontendHostDelegate* delegate) { | |
20 return new DevToolsFrontendHost( | |
21 static_cast<WebContentsImpl*>(client_web_contents), delegate); | |
22 } | |
23 | |
24 // static | |
25 void DevToolsClientHost::SetupDevToolsFrontendClient( | |
26 RenderViewHost* frontend_rvh) { | |
27 frontend_rvh->Send(new DevToolsMsg_SetupDevToolsClient( | |
28 frontend_rvh->GetRoutingID())); | |
29 } | |
30 | |
31 DevToolsFrontendHost::DevToolsFrontendHost( | |
32 WebContentsImpl* web_contents, | |
33 DevToolsFrontendHostDelegate* delegate) | |
34 : WebContentsObserver(web_contents), | |
35 delegate_(delegate) { | |
36 } | |
37 | |
38 DevToolsFrontendHost::~DevToolsFrontendHost() { | |
39 DevToolsManager::GetInstance()->ClientHostClosing(this); | |
40 } | |
41 | |
42 void DevToolsFrontendHost::DispatchOnInspectorFrontend( | |
43 const std::string& message) { | |
44 if (!web_contents()) | |
45 return; | |
46 RenderViewHostImpl* target_host = | |
47 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); | |
48 target_host->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( | |
49 target_host->GetRoutingID(), | |
50 message)); | |
51 } | |
52 | |
53 void DevToolsFrontendHost::InspectedContentsClosing() { | |
54 delegate_->InspectedContentsClosing(); | |
55 } | |
56 | |
57 void DevToolsFrontendHost::ReplacedWithAnotherClient() { | |
58 } | |
59 | |
60 bool DevToolsFrontendHost::OnMessageReceived( | |
61 const IPC::Message& message) { | |
62 bool handled = true; | |
63 IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHost, message) | |
64 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, | |
65 OnDispatchOnInspectorBackend) | |
66 IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder, | |
67 OnDispatchOnEmbedder) | |
68 IPC_MESSAGE_UNHANDLED(handled = false) | |
69 IPC_END_MESSAGE_MAP() | |
70 return handled; | |
71 } | |
72 | |
73 void DevToolsFrontendHost::RenderProcessGone( | |
74 base::TerminationStatus status) { | |
75 switch(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); | |
80 break; | |
81 default: | |
82 break; | |
83 } | |
84 } | |
85 | |
86 void DevToolsFrontendHost::OnDispatchOnInspectorBackend( | |
87 const std::string& message) { | |
88 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorBackend(this, message); | |
89 } | |
90 | |
91 void DevToolsFrontendHost::OnDispatchOnEmbedder( | |
92 const std::string& message) { | |
93 delegate_->DispatchOnEmbedder(message); | |
94 } | |
95 | |
96 } // namespace content | |
OLD | NEW |