- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / devtools / devtools_external_agent_proxy_impl.cc
1 // Copyright (c) 2013 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_external_agent_proxy_impl.h"
6
7 #include "content/browser/devtools/devtools_agent_host_impl.h"
8 #include "content/browser/devtools/devtools_manager_impl.h"
9 #include "content/public/browser/devtools_external_agent_proxy_delegate.h"
10
11 namespace content {
12
13 class DevToolsExternalAgentProxyImpl::ForwardingAgentHost
14     : public DevToolsAgentHostImpl {
15  public:
16   ForwardingAgentHost(DevToolsExternalAgentProxyDelegate* delegate)
17       : delegate_(delegate) {
18   }
19
20   void ConnectionClosed() {
21     NotifyCloseListener();
22   }
23
24  private:
25   virtual ~ForwardingAgentHost() {
26   }
27
28   // DevToolsAgentHostImpl implementation.
29   virtual void Attach() OVERRIDE {
30     delegate_->Attach();
31   };
32
33   virtual void Detach() OVERRIDE {
34     delegate_->Detach();
35   };
36
37   virtual void DispatchOnInspectorBackend(const std::string& message) OVERRIDE {
38     delegate_->SendMessageToBackend(message);
39   }
40
41   DevToolsExternalAgentProxyDelegate* delegate_;
42 };
43
44 //static
45 DevToolsExternalAgentProxy* DevToolsExternalAgentProxy::Create(
46     DevToolsExternalAgentProxyDelegate* delegate) {
47   return new DevToolsExternalAgentProxyImpl(delegate);
48 }
49
50 DevToolsExternalAgentProxyImpl::DevToolsExternalAgentProxyImpl(
51     DevToolsExternalAgentProxyDelegate* delegate)
52     : agent_host_(new ForwardingAgentHost(delegate)) {
53 }
54
55 DevToolsExternalAgentProxyImpl::~DevToolsExternalAgentProxyImpl() {
56 }
57
58 scoped_refptr<DevToolsAgentHost> DevToolsExternalAgentProxyImpl::
59     GetAgentHost() {
60   return agent_host_;
61 }
62
63 void DevToolsExternalAgentProxyImpl::DispatchOnClientHost(
64     const std::string& message) {
65   DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
66       agent_host_.get(), message);
67 }
68
69 void DevToolsExternalAgentProxyImpl::ConnectionClosed() {
70   agent_host_->ConnectionClosed();
71 }
72
73 }  // content