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 #ifndef CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_
6 #define CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_
11 #include "base/atomicops.h"
12 #include "base/basictypes.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "content/public/common/console_message_level.h"
16 #include "content/public/renderer/render_view_observer.h"
17 #include "third_party/WebKit/public/web/WebDevToolsAgentClient.h"
20 class WebDevToolsAgent
;
28 // DevToolsAgent belongs to the inspectable RenderView and provides Glue's
29 // agents with the communication capabilities. All messages from/to Glue's
30 // agents infrastructure are flowing through this communication agent.
31 // There is a corresponding DevToolsClient object on the client side.
32 class DevToolsAgent
: public RenderViewObserver
,
33 public base::SupportsWeakPtr
<DevToolsAgent
>,
34 public blink::WebDevToolsAgentClient
{
36 explicit DevToolsAgent(RenderViewImpl
* render_view
);
37 virtual ~DevToolsAgent();
39 // Returns agent instance for its routing id.
40 static DevToolsAgent
* FromRoutingId(int routing_id
);
42 blink::WebDevToolsAgent
* GetWebAgent();
47 // RenderView::Observer implementation.
48 virtual bool OnMessageReceived(const IPC::Message
& message
) override
;
50 // WebDevToolsAgentClient implementation
51 virtual void sendMessageToInspectorFrontend(const blink::WebString
& data
);
53 virtual long processId() override
;
54 virtual int debuggerId() override
;
55 virtual void saveAgentRuntimeState(const blink::WebString
& state
) override
;
56 virtual blink::WebDevToolsAgentClient::WebKitClientMessageLoop
*
57 createClientMessageLoop() override
;
58 virtual void willEnterDebugLoop() override
;
59 virtual void didExitDebugLoop() override
;
61 typedef void (*TraceEventCallback
)(
62 char phase
, const unsigned char*, const char* name
, unsigned long long id
,
63 int numArgs
, const char* const* argNames
, const unsigned char* argTypes
,
64 const unsigned long long* argValues
,
65 unsigned char flags
, double timestamp
);
66 virtual void resetTraceEventCallback() override
;
67 virtual void setTraceEventCallback(const blink::WebString
& category_filter
,
68 TraceEventCallback cb
) override
;
69 virtual void enableTracing(const blink::WebString
& category_filter
) override
;
70 virtual void disableTracing() override
;
71 virtual void startGPUEventsRecording() override
;
72 virtual void stopGPUEventsRecording() override
;
74 virtual void enableDeviceEmulation(
75 const blink::WebDeviceEmulationParams
& params
) override
;
76 virtual void disableDeviceEmulation() override
;
78 void OnAttach(const std::string
& host_id
);
79 void OnReattach(const std::string
& host_id
,
80 const std::string
& agent_state
);
82 void OnDispatchOnInspectorBackend(const std::string
& message
);
83 void OnInspectElement(const std::string
& host_id
, int x
, int y
);
84 void OnAddMessageToConsole(ConsoleMessageLevel level
,
85 const std::string
& message
);
86 void OnGpuTasksChunk(const std::vector
<GpuTaskInfo
>& tasks
);
87 void ContinueProgram();
88 void OnSetupDevToolsClient();
90 static void TraceEventCallbackWrapper(
91 base::TimeTicks timestamp
,
93 const unsigned char* category_group_enabled
,
95 unsigned long long id
,
97 const char* const arg_names
[],
98 const unsigned char arg_types
[],
99 const unsigned long long arg_values
[],
100 unsigned char flags
);
103 bool is_devtools_client_
;
105 bool paused_in_mouse_move_
;
107 static base::subtle::AtomicWord
/* TraceEventCallback */ event_callback_
;
109 DISALLOW_COPY_AND_ASSIGN(DevToolsAgent
);
112 } // namespace content
114 #endif // CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_