• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Defines the Chrome Extensions Debugger API functions for attaching debugger
6 // to the page.
7 
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_DEBUGGER_DEBUGGER_API_H_
9 #define CHROME_BROWSER_EXTENSIONS_API_DEBUGGER_DEBUGGER_API_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include "chrome/browser/extensions/chrome_extension_function.h"
15 #include "chrome/common/extensions/api/debugger.h"
16 
17 using extensions::api::debugger::Debuggee;
18 
19 // Base debugger function.
20 
21 class DevToolsTargetImpl;
22 
23 namespace base {
24 class DictionaryValue;
25 }
26 
27 namespace content {
28 class DevToolsAgentHost;
29 class WebContents;
30 }
31 
32 namespace extensions {
33 class ExtensionDevToolsClientHost;
34 
35 class DebuggerFunction : public ChromeAsyncExtensionFunction {
36  protected:
37   DebuggerFunction();
38   virtual ~DebuggerFunction();
39 
40   void FormatErrorMessage(const std::string& format);
41 
42   bool InitAgentHost();
43   bool InitClientHost();
44 
45   Debuggee debuggee_;
46   scoped_refptr<content::DevToolsAgentHost> agent_host_;
47   ExtensionDevToolsClientHost* client_host_;
48 };
49 
50 // Implements the debugger.attach() extension function.
51 class DebuggerAttachFunction : public DebuggerFunction {
52  public:
53   DECLARE_EXTENSION_FUNCTION("debugger.attach", DEBUGGER_ATTACH)
54 
55   DebuggerAttachFunction();
56 
57  protected:
58   virtual ~DebuggerAttachFunction();
59 
60   // ExtensionFunction:
61   virtual bool RunAsync() OVERRIDE;
62 };
63 
64 // Implements the debugger.detach() extension function.
65 class DebuggerDetachFunction : public DebuggerFunction {
66  public:
67   DECLARE_EXTENSION_FUNCTION("debugger.detach", DEBUGGER_DETACH)
68 
69   DebuggerDetachFunction();
70 
71  protected:
72   virtual ~DebuggerDetachFunction();
73 
74   // ExtensionFunction:
75   virtual bool RunAsync() OVERRIDE;
76 };
77 
78 // Implements the debugger.sendCommand() extension function.
79 class DebuggerSendCommandFunction : public DebuggerFunction {
80  public:
81   DECLARE_EXTENSION_FUNCTION("debugger.sendCommand", DEBUGGER_SENDCOMMAND)
82 
83   DebuggerSendCommandFunction();
84   void SendResponseBody(base::DictionaryValue* result);
85 
86  protected:
87   virtual ~DebuggerSendCommandFunction();
88 
89   // ExtensionFunction:
90   virtual bool RunAsync() OVERRIDE;
91 };
92 
93 // Implements the debugger.getTargets() extension function.
94 class DebuggerGetTargetsFunction : public DebuggerFunction {
95  public:
96   DECLARE_EXTENSION_FUNCTION("debugger.getTargets", DEBUGGER_ATTACH)
97 
98   DebuggerGetTargetsFunction();
99 
100  protected:
101   virtual ~DebuggerGetTargetsFunction();
102 
103   // ExtensionFunction:
104   virtual bool RunAsync() OVERRIDE;
105 
106  private:
107   void SendTargetList(const std::vector<DevToolsTargetImpl*>& target_list);
108 };
109 
110 }  // namespace extensions
111 
112 #endif  // CHROME_BROWSER_EXTENSIONS_API_DEBUGGER_DEBUGGER_API_H_
113