electron/atom/browser/api/atom_api_debugger.h

79 lines
2.2 KiB
C
Raw Normal View History

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.
#ifndef ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_
#define ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_
#include <map>
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "atom/common/promise_util.h"
2016-01-21 18:22:23 +00:00
#include "base/callback.h"
#include "base/values.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/web_contents_observer.h"
2016-01-21 18:22:23 +00:00
#include "native_mate/handle.h"
namespace content {
class DevToolsAgentHost;
class WebContents;
2018-04-18 01:44:10 +00:00
} // namespace content
2016-01-21 18:22:23 +00:00
namespace mate {
class Arguments;
}
namespace atom {
namespace api {
2018-04-18 01:44:10 +00:00
class Debugger : public mate::TrackableObject<Debugger>,
public content::DevToolsAgentHostClient,
public content::WebContentsObserver {
2016-01-21 18:22:23 +00:00
public:
2018-04-18 01:44:10 +00:00
static mate::Handle<Debugger> Create(v8::Isolate* isolate,
content::WebContents* web_contents);
2016-01-21 18:22:23 +00:00
// mate::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
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:
void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
2016-01-21 18:22:23 +00:00
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
const std::string& message) override;
// content::WebContentsObserver:
void RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
content::RenderFrameHost* new_rfh) override;
2016-01-21 18:22:23 +00:00
private:
using PendingRequestMap = std::map<int, scoped_refptr<atom::util::Promise>>;
2016-01-21 18:22:23 +00:00
void Attach(mate::Arguments* args);
2016-01-22 08:47:23 +00:00
bool IsAttached();
2016-01-21 18:22:23 +00:00
void Detach();
v8::Local<v8::Promise> SendCommand(mate::Arguments* args);
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_;
int previous_request_id_ = 0;
2016-01-21 18:22:23 +00:00
DISALLOW_COPY_AND_ASSIGN(Debugger);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_DEBUGGER_H_