Home | History | Annotate | Download | only in devtools
      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 #include <vector>
     10 
     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"
     18 
     19 namespace blink {
     20 class WebDevToolsAgent;
     21 }
     22 
     23 struct GpuTaskInfo;
     24 
     25 namespace content {
     26 class RenderViewImpl;
     27 
     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 {
     35  public:
     36   explicit DevToolsAgent(RenderViewImpl* render_view);
     37   virtual ~DevToolsAgent();
     38 
     39   // Returns agent instance for its host id.
     40   static DevToolsAgent* FromHostId(int host_id);
     41 
     42   blink::WebDevToolsAgent* GetWebAgent();
     43 
     44   bool IsAttached();
     45 
     46  private:
     47   // RenderView::Observer implementation.
     48   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     49 
     50   // WebDevToolsAgentClient implementation
     51   virtual void sendMessageToInspectorFrontend(const blink::WebString& data);
     52 
     53   virtual int hostIdentifier();
     54   virtual void saveAgentRuntimeState(const blink::WebString& state);
     55   virtual blink::WebDevToolsAgentClient::WebKitClientMessageLoop*
     56       createClientMessageLoop();
     57   virtual void clearBrowserCache();
     58   virtual void clearBrowserCookies();
     59   virtual void visitAllocatedObjects(AllocatedObjectVisitor* visitor);
     60 
     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 setTraceEventCallback(TraceEventCallback cb) OVERRIDE;
     67   virtual void startGPUEventsRecording() OVERRIDE;
     68   virtual void stopGPUEventsRecording() OVERRIDE;
     69 
     70   virtual void enableDeviceEmulation(
     71       const blink::WebRect& device_rect,
     72       const blink::WebRect& view_rect, float device_scale_factor,
     73       bool fit_to_view);
     74   virtual void disableDeviceEmulation();
     75 
     76   void OnAttach();
     77   void OnReattach(const std::string& agent_state);
     78   void OnDetach();
     79   void OnDispatchOnInspectorBackend(const std::string& message);
     80   void OnInspectElement(int x, int y);
     81   void OnAddMessageToConsole(ConsoleMessageLevel level,
     82                              const std::string& message);
     83   void OnGpuTasksChunk(const std::vector<GpuTaskInfo>& tasks);
     84   void ContinueProgram();
     85   void OnSetupDevToolsClient();
     86 
     87   static void TraceEventCallbackWrapper(
     88       base::TimeTicks timestamp,
     89       char phase,
     90       const unsigned char* category_group_enabled,
     91       const char* name,
     92       unsigned long long id,
     93       int num_args,
     94       const char* const arg_names[],
     95       const unsigned char arg_types[],
     96       const unsigned long long arg_values[],
     97       unsigned char flags);
     98 
     99   bool is_attached_;
    100   bool is_devtools_client_;
    101   int32 gpu_route_id_;
    102 
    103   static base::subtle::AtomicWord /* TraceEventCallback */ event_callback_;
    104 
    105   DISALLOW_COPY_AND_ASSIGN(DevToolsAgent);
    106 };
    107 
    108 }  // namespace content
    109 
    110 #endif  // CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_H_
    111