2016-01-22 04:57:25 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
2016-01-21 18:22:23 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_API_ATOM_API_DEBUGGER_H_
|
|
|
|
#define SHELL_BROWSER_API_ATOM_API_DEBUGGER_H_
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/callback.h"
|
|
|
|
#include "base/values.h"
|
|
|
|
#include "content/public/browser/devtools_agent_host_client.h"
|
2018-09-06 14:44:22 +00:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "gin/handle.h"
|
2019-11-01 06:10:32 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_helper/trackable_object.h"
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class DevToolsAgentHost;
|
|
|
|
class WebContents;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace content
|
2016-01-21 18:22:23 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
class Debugger : public gin_helper::TrackableObject<Debugger>,
|
2018-09-06 14:44:22 +00:00
|
|
|
public content::DevToolsAgentHostClient,
|
|
|
|
public content::WebContentsObserver {
|
2016-01-21 18:22:23 +00:00
|
|
|
public:
|
2019-10-25 13:03:28 +00:00
|
|
|
static gin::Handle<Debugger> Create(v8::Isolate* isolate,
|
|
|
|
content::WebContents* web_contents);
|
2016-01-21 18:22:23 +00:00
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
// gin_helper::TrackableObject:
|
2016-01-21 18:22:23 +00:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
protected:
|
2016-04-25 01:17:54 +00:00
|
|
|
Debugger(v8::Isolate* isolate, content::WebContents* web_contents);
|
|
|
|
~Debugger() override;
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
// content::DevToolsAgentHostClient:
|
2018-04-11 11:43:06 +00:00
|
|
|
void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
|
2016-01-21 18:22:23 +00:00
|
|
|
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
|
2020-01-17 18:41:52 +00:00
|
|
|
base::span<const uint8_t> message) override;
|
2016-01-21 18:22:23 +00:00
|
|
|
|
2018-09-06 14:44:22 +00:00
|
|
|
// content::WebContentsObserver:
|
|
|
|
void RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
|
|
|
|
content::RenderFrameHost* new_rfh) override;
|
|
|
|
|
2016-01-21 18:22:23 +00:00
|
|
|
private:
|
2019-08-23 00:03:28 +00:00
|
|
|
using PendingRequestMap =
|
2019-11-01 06:10:32 +00:00
|
|
|
std::map<int, gin_helper::Promise<base::DictionaryValue>>;
|
2016-01-21 18:22:23 +00:00
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
void Attach(gin_helper::Arguments* args);
|
2016-01-22 08:47:23 +00:00
|
|
|
bool IsAttached();
|
2016-01-21 18:22:23 +00:00
|
|
|
void Detach();
|
2019-10-25 13:03:28 +00:00
|
|
|
v8::Local<v8::Promise> SendCommand(gin_helper::Arguments* args);
|
2018-09-06 14:44:22 +00:00
|
|
|
void ClearPendingRequests();
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
content::WebContents* web_contents_; // Weak Reference.
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
|
|
|
|
|
|
|
PendingRequestMap pending_requests_;
|
2018-05-21 22:18:38 +00:00
|
|
|
int previous_request_id_ = 0;
|
2016-01-21 18:22:23 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Debugger);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-01-21 18:22:23 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_API_ATOM_API_DEBUGGER_H_
|