electron/shell/browser/api/electron_api_debugger.h
Charles Kerr ae0c55c0b1
refactor: inherit Observer classes privately, pt. 2 (#42237)
* refactor: use private inheritance in PushNotifications

* refactor: use private inheritance in electron::api::App

* refactor: use private inheritance in electron::api::BrowserWindow

* refactor: use private inheritance in electron::api::NativeTheme

* refactor: use private inheritance in electron::api::Tray

* refactor: use private inheritance in electron::api::Session

* refactor: use private inheritance in electron::api::WebContents

* refactor: use private inheritance in electron::api::DownloadItem

* refactor: use private inheritance in electron::api::MenuBar

* refactor: use private inheritance in ClearDataOperation

* refactor: use private inheritance in electron::api::Screen

* refactor: use private inheritance in electron::ElectronDesktopWindowTreeHostLinux

* refactor: use private inheritance in SpellCheckerHolder

* refactor: use private inheritance in electron::api::PowerMonitor

* refactor: use private inheritance in electron::api::BaseWindow

* refactor: use private inheritance in electron::api::AutoUpdater

* refactor: use private inheritance in electron::api::Menu

* refactor: use private inheritance in electron::api::NativeWindowViews

* refactor: use private inheritance in electron::ElectronBrowserClient

* refactor: use private inheritance in electron::AutofillPopupView

* refactor: use private inheritance in GtkMessageBox

* refactor: use private inheritance in electron::OffScreenRenderWidgetHostView

* refactor: use private inheritance in electron::InspectableWebContents

* refactor: use private inheritance in electron::ElectronUsbDelegate

* refactor: use private inheritance in electron::LoginHandler

* refactor: use private inheritance in WebFrameRenderer

* refactor: use private inheritance in electron::ElectronSerialDelegate

* refactor: use private inheritance in electron::ClientFrameViewLinux

* refactor: use private inheritance in electron::ElectronHidDelegate

* refactor: use private inheritance in IPCRenderer

* refactor: use private inheritance in electron::WinCaptionButtonContainer

* refactor: use private inheritance in electron::ElectronApiIPCHandlerImpl

* refactor: use private inheritance in electron::api::ServiceWorkerContext

* refactor: use private inheritance in ui::FileSelectHelper

* refactor: use private inheritance in electron::api::WebContentsView

* refactor: use private inheritance in electron::api::SimpleURLLoaderWrapper

* refactor: use private inheritance in electron::api::InAppPurchase

* refactor: use private inheritance in electron::api::Debugger

* refactor: use private inheritance in electron::ElectronWebContentsUtilityHandlerImpl

* refactor: use private inheritance in electron::OffScreenWebContentsView
2024-05-29 13:07:02 -05:00

78 lines
2.5 KiB
C++

// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_DEBUGGER_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_DEBUGGER_H_
#include <map>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/web_contents_observer.h"
#include "gin/arguments.h"
#include "gin/handle.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/common/gin_helper/promise.h"
namespace content {
class DevToolsAgentHost;
class WebContents;
} // namespace content
namespace electron::api {
class Debugger : public gin::Wrappable<Debugger>,
public gin_helper::EventEmitterMixin<Debugger>,
public content::DevToolsAgentHostClient,
private content::WebContentsObserver {
public:
static gin::Handle<Debugger> Create(v8::Isolate* isolate,
content::WebContents* web_contents);
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
const char* GetTypeName() override;
// disable copy
Debugger(const Debugger&) = delete;
Debugger& operator=(const Debugger&) = delete;
protected:
Debugger(v8::Isolate* isolate, content::WebContents* web_contents);
~Debugger() override;
// content::DevToolsAgentHostClient:
void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
base::span<const uint8_t> message) override;
// content::WebContentsObserver:
void RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
content::RenderFrameHost* new_rfh) override;
private:
using PendingRequestMap =
std::map<int, gin_helper::Promise<base::Value::Dict>>;
void Attach(gin::Arguments* args);
bool IsAttached();
void Detach();
v8::Local<v8::Promise> SendCommand(gin::Arguments* args);
void ClearPendingRequests();
raw_ptr<content::WebContents> web_contents_; // Weak Reference.
scoped_refptr<content::DevToolsAgentHost> agent_host_;
PendingRequestMap pending_requests_;
int previous_request_id_ = 0;
};
} // namespace electron::api
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_DEBUGGER_H_