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 #ifndef CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_ 6 #define CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "content/public/common/console_message_level.h" 12 #include "content/public/renderer/render_view_observer.h" 13 #include "third_party/WebKit/public/web/WebDevToolsAgentClient.h" 14 15 namespace WebKit { 16 class WebDevToolsAgent; 17 } 18 19 namespace content { 20 class RenderViewImpl; 21 22 // DevToolsAgent belongs to the inspectable RenderView and provides Glue's 23 // agents with the communication capabilities. All messages from/to Glue's 24 // agents infrastructure are flowing through this communication agent. 25 // There is a corresponding DevToolsClient object on the client side. 26 class DevToolsAgent : public RenderViewObserver, 27 public WebKit::WebDevToolsAgentClient { 28 public: 29 explicit DevToolsAgent(RenderViewImpl* render_view); 30 virtual ~DevToolsAgent(); 31 32 // Returns agent instance for its host id. 33 static DevToolsAgent* FromHostId(int host_id); 34 35 WebKit::WebDevToolsAgent* GetWebAgent(); 36 37 bool IsAttached(); 38 39 private: 40 friend class DevToolsAgentFilter; 41 42 // RenderView::Observer implementation. 43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 44 45 // WebDevToolsAgentClient implementation 46 virtual void sendMessageToInspectorFrontend(const WebKit::WebString& data); 47 48 virtual int hostIdentifier(); 49 virtual void saveAgentRuntimeState(const WebKit::WebString& state); 50 virtual WebKit::WebDevToolsAgentClient::WebKitClientMessageLoop* 51 createClientMessageLoop(); 52 virtual void clearBrowserCache(); 53 virtual void clearBrowserCookies(); 54 virtual void visitAllocatedObjects(AllocatedObjectVisitor* visitor); 55 virtual void setTraceEventCallback(TraceEventCallback cb); 56 57 void OnAttach(); 58 void OnReattach(const std::string& agent_state); 59 void OnDetach(); 60 void OnDispatchOnInspectorBackend(const std::string& message); 61 void OnInspectElement(int x, int y); 62 void OnAddMessageToConsole(ConsoleMessageLevel level, 63 const std::string& message); 64 void ContinueProgram(); 65 void OnSetupDevToolsClient(); 66 67 bool is_attached_; 68 bool is_devtools_client_; 69 70 DISALLOW_COPY_AND_ASSIGN(DevToolsAgent); 71 }; 72 73 } // namespace content 74 75 #endif // CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_ 76