2020-06-13 02:54:08 +02:00
|
|
|
// Copyright (c) 2020 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_CONTROLLER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_CONTROLLER_H_
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "base/containers/span.h"
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2020-06-13 02:54:08 +02:00
|
|
|
#include "base/memory/scoped_refptr.h"
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "base/observer_list.h"
|
|
|
|
#include "base/values.h"
|
2024-04-23 22:06:00 +02:00
|
|
|
#include "content/public/browser/devtools_agent_host_client.h"
|
2020-06-13 02:54:08 +02:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class WebContents;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CefDevToolsController : public content::DevToolsAgentHostClient {
|
|
|
|
public:
|
|
|
|
class Observer : public base::CheckedObserver {
|
|
|
|
public:
|
|
|
|
// See CefDevToolsMessageObserver documentation.
|
2024-04-23 22:06:00 +02:00
|
|
|
virtual bool OnDevToolsMessage(const std::string_view& message) = 0;
|
2020-06-13 02:54:08 +02:00
|
|
|
virtual void OnDevToolsMethodResult(int message_id,
|
|
|
|
bool success,
|
2024-04-23 22:06:00 +02:00
|
|
|
const std::string_view& result) = 0;
|
|
|
|
virtual void OnDevToolsEvent(const std::string_view& method,
|
|
|
|
const std::string_view& params) = 0;
|
2020-06-13 02:54:08 +02:00
|
|
|
virtual void OnDevToolsAgentAttached() = 0;
|
|
|
|
virtual void OnDevToolsAgentDetached() = 0;
|
|
|
|
|
|
|
|
virtual void OnDevToolsControllerDestroyed() = 0;
|
|
|
|
|
|
|
|
protected:
|
2024-01-20 23:48:57 +01:00
|
|
|
~Observer() override = default;
|
2020-06-13 02:54:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// |inspected_contents| will outlive this object.
|
|
|
|
explicit CefDevToolsController(content::WebContents* inspected_contents);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefDevToolsController(const CefDevToolsController&) = delete;
|
|
|
|
CefDevToolsController& operator=(const CefDevToolsController&) = delete;
|
|
|
|
|
2020-06-13 02:54:08 +02:00
|
|
|
~CefDevToolsController() override;
|
|
|
|
|
|
|
|
// See CefBrowserHost methods of the same name for documentation.
|
2024-04-23 22:06:00 +02:00
|
|
|
bool SendDevToolsMessage(const std::string_view& message);
|
2020-06-13 02:54:08 +02:00
|
|
|
int ExecuteDevToolsMethod(int message_id,
|
|
|
|
const std::string& method,
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value::Dict* params);
|
2020-06-13 02:54:08 +02:00
|
|
|
|
|
|
|
// |observer| must outlive this object or be removed.
|
|
|
|
void AddObserver(Observer* observer);
|
|
|
|
void RemoveObserver(Observer* observer);
|
|
|
|
|
|
|
|
base::WeakPtr<CefDevToolsController> GetWeakPtr() {
|
|
|
|
return weak_ptr_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// content::DevToolsAgentHostClient implementation:
|
|
|
|
void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
|
|
|
|
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
|
|
|
|
base::span<const uint8_t> message) override;
|
|
|
|
|
|
|
|
bool EnsureAgentHost();
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
const raw_ptr<content::WebContents> inspected_contents_;
|
2020-06-13 02:54:08 +02:00
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
|
|
|
int next_message_id_ = 1;
|
|
|
|
|
|
|
|
base::ObserverList<Observer> observers_;
|
|
|
|
|
|
|
|
base::WeakPtrFactory<CefDevToolsController> weak_ptr_factory_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_CONTROLLER_H_
|