atom_api_debugger.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_
  5. #define ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_
  6. #include <map>
  7. #include <string>
  8. #include "atom/browser/api/trackable_object.h"
  9. #include "base/callback.h"
  10. #include "base/values.h"
  11. #include "content/public/browser/devtools_agent_host_client.h"
  12. #include "native_mate/handle.h"
  13. namespace content {
  14. class DevToolsAgentHost;
  15. class WebContents;
  16. } // namespace content
  17. namespace mate {
  18. class Arguments;
  19. }
  20. namespace atom {
  21. namespace api {
  22. class Debugger : public mate::TrackableObject<Debugger>,
  23. public content::DevToolsAgentHostClient {
  24. public:
  25. using SendCommandCallback =
  26. base::Callback<void(const base::DictionaryValue&,
  27. const base::DictionaryValue&)>;
  28. static mate::Handle<Debugger> Create(v8::Isolate* isolate,
  29. content::WebContents* web_contents);
  30. // mate::TrackableObject:
  31. static void BuildPrototype(v8::Isolate* isolate,
  32. v8::Local<v8::FunctionTemplate> prototype);
  33. protected:
  34. Debugger(v8::Isolate* isolate, content::WebContents* web_contents);
  35. ~Debugger() override;
  36. // content::DevToolsAgentHostClient:
  37. void AgentHostClosed(content::DevToolsAgentHost* agent_host,
  38. bool replaced_with_another_client) override;
  39. void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
  40. const std::string& message) override;
  41. private:
  42. using PendingRequestMap = std::map<int, SendCommandCallback>;
  43. void Attach(mate::Arguments* args);
  44. bool IsAttached();
  45. void Detach();
  46. void SendCommand(mate::Arguments* args);
  47. content::WebContents* web_contents_; // Weak Reference.
  48. scoped_refptr<content::DevToolsAgentHost> agent_host_;
  49. PendingRequestMap pending_requests_;
  50. int previous_request_id_ = 0;
  51. DISALLOW_COPY_AND_ASSIGN(Debugger);
  52. };
  53. } // namespace api
  54. } // namespace atom
  55. #endif // ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_